Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

error method missing when enumerate solution query #11

Open
scauglog opened this issue Jun 20, 2013 · 3 comments
Open

error method missing when enumerate solution query #11

scauglog opened this issue Jun 20, 2013 · 3 comments

Comments

@scauglog
Copy link

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

@cagdasolgun
Copy link

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

@scauglog
Copy link
Author

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

@cagdasolgun
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants