HugeGraphServer为HugeGraph图数据库提供了RESTful API接口。除了顶点和边的CRUD基本操作以外,还提供了一些遍历(traverser)方法,我们称为traverser API
。这些遍历方法实现了一些复杂的图算法,方便用户对图进行分析和挖掘。
HugeGraph支持的Traverser API包括:
使用方法中的例子,都是基于TinkerPop官网给出的图:
数据导入程序如下:
public class Loader { public static void main(String[] args) { HugeClient client = new HugeClient("http://127.0.0.1:8080", "hugegraph"); SchemaManager schema = client.schema(); schema.propertyKey("name").asText().ifNotExist().create(); schema.propertyKey("age").asInt().ifNotExist().create(); schema.propertyKey("city").asText().ifNotExist().create(); schema.propertyKey("weight").asDouble().ifNotExist().create(); schema.propertyKey("lang").asText().ifNotExist().create(); schema.propertyKey("date").asText().ifNotExist().create(); schema.propertyKey("price").asInt().ifNotExist().create(); schema.vertexLabel("person") .properties("name", "age", "city") .primaryKeys("name") .nullableKeys("age") .ifNotExist() .create(); schema.vertexLabel("software") .properties("name", "lang", "price") .primaryKeys("name") .nullableKeys("price") .ifNotExist() .create(); schema.indexLabel("personByCity") .onV("person") .by("city") .secondary() .ifNotExist() .create(); schema.indexLabel("personByAgeAndCity") .onV("person") .by("age", "city") .secondary() .ifNotExist() .create(); schema.indexLabel("softwareByPrice") .onV("software") .by("price") .range() .ifNotExist() .create(); schema.edgeLabel("knows") .multiTimes() .sourceLabel("person") .targetLabel("person") .properties("date", "weight") .sortKeys("date") .nullableKeys("weight") .ifNotExist() .create(); schema.edgeLabel("created") .sourceLabel("person").targetLabel("software") .properties("date", "weight") .nullableKeys("weight") .ifNotExist() .create(); schema.indexLabel("createdByDate") .onE("created") .by("date") .secondary() .ifNotExist() .create(); schema.indexLabel("createdByWeight") .onE("created") .by("weight") .range() .ifNotExist() .create(); schema.indexLabel("knowsByWeight") .onE("knows") .by("weight") .range() .ifNotExist() .create(); GraphManager graph = client.graph(); Vertex marko = graph.addVertex(T.label, "person", "name", "marko", "age", 29, "city", "Beijing"); Vertex vadas = graph.addVertex(T.label, "person", "name", "vadas", "age", 27, "city", "Hongkong"); Vertex lop = graph.addVertex(T.label, "software", "name", "lop", "lang", "java", "price", 328); Vertex josh = graph.addVertex(T.label, "person", "name", "josh", "age", 32, "city", "Beijing"); Vertex ripple = graph.addVertex(T.label, "software", "name", "ripple", "lang", "java", "price", 199); Vertex peter = graph.addVertex(T.label, "person", "name", "peter", "age", 35, "city", "Shanghai"); marko.addEdge("knows", vadas, "date", "20160110", "weight", 0.5); marko.addEdge("knows", josh, "date", "20130220", "weight", 1.0); marko.addEdge("created", lop, "date", "20171210", "weight", 0.4); josh.addEdge("created", lop, "date", "20091111", "weight", 0.4); josh.addEdge("created", ripple, "date", "20171210", "weight", 1.0); peter.addEdge("created", lop, "date", "20170324", "weight", 0.2); } }
顶点ID为:
"2:ripple", "1:vadas", "1:peter", "1:josh", "1:marko", "2:lop"
边ID为:
"S1:peter>2>>S2:lop", "S1:josh>2>>S2:lop", "S1:josh>2>>S2:ripple", "S1:marko>1>20130220>S1:josh", "S1:marko>1>20160110>S1:vadas", "S1:marko>2>>S2:lop"
根据起始顶点、方向、边的类型(可选)和深度depth,查找从起始顶点出发恰好depth步可达的顶点
GET http://localhost:8080/graphs/{graph}/traversers/kout?source="1:marko"&max_depth=2
200
{ "vertices":[ "2:ripple", "1:peter" ] }
查找恰好N步关系可达的顶点。两个例子:
根据起始顶点、步骤(包括方向、边类型和过滤属性)和深度depth,查找从起始顶点出发恰好depth步可达的顶点。
与K-out基础版的不同在于:
- 支持只统计邻居数量
- 支持边属性过滤
- 支持返回到达邻居的最短路径
POST http://localhost:8080/graphs/{graph}/traversers/kout
{ "source": "1:marko", "step": { "direction": "BOTH", "labels": ["knows", "created"], "properties": { "weight": "P.gt(0.1)" }, "max_degree": 10000, "skip_degree": 100000 }, "max_depth": 1, "nearest": true, "limit": 10000, "with_vertex": true, "with_path": true }
200
{ "size": 3, "kout": [ "1:josh", "1:vadas", "2:lop" ], "paths": [ { "objects": [ "1:marko", "1:josh" ] }, { "objects": [ "1:marko", "1:vadas" ] }, { "objects": [ "1:marko", "2:lop" ] } ], "vertices": [ { "id": "1:marko", "label": "person", "type": "vertex", "properties": { "name": "marko", "age": 29, "city": "Beijing" } }, { "id": "1:josh", "label": "person", "type": "vertex", "properties": { "name": "josh", "age": 32, "city": "Beijing" } }, { "id": "1:vadas", "label": "person", "type": "vertex", "properties": { "name": "vadas", "age": 27, "city": "Hongkong" } }, { "id": "2:lop", "label": "software", "type": "vertex", "properties": { "name": "lop", "lang": "java", "price": 328 } } ] }
参见3.2.1.3
根据起始顶点、方向、边的类型(可选)和深度depth,查找包括起始顶点在内、depth步之内可达的所有顶点
相当于:起始顶点、K-out(1)、K-out(2)、... 、K-out(max_depth)的并集
GET http://localhost:8080/graphs/{graph}/traversers/kneighbor?source=“1:marko”&max_depth=2
200
{ "vertices":[ "2:ripple", "1:marko", "1:josh", "1:vadas", "1:peter", "2:lop" ] }
查找N步以内可达的所有顶点,例如:
根据起始顶点、步骤(包括方向、边类型和过滤属性)和深度depth,查找从起始顶点出发depth步内可达的所有顶点。
与K-neighbor基础版的不同在于:
- 支持只统计邻居数量
- 支持边属性过滤
- 支持返回到达邻居的最短路径
POST http://localhost:8080/graphs/{graph}/traversers/kneighbor
{ "source": "1:marko", "step": { "direction": "BOTH", "labels": ["knows", "created"], "properties": { "weight": "P.gt(0.1)" }, "max_degree": 10000, "skip_degree": 100000 }, "max_depth": 3, "limit": 10000, "with_vertex": true, "with_path": true }
200
{ "size": 6, "kneighbor": [ "2:ripple", "1:marko", "1:josh", "1:vadas", "1:peter", "2:lop" ], "paths": [ { "objects": [ "1:marko", "1:josh", "2:ripple" ] }, { "objects": [ "1:marko" ] }, { "objects": [ "1:marko", "1:josh" ] }, { "objects": [ "1:marko", "1:vadas" ] }, { "objects": [ "1:marko", "2:lop", "1:peter" ] }, { "objects": [ "1:marko", "2:lop" ] } ], "vertices": [ { "id": "2:ripple", "label": "software", "type": "vertex", "properties": { "name": "ripple", "lang": "java", "price": 199 } }, { "id": "1:marko", "label": "person", "type": "vertex", "properties": { "name": "marko", "age": 29, "city": "Beijing" } }, { "id": "1:josh", "label": "person", "type": "vertex", "properties": { "name": "josh", "age": 32, "city": "Beijing" } }, { "id": "1:vadas", "label": "person", "type": "vertex", "properties": { "name": "vadas", "age": 27, "city": "Hongkong" } }, { "id": "1:peter", "label": "person", "type": "vertex", "properties": { "name": "peter", "age": 35, "city": "Shanghai" } }, { "id": "2:lop", "label": "software", "type": "vertex", "properties": { "name": "lop", "lang": "java", "price": 328 } } ] }
参见3.2.3.3
查询两个点的共同邻居
GET http://localhost:8080/graphs/{graph}/traversers/sameneighbors?vertex=“1:marko”&other="1:josh"
200
{ "same_neighbors":[ "2:lop" ] }
查找两个顶点的共同邻居:
计算两个顶点的jaccard similarity(两个顶点邻居的交集比上两个顶点邻居的并集)
GET http://localhost:8080/graphs/{graph}/traversers/jaccardsimilarity?vertex="1:marko"&other="1:josh"
200
{ "jaccard_similarity": 0.2 }
用于评估两个点的相似性或者紧密度
计算与指定顶点的jaccard similarity最大的N个点
jaccard similarity的计算方式为:两个顶点邻居的交集比上两个顶点邻居的并集
POST http://localhost:8080/graphs/{graph}/traversers/jaccardsimilarity
{ "vertex": "1:marko", "step": { "direction": "BOTH", "labels": [], "max_degree": 10000, "skip_degree": 100000 }, "top": 3 }
200
{ "2:ripple": 0.3333333333333333, "1:peter": 0.3333333333333333, "1:josh": 0.2 }
用于在图中找出与指定顶点相似性最高的顶点
根据起始顶点、目的顶点、方向、边的类型(可选)和最大深度,查找一条最短路径
GET http://localhost:8080/graphs/{graph}/traversers/shortestpath?source="1:marko"&target="2:ripple"&max_depth=3
200
{ "path":[ "1:marko", "1:josh", "2:ripple" ] }
查找两个顶点间的最短路径,例如:
根据起始顶点、目的顶点、方向、边的类型(可选)和最大深度,查找两点间所有的最短路径
GET http://localhost:8080/graphs/{graph}/traversers/allshortestpaths?source="A"&target="Z"&max_depth=10
200
{ "paths":[ { "objects": [ "A", "B", "C", "Z" ] }, { "objects": [ "A", "M", "N", "Z" ] } ] }
查找两个顶点间的所有最短路径,例如:
根据起始顶点、目的顶点、方向、边的类型(可选)和最大深度,查找一条带权最短路径
GET http://localhost:8080/graphs/{graph}/traversers/weightedshortestpath?source="1:marko"&target="2:ripple"&weight="weight"&with_vertex=true
200
{ "path": { "weight": 2.0, "vertices": [ "1:marko", "1:josh", "2:ripple" ] }, "vertices": [ { "id": "1:marko", "label": "person", "type": "vertex", "properties": { "name": "marko", "age": 29, "city": "Beijing" } }, { "id": "1:josh", "label": "person", "type": "vertex", "properties": { "name": "josh", "age": 32, "city": "Beijing" } }, { "id": "2:ripple", "label": "software", "type": "vertex", "properties": { "name": "ripple", "lang": "java", "price": 199 } } ] }
查找两个顶点间的带权最短路径,例如:
从一个顶点出发,查找该点到图中其他顶点的最短路径(可选是否带权重)
GET http://localhost:8080/graphs/{graph}/traversers/singlesourceshortestpath?source="1:marko"&with_vertex=true
200
{ "paths": { "2:ripple": { "weight": 2.0, "vertices": [ "1:marko", "1:josh", "2:ripple" ] }, "1:josh": { "weight": 1.0, "vertices": [ "1:marko", "1:josh" ] }, "1:vadas": { "weight": 1.0, "vertices": [ "1:marko", "1:vadas" ] }, "1:peter": { "weight": 2.0, "vertices": [ "1:marko", "2:lop", "1:peter" ] }, "2:lop": { "weight": 1.0, "vertices": [ "1:marko", "2:lop" ] } }, "vertices": [ { "id": "2:ripple", "label": "software", "type": "vertex", "properties": { "name": "ripple", "lang": "java", "price": 199 } }, { "id": "1:marko", "label": "person", "type": "vertex", "properties": { "name": "marko", "age": 29, "city": "Beijing" } }, { "id": "1:josh", "label": "person", "type": "vertex", "properties": { "name": "josh", "age": 32, "city": "Beijing" } }, { "id": "1:vadas", "label": "person", "type": "vertex", "properties": { "name": "vadas", "age": 27, "city": "Hongkong" } }, { "id": "1:peter", "label": "person", "type": "vertex", "properties": { "name": "peter", "age": 35, "city": "Shanghai" } }, { "id": "2:lop", "label": "software", "type": "vertex", "properties": { "name": "lop", "lang": "java", "price": 328 } } ] }
查找从一个点出发到其他顶点的带权最短路径,比如:
查找指定顶点集两两之间的最短路径
注意:properties中的属性值可以是列表,表示只要key对应的value在列表中就可以
POST http://localhost:8080/graphs/{graph}/traversers/multinodeshortestpath
{ "vertices": { "ids": ["382:marko", "382:josh", "382:vadas", "382:peter", "383:lop", "383:ripple"] }, "step": { "direction": "BOTH", "properties": { } }, "max_depth": 10, "capacity": 100000000, "with_vertex": true }
200
{ "paths": [ { "objects": [ "382:peter", "383:lop" ] }, { "objects": [ "382:peter", "383:lop", "382:marko" ] }, { "objects": [ "382:peter", "383:lop", "382:josh" ] }, { "objects": [ "382:peter", "383:lop", "382:marko", "382:vadas" ] }, { "objects": [ "383:lop", "382:marko" ] }, { "objects": [ "383:lop", "382:josh" ] }, { "objects": [ "383:lop", "382:marko", "382:vadas" ] }, { "objects": [ "382:peter", "383:lop", "382:josh", "383:ripple" ] }, { "objects": [ "382:marko", "382:josh" ] }, { "objects": [ "383:lop", "382:josh", "383:ripple" ] }, { "objects": [ "382:marko", "382:vadas" ] }, { "objects": [ "382:marko", "382:josh", "383:ripple" ] }, { "objects": [ "382:josh", "383:ripple" ] }, { "objects": [ "382:josh", "382:marko", "382:vadas" ] }, { "objects": [ "382:vadas", "382:marko", "382:josh", "383:ripple" ] } ], "vertices": [ { "id": "382:peter", "label": "person", "type": "vertex", "properties": { "name": "peter", "age": 29, "city": "Shanghai" } }, { "id": "383:lop", "label": "software", "type": "vertex", "properties": { "name": "lop", "lang": "java", "price": 328 } }, { "id": "382:marko", "label": "person", "type": "vertex", "properties": { "name": "marko", "age": 29, "city": "Beijing" } }, { "id": "382:josh", "label": "person", "type": "vertex", "properties": { "name": "josh", "age": 32, "city": "Beijing" } }, { "id": "382:vadas", "label": "person", "type": "vertex", "properties": { "name": "vadas", "age": 27, "city": "Hongkong" } }, { "id": "383:ripple", "label": "software", "type": "vertex", "properties": { "name": "ripple", "lang": "java", "price": 199 } } ] }
查找多个点之间的最短路径,比如:
根据起始顶点、目的顶点、方向、边的类型(可选)和最大深度等条件查找所有路径
GET http://localhost:8080/graphs/{graph}/traversers/paths?source="1:marko"&target="1:josh"&max_depth=5
200
{ "paths":[ { "objects":[ "1:marko", "1:josh" ] }, { "objects":[ "1:marko", "2:lop", "1:josh" ] } ] }
查找两个顶点间的所有路径,例如:
根据起始顶点、目的顶点、步骤(step)和最大深度等条件查找所有路径
注意:properties中的属性值可以是列表,表示只要key对应的value在列表中就可以
注意:properties中的属性值可以是列表,表示只要key对应的value在列表中就可以
POST http://localhost:8080/graphs/{graph}/traversers/paths
{ "sources": { "ids": ["1:marko"] }, "targets": { "ids": ["1:peter"] }, "step": { "direction": "BOTH", "properties": { "weight": "P.gt(0.01)" } }, "max_depth": 10, "capacity": 100000000, "limit": 10000000, "with_vertex": false }
200
{ "paths": [ { "objects": [ "1:marko", "1:josh", "2:lop", "1:peter" ] }, { "objects": [ "1:marko", "2:lop", "1:peter" ] } ] }
查找两个顶点间的所有路径,例如:
根据一批起始顶点、边规则(包括方向、边的类型和属性过滤)和最大深度等条件查找符合条件的所有的路径
注意:properties中的属性值可以是列表,表示只要key对应的value在列表中就可以
POST http://localhost:8080/graphs/{graph}/traversers/customizedpaths
{ "sources":{ "ids":[ ], "label":"person", "properties":{ "name":"marko" } }, "steps":[ { "direction":"OUT", "labels":[ "knows" ], "weight_by":"weight", "max_degree":-1 }, { "direction":"OUT", "labels":[ "created" ], "default_weight":8, "max_degree":-1, "sample":1 } ], "sort_by":"INCR", "with_vertex":true, "capacity":-1, "limit":-1 }
200
{ "paths":[ { "objects":[ "1:marko", "1:josh", "2:lop" ], "weights":[ 1, 8 ] } ], "vertices":[ { "id":"1:marko", "label":"person", "type":"vertex", "properties":{ "city":[ { "id":"1:marko>city", "value":"Beijing" } ], "name":[ { "id":"1:marko>name", "value":"marko" } ], "age":[ { "id":"1:marko>age", "value":29 } ] } }, { "id":"1:josh", "label":"person", "type":"vertex", "properties":{ "city":[ { "id":"1:josh>city", "value":"Beijing" } ], "name":[ { "id":"1:josh>name", "value":"josh" } ], "age":[ { "id":"1:josh>age", "value":32 } ] } }, { "id":"2:lop", "label":"software", "type":"vertex", "properties":{ "price":[ { "id":"2:lop>price", "value":328 } ], "name":[ { "id":"2:lop>name", "value":"lop" } ], "lang":[ { "id":"2:lop>lang", "value":"java" } ] } } ] }
适合查找各种复杂的路径集合,例如:
根据一批起始顶点、边规则(包括方向、边的类型和属性过滤)和最大深度等条件查找符合条件的所有的路径
注意:properties中的属性值可以是列表,表示只要key对应的value在列表中就可以
注意:properties中的属性值可以是列表,表示只要key对应的value在列表中就可以
POST http://localhost:8080/graphs/{graph}/traversers/templatepaths
{ "sources": { "ids": [], "label": "person", "properties": { "name": "vadas" } }, "targets": { "ids": [], "label": "software", "properties": { "name": "ripple" } }, "steps": [ { "direction": "IN", "labels": ["knows"], "properties": { }, "max_degree": 10000, "skip_degree": 100000 }, { "direction": "OUT", "labels": ["created"], "properties": { }, "max_degree": 10000, "skip_degree": 100000 }, { "direction": "IN", "labels": ["created"], "properties": { }, "max_degree": 10000, "skip_degree": 100000 }, { "direction": "OUT", "labels": ["created"], "properties": { }, "max_degree": 10000, "skip_degree": 100000 } ], "capacity": 10000, "limit": 10, "with_vertex": true }
200
{ "paths": [ { "objects": [ "1:vadas", "1:marko", "2:lop", "1:josh", "2:ripple" ] } ], "vertices": [ { "id": "2:ripple", "label": "software", "type": "vertex", "properties": { "name": "ripple", "lang": "java", "price": 199 } }, { "id": "1:marko", "label": "person", "type": "vertex", "properties": { "name": "marko", "age": 29, "city": "Beijing" } }, { "id": "1:josh", "label": "person", "type": "vertex", "properties": { "name": "josh", "age": 32, "city": "Beijing" } }, { "id": "1:vadas", "label": "person", "type": "vertex", "properties": { "name": "vadas", "age": 27, "city": "Hongkong" } }, { "id": "2:lop", "label": "software", "type": "vertex", "properties": { "name": "lop", "lang": "java", "price": 328 } } ] }
适合查找各种复杂的模板路径,比如personA -(朋友)-> personB -(同学)-> personC,其中“朋友”和“同学”边可以分别是最多3层和4层的情况
根据起始顶点、目的顶点、方向、边的类型(可选)和最大深度等条件查找相交点
GET http://localhost:8080/graphs/{graph}/traversers/crosspoints?source="2:lop"&target="2:ripple"&max_depth=5&direction=IN
200
{ "crosspoints":[ { "crosspoint":"1:josh", "objects":[ "2:lop", "1:josh", "2:ripple" ] } ] }
查找两个顶点的交点及其路径,例如:
根据一批起始顶点、多种边规则(包括方向、边的类型和属性过滤)和最大深度等条件查找符合条件的所有的路径终点的交集
sources:定义起始顶点,必填项,指定方式包括:
注意:properties中的属性值可以是列表,表示只要key对应的value在列表中就可以
path_patterns:表示从起始顶点走过的路径规则,是一组规则的列表。必填项。每个规则是一个PathPattern
capacity:遍历过程中最大的访问的顶点数目,选填项,默认为10000000
limit:返回的路径的最大数目,选填项,默认为10
with_path:true表示返回交点所在的路径,false表示不返回交点所在的路径,选填项,默认为false
with_vertex,选填项,默认为false:
POST http://localhost:8080/graphs/{graph}/traversers/customizedcrosspoints
{ "sources":{ "ids":[ "2:lop", "2:ripple" ] }, "path_patterns":[ { "steps":[ { "direction":"IN", "labels":[ "created" ], "max_degree":-1 } ] } ], "with_path":true, "with_vertex":true, "capacity":-1, "limit":-1 }
200
{ "crosspoints":[ "1:josh" ], "paths":[ { "objects":[ "2:ripple", "1:josh" ] }, { "objects":[ "2:lop", "1:josh" ] } ], "vertices":[ { "id":"2:ripple", "label":"software", "type":"vertex", "properties":{ "price":[ { "id":"2:ripple>price", "value":199 } ], "name":[ { "id":"2:ripple>name", "value":"ripple" } ], "lang":[ { "id":"2:ripple>lang", "value":"java" } ] } }, { "id":"1:josh", "label":"person", "type":"vertex", "properties":{ "city":[ { "id":"1:josh>city", "value":"Beijing" } ], "name":[ { "id":"1:josh>name", "value":"josh" } ], "age":[ { "id":"1:josh>age", "value":32 } ] } }, { "id":"2:lop", "label":"software", "type":"vertex", "properties":{ "price":[ { "id":"2:lop>price", "value":328 } ], "name":[ { "id":"2:lop>name", "value":"lop" } ], "lang":[ { "id":"2:lop>lang", "value":"java" } ] } } ] }
查询一组顶点通过多种路径在终点有交集的情况。例如:
根据起始顶点、方向、边的类型(可选)和最大深度等条件查找可达的环路
例如:1 -> 25 -> 775 -> 14690 -> 25, 其中环路为 25 -> 775 -> 14690 -> 25
GET http://localhost:8080/graphs/{graph}/traversers/rings?source="1:marko"&max_depth=2
200
{ "rings":[ { "objects":[ "1:marko", "1:josh", "1:marko" ] }, { "objects":[ "1:marko", "1:vadas", "1:marko" ] }, { "objects":[ "1:marko", "2:lop", "1:marko" ] } ] }
查询起始顶点可达的环路,例如:
根据起始顶点、方向、边的类型(可选)和最大深度等条件查找发散到边界顶点的路径
例如:1 -> 25 -> 775 -> 14690 -> 2289 -> 18379, 其中 18379 为边界顶点,即没有从 18379 发出的边
GET http://localhost:8080/graphs/{graph}/traversers/rays?source="1:marko"&max_depth=2&direction=OUT
200
{ "rays":[ { "objects":[ "1:marko", "1:vadas" ] }, { "objects":[ "1:marko", "2:lop" ] }, { "objects":[ "1:marko", "1:josh", "2:ripple" ] }, { "objects":[ "1:marko", "1:josh", "2:lop" ] } ] }
查找起始顶点到某种关系的边界顶点的路径,例如:
按照条件查询一批顶点对应的“梭形相似点”。当两个顶点跟很多共同的顶点之间有某种关系的时候,我们认为这两个点为“梭形相似点”。举个例子说明“梭形相似点”:“读者A”读了100本书,可以定义读过这100本书中的80本以上的读者,是“读者A”的“梭形相似点”
sources:定义起始顶点,必填项,指定方式包括:
注意:properties中的属性值可以是列表,表示只要key对应的value在列表中就可以
label:边的类型,选填项,默认代表所有edge label
direction:起始顶点向外发散的方向(OUT,IN,BOTH),选填项,默认是BOTH
min_neighbors:最少邻居数目,邻居数目少于这个阈值时,认为起点不具备“梭形相似点”。比如想要找一个“读者A”读过的书的“梭形相似点”,那么min_neighbors
为100时,表示“读者A”至少要读过100本书才可以有“梭形相似点”,必填项
alpha:相似度,代表:起点与“梭形相似点”的共同邻居数目占起点的全部邻居数目的比例,必填项
min_similars:“梭形相似点”的最少个数,只有当起点的“梭形相似点”数目大于或等于该值时,才会返回起点及其“梭形相似点”,选填项,默认值为1
top:返回一个起点的“梭形相似点”中相似度最高的top个,必填项,0表示全部
group_property:与min_groups
一起使用,当起点跟其所有的“梭形相似点”某个属性的值有至少min_groups
个不同值时,才会返回该起点及其“梭形相似点”。比如为“读者A”推荐“异地”书友时,需要设置group_property
为读者的“城市”属性,min_group
至少为2,选填项,不填代表不需要根据属性过滤
min_groups:与group_property
一起使用,只有group_property
设置时才有意义
max_degree:查询过程中,单个顶点遍历的最大邻接边数目,选填项,默认为10000
capacity:遍历过程中最大的访问的顶点数目,选填项,默认为10000000
limit:返回的结果数目上限(一个起点及其“梭形相似点”算一个结果),选填项,默认为10
with_intermediary:是否返回起点及其“梭形相似点”共同关联的中间点,默认为false
with_vertex,选填项,默认为false:
POST http://localhost:8080/graphs/hugegraph/traversers/fusiformsimilarity
{ "sources":{ "ids":[], "label": "person", "properties": { "name":"p1" } }, "label":"read", "direction":"OUT", "min_neighbors":8, "alpha":0.75, "min_similars":1, "top":0, "group_property":"city", "min_group":2, "max_degree": 10000, "capacity": -1, "limit": -1, "with_intermediary": false, "with_vertex":true }
200
{ "similars": { "3:p1": [ { "id": "3:p2", "score": 0.8888888888888888, "intermediaries": [ ] }, { "id": "3:p3", "score": 0.7777777777777778, "intermediaries": [ ] } ] }, "vertices": [ { "id": "3:p1", "label": "person", "type": "vertex", "properties": { "name": "p1", "city": "Beijing" } }, { "id": "3:p2", "label": "person", "type": "vertex", "properties": { "name": "p2", "city": "Shanghai" } }, { "id": "3:p3", "label": "person", "type": "vertex", "properties": { "name": "p3", "city": "Beijing" } } ] }
查询一组顶点相似度很高的顶点。例如:
GET http://localhost:8080/graphs/hugegraph/traversers/vertices?ids="1:marko"&ids="2:lop"
200
{ "vertices":[ { "id":"1:marko", "label":"person", "type":"vertex", "properties":{ "city":[ { "id":"1:marko>city", "value":"Beijing" } ], "name":[ { "id":"1:marko>name", "value":"marko" } ], "age":[ { "id":"1:marko>age", "value":29 } ] } }, { "id":"2:lop", "label":"software", "type":"vertex", "properties":{ "price":[ { "id":"2:lop>price", "value":328 } ], "name":[ { "id":"2:lop>name", "value":"lop" } ], "lang":[ { "id":"2:lop>lang", "value":"java" } ] } } ] }
通过指定的分片大小split_size,获取顶点分片信息(可以与 3.2.21.3 中的 Scan 配合使用来获取顶点)。
GET http://localhost:8080/graphs/hugegraph/traversers/vertices/shards?split_size=67108864
200
{ "shards":[ { "start": "0", "end": "2165893", "length": 0 }, { "start": "2165893", "end": "4331786", "length": 0 }, { "start": "4331786", "end": "6497679", "length": 0 }, { "start": "6497679", "end": "8663572", "length": 0 }, ...... ] }
通过指定的分片信息批量查询顶点(Shard信息的获取参见 3.2.21.2 Shard)。
GET http://localhost:8080/graphs/hugegraph/traversers/vertices/scan?start=0&end=4294967295
200
{ "vertices":[ { "id":"2:ripple", "label":"software", "type":"vertex", "properties":{ "price":[ { "id":"2:ripple>price", "value":199 } ], "name":[ { "id":"2:ripple>name", "value":"ripple" } ], "lang":[ { "id":"2:ripple>lang", "value":"java" } ] } }, { "id":"1:vadas", "label":"person", "type":"vertex", "properties":{ "city":[ { "id":"1:vadas>city", "value":"Hongkong" } ], "name":[ { "id":"1:vadas>name", "value":"vadas" } ], "age":[ { "id":"1:vadas>age", "value":27 } ] } }, { "id":"1:peter", "label":"person", "type":"vertex", "properties":{ "city":[ { "id":"1:peter>city", "value":"Shanghai" } ], "name":[ { "id":"1:peter>name", "value":"peter" } ], "age":[ { "id":"1:peter>age", "value":35 } ] } }, { "id":"1:josh", "label":"person", "type":"vertex", "properties":{ "city":[ { "id":"1:josh>city", "value":"Beijing" } ], "name":[ { "id":"1:josh>name", "value":"josh" } ], "age":[ { "id":"1:josh>age", "value":32 } ] } }, { "id":"1:marko", "label":"person", "type":"vertex", "properties":{ "city":[ { "id":"1:marko>city", "value":"Beijing" } ], "name":[ { "id":"1:marko>name", "value":"marko" } ], "age":[ { "id":"1:marko>age", "value":29 } ] } }, { "id":"2:lop", "label":"software", "type":"vertex", "properties":{ "price":[ { "id":"2:lop>price", "value":328 } ], "name":[ { "id":"2:lop>name", "value":"lop" } ], "lang":[ { "id":"2:lop>lang", "value":"java" } ] } } ] }
GET http://localhost:8080/graphs/hugegraph/traversers/edges?ids="S1:josh>1>>S2:lop"&ids="S1:josh>1>>S2:ripple"
200
{ "edges": [ { "id": "S1:josh>1>>S2:lop", "label": "created", "type": "edge", "inVLabel": "software", "outVLabel": "person", "inV": "2:lop", "outV": "1:josh", "properties": { "date": "20091111", "weight": 0.4 } }, { "id": "S1:josh>1>>S2:ripple", "label": "created", "type": "edge", "inVLabel": "software", "outVLabel": "person", "inV": "2:ripple", "outV": "1:josh", "properties": { "date": "20171210", "weight": 1 } } ] }
通过指定的分片大小split_size,获取边分片信息(可以与 3.2.22.3 中的 Scan 配合使用来获取边)。
GET http://localhost:8080/graphs/hugegraph/traversers/edges/shards?split_size=4294967295
200
{ "shards":[ { "start": "0", "end": "1073741823", "length": 0 }, { "start": "1073741823", "end": "2147483646", "length": 0 }, { "start": "2147483646", "end": "3221225469", "length": 0 }, { "start": "3221225469", "end": "4294967292", "length": 0 }, { "start": "4294967292", "end": "4294967295", "length": 0 } ] }
通过指定的分片信息批量查询边(Shard信息的获取参见 3.2.22.2)。
GET http://localhost:8080/graphs/hugegraph/traversers/edges/scan?start=0&end=3221225469
200
{ "edges":[ { "id":"S1:peter>2>>S2:lop", "label":"created", "type":"edge", "inVLabel":"software", "outVLabel":"person", "inV":"2:lop", "outV":"1:peter", "properties":{ "weight":0.2, "date":"20170324" } }, { "id":"S1:josh>2>>S2:lop", "label":"created", "type":"edge", "inVLabel":"software", "outVLabel":"person", "inV":"2:lop", "outV":"1:josh", "properties":{ "weight":0.4, "date":"20091111" } }, { "id":"S1:josh>2>>S2:ripple", "label":"created", "type":"edge", "inVLabel":"software", "outVLabel":"person", "inV":"2:ripple", "outV":"1:josh", "properties":{ "weight":1, "date":"20171210" } }, { "id":"S1:marko>1>20130220>S1:josh", "label":"knows", "type":"edge", "inVLabel":"person", "outVLabel":"person", "inV":"1:josh", "outV":"1:marko", "properties":{ "weight":1, "date":"20130220" } }, { "id":"S1:marko>1>20160110>S1:vadas", "label":"knows", "type":"edge", "inVLabel":"person", "outVLabel":"person", "inV":"1:vadas", "outV":"1:marko", "properties":{ "weight":0.5, "date":"20160110" } }, { "id":"S1:marko>2>>S2:lop", "label":"created", "type":"edge", "inVLabel":"software", "outVLabel":"person", "inV":"2:lop", "outV":"1:marko", "properties":{ "weight":0.4, "date":"20171210" } } ] }