After several months of gathering updates for RDF.rb, we’ve released version 0.3.4 with several new features:
- Update to BGP query model to support SPARQL semantics,
- Expandable Litereal support, to allow further implementation of XSD datatypes outside of RDF.rb (see RDF::XSD gem),
- More advanced content type detection to allow better selection of the appropriate reader from those available on the client. (Includes selecting among HTML types, such as Microdata and RDFa)
- Improved CLI with the
rdfexecutable providing access to all loaded readers and writers for cross-language serialization and deserialization.</http:>
As an example of format detection, consider the following:
require 'linkeddata' RDF::Graph.load("http://greggkellogg.net/foaf.ttl")
should load Turtle or N3 readers if installed. This becomes more important for ambiguous file types, such as HTML, which could be either RDFa or Microdata, and application/xml, which could be TriX, RDF/XML or even RDFa.
See documentation for more specifics on this version of RDF.rb. Note that I’ve attempted to incorporate suggestions for improving the documentation.
Most of the reader/writer gems have been updated to match this release, in particular JSON::LD, RDF::Microdata, RDF::N3, RDF::RDFa, RDF::RDFXML, and RDF::Turtle.
A future update to the linkeddata gem should reference the latest versions of each, but a simple
gem update will work too.
There is a slight semantic change for repositories to support SPARQL: a context of false should not match a variable context. This is straight out of SPARQL semantics. Repository implementors who have provided custom implementations of
#query_pattern should check behavior against rdf-spec version 0.3.4 to verify correct operation.
Next up is a release of SPARQL implemented in pure Ruby. This gem provides full support for SPARQL 1.0 queries.
I’ve updated RDF::RDFa with updates from recent changes to RDF Core:
- Deprecate explicit use of @profile
- Add rdfa:hasVocabulary when encountering @vocab
- Implemented Reader#expand to perform vocabulary expansion using RDFS rules 5, 7, 9 and 11.
Additionally, experimental support for RDF Collections (lists) has been added, based on RDF Webapps working group Wiki notes.
Remove RDFa Profiles
RDFa Profiles were a mechanism added to allow groups of terms and prefixes to be defined in an external resource and loaded to affect the processing of an RDFa document. This introduced a problem for some implementations needing to perform a cross-origin GET in order to retrieve the profiles. The working group elected to drop support for user-defined RDFa Profiles (the default profiles defined by RDFa Core and host languages still apply) and replace it with an inference regime using vocabularies. Parsing of @profile has been removed from this version.
One of the issues with vocabularies was that they discourage re-use of existing vocabularies when terms from several vocabularies are used at the same time. As it is common (encouraged) for RDF vocabularies to form sub-class and/or sub-property relationships with well defined vocabularies, the RDFa vocabulary expansion mechanism takes advantage of this.
As an optional part of RDFa processing, an RDFa processor will perform limited RDFS entailment, specifically rules rdfs5, 7, 9 and 11. This causes sub-classes and sub-properties of type and property IRIs to be added to the output graph.
RDF::RDFa::Reader implements this using the
#expand method, which looks for
rdfa:hasVocabulary properties within the output graph and performs such expansion. See an example in the usage section.
RDF Collections (lists)
One significant RDF feature missing from RDFa was support for ordered collections, or lists. RDF supports this with special properties
rdf:nil, but other RDF languages have first-class support for this concept. For example, in Turtle, a list can be defined as follows:
[ a schema:MusicPlayList; schema:name "Classic Rock Playlist"; schema:numTracks 5; schema:tracks ( [ a schema:MusicRecording; schema:name "Sweet Home Alabama"; schema:byArtist "Lynard Skynard"] [ a schema:MusicRecording; schema:name "Shook you all Night Long"; schema:byArtist "AC/DC"] [ a schema:MusicRecording; schema:name "Sharp Dressed Man"; schema:byArtist "ZZ Top"] [ a schema:MusicRecording; schema:name "Old Time Rock and Roll"; schema:byArtist "Bob Seger"] [ a schema:MusicRecording; schema:name "Hurt So Good"; schema:byArtist "John Cougar"] ) ]
defines a playlist with an ordered set of tracks. RDFa adds the @member attribute, which is used to identify values (object or literal) that are to be placed in a list. The same playlist might be defined in RDFa as follows:
<div vocab="http://schema.org/" typeof="MusicPlaylist"> <span property="name">Classic Rock Playlist</span> <meta property="numTracks" content="5"/> <div rel="tracks" member=""> <div typeof="MusicRecording"> 1.<span property="name">Sweet Home Alabama</span> - <span property="byArtist">Lynard Skynard</span> </div> <div typeof="MusicRecording"> 2.<span property="name">Shook you all Night Long</span> - <span property="byArtist">AC/DC</span> </div> <div typeof="MusicRecording"> 3.<span property="name">Sharp Dressed Man</span> - <span property="byArtist">ZZ Top</span> </div> <div typeof="MusicRecording"> 4.<span property="name">Old Time Rock and Roll</span> <span property="byArtist">Bob Seger</span> </div> <div typeof="MusicRecording"> 5.<span property="name">Hurt So Good</span> <span property="byArtist">John Cougar</span> </div> </div> </div>
This basically does the same thing, but places each track in an rdf:List in the defined order.
You can try both these and other RDF gems a the distiller.
With the release of RDF::Turtle, starting with version 0.3.5, RDF::N3 no longer asserts that it is a reader for Turtle. This includes MIME Types text/turtle, application/turtle, application/x-turtle. Or the .ttl extension or :ttl or :turtle formats. Of course, N3 remains reasonably compatible with Turtle, but the recent RDF 1.1 Working Group publication of the Turtle Specification has caused some divergence.
Most notably, in Turtle, the empty prefix (‘:’) is no longer a synonym for <#>. In fact, the empty prefix is no longer defined by default.
RDF::Turtle defines MIME Types text/turtle, text/rdf+turtle, application/turtle and application/x-turtle. The officially submitted MIME Type for Turtle is text/turtle with default content coding of UTF-8.