How to filter results for specific languages within a ruby RDF.rb gem DBPedia query -


i'm stuck problem reducing delivered result set of dbpedia query did rdf gem. works fine "non-language specific" results when try reduce delivered literals "abstract" relation i'm struggling limiting results languages.

the code follows:

require 'linkeddata'  graph = rdf::graph.new  graph.load('http://dbpedia.org/resource/nbc')  query_abstract = rdf::query.new({    :wiki_abstract => {     rdf::uri('http://dbpedia.org/ontology/abstract') => :abstract,   }  })  results_abstract = query_abstract.execute(graph)  results_abstract.each |result|   puts "#{result.wiki_abstract} - abstract: #{result.abstract}" end 

i tried same sparql query , able filter output @en language without problem. when try find solution using rdf gem failed , couldn't find helpful hint in rdf documentation. have idea how add filters above query languages?

you need select results have language need, following:

results_abstract.to_a.select {|a| a.abstract.language == :en}.each |result|   puts "#{result.wiki_abstract} - abstract: #{result.abstract}" end 

in case, won't find any, looks languages returned :ru, :ja, :de, :it , nil (plain literal). plain literals using following:

results_abstract.to_a.select {|a| !a.abstract.has_language?} 

Comments

Popular posts from this blog

python - No exponential form of the z-axis in matplotlib-3D-plots -

php - Best Light server (Linux + Web server + Database) for Raspberry Pi -

c# - "Newtonsoft.Json.JsonSerializationException unable to find constructor to use for types" error when deserializing class -