Re: canonical RDF graph representations

Yes, that case (cyclical references) works alright in RDFLib.

I expect that algorithm to work fine for *almost* anything. But I just
discovered it can smush two bnodes together in at least *one*
particular case -- number 2 in this example test (requires Python 2.5+
and RDFLib 3.0+):

    from rdflib import Graph, compare

    for data in [

      # 1. Ok.
      """
      _:b1 :knows _:b2 .
      _:b2 :knownBy _:b1 .
      """,

      # 2. Fails - smushes these bnodes together.
      """
      _:b1 :knows _:b2 .
      _:b2 :knows _:b1 .
      """,

      # 3. Ok again with some additional data.
      """
      _:b1 :knows _:b2 .
      _:b2 :knows _:b1 .
      _:b1 :name "blank 1" .
      """,

      ]:
      g = Graph().parse(format='n3', data=
          "@prefix : <http://example.org/def/vocab#> . " + data)
      c14n = compare.to_canonical_graph(g).serialize(format='nt')
      print "Using:"; print data; print "Got:"
      print compare.to_canonical_graph(g).serialize(format='nt')

Anyhow, I audaciously expect this to occur extremely rarely (probably
only for this artificial case), and will keep using this module for
comparisons. ;)

Best regards,
Niklas



2011/3/1 Nathan <nathan@webr3.org>:
> can these two handle the case of:
>
>  _:b1 :x _:b2 .
>  _:b2 :y _:b1 .
>
> + yes I agree, would be great to have a canonical representaion and
> comparison method.
>
> Cheers,
>
> Nathan
>
> Niklas Lindström wrote:
>>
>> Hi Ivan,
>>
>> while this isn't based on this or any newer standard proposal, the
>> Python-based RDFLib contains an implementation for canonicalizing and
>> comparing graphs. See the the "rdflib.compare" module:
>>
>>  http://code.google.com/p/rdflib/source/browse/trunk/rdflib/compare.py
>>
>> It would be interesting to standardize something like that; and
>> certainly useful for some things.
>>
>> Best regards,
>> Niklas
>>
>>
>>
>> On Tue, Mar 1, 2011 at 10:50 AM, Ivan Shmakov <ivan@main.uusia.org> wrote:
>>>
>>>       The “The case for generating URIs by hashing RDF content” paper
>>>       [1], dating back to 2002, mentions that “there is no current
>>>       canonical serialization standard for RDF”.  (Then, they suggest
>>>       their own canonical representation.)
>>>
>>>       I wonder, has such a standard been since proposed?
>>>
>>> [1] http://www.hpl.hp.com/techreports/2002/HPL-2002-216.pdf
>>>
>>> --
>>> FSF associate member #7257
>>>
>>
>>
>>
>
>

Received on Tuesday, 1 March 2011 17:56:25 UTC