Tinkerpop: seleziona i vertici che non hanno il percorso verso i vertici che hanno una proprietà
Aug 21 2020
In Tinkerpop, voglio selezionare i vertici che non sono direttamente collegati ai vertici con proprietà foo
uguale abar
Per es:
Vertex user1 = graph.addVertex("vid","one");
Vertex user2 = graph.addVertex("vid","two");
Vertex user3 = graph.addVertex("vid","three");
Vertex tag1 = graph.addVertex("tagKey", "tagKey1");
Vertex tag2 = graph.addVertex("tagKey", "tagKey2");
Vertex tag3 = graph.addVertex("tagKey", "tagKey3");
user1.addEdge("user_tag", tag1);
user2.addEdge("user_tag", tag2);
user2.addEdge("user_tag", tag3);
Nel caso di test sopra voglio selezionare tutti i user
vertici che non sono collegati per taggare i vertici con tagKey
un valore di tagKey2
. L'output dovrebbe essere di 2 verticiuser3 , user 1
Risposte
1 codetiger Aug 21 2020 at 15:55
Query per recuperare i vertici che non sono collegati ai tag.
g.V().hasLabel("Vertex").
filter(
not(outE().hasLabel('connected'))
).
properties()
Query per aggiungere i dati Vertex:
g.addV('Vertex').as('1').property(single, 'name', 'One').
addV('Vertex').as('2').property(single, 'name', 'Two').
addV('Vertex').as('3').property(single, 'name', 'Three').
addV('Vertex').as('4').property(single, 'name', 'Four').
addV('Tag').as('5').property(single, 'name', 'Key1').
addV('Tag').as('6').property(single, 'name', 'Key2').
addV('Tag').as('7').property(single, 'name', 'Key3').
addE('connected').from('1').to('5').
addE('connected').from('2').to('6').
addE('connected').from('4').to('7')
Collegamento Gremlify:https://gremlify.com/f1muf12xhdv/2
1 noam621 Aug 21 2020 at 15:58
È possibile ottenere ciò utilizzando una combinazione di not
e where
passaggi:
g.V().hasLabel('User').
not(where(out('user_tag').has('tagKey', 'tagKey2'))).
valueMap().with(WithOptions.tokens)
esempio:https://gremlify.com/jybeipj4zjg