Skip to content

ObdalibComponentsDatalogParser

Martin Rezk edited this page Nov 29, 2013 · 3 revisions

Table of Contents

Introduction

Datalog grammar

[1] parse ::= prog EOF
[2] prog ::= base? directive* rule+
[3] directive ::= 'prefix' prefix '<'uriref'>'
[4] base ::= 'base' '<'uriref'>'
[5] rule ::= datalog_syntax_rule / swirl_syntax_rule
[6] prefix ::= STRING_PREFIX/':'
[7] uriref ::= STRING_URI
[8] datalog_syntax_rule ::= head? ':-' body?
[9] swirl_syntax_rule ::= body? '->' head?
[10] head ::= atom
[11] body ::= atom ((','/'^') atom)*
[12] atom ::= predicate '(' terms ')'
[13] predicate ::= full_name
[14] terms ::= term (',' term)*
[15] qualified_name ::= prefix id
[16] plain_name ::= id
[17] full_name ::= uriref
[18] term ::= object_term uri_term
[19] variable_term ::= '*'
[20] literal_term ::= STRING_LITERAL / STRING_LITERAL2
[21] object_term ::= function '(' terms ')'
[22] uri_term ::= STRING_URI
[23] id ::= ID_PLAIN
[24] function ::= full_name
[25] ID_PLAIN ::= ID_START (ID_CORE)*
[26] ID_START ::= ALPHA / '_'
[27] ID_CORE ::= ID_START / DIGIT
[28] SCHEMA ::= ALPHA (ALPHA/DIGIT|'+'|'-'|'.')*
[29] URI_PATH ::= ALPHA/DIGIT|'_'|'-'|':'|'.'|'#'|'?'|'/'
[30] ALPHA ::= [a-z] / [A-Z]
[31] DIGIT ::= [0-9]
[32] STRING_URI ::= SCHEMA '://' (URI_PATH)*
[33] STRING_LITERAL ::= '"' .* '"'
[34] STRING_LITERAL2 ::= ''' .* '''
[35] STRING_PREFIX ::= ID':'


Examples

Input query using Datalog syntax

base        <http://base.org/stuff/1.0/>
prefix abc: <http://www.abc.org/1999/02/22-abc-syntax-ns#>
prefix    : <http://example.org/stuff/1.0/>
abc:p($x, $y) :- :q($x), r($y)

Input query using SWIRL syntax

base        <http://base.org/stuff/1.0/>
prefix abc: <http://www.abc.org/1999/02/22-abc-syntax-ns#>
prefix    : <http://example.org/stuff/1.0/>
:q($x), r($y) -> abc:p($x, $y)

Input query with caret symbol

base        <http://base.org/stuff/1.0/>
prefix abc: <http://www.abc.org/1999/02/22-abc-syntax-ns#>
prefix    : <http://example.org/stuff/1.0/>
abc:p($x, $y) :- :q($x) ^ r($y)

Supported terms

prefix abc: <http://www.abc.org/1999/02/22-abc-syntax-ns#>
prefix    : <http://example.org/stuff/1.0/>
abc:p($x, $y) :- :q($x, "Person"), :r(:obj($y, "Student"), http://example.org/stuff/1.1/FUB)

Multiple rules

prefix abc: <http://www.abc.org/1999/02/22-abc-syntax-ns#>
prefix    : <http://example.org/stuff/1.0/>
abc:p($x) :- :q($x, "Person")
abc:r($y) :- :s($y, http://example.org/stuff/1.1/FUB)
abc:t($z) :- :u($z, f(http://example.org/stuff/1.2/Occupation, "Student"))

Recursive object term

prefix abc: <http://www.abc.org/1999/02/22-abc-syntax-ns#>
prefix    : <http://example.org/stuff/1.0/>
abc:p($x) :- :q($x, :rec1(http://example.org/stuff/1.1/FUB, 
                    :rec2(http://example.org/stuff/1.2/Occupation, 
                    :rec3(http://example.org/stuff/1.3/Degree, "Master"))))

No head

prefix abc: <http://www.abc.org/1999/02/22-abc-syntax-ns#>
prefix    : <http://example.org/stuff/1.0/>
 :- :q($x)

No body

prefix abc: <http://www.abc.org/1999/02/22-abc-syntax-ns#>
prefix    : <http://example.org/stuff/1.0/>
abc:p($x) :-

SELECT ALL input

base        <http://base.org/stuff/1.0/>
prefix abc: <http://www.abc.org/1999/02/22-abc-syntax-ns#>
prefix    : <http://example.org/stuff/1.0/>
abc:p(*) :- :q($x), r($y)

Empty term in the head

base        <http://base.org/stuff/1.0/>
prefix abc: <http://www.abc.org/1999/02/22-abc-syntax-ns#>
prefix    : <http://example.org/stuff/1.0/>
abc:p() :- :q($x), r($y)

Without prefix definitions

http://www.abc.org/1999/02/22-abc-syntax-ns#p($x, $y) :- 
      http://example.org/stuff/1.0/q($x), 
      http://base.org/stuff/1.0/r(http://example.org/stuff/1.0/s($y, "Student"), http://example.org/stuff/1.1/FUB)
Clone this wiki locally