Reputation: 20150
I have the following query in Cypher.
MATCH (n:Resource { uri: 'http://elite.polito.it/ontologies/dogont.owl#StateValue' }),(m:Resource { uri: 'http://elite.polito.it/ontologies/dogont.owl#Actuator'}), p=allShortestPaths((n)-[r*]-(m)) WHERE NONE(x IN NODES(p) WHERE x.uri='http://www.w3.org/2002/07/owl#Thing')
RETURN p
It is returning the following results:
│[{"uri":"http://elite.polito.it/ontologies/dogont.owl#StateValue"},{},│
│{"uri":"http://elite.polito.it/ontologies/dogont.owl#realStateValue"},│
│{"uri":"http://elite.polito.it/ontologies/dogont.owl#realStateValue"},│
│{},{"uri":"http://www.w3.org/2001/XMLSchema#string"},{"uri":"http://ww│
│w.w3.org/2001/XMLSchema#string"},{},{"uri":"http://purl.org/goodrelati│
│ons/v1#serialNumber"},{"uri":"http://purl.org/goodrelations/v1#serialN│
│umber"},{},{"rdfs__comment":"All building things that can be controlle│
│d by domotic system","uri":"http://elite.polito.it/ontologies/dogont.o│
│wl#Controllable","rdfs__label":"Controllable"},{"rdfs__comment":"All b│
│uilding things that can be controlled by domotic system","uri":"http:/│
│/elite.polito.it/ontologies/dogont.owl#Controllable","rdfs__label":"Co│
│ntrollable"},{},{"rdfs__comment":"A mechanism that puts something into│
│ automatic action","uri":"http://elite.polito.it/ontologies/dogont.owl│
│#Actuator","rdfs__label":"Actuator"}] │
In the result, the intermediary nodes appear twice. Why does that happen and how to prevent this ? Also for now, the relationships
are blank, how can replace {}
for relationships
with their type
.
Upvotes: 0
Views: 49
Reputation: 66975
A returned path consists of a series of relationships, and the data returned for each relationship is actually a triplet (start node, relationship, end node). So, the end node of one relationship appears again as the start node of the next relationship.
If you want to just get the relationships without the nodes, you can use RELATIONSHIPS(p)
; and if you just want the nodes without the relationships, you can use NODES(p)
.
And if you want to generate your own path lists without doubled-up nodes, try this:
MATCH
(n:Resource { uri: 'http://elite.polito.it/ontologies/dogont.owl#StateValue'}),
(m:Resource { uri: 'http://elite.polito.it/ontologies/dogont.owl#Actuator'}),
p=allShortestPaths((n)-[*]-(m))
WHERE NONE(x IN NODES(p) WHERE x.uri='http://www.w3.org/2002/07/owl#Thing')
RETURN REDUCE(s=[PROPERTIES(n)], r IN RELATIONSHIPS(p) | s + r + ENDNODE(r)) AS p
Upvotes: 1