The Knowledge Graph Conference Icon
The Knowledge Graph Conference
  • 馃彔Home
  • 馃搮Events
  • 馃懁Members
  • 馃數Announcements
  • 馃數Ask
  • 馃數Ask The Ontologists
  • 馃數Events
  • 馃數Jobs
  • 馃數Promotions
  • 馃數Share
Powered by Tightknit
Ask
Ask

Checklist for Troubleshooting Empty SPARQL Query Results in RDFLib

Avatar of Leia D.Leia D.
路Jun 15, 2022 07:54 PM

Does anyone have a checklist of things to look at when getting empty results in a SPARQL query? The work is in RDFLib. I'm looking at StackOverflow and some other things and am still coming up short. I know the query should return something because the usage view in Protege clearly shows it. And I'm not in a position to share my code. Thanks for any thoughts you have!

9 comments

路 Sorted by Oldest
    • Avatar of Andrew P.
      Andrew P.
      路

      this is from my exp. w/SQL Leia D. but it may apply here as well. I start removing condition filters one-by-one to see how it affects the result set.

      馃憤1
    • Avatar of Leia D.
      Leia D.
      路

      Thank you, Andrew P.. I've found one of the queries that returns null, but am still trying to figure out why that particular one does.

      馃憤1
    • Avatar of Evangelos S.
      Evangelos S.
      路

      maybe it would be better to add line by line in SPARQL query and see what gives each addition

    • Avatar of Phil T.
      Phil T.
      路

      Does this offer any insight? https://www.stardog.com/labs/blog/joins-and-nulls-in-sparql/

    • Avatar of Leia D.
      Leia D.
      路

      Evangelos S. Phil T. thank you. This has helped. I鈥檓 now trying to figure out precisely how to query my restrictions. I've written it in a way I think I should but still empty set. So troubleshooting continues.

    • Avatar of Leia D.
      Leia D.
      路

      OK. So to make sure, is this the syntax for querying restrictions? I feel like I've exhausted my troubleshooting. The other parts of my queries are working. I'm trying to find every individual that meets this restriction. I truly welcome the feedback. Thank you. ?restriction rdf:type owl:Restriction . ?restriction owl:onProperty (name of property in my ontology) . ?restriction owl:someValuesFrom (Name of class in my ontology) .

    • Avatar of Phil T.
      Phil T.
      路

      This partial illustration is derived from The African Wildlife Ontology tutorial ontologies: requirements, design, and content

      <owl:Class rdf:about="&AfricanWildlifeOntology1;lion">
          <rdfs:subClassOf rdf:resource="&AfricanWildlifeOntology1;animal"/>
          <rdfs:subClassOf>
              <owl:Restriction>
                  <owl:onProperty rdf:resource="&AfricanWildlifeOntology1;eats"/>
                  <owl:allValuesFrom rdf:resource="&AfricanWildlifeOntology1;herbivore"/>
              </owl:Restriction>
          </rdfs:subClassOf>
          <rdfs:subClassOf>
              <owl:Restriction>
                  <owl:onProperty rdf:resource="&AfricanWildlifeOntology1;eats"/>
                  <owl:someValuesFrom rdf:resource="&AfricanWildlifeOntology1;Impala"/>
              </owl:Restriction>
          </rdfs:subClassOf>
          <rdfs:comment>Lions are animals that eat only herbivores.</rdfs:comment>
      </owl:Class>
      
      <owl:Class rdf:about="&AfricanWildlifeOntology1;Impala">
          <rdfs:subClassOf rdf:resource="&AfricanWildlifeOntology1;animal"/>
          <rdfs:comment>An african antelope http://en.wikipedia.org/wiki/Impala</rdfs:comment>
      </owl:Class>

      # Which animal eats which other animal?
      
      prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#>
      prefix owl: <http://www.w3.org/2002/07/owl#>
      prefix : <http://www.meteck.org/teaching/ontologies/AfricanWildlifeOntology1.owl#>
      
      select distinct *
      where
      {
        ?eats rdfs:subClassOf :animal, [
          a owl:Restriction ;
          owl:onProperty :eats;
          owl:someValuesFrom ?eaten
        ] .
        ?eaten rdfs:subClassOf :animal .
        filter(?eats != owl:Nothing)
      }

    • Avatar of Leia D.
      Leia D.
      路

      Phil T. thank you!!! This is perfect. I've looked at a couple of examples, but nothing as clear as this.

      馃檹1
    • Avatar of Phil T.
      Phil T.
      路

      You鈥檙e welcome Leia D.. All due credit to the paper鈥檚 author and tutorial producers for a wonderfully concise and relatable example.

    馃憤
    1