I use sesame2 with a Posgresql sail. I am looking for a query in SERQL, which let me find the lowest common ancestor (in a tree) of two concept A and B. I don't know how many levels I have above A and B. A and B are linked by predicate "parent_category".

asked 10 Feb '11, 14:47

Skarab's gravatar image

accept rate: 0%

edited 10 Feb '11, 14:55

What you need for this to work is support for querying property paths (as is being specified in the current SPARQL 1.1 Query working draft). Sesame, unfortunately, does not support this yet (note that SPARQL 1.1 is not yet supported by Sesame, it's being worked on though, planned for release 2.4).

However, a way around this is to make use of reasoning and define your property "parent_category" as a transitive property. This can be done in roughly three ways in Sesame (listed from dirtiest to cleanest solution ;) ):

  1. Use a Sesame store with RDFS inferencing, and define your own property as a rdfs:subPropertyOf rdfs:subClassOf. The consequence will be that all your categories will be defined as classes, and because your own property is defined as a subproperty of rdfs:subClassOf, your concept tree is now also a class hierarcy.

  2. Use a custom rule-based reasoner (for example the SeRQL-based custom reasoner provided as a Sesame extension and define your own rule to make your own property a transitive one.

  3. Use an OWLIM store, which provides OWL reasoning out of the box, and define your own property as an owl:TransitiveProperty.

Once you have defined your property as transitive, you can then use this query for the lowest common ancestor (in SeRQL):

FROM {ex:A} ex:parent_category {X},
     {ex:B} ex:parent_category {X}
                   FROM {W} ex:parent_category {Z} ex:parent_category {X}
                   WHERE NOT(Z IN (ex:A, ex:B))
                         AND W IN (ex:A, ex:B)

(note: if you use option 1, you will have to query for rdfs:subClassOf properties instead of ex:parent_category properties).

permanent link

answered 10 Feb '11, 20:22

Jeen%20Broekstra's gravatar image

Jeen Broekstra ♦
accept rate: 37%

@Jeen. Did you try Neo4j sail? It looks like it also supports transitive properties.

(15 Feb '11, 12:39) Skarab Skarab's gravatar image

Skarab, I didn't - to be honest I didn't even know it existed. Sounds interesting though!

(15 Feb '11, 20:30) Jeen Broekstra ♦ Jeen%20Broekstra's gravatar image

Jeen, that was kind of funny. As you wrote about SparQL 1.1, i imagined the openrdf issue navigator, where one may find the current status of a development process (i am not expaining that for you...). I changed there with the plan, to post this link here. I had to smile a bit, but maybe i'll let the people just explore themselfes :)

Wanna have the current status of sesame supporting sparql 1.1? Please look at


cheers josh and thanks Jeen. I am hot for this feature.

permanent link

answered 11 Feb '11, 14:37

Joshua%20Bacher's gravatar image

Joshua Bacher
accept rate: 0%

Heh - the Sesame project may not always be the best or fastest with its PR messages, but that doesn't mean nothing is happening :)

(11 Feb '11, 19:46) Jeen Broekstra ♦ Jeen%20Broekstra's gravatar image
Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here



Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Question tags:


question asked: 10 Feb '11, 14:47

question was seen: 2,070 times

last updated: 11 Feb '11, 14:37