The N3 Cheat Sheet

When I was getting to know RDF, I put together a short quickref guide of the N3 Notation to help remind me while I wrote ontologies. I’ve found many of the tools such as Protege awkward or cumbersome, so I tend to use a text editor. Needless to say there’s no integrated to help, so I used the following table to help me. I hope it helps you get started. I know it is pretty rough, and in some cases I’m using namespaces from all over the place. I will tidy it up soon. I promise.

You might also want to take a look a the W3C’s N3 Primer, the Specification and the Resources link page.

Task

Example and Commentary

Ontologies – importing <> a daml:Ontology;
daml:comment "An example ontology";
daml:imports <http://www.daml.org/2000/10/daml-ont&gt;;
daml:versionInfo "$Id: daml-ex.n3,v 1.5 2001/05/21 03:11:59 timbl Exp $"
Ontologies – namespaces @prefix dc: <http://purl.org/dc/elements/1.1/&gt; .
Ontologies – this document <> <#title> "A simple example of N3".
the empty brackets indicate the current document
Basics – triples <#subject> <#predicate> <#object> .
the fullstop matters
Basics – literals <#subject> <#predicate> 1524 .
on object only
Basics – default namespace @prefix : <#> .
now you can refer to things as :Foo rather than <#Foo>
Syntax – comments # this is a comment
Syntax – chaining :MyCar :make :Hyundai; :model :SantaFe .
Syntax – multiline literals """something over
a few lines"""
Syntax – blank nodes <#pat> <#child> [ <#age> 4] , [ <#age> 3].
creates an anonymous subject for the predicate and object. i.e. some child of age 4
Syntax – string escaping Goto here
It follows the rules laid down by Python.
Syntax – equivalence :Woman = foo:FemaleAdult .
Title a rdf:Property; = dc:title .

Syntax – going down paths :joe!fam:mother!loc:office!loc:zip
Joe’s mother’s office’s zipcode
Syntax – going up paths :joe!fam:mother^fam:mother
Anyone whose mother is Joe’s mother.
Syntax – formulae { [ x:firstname "Ora" ] dc:wrote [ dc:title "Moby Dick" ] } a n3:falsehood .
the expression in {braces} is false – that there is nothing called Ora which wrote anything titled "Moby Dick".
Syntax – lists (:Tom :D ick :Harry)
Syntax – comments :P erson a daml:Class;
daml:comment "every person is a man or a woman";
daml:disjointUnionOf (
:Man
:Woman ).
Syntax – enumerations :Height a daml:Class;
daml:oneOf (
:short
:medium
:tall ) .
Classes – declarations :P erson a rdfs:Class.
Classes – inheritance :Woman a rdfs:Class; rdfs:subClassOf :P erson .
Classes – multiple inheritance :TallMan a daml:Class;
daml:intersectionOf (
:TallThing
:Man ) .
Classes – disjoint union :P erson a daml:Class;
daml:comment "every person is a man or a woman";
daml:disjointUnionOf (
:Man
:Woman ).
Classes – complement :Car a daml:Class;
daml:comment "no car is a person";
daml:subClassOf [
a daml:Class;
daml:complementOf :P erson ] .
Properties – declaration :sister a rdf:Property.
sister rdfs:domain :P erson; rdfs:range :Woman.

Properties – transitive :descendant a daml:TransitiveProperty .
Properties – restrictions :TallThing a daml:Class;
daml:restrictedBy [
a daml:Restriction;
daml:onProperty :height;
daml:toValue :tall ] .
Properties – cardinality :father a daml:Property;
daml:cardinality "1";
daml:range :Man;
daml:subProperty :parent .
Properties – max and min cardinalities :wheels a daml:Property;
daml:minCardinality "1" .
daml:maxCardinality "3" .
Properties – subproperties :father a daml:Property;
daml:cardinality "1";
daml:range :Man;
daml:subProperty :parent .

redefines the range of the property
Properties – inverse :child a daml:Property;
daml:inverseOf :parent .
Rules – implication
Foo log:implies :Bar
Foo => :Bar

Rules – quantifiers (for each) @forSome <#g>.
The universal quantifier (∀g) – this is global to the document
Rules – quantifiers (for some) @forSome <#g>.
the existential quantifier (∃g) – also global to the document
Rules – free variables {?P @has owl:inverseOf ?Q. ?S ?P ?O} => {?O ?Q ?S}.
?P, ?Q, ?S, and ?O are all free variables.
these variables are local to the clause only
  1. Nice, except that I think DAML has mostly been replaced by OWL now. It would be worth updating that aspect of things.

  1. October 24th, 2007
  2. March 11th, 2008
  3. November 17th, 2008
You must be logged in to post a comment.
Follow

Get every new post delivered to your Inbox.

%d bloggers like this: