KGConf / Bookclub-DemystifyingOWL

Notes and material for the DemistifyingOWL bookclub
7 stars 1 forks source link

Chapter 3: SparQL Query to count property instances is not working #21

Closed Robert-Muil closed 3 years ago

Robert-Muil commented 3 years ago

Apologies for these lagging questions, but I can't get the query for instances of object properties to work in DBpedia. The query is in section 3.1.12:

select ?p count(?i)
WHERE {
    ?p a owl:ObjectProperty .
    ?i ?p ?o .
} 
GROUP BY ?p

When I execute that against the DBpedia endpoint I get no results:

p callret-1

I've tried it with and without the GROUP BY clause.

Any ideas?

uscholdm commented 3 years ago

That's a good question. I get the same result. I also tried it on an AllegroGraph repo and it also did not work. Not sure why.

Robert-Muil commented 3 years ago

In Protege's SPARQL interface I even get a syntax error which completely befuddles me:

Caused by: org.openrdf.query.MalformedQueryException: Encountered " "count" "count "" at line 5, column 11.
Was expecting one of:
    "(" ...
    "{" ...
    "from" ...
    "where" ...
    <VAR1> ...
    <VAR2> ...
Robert-Muil commented 3 years ago

Got it working... in Protege at least It seems that brackets are necessary around the count, as is the as clause:

select ?p (count(?i) as ?count)
WHERE {
    ?p a owl:ObjectProperty .
    ?i ?p ?o .
} 
GROUP BY ?p

EDIT: Still empty result set in DBpedia.

uscholdm commented 3 years ago

The query works fine on other repos I have, don't know why not working on DBPedia. Try ordering the results putting the most often used first, like this:

select ?p (count(?i) as ?count)
WHERE {
    ?p a owl:ObjectProperty .
    ?i ?p ?o .
} 
GROUP BY ?p 
ORDER BY desc(?count)