Search code examples
sparqlontologydbpediasparqlwrapper

How to query for publication date of books using SPARQL in DBPEDIA


I am trying to retrieve the publication date and the no.of pages for books in DBpedia. I tried the following query and it gives empty results. I see that these are properties under book(http://mappings.dbpedia.org/server/ontology/classes/Book) but could not retrieve it.

I would like to know if there is an error in the code or if dbpedia does not store these dates related to books.

SELECT  ?book  ?genre ?date ?numberOfPages
WHERE {
     ?book rdf:type dbpedia-owl:Book .
     ?book dbp:genre ?genre .
     ?book dbp:firstPublicationDate ?date .
     OPTIONAL {?book dbp:numberOfPages ?numberOfPages .}
     }

Solution

  • The dbp:firstPublicationDate does not work for two reasons:

    First, as pointed in the first answer, you used the wrong prefix.

    But even if you correct it, you'll see that you would still have no results. Then the best thing to do is to test with the minimum number of patters, in you case you should as for books with first publication date, two triple pattern only. If you still don't get results, you should test how <http://dbpedia.org/ontology/firstPublicationDate> is actually used with a query like this:

    SELECT  ?class (COUNT (DISTINCT ?s) AS ?instances)
    WHERE {
    
         ?s <http://dbpedia.org/ontology/firstPublicationDate> ?date ;
            a ?class
    
         }
    
    GROUP BY ?class
    ORDER BY DESC(?instances)
    
    LIMIT 1000