Lookup DBpedia gloss using JSON API

Is there a quick and easy way to search only text on Wikipedia in DBpedia for a specific URI using the DBpedia JSON API?

eg. I can get all the triplets that DBpedia has on cats by downloading http://dbpedia.org/data/Cat.json , but all I want is the triplets with {"type" : "literal" ...}

. Can I get this without downloading and parsing the entire JSON output? The JSON API does not support any type of filtering and I cannot find any docs.

+3


source to share


1 answer


Looks like what you are looking for is all triplets of the form [dbpedia: Cat? p? o], where? o is literal. You can get the ones that have a SPARQL CONSTRUCT request to the public DBpedia endpoint and query the results in RDF / JSON.

construct where {
  dbpedia:Cat ?p ?o
  filter isLiteral(?o)
}

      

SPARQL Results

Constructive queries are part of the SPARQL standard and are described in 16.2 CONSTRUCT . If you are using the sparql-client for Python (there is no language tag on this question, so there is no reason to assume a general reader will be), note that its documentation says:

sparql-client is a SPARQL query library that executes SELECT and ASK queries with a SPARQL endpoint over HTTP.



Since this particular client does not support CONSTRUCT queries, you need to use a SELECT query. You can use:

select ?p ?o { 
  dbpedia:Cat ?p ?o 
  filter isLiteral(?o)
}

      

SPARQL Results

The resulting JSON isn't exactly the same, but it's still pretty regular and you should be able to process it without too much trouble:

{ "head": { "link": [], "vars": ["p", "o"] },
  "results": { "distinct": false, "ordered": true, "bindings": [
    { "p": { "type": "uri", "value": "http://dbpedia.org/ontology/abstract" }   , "o": { "type": "literal", "xml:lang": "nl", "value": "De kat of huiskat (Felis catus) is een van de oudste huisdieren van de mens. De gedomesticeerde kat behoort tot de familie der katachtigen (Felidae). De oude soortnaam was Felis domesticus, tegenwoordig is deze vervangen door Felis catus. Eind 2009 waren in Nederland ongeveer 3,6 miljoen katten aanwezig." }},
    { "p": { "type": "uri", "value": "http://dbpedia.org/ontology/conservationStatus" } , "o": { "type": "literal", "xml:lang": "en", "value": "DOM" }},
    { "p": { "type": "uri", "value": "http://dbpedia.org/ontology/synonym" }    , "o": { "type": "literal", "xml:lang": "en", "value": "Felis catus domestica (invalid junior synonym)" }},
    { "p": { "type": "uri", "value": "http://dbpedia.org/ontology/synonym" }    , "o": { "type": "literal", "xml:lang": "en", "value": "Felis silvestris catus (subjective synonym)" }},
    { "p": { "type": "uri", "value": "http://dbpedia.org/ontology/wikiPageID" } , "o": { "type": "typed-literal", "datatype": "http://www.w3.org/2001/XMLSchema#integer", "value": "6678" }},
    { "p": { "type": "uri", "value": "http://dbpedia.org/ontology/wikiPageRevisionID" } , "o": { "type": "typed-literal", "datatype": "http://www.w3.org/2001/XMLSchema#integer", "value": "547667240" }},
    { "p": { "type": "uri", "value": "http://www.w3.org/2000/01/rdf-schema#label" } , "o": { "type": "literal", "xml:lang": "zh", "value": "\u732B" }},
    { "p": { "type": "uri", "value": "http://www.w3.org/2000/01/rdf-schema#label" } , "o": { "type": "literal", "xml:lang": "de", "value": "Hauskatze" }},

      

+5


source







All Articles