Notation 3 support

Toby Inkster mail at tobyinkster.co.uk
Fri Jul 2 18:15:37 CEST 2010


Attached is a patch for Notation 3 support in RDF::Trine. It's against
Trine 0.124_04 which was the latest version when I started working on
it. I imagine it will apply cleanly to 0.125 though.

What does this add:

* RDF::Trine::Node::Formula

Formulae are represented in Notation 3 in curly braces. They are
essentially little graphs which can contain variables. They can be
nested.

	<#me> ex:believes
		{
		  { ?someone a foaf:Person . }
		     => { ?someone a foaf:Agent . } .
		} .

This is implemented as a subclass of RDF::Trine::Node::Literal. Formulas
are internally represented as RDF::Trine::Pattern objects plus some
additional data. Because formulae can be stringified (using Notation 3
syntax) in a round-trip safe way, this package is able to pretend that
formulae are good old datatyped literals when dealing with code that
doesn't natively understand formulae (e.g. the RDF/XML parser and
serializer).

You can create formulae from an RDF::Trine::Pattern:

	$formula = RDF::Trine::Node::Formula->new($pattern);

Or from some Notation3-like syntax without the outer braces:

	$formula = RDF::Trine::Node::Formula->new(<<'N3');
	@prefix foaf: <http://xmlns.com/foaf/0.1/> .
	"Toby Inkster" is foaf:name of <#me> .
	N3

* RDF::Trine::Parser::Notation3

This is a subclass of RDF::Trine::Parser::Turtle which adds the
following:

	- N3 formulae
	- @keywords support
	- @forAll/@forSome quantifiers
	- Default prefix ":" has default binding <#>
	- Allow literals, variables, formulae, bnodes and resources
	  as subjects, predicates and objects
	- "is ... of" notation
	- "=>", "<=" and "=" symbols

It does not currently support property paths, though maybe this will be
added later.

The combination of these two modules (plus a tiny patch to
RDF::Trine::Node::Literal) allows us to parse arbitrary Notation 3
documents. 

Some Notation 3 data can be serialised using the existing serializers,
though not all. If the top-most graph in the Notation 3 data is respects
RDF semantics (e.g. no literals in subject position), then it should be
possible to serialise this data - formulae in the object position should
serialise fine.

It still needs a bit of work and a lot of testing. Do people think these
features are worth adding to RDF::Trine's main distribution, or better
to package up separately?

-- 
Toby A Inkster
<mailto:mail at tobyinkster.co.uk>
<http://tobyinkster.co.uk>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: RDF-Trine-n3model.patch
Type: text/x-patch
Size: 20299 bytes
Desc: not available
URL: <http://lists.perlrdf.org/pipermail/dev/attachments/20100702/14057863/attachment-0001.bin>


More information about the Dev mailing list