-
Notifications
You must be signed in to change notification settings - Fork 4
/
data_rdf.py
executable file
·149 lines (141 loc) · 5.53 KB
/
data_rdf.py
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
"""RDF example data for tests."""
# Copyright Permission.io, Inc. (formerly known as Algebraix Data Corporation), Copyright (c) 2022.
#
# This file is part of algebraixlib <http://github.com/AlgebraixData/algebraixlib>.
#
# algebraixlib is free software: you can redistribute it and/or modify it under the terms of version
# 3 of the GNU Lesser General Public License as published by the Free Software Foundation.
#
# algebraixlib is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
# even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License along with algebraixlib.
# If not, see <http://www.gnu.org/licenses/>.
# --------------------------------------------------------------------------------------------------
import os as _os
from rdflib import URIRef as _URIRef
from rdflib import BNode as _BNode
from algebraixlib.util.rdf import get_file_url as _get_file_url
from algebraixlib.mathobjects import Couplet, Set
from algebraixlib.util.test import get_test_file_path as _get_test_file_path
_print_examples = False
_cwd_url = _get_file_url(_os.getcwd()) + '/'
def _print_object_collection(name):
if _print_examples:
print('{name}:'.format(name=name))
for key, val in sorted(globals()[name].items()):
print(' "{key}": {val}'.format(key=key, val=val))
#: Basic RDF graphs.
basic_graphs = {
'1': {
'graph': lambda: """<absolute:b> <relative> "literal" .""",
'mo': lambda: Set(Set([
Couplet('s', _URIRef('absolute:b')),
Couplet('p', _URIRef(_cwd_url + 'relative')),
Couplet('o', 'literal')])
)
},
'2': {
'file': lambda: _get_test_file_path(__file__, '2.ttl'),
'mo': lambda: Set({
Set({
Couplet('s', _URIRef('http://foo/a#b')),
Couplet('p', _URIRef('http://foo/a#p1')),
Couplet('o', '123')
}),
Set({
Couplet('s', _URIRef('http://foo/a#b')),
Couplet('p', _URIRef('http://foo/a#p1')),
Couplet('o', '456')
}),
Set({
Couplet('s', _URIRef('http://foo/b#b')),
Couplet('p', _URIRef('http://foo/a#p2')),
Couplet('o', _URIRef('http://foo/a#v1'))
}),
Set({
Couplet('s', _URIRef('http://foo/b#b')),
Couplet('p', _URIRef('http://foo/a#p3')),
Couplet('o', _URIRef('http://foo/a#v2'))
}),
})
},
'3': {
'graph': lambda: """
<:claudius> <a:spouseOf> <:gertrude> .
<:claudius> <a:uncleOf> <:hamlet> .
<:gertrude> <a:motherOf> <:hamlet> .
<:hamlet> <a:friendOf> <:horatio> .
<:hamlet> <a:friendOf> <:rosencrantz> .
<:hamlet> <a:friendOf> <:guildenstern> .
<:ophelia> <a:girlfriendOf> <:hamlet> .
""",
'mo': lambda: Set({
Set({
Couplet('s', _URIRef(':claudius')),
Couplet('p', _URIRef('a:spouseOf')),
Couplet('o', _URIRef(':gertrude'))
}),
Set({
Couplet('s', _URIRef(':claudius')),
Couplet('p', _URIRef('a:uncleOf')),
Couplet('o', _URIRef(':hamlet'))
}),
Set({
Couplet('s', _URIRef(':gertrude')),
Couplet('p', _URIRef('a:motherOf')),
Couplet('o', _URIRef(':hamlet'))
}),
Set({
Couplet('s', _URIRef(':hamlet')),
Couplet('p', _URIRef('a:friendOf')),
Couplet('o', _URIRef(':horatio'))
}),
Set({
Couplet('s', _URIRef(':hamlet')),
Couplet('p', _URIRef('a:friendOf')),
Couplet('o', _URIRef(':rosencrantz'))
}),
Set({
Couplet('s', _URIRef(':hamlet')),
Couplet('p', _URIRef('a:friendOf')),
Couplet('o', _URIRef(':guildenstern'))
}),
Set({
Couplet('s', _URIRef(':ophelia')),
Couplet('p', _URIRef('a:girlfriendOf')),
Couplet('o', _URIRef(':hamlet'))
})
})
},
}
_print_object_collection('basic_graphs')
#: RDF result tables
result_tables = {
'1': Set([
Set([
Couplet(right=_URIRef('type:couplet'), left='?fav'),
Couplet(right='james', left='?name'),
Couplet(right=_URIRef('id:james'), left='?eng'),
Couplet(right=6, left='?cnt'),
Couplet(right=_BNode('blank node'), left='_:b0')
]),
]),
'2': Set([
Set([
Couplet(right=_URIRef('type:couplet'), left='?fav'),
Couplet(right='james', left='?name'),
Couplet(right=_URIRef('id:james'), left='?eng'),
Couplet(right=6, left='?cnt'),
Couplet(right=_BNode('blank node0'), left='_:b0')
]),
Set([
Couplet(right='jeff', left='?name'),
Couplet(right=_URIRef('id:jeff'), left='?eng'),
Couplet(right=2.0, left='?cnt'),
Couplet(right=_BNode('blank node1'), left='_:b1')
]),
]),
}
_print_object_collection('result_tables')