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>;
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/> .
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 :Dick :Harry)
Syntax - comments :Person 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 :Person a rdfs:Class.
Classes - inheritance :Woman a rdfs:Class; rdfs:subClassOf :Person .
Classes - multiple inheritance :TallMan a daml:Class;
daml:intersectionOf (
:TallThing
:Man ) .
Classes - disjoint union :Person 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 :Person ] .
Properties - declaration :sister a rdf:Property.
sister rdfs:domain :Person; 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

Make A Comment: ( 2 so far )

blockquote and a tags work here.

2 Responses to “The N3 Cheat Sheet”

RSS Feed for The Wandering Glitch Comments RSS Feed

[...] far, I’ve got it producing N3 notation from models, like [...]

[...] Did you like this brief introduction? Find out about it in full detail here. [...]

Where's The Comment Form?

Liked it here?
Why not try sites on the blogroll...