Search code examples
sparqldbpedia

How to retrieve abstract for a DBpedia resource?


I need to find all DBpedia categories and articles that their abstract include a specific word. I know how to write a SPARQL query that queries the label like the following:

SELECT ?uri ?txt  WHERE {
  ?uri rdfs:label ?txt .
  ?txt bif:contains "Machine" .
}

but I have not figured out yet how to search the abstract. I've tried with the following but it seems not to be correct.

SELECT ?uri ?txt  WHERE {
  ?uri owl:abstract ?txt .
  ?txt bif:contains "Machine" .
}

How can I retrieve the abstract in order to query its text?


Solution

  • Since you already know how to search a string for text content, this question is really about how to get the abstract. If you retrieve any DBpedia resource in a web browser, e.g., http://dbpedia.org/resource/Mount_Monadnock (which will redirect to http://dbpedia.org/page/Mount_Monadnock), you can see the triples of which it's a subject or predicate. In this case, you'll see that the property is dbpedia-owl:abstract. Thus you can do things like

    select * where { 
      ?s dbpedia-owl:abstract ?abstract .
      ?abstract bif:contains "Monadnock" .
      filter langMatches(lang(?abstract),"en")
    }
    limit 10
    

    SPARQL results

    Instead of visiting the page for the resource, which not endpoints will support, you could have simply retrieved all the triples for the subject, and looked at which ones relate it to its abstract. Since you know the abstract is a literal, you could even restrict it to triples where the object is a literal, and perhaps with a language that you want. E.g.,

    select ?p ?o where { 
      dbpedia:Mount_Monadnock ?p ?o .
      filter ( isLiteral(?o) && langMatches(lang(?o),'en') )
    }
    

    SPARQL results

    This also clearly shows that the property you want is http://dbpedia.org/ontology/abstract. When you have a live query interface that you can use to pull down arbitrary data, it's very easy to find out what parts of the data you want. Just pull down more than you want at first, and then refine to get just what you want.