OpenBioLink / Explorer

MIT License
17 stars 1 forks source link

Sparql query to get the original triples #21

Open fburdet opened 1 year ago

fburdet commented 1 year ago

Hello,

What would be the sparql query to run in blazegraph to get back all the triples that correspond to a rule?

Thanks in advance!

matthias-samwald commented 1 year ago

@nomisto ?

fburdet commented 1 year ago

If possible with the labels ;)

nomisto commented 1 year ago

Hello @fburdet,

As different rules require different sparql queries there is not a single one. But here you can find the code for generating the sparql query. We use this to get the instantiation of variables (A, B, ...), we use no query to retrieve all the triples as this could be a lot depending on the rule. https://github.com/OpenBioLink/Explorer/blob/72b5bc2246e3f185004ef4104958cc9d4ce62c3c/api/rdf.js#L343-L403

If you mean by "all the triples that correspond to a rule" all triples that are entailed by the body of the rule, you could issue the following query:

E.g. speak(X,Y) -> lives(X,A), lang(A,Y)

  PREFIX obl:  <https://ai-strategies.org/kgc/>
  SELECT ?X ?A ?Y ?X_label ?A_label ?Y_label
  WHERE {
      <<?X https://ai-strategies.org/kgc/lives ?A>> obl:split obl:train .
      <<?A https://ai-strategies.org/kgc/lang ?Y>> obl:split obl:train .
      OPTIONAL {?X <http://www.w3.org/2000/01/rdf-schema#label> ?X_label}"
      OPTIONAL {?A <http://www.w3.org/2000/01/rdf-schema#label> ?A_label}"
      OPTIONAL {?Y <http://www.w3.org/2000/01/rdf-schema#label> ?Y_label}"
  }