ruby-rdf / rdf

RDF.rb is a pure-Ruby library for working with Resource Description Framework (RDF) data.
http://rubygems.org/gems/rdf
The Unlicense
381 stars 92 forks source link

Operations with graphs #186

Open b-mandelbrot opened 9 years ago

b-mandelbrot commented 9 years ago

Is there a way to realize operations with graphs? I have two graphs and I need to subtract them.

gkellogg commented 9 years ago

The Ruby RDF toolset doesn't specifically have such a tool, or an RDF Diff tool, which would be useful, however you may be able to achieve what you want using a SPARQL MINUS or SPARQL UPDATE DELETE WHERE, both available using the SPARQL gem. Note that the problem is that BNodes in two different graphs are different, and a simple removal doesn't work. Even if you load the same serialization into two different graphs, the BNodes aren't equivalent.

However, if you can put the graph you want to do in a SPARQL WHERE clause, BNodes act like existential variables, so that they will match BNodes that have the same pattern.

Lastly, on the books to implement is RDF Normalization, which might work, as it can create canonical serializations of both graphs allowing a text diff to work, or by skolemizing the BNodes in each graph using normalized identifiers allowing the use of something like RDF::Mutable.delete.

gkellogg commented 9 years ago

See issue #209 on how rdf-normalize might add a diff command to the rdf executable.

no-reply commented 8 years ago

(closed by mistake)

no-reply commented 8 years ago

This seems like a punt for 2.0 so I'm removing the tag.

I have some ideas about supporting graph operations through FFI to C and/or Rust, but think this is a larger work chunk than we can take on on the 2.0 timeline. It would be useful for any interested parties to chime in on use cases.