Open scauglog opened 11 years ago
i think the correct syntax is like
a=[]
@repo.build_query do |q|
q.pattern [item_uri,SCHEMA.associatedMedia,:uri]
q.pattern [:uri,SCHEMA.image, :image_url]
end.run do |s|
a << s.image_url.to_s
end
And maybe you can print out solutions after you run query.
end.run do |s|
puts s.inspect
end
Also you can check query patterns to see if your statements are correct.
query = @repo.build_query do |q|
q.pattern [item_uri,SCHEMA.associatedMedia,:uri]
q.pattern [:uri,SCHEMA.image, :image_url]
end
puts query.patterns.inspect
thanks for the answer but rewrite the query with pattern didn't solve my problem. I have write a sparql query and this seems better.
a=[]
@repo.sparql_query("SELECT ?image_url WHERE {
<#{item_uri}> <#{SCHEMA.associatedMedia}> ?uri.
?uri <#{SCHEMA.image}> ?image_url.}"
).each do |s|
a << s.image_url.to_s
end
quick fix about example;
run method returns an enumeration. And it should be ,
a=[]
@repo.build_query do |q|
q.pattern [item_uri,SCHEMA.associatedMedia,:uri]
q.pattern [:uri,SCHEMA.image, :image_url]
end.run.each do |s|
a << s.image_url.to_s
end
Sometimes when i ran a query and enumerate the solution an error occur
C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/rdf-1.0.6/lib/rdf/query/solution.rb:257:in 'method_missing': undefined method 'image_url' for #<RDF::Query::Solution:0x2b0b8b8> (NoMethodError)
It's very strange because i can rerun the same query, without any change, few minute later and this message doesn't show up.
this is the query i run :
a=[] @repo.build_query do |q| q << [item_uri,SCHEMA.associatedMedia,:uri] q << [:uri,SCHEMA.image, :image_url] end.run do |s| a << s.image_url.to_s end