LD Patch for RDF.rb

This is a Ruby implementation of LD Patch for RDF.rb.

Description

This gem implements the LD Patch specification with a couple of changes and/or limitations:

  • The INDEX terminal was replaced by INTEGER. Having two terminals matching the same token strings causes a conflict. As a result, a slice may contain positive integers, as well as unsigned and negative-integers.

  • The graph rule is changed to the following:

    [18] graph ::= triples (‘.’ triples?)*

This is necessary as the specified production is not context-free. As a result, it is possible for a graph to contain multiple trailing “.”.

LD Patch is useful inside a Rack container where it can respond to POST messages to affect the modification of a target graph identified using the URL of the POST.

Features

Documentation

Full documentation available on Rubydoc.info

Examples

require 'rubygems'
require 'ld/patch'

Example Patch

queryable = RDF::Repository.load("etc/doap.ttl")
patch = %(
  @prefix doap: <http://usefulinc.com/ns/doap#> .
  @prefix earl: <http://www.w3.org/ns/earl#> .
  @prefix foaf: <http://xmlns.com/foaf/0.1/> .

  Delete { <> a earl:TestSubject, earl:Software } .
  Add {
    <http://greggkellogg.net/foaf#me> a foaf:Person;
      foaf:name "Gregg Kellogg"
  } .
  Bind ?ruby <> / doap:programming-language .
  Cut ?ruby .
)
operator = LD::Patch.parse(patch, base_uri: "https://rubygems.org/gems/ld-patch")
operator.execute(queryable) # alternatively queryable.query(operator)

Command Line

When the linkeddata gem is installed, RDF.rb includes a rdf executable which acts as a wrapper to perform a number of different operations on RDF files, including LD::Patch, which is used as a stream command and must be followed by serialize to see the results. The commands specific to LD::Patch is

  • ld-patch: Patch the current graph using a patch file

Using this command requires either a patch-input where the patch is URI encoded, or patch-file, which references a URI or file path to the patch. Example usage:

rdf patch serialize https://raw.githubusercontent.com/ruby-rdf/ld-patch/develop/etc/doap.ttl \
  --patch-input Add%20%7B%20%3Chttp://example.org/s2%3E%20%3Chttp://example.org/p2%3E%20%3Chttp://example.org/o2%3E%20%7D%20. \
  --output-format ttl

Implementation Notes

The reader uses the EBNF gem to generate first, follow and branch tables, and uses the Parser and Lexer modules to implement the LD Patch parser.

The parser takes branch and follow tables generated from the LD Patch Grammar described in the specification. Branch and Follow tables are specified in the generated LD::Patch::Meta.

Dependencies

Mailing List

Author

Contributing

This repository uses Git Flow to mange development and release activity. All submissions must be on a feature branch based on the develop branch to ease staging and integration.

  • Do your best to adhere to the existing coding conventions and idioms.

  • Don’t use hard tabs, and don’t leave trailing whitespace on any line.

  • Do document every method you add using YARD annotations. Read the tutorial or just look at the existing code for examples.

  • Don’t touch the .gemspec, VERSION or AUTHORS files. If you need to change them, do so on your private branch only.

  • Do feel free to add yourself to the CREDITS file and the corresponding list in the the README. Alphabetical order applies.

  • Do note that in order for us to merge any non-trivial changes (as a rule of thumb, additions larger than about 15 lines of code), we need an explicit public domain dedication on record from you, which you will be asked to agree to on the first commit to a repo within the organization. Note that the agreement applies to all repos in the Ruby RDF organization.

License

This is free and unencumbered public domain software. For more information, see unlicense.org/ or the accompanying LICENSE file.

A copy of the LD Patch EBNF and derived parser files are included in the repository, which are not covered under the UNLICENSE. These files are covered via the W3C Document License.