4

I have a bunch of ISBN's. I want to query DBpedia and get the meta-data of the books.

I am unable to understand the SPARQL.

Can someone tell me how can I get the meta-data of a book from DBpedia in Java?

JHS
  • 7,761
  • 2
  • 29
  • 53

2 Answers2

2

SPARQL is both a query language and a protocol to query so-called SPARQL endpoints.

A SPARQL query that asks DBpedia for a book (or books) that have the ISBN 0-553-05250-0, and its (or their) associated properties and values is this:

select distinct ?book ?prop ?obj 
where {
  ?book a dbo:Book .
  ?book ?prop ?obj .
  ?book dbp:isbn ?isbn .
  FILTER (regex(?isbn, "0-553-05250-0"))
} 
LIMIT 100

See the result of the query in your browser here.

Be aware that regex(?isbn, "0-553-05250-0") takes some time to evaluate. It may not work for all ISBNs, because

  • Wikipedia may never have a complete list of ISBNs, so neither may DBpedia
  • the same ISBN without dashes will not match a query with dashes.

Also, I noticed that some ISBNs are just a string of digits and dashes, others have "ISBN" in it or "(paperback)" appended.

You can send this query to the DBpedia endpoint via the webform (by visiting the endpoint with your browser) via Jena, a well-known Java toolkit for RDF and SPARQL.
Here is the query in some Java code that queries DBpedia for results and prints them to the command line (based on another Jena, SPARQL and DBpedia related question, of which there are many):

String sparqlQueryString1= "select distinct ?book ?prop ?obj " +
       "where { " +
       "  ?book a dbpedia-owl:Book . " +
       "  ?book ?prop ?obj . " +
       "  ?book dbpprop:isbn ?isbn . " +
       "  FILTER (regex(?isbn, \"0-553-05250-0\")) " +
       "} " +
       "LIMIT 100";

Query query = QueryFactory.create(sparqlQueryString1);
QueryExecution qexec = QueryExecutionFactory.sparqlService("http://dbpedia.org/sparql", query);

ResultSet results = qexec.execSelect();
ResultSetFormatter.out(System.out, results, query);       

qexec.close() ;

My favourite SPARQL resource is Lee Feigenbaum's cheat sheet, which is a pretty comprehensive reference. Perhaps you would like to check out the tutorials Jena provides with its documentation.

Community
  • 1
  • 1
Ben Companjen
  • 1,417
  • 10
  • 24
  • Ben - Thanks for the answer. I have another question. Where can I get, what details can DBpedia provide to me when I give in an ISBN number? Also can I get a JSON by just entering the query in my Browser something like - https://www.googleapis.com/books/v1/volumes?q=isbn:3772508456 – JHS Jan 13 '13 at 05:03
  • You can look at some books on Wikipedia to see what is in the Infobox - that info is in DBpedia. Or use SPARQL to get [this list](http://dbpedia.org/sparql?default-graph-uri=http%3A%2F%2Fdbpedia.org&query=select+distinct+%3Fprop+%3Flabel+%3Fdescription%0D%0Awhere+{+%0D%0A++%3Fbook+a+dbpedia-owl%3ABook+.+%0D%0A++%3Fbook+%3Fprop+%3Fobj+.+%0D%0A++OPTIONAL+{%0D%0A++++%3Fprop+rdfs%3Alabel+%3Flabel+.%0D%0A++}+.%0D%0A++OPTIONAL+{%0D%0A++++%3Fprop+rdfs%3Acomment+%3Fdescription+.%0D%0A++}%0D%0A}+%0D%0ALIMIT+1000&format=text%2Fhtml&timeout=0&debug=on) of properties of books with labels and descriptions. – Ben Companjen Jan 13 '13 at 09:48
  • The DBpedia endpoint provides JSON output as described in the W3C Note [Serializing SPARQL Query Results in JSON](http://www.w3.org/TR/rdf-sparql-json-res/). However, it's more like a table of results serialised in JSON than it is a 'direct' JSON description like Google's Book API returns. – Ben Companjen Jan 13 '13 at 10:03
  • Ben - I have about 600,000 ISBN's. I tried to lookup for about a random 30 and there was no result. Also the the example you have given gives out a lot data which is difficult to figure out. For eg. It gives out 2 ISBN's and the title in various languages. I would like to find out the exact book against the ISBN and its details like publisher, authors, place, etc. Could you please help me on this? – JHS Jan 17 '13 at 17:16
  • I'm afraid the data in DBpedia isn't fine-grained enough for your application. ISBNs are associated with specific editions of books, but DBpedia has no notion of editions. You could take a look at the [APIs of OpenLibrary](http://openlibrary.org/developers/api) (disclosure: I am a user of/volunteer for OpenLibrary). It has editions and many ISBNs although you'll find ISBNs missing as well. – Ben Companjen Jan 17 '13 at 21:09
0

As far as I can tell, Wikipedia does not have an ISBN search.

Wikipedia has this page for using other ISBN search engines.

Amazon.com has an ISBN search here. I couldn't find an API for automating the ISBN search on Amazon.

Gilbert Le Blanc
  • 50,182
  • 6
  • 67
  • 111