Ivo Velitchkov
Ivo Velitchkov

Reputation: 2431

Filter by datatype

I'm trying to filter by datatype in DBpedia. For example:

SELECT *
WHERE {?s ?p ?o .
    FILTER ( datatype(?o) = xsd:integer) 
    } 
LIMIT 10

But I get no results, while there are certainly integer values. I get the same from other endpoints using Virtuoso, but I do get results from alternative endpoints. What could be the problem? If Virtuoso does not implement this SPARQL function properly, what to use instead?

Upvotes: 0

Views: 2654

Answers (1)

Jindřich Mynarz
Jindřich Mynarz

Reputation: 1613

This is an expensive query, since it has to traverse all triples (?s ?p ?o .). The query's execution time exceeds the maximum time configured for the Virtuoso instance that serves DBpedia's SPARQL endpoint at http://dbpedia.org/sparql.

If you don't use the timeout parameter, then you will get a time out error (Virtuoso S1T00 Error SR171: Transaction timed out). When you use the timeout (by default set to 30000 for the DBpedia endpoint), you will get incomplete results that will contain HTTP headers like these:

X-SQL-State: S1TAT
X-SQL-Message: RC...: Returning incomplete results, query interrupted by result timeout.  Activity:  1.389M rnd  5.146M seq      0 same seg   55.39K same pg    195 same par      0 disk      0 spec disk      0B /      0 me

Empty results thus may be incomplete and it doesn't need to indicate there are no xsd:integer literals in DBpedia. A related discussion about the partial results in Virtuoso can be found here.

As a solution to your query, you can load the DBpedia from dumps and analyze it locally.

As a side note, your query is syntactically invalid, because it's missing namespace for the xsd prefix. You can check the syntax of SPARQL queries via SPARQLer Query Validator. You can find the namespaces for common prefixes using Prefix.cc. Virtuoso that provides the DBpedia SPARQL endpoint ignores the missing namespace for the xsd prefix, but it's a good practice to stick to syntactically valid SPARQL queries for greater interoperability.

Upvotes: 4

Related Questions