[Activerdf] query results metadata
Eyal Oren
eyal.oren at deri.org
Wed Oct 4 21:05:50 IST 2006
On 10/04/06/10/06 12:49 -0700, Eric Hanson wrote:
>The other thing is the "column" names that a SPARQL query returns. I
>want the user to be able to enter in an arbitrary query in form, and
>then display the results as a table, with the column names labeled at
>the top. So if I do:
>
>SELECT ?s ?p ?o WHERE {?s ?p ?o}
the new Query API (in trunk) allows following:
Query.new.select(:s,:p,:o).where(:s,:p,:o).execute do |s,p,o|
# code to build your table or whatevere
# e.g. print as <s,p,o>
p "<" + [s,p,o].join(',') + ">"
end
does something like this help?
btw, you can also write stuff like this to get the name of every foaf
person:
rdf_type = Namespace.lookup(:rdf,:type)
foaf_person = Namespace.lookup(:foaf,:person)
foaf_name = Namespace.lookup(:foaf,:name)
Query.new.distinct(:name).where(:s,rdf_type,foaf_person).where(:s,foaf_name,
:name).execute
(and we use json internally when the sparql server returns it)
-eyal
More information about the Activerdf
mailing list