我是Java,Gremlin,Nodejs,Tickerpop,Maven以及其他所有人的新手.这段代码有什么作用?特别是'java.import'在做什么?它是Java类吗?这与Titan有什么关系?
var Titan = require('titan-node');
var gremlin = new Titan.Gremlin({ loglevel: 'OFF' });
var TinkerGraphFactory = gremlin.java.import('com.tinkerpop.blueprints.impls.tg.TinkerGraphFactory');
var graph = TinkerGraphFactory.createTinkerGraphSync();
var g = gremlin.wrap(graph);
g.V('name', 'marko').next(function (err, v) {
v.getProperty('name', function (err, value) {
console.log(value);
});
});
Run Code Online (Sandbox Code Playgroud)
为什么当我使用Rexster时,我看不到这里要查询的数据库?
如果给定的顶点没有特定的属性,g.V.hasNot('non-existent-property', 'value')
查询的结果应该是什么
?顶点是否应该由这样的查询发出?
使用 TinkerPop 和 Titan 的内存图时,我得到了矛盾的结果:
gremlin> g = TinkerGraphFactory.createTinkerGraph()
==>tinkergraph[vertices:6 edges:6]
gremlin> g.V.hasNot("abcd", true)
==>v[1]
==>v[2]
==>v[3]
==>v[4]
==>v[5]
==>v[6]
Run Code Online (Sandbox Code Playgroud)
以上对我来说很好 - 顶点没有指定的属性(设置为true
),所以所有都返回。但是如果我在 Titan 的内存图中做类似的事情:
gremlin> g2 = TitanFactory.open(com.thinkaurelius.titan.graphdb.configuration.GraphDatabaseConfiguration.buildConfiguration().set(com.thinkaurelius.titan.graphdb.configuration.GraphDatabaseConfiguration.STORAGE_BACKEND, "inmemory"))
==>titangraph[inmemory:[127.0.0.1]]
gremlin> g2.addVertex(null)
==>v[256]
gremlin> g2.V.hasNot("abcd", true)
Run Code Online (Sandbox Code Playgroud)
它不返回任何结果。哪一个是对的?
我试图了解Tinkerpop和Gremlin(上下文:http ://tinkerpop.apache.org/ )之间的区别。
我的假设是Gremlin只是可以使用不同后端的查询/遍历语言,而Tinkerpop是Gremlin客户端+ Gremlin后端(db)。官方描述说Tinkerpop是一个“图形计算框架”,对我来说有点太含糊。
我正在使用Graph API,Cosmos DB
其中使用Gremlin语法进行查询.
我在图中有许多用户(Vertex),每个用户都有"知道"属性给其他用户.其中一些是外边缘(outE),另一些是边缘(inE),具体取决于关系的创建方式.我现在正在尝试创建一个查询,它将返回给定用户(Vertex)的所有"已知"关系.我可以通过以下方式轻松获取inE或outE的ID:
g.V('7112138f-fae6-4272-92d8-4f42e331b5e1').inE('knows')
g.V('7112138f-fae6-4272-92d8-4f42e331b5e1').outE('knows')
Run Code Online (Sandbox Code Playgroud)
'7112138f-fae6-4272-92d8-4f42e331b5e1'
我正在查询的用户的ID 在哪里,但我不知道这是一个进入还是出现边缘,所以想要得到两者(例如,如果用户进出边缘'知道'标签).我尝试过使用投影和OR运算符以及各种组合,例如:
g.V('7112138f-fae6-4272-92d8-4f42e331b5e1').where(outE('knows').or().inE('knows'))
Run Code Online (Sandbox Code Playgroud)
但它没有让我回到我想要的数据.
我想要的只是所有inE和outE的Id的列表,其具有给定顶点的'已知'标签.
或者是否有更简单/更好的方法来模拟双向关联,例如'knows'或'friendOf'?
谢谢
在JanusGraph中,我想获得一些Date
属性的min().
由于min()和max()都只支持Number
type,我使用map{it.get().getTime()}
.但奇怪的结果.
怎么做 ?
gremlin> mgmt = graph.openManagement()
==>org.janusgraph.graphdb.database.management.ManagementSystem@496a8a94
gremlin> person = mgmt.makeVertexLabel('Person').make()
==>Person
gremlin> t_created = mgmt.makePropertyKey('t_created').dataType(Date.class).cardinality(SINGLE).make()
==>t_created
gremlin> t_modified = mgmt.makePropertyKey('t_modified').dataType(Date.class).cardinality(SINGLE).make()
==>t_modified
gremlin> mgmt.buildIndex('i_t_created', Vertex.class).addKey(t_created).buildMixedIndex('search')
==>i_t_created
gremlin> mgmt.buildIndex('i_t_modified', Vertex.class).addKey(t_modified).buildMixedIndex('search')
==>i_t_modified
gremlin> mgmt.commit()
==>null
Run Code Online (Sandbox Code Playgroud)
gremlin> person = g.addV('Person').property('t_created', new Date()).property('t_modified', new Date()).next()
==>v[16488]
gremlin> g.tx().commit()
==>null
gremlin> g.V(person).properties()
==>vp[t_created->Tue Sep 05 07:40:16 ]
==>vp[t_modified->Tue Sep 05 07:40:16 ]
gremlin> g.V(person).values('t_created', 't_modified')
==>Tue Sep 05 07:40:16 UTC 2017
==>Tue …
Run Code Online (Sandbox Code Playgroud) 我开始玩gremlin-python包装器来与我的gremlin服务器进行交互.
我做了以下步骤:
./bin/gremlin.sh
Run Code Online (Sandbox Code Playgroud)
一旦Gremlin控制台打开,我使用以下命令加载配置:
graph = JanusGraphFactory.open('conf/gremlin-server/janusgraph-cassandra-es.properties')
g = graph.traversal()
saturn = g.V().has('name', 'saturn')
Run Code Online (Sandbox Code Playgroud)
gremlin shell中的上面一组代码工作得很好,我可以看到列出的脊椎,但是当我尝试在python中做同样的事情时,我得到一个空图.以下是我的python代码:
graph = Graph()
g = graph.traversal().withRemote(DriverRemoteConnection('ws://localhost:8182/gremlin','g'))
print(g)
Run Code Online (Sandbox Code Playgroud)
它返回: graphtraversalsource [graph [empty]]
为什么我得到空图?据我所知,它无法连接到相同的Graph源.有什么我想念的吗?
请注意:
JanusGraphFactory.open('conf/gremlin-server/janusgraph-cassandra-es.properties')
Run Code Online (Sandbox Code Playgroud)
提供的配置文件名是用于启动gremlin服务器的文件名.
任何帮助都非常感谢.
谢谢
我正在计划SWI Prolog程序(语义自然语言解析器),它具有庞大而动态的事实集(具有大约30.000个条目的词典).是否可以将这些事实存储在外部数据库中.由于其他要求,我正在考虑Apache TinkerPop/JanusGraph/Cassandra作为我的数据库,但我也对SQL/JDBC/ODBC数据库支持感到满意.
这是一个非常简单的查询:
g.V('customerId').out().path()
Run Code Online (Sandbox Code Playgroud)
这个的 JSON 输出是
{
"requestId":"96b26c1d-d032-2004-d36e-c700bd6db2a2",
"status":{
"message":"",
"code":200,
"attributes":{
"@type":"g:Map",
"@value":[
]
}
},
"result":{
"data":{
"@type":"g:List",
"@value":[
{
"@type":"g:Path",
"@value":{
"labels":{
"@type":"g:List",
"@value":[
{
"@type":"g:Set",
"@value":[
]
},
{
"@type":"g:Set",
"@value":[
]
}
]
},
"objects":{
"@type":"g:List",
"@value":[
{
"@type":"g:Vertex",
"@value":{
"id":"customerId",
"label":"customer"
}
},
{
"@type":"g:Vertex",
"@value":{
"id":"e:customerIdemail@email.com",
"label":"email"
}
}
]
}
}
}
]
},
"meta":{
"@type":"g:Map",
"@value":[
]
}
}
}
Run Code Online (Sandbox Code Playgroud)
现在,客户顶点还包含属性名称和年龄。我想了解的是如何(如果可能的话)形成我的 gremlin 查询,以便它在图中嵌套顶点属性。请注意,当我只运行 gV("customerId") 时,响应确实包含这些属性。
我有一个用例,其中用户位于诸如
user1 --HAS_CHILD-> user2 --HAS_CHILD-> user3 --HAS_CHILD-> user4
对于给定的用户,我需要获得该用户拥有的所有汽车以及该用户的孩子拥有的所有汽车。对于汽车,我需要拥有用户(所有者)以及该用户与给定用户的深度。
例如 给定的用户为user2,则user3的深度为1,user4的深度为2。
我可以使用以下查询获取汽车的详细信息和所有者信息,但如何获取childDepth呢?
g.V().has("User", "id", "user2")
.union(
__.out("OWNS").hasLabel("Car"),
__.repeat(
__.out("HAS_CHILD").hasLabel("User")
).emit().out("OWNS").hasLabel("Car")
)
.project("plateNumber", "owner", "model", "year", "childDepth")
.by(__.values("plateNumber").fold())
.by(__.in("OWNS").values("owner").fold())
.by(__.values("model").fold())
.by(__.values("year").fold())
.by(???)
Run Code Online (Sandbox Code Playgroud) 我正在做一个小的 POC 项目,我想使用亚马逊的海王星图来表示一个村庄的道路网络。
我有我打算在这个图中用作顶点的交叉点,以及街道作为边缘。一个简单的表示是:
Intersection {
id: 1089238983,
name: 'Madrid & 99th'
labels: ['has_pedestrian_signals', 'four_way_intersection']
}
Street {
id: 9808787868,
name: 'Madrid St'
from_int_id: 1089238983,
to_int_id: 1089238973,
labels: ['has_hospital_on_street', 'is_snow_route', 'is_one_way_street']
}
Run Code Online (Sandbox Code Playgroud)
问题是AWS 的文档指出 Edges 只能有 1 个标签。
我希望能够最终根据边的属性执行遍历。我曾尝试寻找将更多数据合并到 Tinkerpop 图表中的方法,但没有发现任何有用的信息。
如果有任何建议,我将不胜感激。
tinkerpop ×10
gremlin ×9
janusgraph ×3
graph ×2
tinkerpop3 ×2
titan ×2
database ×1
node.js ×1
prolog ×1
python ×1
swi-prolog ×1