'Or' operator for node properties in Gremlin assigned to one subgraph

半腔热情 提交于 2020-06-16 19:26:06

问题


I have a Janusgraph database which contains nodes with the label 'Paper', the node properties 'paperTitle' and 'year' and the edge type 'References'.

I'm trying to write a query that will allow me to select two papers by title and all their references and assign that result to a subgraph.

I can select one paper using two conditions like this:

sg = g.V().
     and(has('Paper', 'paperTitle', 'ladle pouring guide'), has('Paper', 'year', '1950')).
     inE('References').
     subgraph('sg1').
     cap('sg1').
     next()

Using this query as my starting point I had hoped I could do this:

sg = g.V().
     or(has('Paper', 'paperTitle', 'ladle pouring guide'), has('Paper', 'paperTitle', 'the development of the human mandibular joint')).
     inE('References').
     subgraph('sg1').
     cap('sg1').
     next()

But this returns a subgraph with 0 nodes and 0 edges.

I saw this page in the Janusgraph documentation http://tinkerpop.apache.org/docs/current/reference/#or-step but it seems to only describe selections of multiple edges not multiple node properties.

Is it possible to create this kind of subgraph or do I need to runs these as two separate queries?


回答1:


I don't see why you can't do this in one query and I'm not sure why your traversal doesn't work, however I would write it as:

sg = g.V().
     has('Paper', 'paperTitle', within('ladle pouring guide', 
                                       'the development of the human mandibular joint')).
     inE('References').
     subgraph('sg1').
     cap('sg1').
     next()


来源:https://stackoverflow.com/questions/61108800/or-operator-for-node-properties-in-gremlin-assigned-to-one-subgraph

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!