Project

General

Profile

RLog » History » Version 1

Paula Gearon, 03/24/2009 09:25 PM
Creation of a page describing RLog syntax

1 1 Paula Gearon
= RLog =
2
RLog is a language based on logic programming, which is specifically aimed at describing RDF.
3
4
Statements in RDF are equivalent to unary and binary predicates in logic. Most relationships can be described with these simple predicate, although occasionally predicates with higher arities may be called for. These higher arities are simulated in RDF using a [http://www.w3.org/TR/swbp-n-aryRelations/ number of mechanisms], including blank nodes with named operators, and lists. So the restriction to unary and binary arities is appropriate when dealing with RDF.
5
6
RLog programs are built using statements that resemble Horn Clauses. Statements are built using a series of predicates, and predicates are built using the basic elements of atoms and variables.
7
8
=== A Note on URIs ===
9
RDF uses URIs as the basic syntactic element, which can be unwieldy in examples. [http://en.wikipedia.org/wiki/QName QNames] are a much shorter form for a URI which abbreviates an entire domain down to a short string. For instance, the ''type'' predicate in RDF has a full URI of:[[BR]]
10
{{{  http://www.w3.org/1999/02/22-rdf-syntax-ns#type }}}[[BR]]
11
In QName form, this is abbreviated to:[[BR]]
12
{{{  rdf:type }}}
13
14
The following text will stick to QNames, and will often use ''unprefixed'' QNames to illustrate examples (e.g. '''foo''').
15
16
RLog uses QNames exclusively for URIs.
17
18
----
19
20
= Basic Elements =
21
22
=== Atoms ===
23
24
RLog uses QNames, numbers, and quoted strings for atoms. QNames can be used anywhere. Strings are surrounded by double quotes. Since RLog represents RDF, then numbers and strings can usually only appear in the second element of a binary predicate.
25
26
All URIs are represented as QNames. A number of prefixes are pre-defined:
27
|| rdf     || !http://www.w3.org/1999/02/22-rdf-syntax-ns# ||
28
|| rdfs    || !http://www.w3.org/2000/01/rdf-schema#       ||
29
|| owl     || !http://www.w3.org/2002/07/owl#              ||
30
|| xsd     || !http://www.w3.org/2001/XMLSchema#           ||
31
|| mulgara || !http://mulgara.org/mulgara#                 ||
32
|| krule   || !http://mulgara.org/owl/krule/#              ||
33
|| foaf    || !http://xmlns.com/foaf/0.1/                  ||
34
|| skos    || !http://www.w3.org/2004/02/skos/core#        ||
35
|| dc      || !http://purl.org/dc/elements/1.1/            ||
36
37
Prefixes can be added using the '''@prefix''' instruction.
38
39
=== Variables ===
40
41
Variables are represented with a single upper-case letter. This restricts each statement to only allowing a maximum of 26 variables. ''This was considered adequate at design time, but if there is a legitimate need for more, then please contact the developers.''
42
43
----
44
45
= Predicates =
46
47
=== Unary Predicates ===
48
A unary predicate indicates the type of an object. So the following statement indicates that the object named ''foo'' is an instance of the ''Bar'' type:
49
{{{
50
  Bar(foo)
51
}}}
52
53
This is expressed in RDF using the special predicate ''rdf:type'':
54
{{{
55
  foo  rdf:type  Bar .
56
}}}
57
58
RLog enforces the RDF convention that types begin with an upper case letter.
59
60
=== Binary Predicates ===
61
Binary predicates indicate a relationship between two resources:
62
{{{
63
  friend(fred,barney)
64
}}}
65
66
This is expressed in RDF using an "infix" notation, meaning that the predicate is in the middle:
67
{{{
68
  fred  friend  barney .
69
}}}
70
71
RLog enforces the RDF convention that relationships begin with a lower case letter.
72
73
----
74
75
= Statements =
76
77
Mulgara uses 3 types of statements: Axioms, Consistency-Checks (which are a kind of Axiom), and Rules.
78
79
=== Axioms ===
80
Axioms are a statement of fact. They consist of a single predicate followed by a dot.
81
82
The general form of an axiom is:[[BR]]
83
{{{ predicate. }}}
84
85
''Examples''
86
The following states that '':fred'' is a ''foaf:Person'':
87
{{{
88
  foaf:Person(fred).
89
}}}
90
91
This statement says that '':fred'' has the friend '':barney'':
92
{{{
93
  :friend(:fred, :barney).
94
}}}
95
96
Axioms can be considered as rules with the body set to "nothing" or "bottom" (to use the term from logic), meaning that nothing else is needed in order to generate the predicate in the ''head'' of the statement.
97
98
=== Rules ===
99
Rules are Horn Clauses, consisting of a head followed by a body. The basic form is:[[BR]]
100
{{{ head :- body. }}}
101
102
The ''head'' is a single predicate (this may change in a later revision).
103
104
The ''body'' is a list of comma-separated predicates.
105
106
So the general form is:[[BR]]
107
{{{ predicate :- predicate [, predicate]* . }}}
108
109
If the body of the rule is matched, then the head will be asserted. ''Matching'' is the process of finding existing assertions which share the atoms of all the predicates. Once a match is found, then the variables in the predicate are bound to the corresponding values in the matched assertion. These binding are then used in the assertion described in the ''head' of the statement.
110
111
''Examples''
112
The following statement declares that all instances of the class '''transport:Car''' are therefore instances of the class '''transport:Vehicle''':
113
{{{
114
  transport:Vehicle(X) :- transport:Car(X).
115
}}}
116
117
This next statement declares that if any two resources are related by a predicate, and that predicate is an ''rdfs:subPropertyOf'' another predicate, then those resources are also related by the second predicate.
118
{{{
119
  B(X,Y) :- A(X,Y), rdfs:subPropertyOf(A,B).
120
}}}
121
122
'''Note:''' all the variables appearing in the ''head'' of a statement MUST appear in the body. This prevents the creation of blank nodes. This feature may be allowed in future, but it has the side-effect of allowing infinite generation of new node. To see this, consider the following program:
123
{{{ 
124
  :father(X,Y) :- :Man(X).
125
  :Man(:fred).
126
}}}
127
This will continue looping until system resources are exhausted.
128
129
=== Checks ===
130
Checks perform tests for consistency on the data. If a check fails, then an error is reported and the current operation is discarded. If a transaction is in progress, then it will be rolled back.
131
132
Checks are like rules without a ''head'', meaning that the ''body'' should imply "nothing" or "bottom" (to use the logic term). Anything matching the body of a check is considered an error, so the number of matches is reported in the error.
133
134
The general form of a check is:[[BR]]
135
{{{  :- predicate [, predicate]*. }}}
136
137
''Examples:''
138
This checks that if two things are declared to be the same, they cannot also be different:
139
{{{
140
  :- owl:sameAs(X,Y), owl:differentFrom(X,Y).
141
}}}
142
Note that this check is likely to work in conjunction with other rules, such as the ones declaring the symmetry of the ''owl:sameAs'' and ''owl:differentFrom'' predicates. Otherwise, a second check would be needed which reversed the order of X and Y in one of the predicates above.
143
144
This check tests that nothing can be declared to be "Nothing":
145
{{{
146
  :- owl:Nothing(X).
147
}}}
148
This test may seem redundant at first glance, but it is one of the fundamental tests for ontological consistency.
149
150
----
151
152
= Comments =
153
154
Comments in Mulgara are created using a pair of dashes and extend to the end of that line. The general form is:[[BR]]
155
{{{ -- comment }}}
156
157
''Examples:''
158
{{{
159
  -- This is full line comment
160
}}}
161
162
The following adds a comment to a rule:
163
{{{
164
  rdf:Property(A) :- A(X,Y).   -- RDFS rule #1
165
}}}
166
167
= Directives =
168
169
=== @prefix ===
170
The '''@prefix''' directive is used to create a new prefix for use in QNames. It is only applied to QNames appearing after the '''@prefix''' statement. The syntax is the same as in N3:[[BR]]
171
{{{ @prefix string: <uri> . }}}
172
173
174
''Examples:''
175
This sets the owl11 prefix to {{{http://www.w3.org/2006/12/owl11#}}}:
176
{{{
177
  @prefix owl11: <http://www.w3.org/2006/12/owl11#> .
178
}}}
179
180
This sets the empty prefix to {{{http://example.com/example/}}}:
181
{{{
182
  @prefix : <http://www.w3.org/2006/12/owl11#> .
183
}}}
184
185
=== @import ===
186
187
The '''@import''' directive is used to import the contents of another RLog file. A URI is provided to locate the file. If it is an absolute URL, then this is used to locate and read the file. If the URI is relative, then it is used to identify a path relative to the URL of the original file being loaded. Imports may be nested, but relative URIs are always relative to the original file, and not the most recent importing file.
188
189
The syntax is:[[BR]]
190
{{{ @import <url> . }}}
191
192
Examples:
193
This imports the file {{{/tmp/rules.rl}}}:
194
{{{
195
  @import <file:///tmp/rules.rl> .
196
}}}
197
198
The following statement is in the file {{{/home/user/programs/first.dl}}}. It is used to import the file {{{/home/user/programs/second.dl}}}:
199
{{{
200
  @import <second.dl> .
201
}}}