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 |
| 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 .
|
| 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; |
| Syntax - enumerations | :Height a daml:Class; |
| Classes - declarations | :Person a rdfs:Class. |
| Classes - inheritance | :Woman a rdfs:Class; rdfs:subClassOf :Person . |
| Classes - multiple inheritance | :TallMan a daml:Class; |
| Classes - disjoint union | :Person a daml:Class; |
| Classes - complement | :Car a daml:Class; |
| Properties - declaration | :sister a rdf:Property.
|
| Properties - transitive | :descendant a daml:TransitiveProperty . |
| Properties - restrictions | :TallThing a daml:Class; |
| Properties - cardinality | :father a daml:Property; |
| Properties - max and min cardinalities | :wheels a daml:Property; |
| Properties - subproperties | :father a daml:Property; redefines the range of the property |
| Properties - inverse | :child a daml:Property; |
| Rules - implication |
|
| 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 |
[...] far, I’ve got it producing N3 notation from models, like [...]
Semantic Web Visual Designer for Visual Studio >NET « The Wandering Glitch 2
24/10/2007
[...] Did you like this brief introduction? Find out about it in full detail here. [...]
Blogs and RSS » The N3 Cheat Sheet The Wandering Glitch 2
11/03/2008