1

I am trying to create a query in SPARQL that:

given two or more nodes (selected children) and their parent-child relationship, produces:

  • least common parent among selected children

  • shortest paths to least common parent from each child

I am doing this in Neo4j with the following code *(Cypher):

MATCH (children) where children.label IN ["rope", "pope", "dope"]
MATCH (root) where root.label="entity"
WITH * WHERE id(children) < id(root)
MATCH path = allShortestPaths( (children)-[*..100]->(root) )
RETURN path

I know what the "highest common ancestor" is (root) though in this case and are checking paths from found child items to it.

I wonder how one tackles such problems using SPARQL (1.1) and whether it is possible to do these types of queries (and if yes - efficiently).

My example RDF data is WordNet RDF triples and "hypernym" relationship between the nodes.

Igor Malin
  • 652
  • 2
  • 8
  • 26
  • 1
    "efficient" for sure not. Triple stores usually don't have path optimized indexes like graph databases. Related are mostly the answers of JoshuaTaylor here at Stackoverflow. For example, the distance between nodes: https://stackoverflow.com/questions/5198889/calculate-length-of-path-between-nodes – UninformedUser Dec 19 '17 at 04:36
  • 1
    And your question is more or less a duplicate of https://stackoverflow.com/questions/23510851/how-to-get-least-common-subsumer-in-ontology-using-sparql-query and https://stackoverflow.com/questions/19680440/finding-common-superclass-and-length-of-path-in-class-hierarchies – UninformedUser Dec 19 '17 at 04:39
  • 1
    Possible duplicate of [How to get Least common subsumer in ontology using SPARQL Query?](https://stackoverflow.com/questions/23510851/how-to-get-least-common-subsumer-in-ontology-using-sparql-query) – UninformedUser Dec 19 '17 at 07:17
  • Thank you AKSW - I will check out the above links. – Igor Malin Jan 03 '18 at 23:03
  • If you figured out the solution, feel free to post it as an answer here. – UninformedUser Jan 04 '18 at 07:00

0 Answers0