-
Notifications
You must be signed in to change notification settings - Fork 2
/
iam-schema.tql
249 lines (215 loc) · 5.75 KB
/
iam-schema.tql
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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
#
# Copyright (C) 2022 Vaticle
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program 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 Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
#
define
email sub attribute, value string;
person-name sub attribute, abstract, value string;
first-name sub person-name;
last-name sub person-name;
birth-date sub attribute, value datetime;
gender sub attribute, value string;
address sub attribute, value string;
marital-status sub attribute, value string;
code sub attribute, value string;
name sub attribute, value string;
company-number sub attribute, value string;
incorporation-date sub attribute, value datetime;
currency sub attribute, value string;
marriage-licence sub attribute, value string;
marriage-date sub attribute, value datetime;
start-date sub attribute, value datetime;
end-date sub attribute, value datetime;
id sub attribute, value long;
price sub attribute, value double;
person sub entity,
owns email @key,
owns first-name,
owns last-name,
owns birth-date,
owns gender,
owns address,
owns marital-status,
plays birth-place:child,
plays residentship:resident,
plays nationality:national,
plays citizenship:citizen,
plays marriage:husband,
plays marriage:wife,
plays parenthood:parent,
plays parenthood:child,
plays grandparenthood:grandparent,
plays grandparenthood:grandchild,
plays lineage:ancestor,
plays lineage:descendent,
plays friendship:friend,
plays employment:employee,
plays study:student,
plays purchase:buyer,
plays purchase:seller;
organisation sub entity,
owns name,
owns address,
plays locates:located;
company sub organisation,
owns company-number @key,
owns incorporation-date,
plays employment:employer,
plays purchase:buyer,
plays purchase:seller;
school sub organisation,
plays study:school;
primary-school sub school;
secondary-school sub school;
university sub school;
region sub entity, abstract,
owns code @key,
owns name,
plays birth-place:place,
plays locates:location,
plays residentship:residence,
plays contains:container,
plays contains:contained;
continent sub region;
country sub region,
owns currency,
plays nationality:nation,
plays citizenship:country;
city sub region;
product sub entity,
owns id @key,
owns name,
plays purchase:product;
birth-place sub relation,
relates place,
relates child;
locates sub relation,
relates location,
relates located;
residentship sub locates,
relates residence as location,
relates resident as located;
marriage sub relation,
owns marriage-licence @key,
owns marriage-date,
plays locates:located,
relates husband,
relates wife;
nationality sub relation,
relates nation,
relates national;
citizenship sub relation,
relates country,
relates citizen;
parenthood sub relation,
relates parent,
relates child;
grandparenthood sub relation,
relates grandparent,
relates grandchild;
lineage sub relation,
relates ancestor,
relates descendent;
friendship sub relation,
relates friend;
employment sub relation,
plays locates:located,
relates employer,
relates employee;
study sub relation,
owns start-date,
owns end-date,
relates school,
relates student;
purchase sub relation,
owns id @key,
owns price,
owns currency,
relates buyer,
relates seller,
relates product;
contains sub relation,
relates container,
relates contained;
rule parenthood-is-lineage:
when {
(parent:$p, child:$c) isa parenthood;
} then {
(ancestor:$p, descendent:$c) isa lineage;
};
rule lineage-is-transitive:
when {
(ancestor:$a, descendent:$b) isa lineage;
(ancestor:$b, descendent:$c) isa lineage;
} then {
(ancestor:$a, descendent:$c) isa lineage;
};
rule parent-of-parent-is-grandparent:
when {
(parent:$p, child:$gc) isa parenthood;
(parent:$gp, child:$p) isa parenthood;
} then {
(grandchild: $gc, grandparent: $gp) isa grandparenthood;
};
rule birthplace-determines-nationality:
when {
$city isa city;
$country isa country;
(container:$country, contained:$city) isa contains;
$person isa person;
(place:$city, child:$person) isa birth-place;
} then {
(national:$person, nation:$country) isa nationality;
};
rule children-of-nationals-are-nationals:
when {
(parent:$p, child:$c) isa parenthood;
(national:$p, nation:$country) isa nationality;
} then {
(national:$p, nation:$country) isa nationality;
};
rule nationals-are-citizens:
when {
(national:$person, nation:$country) isa nationality;
} then {
(citizen:$person, country:$country) isa citizenship;
};
rule married-partners-of-nationals-are-citizens:
when {
($p1, $p2) isa marriage;
(national:$p1, nation:$country) isa nationality;
} then {
(citizen:$p2, country:$country) isa citizenship;
};
rule marital-status-single:
when {
$p isa person;
not { ($p) isa marriage; };
} then {
$p has marital-status "single";
};
rule marital-status-married:
when {
$p isa person;
($p) isa marriage;
} then {
$p has marital-status "married";
};
rule married-couples-are-friends:
when {
($p1, $p2) isa marriage;
} then {
(friend:$p1, friend:$p2) isa friendship;
};