parse and serialize not idempotent (and they should)

21 views
Skip to first unread message

ixemad

unread,
Mar 4, 2015, 5:34:54 AM3/4/15
to rdfli...@googlegroups.com
When a Turtle resource have relative IRIs, parse() and serialize() don't generate the same result.

In the following example, g1 serializes to s1_relative with relatives IRIs to base_iri. Whether I parse s1_relative to g2 using base_iri as publicID the result is not the same as g1. Specifically, the homepage IRI is <http://my.domain/bond/public> in g1 but <http://my.domain/public> in g2.


from rdflib import RDF, ConjunctiveGraph
from rdflib.term import URIRef
from rdflib.resource import Resource
from rdflib.plugins.parsers.notation3 import BadSyntax

import pdb

data = """@prefix ns1: <http://xmlns.com/foaf/0.1/> .
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .

<http://my.domain/bond> a ns1:Person ;
    ns1:homepage <http://my.domain/bond/public> ."""

pdb.set_trace()
base_iri = "http://my.domain/bond"
g1 = ConjunctiveGraph()
t1 = g1.parse(format='turtle', data=data)
s1_full = g1.serialize(format='turtle')
s1_relative = g1.serialize(format='turtle', base=base_iri)

g2 = ConjunctiveGraph()
g2 = g2.parse(format='turtle', publicID=base_iri, data=s1_relative)
s2_full = g2.serialize(format='turtle')

print s1_full
print s2_full

Is there other way to get g2 equals to g1 using s1_relative?

Thanks.
Reply all
Reply to author
Forward
0 new messages