This is a language which is a compact and readable alternative to
RDF's XML syntax, but also is extended to allow greater expressiveness. It has
subsets, one of which is RDF 1.0 equivalent, and one of which is RDF plus a
form of RDF rules.
目标
The aims of the
language are
- to optimize expression of data and logic in the same
language,
- to allow RDF
to be expressed,
- to allow rules
to be integrated smoothly with RDF,
- to allow
quoting so that statements about statements can be made, and
- to be as readable, natural, and symmetrical as
possible.
功能
The language
achieves these with the following features:
- URI abbreviation using prefixes which are bound to a
namespace (using @prefix) a bit like in XML,
- Repetition of
another object for the same subject and predicate using a comma
","
- Repetition of
another predicate for the same subject using a semicolon ";"
- Bnode syntax
with a certain properties just put the properties between [ and ]
- Formulae
allowing N3 graphs to be quoted within N3 graphs using { and }
- Variables and
quantification to allow rules, etc to be expressed
- A simple and consistent grammar.
语法
语法以上下文无关文法的方式来定义:
N3文件以UTF-8为默认的编码方式,MIME类型为text/rdf+n3;charset=utf-8。
语法表示
Whitespace
为了简单化,单词(Token)和空白(white space)并没有在语法中明确地指定其应遵循的规则。空白必须在后续单词以一个能延伸前述单词的字符开始的时候,而不能插入到一个单词的内部,除非在以尖括号(<>)分隔的URI内部可以自由地添加和移除空白。
All URIs are quoted with angle brackets. Whitespace within the
<> is to be ignored. Whitespace may therefore be used on output to split
a long URI between lines.
Namespaces
@prefix标志将前缀和名称空间URI绑定在一起。
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
.
名称空间前缀可以为空,此时,qname(限定名称)以:开头,表示使用的是默认的名称空间。空前缀””默认表示空URI ””,意味着<#foo>等价于:foo,也可通过使用@keywords简写为foo。
@keywords
Keywords are a very limited set
of alphanumeric strings which are in the grammar prefixed by an at sign
"@".
If no @keywords directive is
given, qualified names all have colons, and unquoted alphanumerics are all
keywords. Only the keywords is, of, and a may be used naked.
If the @keywords directive is
given, the keywords given will thereafter be recognized without a "@"
prefix, and anything else is a local name in the default namespace. Any keyword
may still be given, even if not in the keyword list, by prefixing it with
"@". Because keywords are declared in this way, we will have the
freedom later to make extensions to the syntax using new keywords without fear
of ambiguity. However, the tokenizer has to be aware of the @keywords setting.
The grammar is written as without reference to the keywords system at all, on
the asssumption that the string has been preprocessed by a keyword processor to
put a "@" on all keywords and a ":" on all qnames in the
default namespace.
Strings
The """value""" string form is used
simply for multi-line values or values containg quote marks.
|
Escape Sequence
|
Meaning
|
|
newline
|
Ignored
|
|
\
|
Backslash ()
|
|
'
|
Single quote (')
|
|
"
|
Double quote (")
|
|
n
|
ASCII Linefeed (LF)
|
|
r
|
ASCII Carriage Return (CR)
|
|
t
|
ASCII Horizontal Tab (TAB)
|
|
uhhhh
|
character in BMP with Unicode value U+hhhh
|
|
U00hhhhhh
|
character in plane 1-16 with Unicode
value U+hhhhhh
|
在N3中,””用于表示字符串,’’被保留到将来用,因而’在N3串中也不需被转义。
Semantics
An N3 document encodes a set of statements, and its meaning is the
conjunction of the meaning of the statements.
The statement of the form x p y. asserts that the
relation p holds between x and y.
In property lists, the semicolon ;
is shorthand for repeating the subject. In object lists , is shorthand for
repeating the verb.
Shorthand for common predicates
| Shorthand |
stands for |
a |
<http://www.w3.org/1999/02/22-rdf-syntax-ns#type> |
= |
<http://www.w3.org/2002/07/owl#sameAs> |
=> |
<http://www.w3.org/2000/10/swap/log#implies> |
Blank nodes
There are several ways in N3 of
representing a blank or unnamed node: the underscore namespace, the square
bracket syntax, and the path syntax.
Underscore namespace
N3 allows has a special _:
namespace prefix. An identifier of such a form (e.g. _:a17) represents a blank node.
Square bracket blank node syntax
[pl] means x, where there exists some x such that x has
properties in the property list pl.
[:firstname
"Ora"] dc:wrote [ dc:title "Moby Dick"] .
用数学术语表示为:∃x, y . firstname(x, "Ora")&dc:wrote(x,y)&dc:title (y,
"Moby Dick")或者用英语表示为Some person who has a first name
Ora wrote a book entitled "Moby Dick".
上述写法可等价于:[x:firstname "Ora" ; dc:wrote
[dc:title "Moby Dick" ]] .或
[] x:firstname "Ora" ;
dc:wrote [dc:title "Moby Dick" ].其中[]表示“有些”。
Paths
The x!p
means [ is p
of x ] in the
above anonymous node notation. You can read it as "x's p".
The
x^p
means [ p x ] . For either forward
or backward traversal, p
is a property, and x
can be a whole path with both ! and ^ in it.
:joe!fam:mother!loc
ffice!loc:zip
表示Joe's mother's office's zipcode
:joe!fam:mother^fam:mother
表示Anyone whose mother is Joe's mother.
An RDF document
parses to a set of statements, or graph. However RDF itself has no data type
allowing a graph as a literal value. N3 extends RDF allows a graph itself to be
referred to within the language, where it is known as a formula. A {statement
list} is a formula whose meaning is the logical conjunction of the statements
in the list which is an unordered set.
{ [
x:firstname "Ora" ] dc:wrote [
dc:title "Moby Dick" ] } a
n3:falsehood .
This claims that
the expression in {braces} is false - that there is nothing called Ora which
wrote anything titled "Moby Dick".
A formula is
considered, like a literal string, to be defined only by its contents.
Quantification
@forAll:全称量词
@forSome:存在量词
@forAll
<#h>. @forSome <#g>. <#g> <#loves> <#h> .表示"Every has someone who loves them" e.g.:∀h(∃g(loves(g,h))
Boolean literals
The words true and false
are boolean literals.
来源:http://www.w3.org/DesignIssues/Notation3