Search code examples
sparqljenadbpedia

Writing Query result to .ttl file format


Any ideas on how to save the results of this SPARQL query into a TURTLE format?

PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX dbo: <http://dbpedia.org/ontology/>

select distinct ?city ?labelEn{
?city a dbo:City.
?city rdfs:label ?labelEn.
filter(lang(?labelEn) = 'en').
}
LIMIT 10

Solution

  • One way is to just ask the DBpedia endpoint to do so. Of course, you may not be expecting the reification that results there.

    Later comments suggest what you really want is rather different from your original question... More like --

    PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> 
    PREFIX dbo: <http://dbpedia.org/ontology/> 
    
    CONSTRUCT
     { ?city           a  dbo:City . 
       ?city  rdfs:label  ?labelEn . 
     } 
    WHERE
     { ?city a dbo:City . 
       ?city rdfs:label ?labelEn . 
       FILTER(lang(?labelEn) = 'en') 
     }
    

    -- which again you can ask the endpoint to serialize as Turtle.