ShEx 0.1.0 gem

I’ve just released version 0.1.0 of the shex gem [1], which implements the latest Shape Expressions (ShEx) community specification [2].

Shape Expressions can be used to validate nodes within RDF graphs using schema language for describing various restrictions on nodes within a graph. For example, the project DOAP description [3], can be validated using the following ShEX schema [4]:

PREFIX doap:  <http://usefulinc.com/ns/doap#>
PREFIX dc:    <http://purl.org/dc/terms/>
<TestShape> EXTRA a {
  a [doap:Project];

  # May have either or both of doap:name/doap:description or dc:title/dc:description
  ( doap:name Literal;
    doap:description Literal
  | dc:title Literal;
    dc:description Literal)+;

  # Good idea to use a category for what the project relates to
  doap:category IRI*;

  # There must be at least one developer
  doap:developer  IRI+;

  # For our purposes, it MUST implement the ShEx specification.
  doap:implements [<https://shexspec.github.io/spec/>]
}

The project is UNLICENCED to the Public Domain, available on GitHub [5].

The gem implements an LL(1) parser to generate an executable algebra, similar to that used for SPARQL and LD Patch gems. For example, the proceeding ShExC can be expressed in the following S-Expression:

(schema
 (prefix (("doap" <http://usefulinc.com/ns/doap#>) ("dc" <http://purl.org/dc/terms/>)))
 (shapes
  ((<TestShape> (shape
     (eachOf
      (tripleConstraint a
       (nodeConstraint (value <http://usefulinc.com/ns/doap#Project>)))
      (oneOf
       (eachOf
        (tripleConstraint <http://usefulinc.com/ns/doap#name>
         (nodeConstraint literal))
        (tripleConstraint <http://usefulinc.com/ns/doap#description>
         (nodeConstraint literal)) )
       (eachOf
        (tripleConstraint <http://purl.org/dc/terms/title>
         (nodeConstraint literal))
        (tripleConstraint <http://purl.org/dc/terms/description>
         (nodeConstraint literal)))
       (min 1) (max "*"))
      (tripleConstraint <http://usefulinc.com/ns/doap#category>
       (nodeConstraint iri)
       (min 0) (max "*"))
      (tripleConstraint <http://usefulinc.com/ns/doap#developer>
       (nodeConstraint iri)
       (min 1) (max "*"))
      (tripleConstraint <http://usefulinc.com/ns/doap#implements>
       (nodeConstraint (value <https://shexspec.github.io/spec/>))) )
     (extra a))))))

Gregg Kellogg
gregg@greggkellogg.net

[1] https://rubygems.org/gems/shex
[2] https://shexspec.github.io/spec/
[3] https://github.com/ruby-rdf/shex/blob/develop/etc/doap.ttl
[4] https://github.com/ruby-rdf/shex/blob/develop/etc/doap.shex
[5] https://github.com/ruby-rdf/shex

Received on Monday, 12 December 2016 00:23:10 UTC