Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to restrict DBpedia abstract result to English only

Tags:

sparql

dbpedia

I'm querying DBpedia for the title and abstract of a place-name in English only. The query works, but it returns the results in seven languages.

This is my query:

PREFIX foaf: <http://xmlns.com/foaf/0.1/>
PREFIX dbpedia-owl: <http://dbpedia.org/ontology/>
SELECT ?wikipedia_data_field_name ?wikipedia_data_field_abstract
WHERE {
    ?wikipedia_data foaf:name "Ballyhaunis"@en; foaf:name 
    ?wikipedia_data_field_name; dbpedia-owl:abstract ?wikipedia_data_field_abstract.
  }   

SPARQL result

I tried to add a filter using various permutations of

FILTER (LANGMATCHES(LANG(?abstract), 'en'))

but then the query returned no results. I can't see any other property in the corresponding page (http://dbpedia.org/page/Ballyhaunis) that I might be able to filter by. How can I restrict the results to show only the English abstract?

like image 264
Frank H. Avatar asked Dec 09 '25 19:12

Frank H.


1 Answers

With thanks to @Joshua Taylor for advice on the correct way to compare language tags, here is a better answer that works.

PREFIX foaf: <http://xmlns.com/foaf/0.1/>
    PREFIX dbpedia-owl: <http://dbpedia.org/ontology/>
    SELECT ?wikipedia_data_field_name ?wikipedia_data_field_abstract
    WHERE {
        ?wikipedia_data foaf:name "Ballyhaunis"@en; foaf:name 
        ?wikipedia_data_field_name; dbpedia-owl:abstract ?wikipedia_data_field_abstract.
        FILTER langMatches(lang(?wikipedia_data_field_abstract),'en')
      }

SPARQL result

like image 51
Frank H. Avatar answered Dec 11 '25 23:12

Frank H.