-
Notifications
You must be signed in to change notification settings - Fork 1
/
compiler.n3
69 lines (57 loc) · 1.8 KB
/
compiler.n3
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
@prefix math: <http://www.w3.org/2000/10/swap/math#>.
@prefix string: <http://www.w3.org/2000/10/swap/string#>.
@prefix graph: <http://www.w3.org/2000/10/swap/graph#>.
@prefix log: <http://www.w3.org/2000/10/swap/log#>.
@prefix : <http://example.org/ns#>.
## Compiler
# Search for forward rules
# ... For each triple check if the predicate is available as a backward rule
# ... If this is the case, then create a getter triple for the subject/object
{
?F => ?G .
?F log:includes { ?S ?P ?O } .
# Do we have a backward rule for this ?P
{ ?X ?P ?Y } :backward ?H .
# Create a data name
?P log:uri ?Puri .
( ?Puri "_data" ) string:concatenation ?Py .
?Pdata log:uri ?Py .
}
=>
{
# Create a triple .. using a { false log:equalTo true . ?S ?P ?O } => true trick to
# keep possible variables in ?S ?P ?O available as variables.
# The (false log:equalTo true) trick is used to stop this rule from firing
{ false log:equalTo true . (?S ?O) ?Pdata true } => true .
} .
# Transform the backward rule into a getter
{
{ ?S ?P ?O } :backward ?G .
?P log:uri ?Puri .
# Create a getter name
( ?Puri "_get" ) string:concatenation ?Px .
?Pgetter log:uri ?Px .
# Create a data name
( ?Puri "_data" ) string:concatenation ?Py .
?Pdata log:uri ?Py .
# Create a functor name
( ?Puri "_funktor" ) string:concatenation ?Pz .
?Pfunc log:uri ?Pz .
# Package the old body into the new head
(
{ { false log:equalTo true . (?S ?O) ?Pgetter true } => true }
?G
) graph:union ?Magic .
}
=>
{
{ ?X ?Pfunc ?Y } => { ?X ?P ?Y }.
?Magic => { ?S ?Pfunc ?O } .
{
{ false log:equalTo true . (?X ?Y) ?Pdata true . } => true .
}
=>
{
{ false log:equalTo true . (?X ?Y) ?Pgetter true . } => true .
} .
}.