Search code examples
sparqlwikipediadbpedia

SPARQL: retrieve all the info from DBpedia from a URI


If I want to retrieve the abstract from a URI, I do the following:

PREFIX dbp_owl: <http://dbpedia.org/ontology/> 

SELECT DISTINCT ?abstract WHERE { <http://dbpedia.org/resource/Horizon_High_School_(Thornton,_Colorado)> dbp_owl:abstract ?abstract FILTER (lang(?abstract) = "en" )}

If I want to retrieve the thumbnail:

SELECT DISTINCT ?thumb WHERE { <http://dbpedia.org/resource/Horizon_High_School_(Thornton,_Colorado)>  dbp_owl:thumbnail ?thumb }

How can I retrieve everything from the URI and not only one property?


Solution

  • As to retrieving multiple properties, you can do that by using a variable in the property position. E.g.,

    select ?property ?value where {
      dbpedia:Mount_Monadnock ?property ?value
    }
    

    SPARQL results

    Note that if you try to filter ?value here by language, you'll miss a lot of results, because results that aren't literals, or aren't language tagged literals won't give you a value with the lang function. So you really need restrict the filter a bit:

    select ?property ?value where {
      dbpedia:Mount_Monadnock ?property ?value
      filter ( !isLiteral(?value)               #-- ?value is not a literal
            || lang(?value) = ""                #-- ?value is a non-language tagged literal
            || langMatches(lang(?value),"en"))  #-- ?value has a language tag matching "en"
    }
    

    SPARQL results

    Note that you should not check languages with =, but with langMatches instead. That will handle differences in capitalization, as well as a regional variants in language.