Created
June 29, 2010 03:56
-
-
Save bhuga/456775 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby1.9 | |
require 'rdf' | |
require 'rdf/rdfxml' | |
require 'rdf/ntriples' | |
require 'rdf/isomorphic' | |
s1 = %(<?xml version="1.0"?> | |
<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" | |
xmlns:eg="http://example.org/"> | |
<rdf:Description rdf:about="http://example.org/foo"> | |
<eg:bar rdf:datatype="http://www.w3.org/2001/XMLSchema#integer">10</eg:bar> | |
<eg:baz rdf:datatype="http://www.w3.org/2001/XMLSchema#integer">10</eg:baz> | |
</rdf:Description> | |
</rdf:RDF>) | |
s2 = %(<http://example.org/foo> <http://example.org/bar> "10"^^<http://www.w3.org/2001/XMLSchema#integer> . | |
<http://example.org/foo> <http://example.org/baz> "10"^^<http://www.w3.org/2001/XMLSchema#integer> . | |
) | |
g1 = RDF::Graph.new | |
RDF::RDFXML::Reader.new(s1).each {|s| g1 << s} | |
g2 = RDF::Graph.new | |
RDF::NTriples::Reader.new(s2).each {|s| g2 << s} | |
s1 = RDF::Writer.for(:ntriples).dump(g1) | |
s2 = RDF::Writer.for(:ntriples).dump(g2) | |
puts g1.to_a.first.object.datatype.class | |
puts g2.to_a.first.object.datatype.class | |
puts g1.isomorphic_with?(g2) ? "graphs isomorphic" : "graphs non-isomorphic" | |
puts g1.to_a.inspect | |
puts g2.to_a.inspect | |
puts s1 == s2 ? "strings equivalent" : "strings differ" | |
puts s1 | |
puts s2 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment