Search code examples
rdfsparqldbpedia

How to query DBPedia data for a given Wikipedia URL?


If I want to query the RDF for Appomattox Court House National Historical Park in DBPedia, what's the query string if I search by wiki page URL?

I tested the following string but get no result:

select ?building 
where {
   ?building a dbo:Building .
   ?building foaf:primaryTopic <http://en.wikipedia.org/wiki/Appomattox_Court_House_National_Historical_Park>
} LIMIT 100

Solution

  • As said in my comment as well: the problem is that you are using the foaf:primaryTopic relation the wrong way around. The wiki page is the subject of the relation, and the DBPedia resource the object value. So it should be this:

    SELECT ?building 
    WHERE {
        ?building a dbo:Building .
        <http://en.wikipedia.org/wiki/Appomattox_Court_House_National_Historical_Park> foaf:primaryTopic ?building .
    } 
    LIMIT 100
    

    Alternatively, as @AKSW commented, you can use the inverse relation, which is called foaf:isPrimaryTopicOf:

    SELECT ?building 
    WHERE {
        ?building a dbo:Building .
        ?building foaf:isPrimaryTopicOf <http://en.wikipedia.org/wiki/Appomattox_Court_House_National_Historical_Park> .
    } 
    LIMIT 100