0

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.

Following previous questions related to this in SO, I tried to use the following wildcard query to do it (without specifying the dct:subject and skos:broader properties).

ASK {
  <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.

EmJ
  • 4,398
  • 9
  • 44
  • 105
  • 1
    No, there is not. This is the standard hackyisch way. You're getting an OOM because this are in worst case a lots of joins - that's the whole reason. You know, even "standard" property paths in general are mostly not really good performing, but this wildcard pattern is even worse with no predicate given. And yes, SPARQL is not a graph traversal language, other more sophisticated graph languages and engines might perform better here because of other optimizations etc. – UninformedUser Jan 30 '20 at 04:25
  • 2
    Other than that, for the first case you should at least rewrite your query to get the categories first and than only search for paths via `skos:broader` starting from those categories - strange that you're still working on the category stuff, I remember you did it months ago and you already did such path things ... – UninformedUser Jan 30 '20 at 04:29
  • @AKSW thanks a lot for the comments. Yes, I used DBpedia for a different project. Since then, I did not use SPARQL, so I have completely forgotton the things I learnt. This is a new project and I have to do the knowledge-base feature related section of that project. So, I am starting to learn sparql again. So, the point you are saying is that it is not possible to perform such graph traversal using sparql? :) – EmJ Jan 30 '20 at 05:18
  • 1
    It's possible as your query indicates, but as you can see it all depends on dataset size, query engine and hardware. If you have a more powerful server, feel free to deploy your own DBpedia SPARQL endpoint there. In the end, the public DBpedia endpoint is a shared resource and obviously also limited. I mean, somebody has to pay for maintainance, you're clearly using the service for free. – UninformedUser Jan 30 '20 at 07:32
  • @AKSW thank you very much. Maybe as the first step I will follow your this suggestion "you should at least rewrite your query to get the categories first and than only search for paths via `skos:broader` starting from those categories". I have one more question. Suppose, I have two entities "Cat" and "Dog". I get their immediate categories using `dct:subject`. Is it possible to check if these immediate categories I got for "Cat" and "Dog" have common ancestral categories may be within 5 hops of `skos:broader`. – EmJ Jan 30 '20 at 22:56
  • If it is possible with the public endpoint, please kindly let me know how I can find such common categories within 5 hops in an efficient way. I look forward to hearing from you. Thank you :) – EmJ Jan 30 '20 at 22:56
  • 1
    you already know the answer, because this is something we already discussed in your previous questions ... use a different property path, e.g. `skos:broader?/skos:broader?` for at most two hops – UninformedUser Jan 31 '20 at 07:58

0 Answers0