JanusGraph

来源:互联网 发布:手机黄金交易软件 编辑:程序博客网 时间:2024/06/05 17:19

推荐:http://www.cnblogs.com/jiyuqi/p/7127178.html?utm_source=itdadao&utm_medium=referral
1. 配置
4.1. 示例配置
4.1.1. Cassandra+ Elasticsearch
storage.backend=cassandra
storage.hostname=localhost
index.search.backend=elasticsearch
index.search.hostname=100.100.101.1, 100.100.101.2
index.search.elasticsearch.client-only=true
4.1.2. HBase+Caching
storage.backend=hbase
storage.hostname=100.100.101.1
storage.port=2181
cache.db-cache = true
cache.db-cache-clean-wait = 20
cache.db-cache-time = 180000
cache.db-cache-size = 0.5
4.1.3. BerkeleyDB
storage.backend=berkeleyje
storage.directory=/tmp/graph
index.search.backend=elasticsearch
index.search.directory=/tmp/searchindex
index.search.elasticsearch.client-only=false
index.search.elasticsearch.local-mode=true
4.2. 使用配置
4.2.1. JanusGraphFactory
graph = JanusGraphFactory.open(‘path/to/configuration.properties’)
4.2.2. JanusGraph服务器
1. JanusGraph可以通过将JanusGraph调用嵌入到程序提供执行线程的客户机程序中来使用。
2. JanusGraph打包长时间运行的服务器进程,当启动时,允许远程客户端或逻辑运行在单独的程序中进行JanusGraph调用。这个长时间运行的服务器进程称为JanusGraph Server。
4.3. 全局配置
LOCAL:这些选项仅适用于单个JanusGraph实例,并在初始化JanusGraph实例时提供的配置中指定。
MASKABLE:本地配置文件可以为单个JanusGraph实例覆盖这些配置选项。如果本地配置文件未指定该选项,则其值将从全局JanusGraph集群配置读取。
GLOBAL:这些选项始终从集群配置读取,不能在实例的基础上覆盖。
GLOBAL_OFFLINE:像 GLOBAL一样,但是更改这些选项需要重新启动集群才能确保整个集群的值是相同的。
FIXED:像 GLOBAL一样,但是一旦JanusGraph集群被初始化,该值就不能被更改。
mgmt = graph.openManagement()
mgmt.get(‘cache.db-cache’)
// Prints the current config setting
mgmt.set(‘cache.db-cache’, true)
// Changes option
mgmt.get(‘cache.db-cache’)
// Prints ‘true’
mgmt.commit()
// Changes take effect
5.1. 定义边缘标签
5.1.1. 边缘标签多重性
MULTI:允许在任何顶点对之间使用相同标签的多个边。换句话说,该图是关于这种边缘标签的多图。边缘多重性没有约束。
简单:允许任何顶点之间的这种标签的最多一个边缘。换句话说,该图是关于标签的简单图形。确保边缘对于给定的标签和顶点对是唯一的。
MANY2ONE:允许在图形中的任何顶点上最多只有一个这样的标签的外边缘,但不会对进入边缘施加约束。边缘标签mother是
MANY2ONE多重性的例子,因为每个人至多有一个母亲,但母亲可以有多个孩子。
ONE2MANY:允许图形中任何顶点上的这种标签的最多一个进入边,但不对出局边缘施加约束。边缘标签winnerOf是ONE2MANY多重性的一个例子,因为每个比赛最多只赢得一个人,但是一个人可以赢得多个比赛。
ONE2ONE:允许图形中任何顶点上最多只有一个进入和一个输出边。边缘标签 marriedTo是因为一个人是结婚恰好一个其它人与ONE2ONE多个的例子。
mgmt = graph.openManagement()
follow = mgmt.makeEdgeLabel(‘follow’).multiplicity(MULTI).make()
mother = mgmt.makeEdgeLabel(‘mother’).multiplicity(MANY2ONE).make()
mgmt.commit()
5.2. 定义属性键
5.2.1. 属性键数据类型
Use dataType(Class) to define the data type of a property key.
支持的数据类型
5.2.2. 物业钥匙基数
基数设置:
SINGLE:每个元素最多允许一个这样的值。换句话说,键→值映射对于图中的所有元素是唯一的。属性密钥birthDate是SINGLE基数的一个例子,因为每个人都有一个出生日期。
LIST:允许每个元素的任意数量的值用于这样的键。换句话说,该密钥与允许重复值的值列表相关联。假设我们将传感器建模为图形中的顶点,则属性键sensorReading是具有LIST基数的示例,可以记录许多(可能重复的)传感器读数。
SET:允许多个值,但不包含每个元素的重复值。换句话说,密钥与一组值相关联。name如果要捕获个人的所有名称(包括昵称,少女姓名等),属性键具有SET基数。
mgmt = graph.openManagement()
birthDate = mgmt.makePropertyKey(‘birthDate’).dataType(Long.class).cardinality(Cardinality.SINGLE).make()
name = mgmt.makePropertyKey(‘name’).dataType(String.class).cardinality(Cardinality.SET).make()
sensorReading = mgmt.makePropertyKey(‘sensorReading’).dataType(Double.class).cardinality(Cardinality.LIST).make()
mgmt.commit()
5.3. 关系类型
mgmt = graph.openManagement()
if (mgmt.containsRelationType(‘name’))
name = mgmt.getPropertyKey(‘name’)
mgmt.getRelationTypes(EdgeLabel.class)
mgmt.commit()
5.4. 定义顶点标签
mgmt = graph.openManagement()
person = mgmt.makeVertexLabel(‘person’).make()
mgmt.commit()
// Create a labeled vertex
person = graph.addVertex(label, ‘person’)
// Create an unlabeled vertex
v = graph.addVertex()
graph.tx().commit()
5.5. 自动模式制作器
5.6. 更改模式元素
mgmt = graph.openManagement()
person = mgmt.makeVertexLabel(‘person’).make()
mgmt.commit()
// Create a labeled vertex
person = graph.addVertex(label, ‘person’)
// Create an unlabeled vertex
v = graph.addVertex()
graph.tx().commit()
6.Gremline
Gremlin查询是从左到右进行评估的一组操作/函数。
g.V().has(‘name’, ‘hercules’).out(‘father’).out(‘father’).values(‘name’)
g:用于当前图形遍历。
V:对于图中的所有顶点
has(‘name’, ‘hercules’):将顶点过滤到名称属性“hercules”(只有一个)的顶点。
out(‘father’):从赫拉克勒斯横渡离开的父亲边缘。
out(‘father’):从赫拉克勒斯的父亲的顶点(即木星)穿过传出的父亲的边缘。
name:获取“hercules”顶点的祖父的名称属性。