alan turing
alan turing

Reputation: 463

Refering OWL Class In SPARQL Filter Stament

I have developed an ontology which you can access with the link exist in the code below. The code working fine except FILTER section. If I use equal operator in FILTER, it does not return anything. If I use not equal operator (!=), it does not filter anything. I guess my reference for Brands class in my ontology with "owl:Brands" is not working. I shortened url, because I don't want it to be indexed by web crawlers. I am using original URL in the code. You can access original url with the shortened one. You can browse the ontology by an editor. I am pretty sure that "owl:Brands" is not working, I tried many other possibilities but could not figure out how to make it work.

Without FILTER statement, it works equal to "FILTER(?sub!=owl:Brands)", because there is nothing matching with owl:Brands. FYI, I am using python and rdflib.

    plugin.register(
     'sparql', rdflib.query.Processor,
     'rdfextras.sparql.processor', 'Processor')
    plugin.register(
       'sparql', rdflib.query.Result,
           'rdfextras.sparql.query', 'SPARQLQueryResult')

       qres = g.query(
             """
                PREFIX owl: <http://goo.gl/ZwwgT>
                SELECT ?class WHERE { ?sub rdfs:subClassOf ?class .
                FILTER(?sub=owl:Brands)}

                """)

       for row in qres.result:
         print(row)

Upvotes: 3

Views: 515

Answers (1)

Michael
Michael

Reputation: 4886

I can only assume that either you mis-transcribed your example, or rdflib has a bug. I loaded your ontology, executed your query (using the expanded URL for your ontology) and got a single result, Beer. I however, was not using RDFlib. You might try distilling it down to a single test case and providing it to the RDFlib authors so they can fix the issue, and/or look into using a different database.

Upvotes: 2

Related Questions