I want to check if two DBpedia nodes have a path using;

  • dct:subject and skos:broader properties
  • without specifying properties

For instance consider the two DBpedia nodes http://dbpedia.org/resource/Cat and http://dbpedia.org/resource/Dog. I tried to use the following wildcard query to do it.

  <http://dbpedia.org/resource/Cat> ((<>|!<>)|^(<>|!<>))* <http://dbpedia.org/resource/Dog> 

However, I get a memory error. I am wondering if there is a more suitable way of doing this in sparql.

I am happy to provide more details if needed.

1 Answer 1


Your question shows <> which is not a valid property or wildcard.

You cannot use property variables (wildcards) in property paths.

So you need to understand the structure of how dct:subject and skos:broader are used, and exploit that. I happen to know that

  • dct:subject links pages to categories
  • skos:broader makes the category hierarchy

I should warn you that the wikipedia category hierarchy is vast and diverging. Eg see "Domain-specific modeling: Towards a Food and Drink Gazetteer" (Slides, pdf, published).

You don't want to use skos:broader*, instead use Transitive reasoning and skos:broaderTransitive (eg get our GraphDB Free edition). So you can try

select * {
  ?cat skos:subject/skos:broaderTransitive ?x.
  ?dog skos:subject/skos:broaderTransitive ?x.

but because of the vast and diverging structure, this will take a LOT of time and return lots of cats, many of them barely relevant.

  • <> denotes a relative URI reference that resolves to the base URI and is definitely valid when used as a property. As (<>|!<>), it effectively denotes "any property", so the query asks whether there is something both Cat and Dog are transitively linked to. Not much useful on its own, considering any two entities are likely linked to rdfs:Resource.
    – IS4
    Jul 14, 2023 at 10:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.