Separated instances in a graph

11 views
Skip to first unread message

anoga...@gmail.com

unread,
Mar 20, 2015, 1:06:05 PM3/20/15
to rdfli...@googlegroups.com
Hello I need to obtain something like that:

@prefix semag: <http://semagrow.eu/rdf/recom#> .

AGRIS_URI_1 semag:rel [
semag:order "1"^^xsd:integer ;
semag:recom <http:/weburl1.com> ] .
<http://weburl1.com> rdf:type semag:CrawledDocument .

AGRIS_URI_1 semag:rel [
semag:order "2"^^xsd:integer ;
semag:recom <http:/weburl2.com> ] .
<http://weburl2.com> rdf:type semag:CrawledDocument .

I have done that code:

final_g = Graph()
semag = Namespace("http://semagrow.eu/rdf/recom#")
rdf = Namespace("http://www.w3.org/2000/01/rdf-schema#")
relation = BNode()
order=1

for url, count in counter_urls:
g = Graph()
g.add( (Literal(uri), semag.rel, relation) )
g.add( (relation, semag.order, Literal(order)) )
g.add( (relation, semag.recom, Literal(url)) )
g.add( (Literal(url), rdf.type, semag.CrawledDocument) )
order += 1
final_g += g

And what I am obtaining is:

@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
@prefix semag: <http://semagrow.eu/rdf/recom#> .
@prefix xml: <http://www.w3.org/XML/1998/namespace> .
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .

"AGRIS_URI_1" semag:rel [ semag:order 1,
2 ;
semag:recom "http://weburl1.com",
"http://weburl2.com"] .

"http://weburl1.com" rdfs:type semag:CrawledDocument .

"http://weburl2.com" rdfs:type semag:CrawledDocument .

I want to have each instance separated and not one with everything that I do not know if it is equivalent.
Thanks a lot.
Regards.

Niklas Lindström

unread,
Mar 20, 2015, 1:12:27 PM3/20/15
to rdfli...@googlegroups.com
Hello,

You need to create two separate blank nodes for the relation (you're describing the same node twice). Move:

    relation = BNode()

Into the for loop and you should get what you need. (Note that the order of the serialized statements has no semantics.)

Cheers,
Niklas

 
--
http://github.com/RDFLib
---
You received this message because you are subscribed to the Google Groups "rdflib-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rdflib-dev+...@googlegroups.com.
To post to this group, send email to rdfli...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rdflib-dev/2002bd96-820d-4d58-afa5-14ece3395564%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Alberto Nogales

unread,
Mar 20, 2015, 1:17:46 PM3/20/15
to rdfli...@googlegroups.com
I tried that and I got:

> .

"AGRIS_URI_1" semag:rel [ semag:order 2 ;
            semag:recom "http://weburl2.com/" ],
        [ semag:order 1 ;
            semag:recom "http://weburl1.com/" ] .

"http://weburl1.com/" rdfs:type semag:CrawledDocument .

"http://weburl2.com/" rdfs:type semag:CrawledDocument .

It is not exactly what I need.
Thanks

--
http://github.com/RDFLib
---
You received this message because you are subscribed to a topic in the Google Groups "rdflib-dev" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/rdflib-dev/dlMkOyhtV7U/unsubscribe.
To unsubscribe from this group and all its topics, send an email to rdflib-dev+...@googlegroups.com.

To post to this group, send email to rdfli...@googlegroups.com.

Niklas Lindström

unread,
Mar 20, 2015, 1:42:49 PM3/20/15
to rdfli...@googlegroups.com
You also need to use URIRef(uri) instead of Literal(uri) (and similarly for url).

(Note that:
    <a> :rel <b>, <c> .
is exactly equivalent to:
    <a> :rel <b> . <a> :rel <c> .
)

Cheers,
Niklas


anoga...@gmail.com

unread,
Mar 20, 2015, 2:04:54 PM3/20/15
to rdfli...@googlegroups.com, anoga...@gmail.com
Ok, thanks. I am not too much in semantic languages. :)
Reply all
Reply to author
Forward
0 new messages