Semantic Web Tutorial

Part B1: Shorthand: Paths and Lists

Text of this part; all slides

DanC, Sandro, and TimBL
$Id: all.htm,v 1.5 2003/05/19 22:27:22 connolly Exp $

Path-like phrases

An N3 expression for George's mother's assistant's home's address' zipcode:

[is con:zipcode of [
    is con:address of [
        is con:home of [
            is off:assistant of [
                is rel:mother of :George]]]]]

Special Syntax for paths

Shorter version of George's mother's assistant's home's address' zipcode using N3 path syntax:

:George.rel:mother
          .off:assistant
            .con:home
              .con:address
                 .con:zipcode

kinda like javascript, python, and other object-oriented programming langauges

Backward traversal

You can do backward traversal, using "^" instead of "." as punctuation. For example, if we know Dan's mailbox...

:dan con:mailbox <mailto:connolly@w3.org>

then we can write this expression for Dan:

<mailto:connolly@w3.org>^con:mailbox

Note: This is rather unlike javascript, python, and other object-oriented programming langauges

Paths (example with diagram)

Joe, Joe's mother, and somebody whose boss is Joe's mother:

graphviz source, diagram in SVG, Makefile

Variables in paths

If somebody has a mailbox whose URI ends with w3.org, then they're a W3C person:

{
 ?x a con:Person.
 ?x.con:mailbox.log:uri.str:endsWith "@w3.org"
} => { ?x a :W3CPerson}

Some value, not the value

Note that there isn't necessarily only one match for a path - often there are many, when it is used on the left side of a rule.

:me.rel:parent

would be "Some x such that I have parent x", and

:me.rel:parent^rel:parent

would mean "Some y such that for some x, I had parent x and y had parent x", or loosely, some sibling of mine.

Whitespace: beware!

The dot must be immediately followed by the next thing, with no whitespace. Like this:

:joe.rel:mother has :hairColor :brown.

or this:

:joe .rel:mother has :hairColor :brown.

but not like this:

:joe . rel:mother has :hairColor :brown.

cwm only reads paths

Cwm doesn't currently use paths on output, so getting cwm to input and output a file will turn it into the form of N3 you already know.

Lists

(:x :y)

( :cust.bus:order.bus:number 
  :cust.bus:order
      .bus:referncedPurchaseOrder
          .bus:number )

What lists are short for

()
rdf:nil
("y")
[ rdf:first "a"; rdf:rest () ]
("x" "y")
[ rdf:first "x"; rdf:rest ("y") ]

What lists are short for (example)

( "Monday" "Tuesday" "Wednesday" )

short for

list diagram

Using lists for n-ary relationships

especially cwm built-ins:

(  "Dear " ?name " "," )   
             string:conatenation   ?salutation.