List Info

Thread: serialize as RDF/XML




serialize as RDF/XML
user name
2007-06-18 05:02:06
Hi,

How can i serialize triples or result of a query as RDF/XML using redland with active_rdf ?
Is this possible with rdflite too ?

Thanks by advance.


--
Samuel
Re: serialize as RDF/XML
country flaguser name
Ireland
2007-06-18 05:46:15
Hi Samuel.

On Jun 18, 2007, at 11:02 AM, Samuel MORELLO wrote:
> How can i serialize triples or result of a query as
RDF/XML using  
> redland
> with active_rdf ?
> Is this possible with rdflite too ?

Firstly: ActiveRDF provides you with an object oriented
abstraction  
layer over triples.
The result of this is, that accessing the actual triples,
instead  
accessing the objects is not very straight forward.

Secondly: SPARQL query results can either be an array of
variables  
and their bindings, or they can be a whole graph. ActiveRDF
currently  
does not support graph queries. Please see the SPARQL spec
for an  
explanation of the different result types.


Thirdly: the results which are returned by a Query object,
are just  
an array.

So, to have the ntriples of a Query result, you could do
something  
like this:

==========
# convert object to string representation dependent on type
of  
object, needed below
def serialise(r)
    case r
    when RDFS::Resource
      "<#{r.uri}>"
    else
      ""#{r.to_s}""
    end
end

# an example query:
result = Query.new.select(:s).where(:s, RDF::type,
SIOC::Post).execute

# now we have to iterate through the one dimensional results
array,
# in this example I will just get all the predicates for all
results.
# you can highly customize all of this

result.each do |subject|
	subject.direct_predicates.each do |predicate|
		objects = Query.new.distinct(.where(subj
ect, predicate, .execute
		objects.each do |object|
			puts "<#{subject.uri}>
<#{predicate.uri}> #{serialise(object)} ."
		end
	end
end
================================

You can customize this, e.g. with a more complex query
(multiple  
where clauses and mutliple variables, then the results will
be a  
multidimensional array).
Or you could fetch different triples to print.


So, yes, you can output triples from a search result, but
you have to  
roll your own right now, but as you can see, it is really
not that  
hard to do.
Also, it is independent of which adapter you use.
_______________________________________________
ActiveRDF mailing list
ActiveRDFlists.deri.org
http
://lists.deri.org/mailman/listinfo/activerdf

Re: serialize as RDF/XML
user name
2007-06-18 06:35:51
On 06/18/07/06/07 12:02 +0200, Samuel MORELLO wrote:
>Hi,
>
>How can i serialize triples or result of a query as
RDF/XML using redland
>with active_rdf ?
Could you maybe explain your use case, I'm not sure if I
understand why you 
would want to do this?

 -eyal
_______________________________________________
ActiveRDF mailing list
ActiveRDFlists.deri.org
http
://lists.deri.org/mailman/listinfo/activerdf

Re: serialize as RDF/XML
user name
2007-06-18 06:43:21
Hi eyal and thanks Benjamin for your response.

What i would like to do is a request to a rails controller that respond with a RDF/XML document like :

<?xml version=&quot;1.0&quot;?>
<rdf:RDF
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:test="http://test/"&gt;
<rdfescription
rdf:about="http://dsfklsjsdf&quot;>
<test:artist>sdfsdfsdf</test:artist>
<test:country>USA</test:country>;
</rdfescription>
<rdfescription
rdf:about="http://yuiyui"&gt;
<test:artist>yuiyui</test:artist&gt;
<test:country>UK</test:country>
</rdfescription>
.
.
.
</rdf:RDF>
Thanks,

Smauel

On 6/18/07, Eyal Oren < eyal.orenderi.org">eyal.orenderi.org > wrote:
On 06/18/07/06/07 12:02 +0200, Samuel MORELLO wrote:
>;Hi,
>
>How can i serialize triples or result of a query as RDF/XML using redland
&gt;with active_rdf ?
Could you maybe explain your use case, I'm not sure if I understand why you
would want to do this?

-eyal
_______________________________________________
ActiveRDF mailing list
ActiveRDFlists.deri.org">ActiveRDFlists.deri.org
http://lists.deri.org/mailman/listinfo/activerdf



--
Samuel
Re: serialize as RDF/XML
user name
2007-06-18 07:26:08
On 06/18/07/06/07 13:43 +0200, Samuel MORELLO wrote:
>Hi eyal and thanks Benjamin for your response.
>
>What i would like to do is a request to a rails
controller that respond with
>a RDF/XML document like :
ok. we don't currently support that, since (as Benjamin
explained) 
ActiveRDF translates RDF to objects, whereas you want to do
things the 
other way around. In ActiveRDF we typically don't deal with
triples but 
with objects (single objects or sets of objects). 

However, ActiveRDF is not only a OO layer but also an
abstraction over 
datastores. For example, you can use the Query API directly,
because it 
nicely abstracts over datastores, but you maybe don't need
the results to 
be returned as objects. So I see where we can fit your
requirement into 
ActiveRDF and I also understand the need for this.

What do you think of:

Query.new.select(:s, .where(:s,
FOAF::name, .execute(:s
yntax => :rdfxml)

This would return a string of RDF/XML which you can serve
using Rails?
If this would do what you want, I have to find a bit of time
to build it, 
but it shouldn't take long.

 -eyal
_______________________________________________
ActiveRDF mailing list
ActiveRDFlists.deri.org
http
://lists.deri.org/mailman/listinfo/activerdf

Re: serialize as RDF/XML
user name
2007-06-18 07:34:08
Excellent!
It could be very cool for me ! many thanks for that.
I will try to do as you and benjamin explain before you can do this

Thanks again for your response

Samuel


On 6/18/07, Eyal Oren < eyal.orenderi.org">eyal.orenderi.org&gt; wrote:
On 06/18/07/06/07 13:43 +0200, Samuel MORELLO wrote:
>;Hi eyal and thanks Benjamin for your response.
>
>What i would like to do is a request to a rails controller that respond with
>a RDF/XML document like :
ok. we don't currently support that, since (as Benjamin explained)
ActiveRDF translates RDF to objects, whereas you want to do things the
other way around. In ActiveRDF we typically don't deal with triples but
with objects (single objects or sets of objects).

However, ActiveRDF is not only a OO layer but also an abstraction over
datastores. For example, you can use the Query API directly, because it
nicely abstracts over datastores, but you maybe don't need the results to
be returned as objects. So I see where we can fit your requirement into
ActiveRDF and I also understand the need for this.

What do you think of:

Query.new.select(:s, .where(:s, FOAF::name, .execute(:syntax => :rdfxml)

This would return a string of RDF/XML which you can serve using Rails?
If this would do what you want, I have to find a bit of time to build it,
but it shouldn9;t take long.

-eyal
_______________________________________________
ActiveRDF mailing list
ActiveRDFlists.deri.org">ActiveRDFlists.deri.org
http://lists.deri.org/mailman/listinfo/activerdf



--
Samuel
[1-6]

about | contact  Other archives ( Real Estate discussion Medical topics )