forked from typedb/typedb-driver-examples
-
Notifications
You must be signed in to change notification settings - Fork 0
/
social-network-schema.gql
908 lines (742 loc) · 19.7 KB
/
social-network-schema.gql
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
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
define
################
## ATTRIBITES ##
################
name sub attribute,
value string;
full-name sub name;
nickname sub name;
title sub attribute,
value string;
event-date sub attribute,
abstract,
value datetime;
approved-date sub event-date;
birth-date sub event-date;
start-date sub event-date;
end-date sub event-date;
engagement-date sub event-date;
published-date sub attribute,
value datetime;
reference-id sub attribute,
value string;
salary sub attribute,
value long;
registration-number sub attribute,
value string;
identifier sub attribute,
value string;
graduated sub attribute,
value boolean;
score sub attribute,
value double;
ranking sub attribute,
value long;
phone-number sub attribute,
value string;
email sub attribute,
value string;
gender sub attribute,
value string;
engaged sub attribute,
value boolean;
separated sub attribute,
value boolean;
divorced sub attribute,
value boolean;
file sub attribute,
value string;
caption sub attribute,
value string;
language sub attribute,
value string,
plays spoken,
plays mutual-language;
content sub attribute,
value string,
has language;
emotion sub attribute,
value string,
regex "^(like|love|funny|shocking|sad|angry)$",
plays reacted-emotion;
link sub attribute,
value string,
plays attached;
person sub entity,
has full-name,
has nickname,
has gender,
has phone-number,
key email;
###################
## GENERIC TYPES ##
###################
location-of-everything sub relation,
abstract,
relates located-subject,
relates subject-location;
location-hierarchy sub relation,
relates subordinate-location,
relates superior-location;
ownership sub relation,
relates owner,
relates owned;
location sub entity,
key name,
plays subordinate-location,
plays superior-location;
request sub relation,
relates approved-subject,
relates requester,
relates respondent;
periodic-event sub relation,
abstract,
has start-date,
has end-date,
plays overlapped-event;
########################
## events overlapping ##
########################
event-overlapping sub relation,
relates overlapped-event;
events-overlap sub rule,
when {
$e1 isa periodic-event;
$e1 has start-date $sd1, has end-date $ed1;
$e2 isa periodic-event;
$e2 has start-date $sd2, has end-date $ed2;
$sd2 > $sd1;
$sd2 < $ed1;
$e1 != $e2;
}, then {
(overlapped-event: $e1, overlapped-event: $e2) isa event-overlapping;
};
###########
## BIRTH ##
###########
## query the schema section
# match
# $per sub person;
# $lob sub location-of-birth;
# $bir sub birth;
# $loc sub location;
# $blm sub birth-location-mutuality;
# get;
location-of-birth sub location-of-everything,
relates located-birth as located-subject,
relates birth-location as subject-location;
birth sub relation,
has birth-date,
relates birthed-child,
plays located-birth,
plays mutual-birth;
person sub entity,
plays birthed-child,
plays mutual-birthed-child;
location sub entity,
plays birth-location,
plays mutual-birth-location;
##############################
## birth location in common ##
##############################
birth-mutuality sub relation,
relates mutual-birthed-child,
relates mutual-birth-location,
relates mutual-birth;
people-born-at-the-same-location sub rule,
when {
$b1 (birthed-child: $p1) isa birth;
$b2 (birthed-child: $p2) isa birth;
($b1, birth-location: $l) isa location-of-birth;
($b2, birth-location: $l) isa location-of-birth;
$p1 != $p2;
}, then {
(mutual-birthed-child: $p1, mutual-birthed-child: $p2, mutual-birth-location: $l, mutual-birth: $b1, mutual-birth: $b2) isa birth-mutuality;
};
###############
## RESIDENCY ##
###############
## query the schema section
# match
# $per sub person;
# $lor sub location-of-residence;
# $res sub residency;
# $loc sub location;
# get;
location-of-residence sub location-of-everything,
relates located-residence as located-subject,
relates residence as subject-location;
residency sub periodic-event,
relates resident,
plays located-residence,
plays mutual-residency;
person sub entity,
plays resident,
plays mutual-resident;
location sub entity,
plays residence,
plays mutual-residence;
#########################
## residence in common ##
#########################
residence-mutuality sub relation,
relates mutual-resident,
relates mutual-residency,
relates mutual-residence;
people-resided-at-the-same-location sub rule,
when {
$r1 (resident: $p1) isa residency;
$r2 (resident: $p2) isa residency;
($r1, residence: $l) isa location-of-residence;
($r2, residence: $l) isa location-of-residence;
$p1 != $p2;
}, then {
(mutual-resident: $p1, mutual-resident: $p2, mutual-residence: $l, mutual-residency: $r1, mutual-residency: $r2) isa residence-mutuality;
};
###############
## EDUCATION ##
###############
## query the schema section
# match
# $sco sub school-course-offerring;
# $los sub location-of-school;
# $sce sub school-course-enrollment;
# $sch sub school;
# $scc sub school-course;
# $per sub person;
# $loc sub location;
# get;
location-of-school sub location-of-everything,
relates located-school as located-subject,
relates school-location as subject-location;
school-course-enrollment sub periodic-event,
has graduated,
has score,
relates student,
relates enrolled-course,
relates enrolling-school,
plays mutual-course-enrollment;
school sub entity,
key name,
has ranking,
plays offerring-school,
plays located-school,
plays enrolling-school,
plays mutual-school;
school-course sub entity,
key title,
plays offered-course,
plays enrolled-course;
person sub entity,
plays student,
plays schoolmate,
plays coursemate;
location sub entity,
plays school-location;
##########################
## school offerings ##
##########################
school-course-offerring sub relation,
relates offerring-school,
relates offered-course;
school-offers-the-enrolled-courses sub rule,
when {
(student: $p, enrolled-course: $c, enrolling-school: $s) isa school-course-enrollment;
}, then {
(offerring-school: $s, offered-course: $c) isa school-course-offerring;
};
##########################
## educations in common ##
##########################
school-mutuality sub relation,
relates schoolmate,
relates mutual-school;
people-gone-to-the-same-school sub rule,
when {
(student: $p1, enrolled-course: $c1) isa school-course-enrollment;
(student: $p2, enrolled-course: $c2) isa school-course-enrollment;
(offered-course: $c1, offerring-school: $s) isa school-course-offerring;
(offered-course: $c2, offerring-school: $s) isa school-course-offerring;
$p1 != $p2;
}, then {
(schoolmate: $p1, schoolmate: $p2, mutual-school: $s) isa school-mutuality;
};
course-enrollment-mutuality sub relation,
relates coursemate,
relates mutual-course-enrollment;
people-taken-the-same-course sub rule,
when {
$sce1 (student: $p1, enrolled-course: $sc) isa school-course-enrollment;
$sce2 (student: $p2, enrolled-course: $sc) isa school-course-enrollment;
$p1 != $p2;
}, then {
(coursemate: $p1, coursemate: $p2, mutual-course-enrollment: $sce1, mutual-course-enrollment: $sce2) isa course-enrollment-mutuality;
};
############
## TRAVEL ##
############
## query the schema section
# match
# $lot sub location-of-travel;
# $tra sub travel;
# $per sub person;
# $loc sub location;
# get;
location-of-travel sub location-of-everything,
relates located-travel as located-subject,
relates travel-location as subject-location;
travel sub periodic-event,
relates traveler,
plays located-travel,
plays mutual-travel;
person sub entity,
plays traveler,
plays mutual-traveler;
location sub entity,
plays travel-location,
plays mutual-travel-location;
#######################
## travels in common ##
#######################
travel-mutuality sub relation,
relates mutual-traveler,
relates mutual-travel,
relates mutual-travel-location;
people-traveled-to-the-same-location sub rule,
when {
$t1 (traveler: $p1) isa travel;
$t2 (traveler: $p2) isa travel;
($t1, travel-location: $l) isa location-of-travel;
($t2, travel-location: $l) isa location-of-travel;
$p1 != $p2;
}, then {
(mutual-traveler: $p1, mutual-traveler: $p2, mutual-travel-location: $l, mutual-travel: $t1, mutual-travel: $t2) isa travel-mutuality;
};
##########
## WORK ##
##########
## query the schema section
# match
# $oow sub office-ownership;
# $emp sub employment;
# $loo sub location-of-office;
# $wpo sub work-position;
# $org sub organisation;
# $off sub office;
# $loc sub location;
# $per sub person;
# $emm sub employment-mutuality;
# $wpm sub work-position-mutuality;
# get;
employment sub periodic-event,
key reference-id,
has salary,
relates employer,
relates employee,
relates offered-position,
plays mutual-employment;
location-of-office sub location-of-everything,
relates located-office as located-subject,
relates office-location as subject-location;
office-ownership sub ownership,
relates office-owner as owner,
relates owned-office as owned;
work-position sub entity,
key title,
plays offered-position,
plays mutual-position;
organisation sub entity,
key name,
key registration-number,
plays office-owner,
plays employer,
plays mutual-organisation;
office sub entity,
key registration-number,
plays owned-office,
plays located-office;
location sub entity,
plays office-location;
person sub entity,
plays employee,
plays mutual-employee;
##########################
## employment in common ##
##########################
employment-mutuality sub relation,
relates mutual-employee,
relates mutual-employment,
relates mutual-organisation;
people-work-at-the-same-organisation sub rule,
when {
$e1 (employee: $p1, employer: $o) isa employment;
$e2 (employee: $p2, employer: $o) isa employment;
$p1 != $p2;
}, then {
(mutual-employee: $p1, mutual-employee: $p2, mutual-organisation: $o, mutual-employment: $e1, mutual-employment: $e2) isa employment-mutuality;
};
work-position-mutuality sub relation,
relates mutual-employee,
relates mutual-employment,
relates mutual-position;
people-work-at-the-same-position sub rule,
when {
$e1 (employee: $p1, offered-position: $p) isa employment;
$e2 (employee: $p2, offered-position: $p) isa employment;
$p1 != $p2;
}, then {
(mutual-employee: $p1, mutual-employee: $p2, mutual-position: $p, mutual-employment: $e1, mutual-employment: $e2) isa work-position-mutuality;
};
##############
## Language ##
##############
## query the schema section
# match
# $sol sub speaking-of-language;
# $per sub person;
# $lan sub language;
# $slm sub speaking-language-mutuality;
# get;
speaking-of-language sub relation,
relates speaker,
relates spoken,
plays mutual-language-speaking;
person sub entity,
plays speaker,
plays mutual-speaker;
##################################
## speaking languages in common ##
##################################
speaking-language-mutuality sub relation,
relates mutual-speaker,
relates mutual-language-speaking,
relates mutual-language;
people-speak-the-same-language sub rule,
when {
$sol1 (speaker: $p1, spoken: $l) isa speaking-of-language;
$sol2 (speaker: $p2, spoken: $l) isa speaking-of-language;
$p1 != $p2;
}, then {
(mutual-speaker: $p1, mutual-speaker: $p2, mutual-language: $l, mutual-language-speaking: $sol1, mutual-language-speaking: $sol2) isa speaking-language-mutuality;
};
#########################
## RELATIONSHIP STATUS ##
#########################
## query the schema section
# match
# $ror sub romantic-relationship;
# $mar sub marriage;
# $per sub person;
# get;
romantic-relationship sub relation,
has start-date,
has end-date,
has engaged,
has engagement-date,
relates partner;
open-relationship sub romantic-relationship,
relates partner;
domestic-relationship sub romantic-relationship,
relates partner;
complicated-relationship sub romantic-relationship,
relates partner;
marriage sub relation,
has start-date,
has end-date,
has separated,
has divorced,
relates husband,
relates wife,
relates spouse;
person sub entity,
plays partner,
plays spouse,
plays wife,
plays husband;
################
## FRIENDSHIP ##
################
## query the schema section
# match
# $fri sub friendship;
# $frr sub friend-request;
# $frl sub friends-list;
# $per sub person;
# $muf sub mutual-friendship;
# get;
friendship sub relation,
relates friend,
plays approved-friendship,
plays listed-friendship;
friend-request sub request,
has approved-date,
relates approved-friendship as approved-subject,
relates friendship-requester as requester,
relates friendship-respondent as respondent;
friends-list sub relation,
has title,
relates list-owner,
relates listed-friendship;
person sub entity,
plays friend,
plays friendship-requester,
plays friendship-respondent,
plays list-owner,
plays mutual-friend,
plays one-degree-friend;
#######################
## mutual friendship ##
#######################
mutual-friendship sub relation,
relates mutual-friend,
relates one-degree-friend;
people-have-mutual-friends sub rule,
when {
($p1, $p2) isa friendship;
($p2, $p3) isa friendship;
}, then {
(one-degree-friend: $p1, one-degree-friend: $p3, mutual-friend: $p2) isa mutual-friendship;
};
###########
## GROUP ##
###########
## query the schema section
# match
# $gro sub group-ownership;
# $grm sub group-membership;
# $gmr sub group-membership-request;
# $pug sub public-group;
# $clg sub closed-group;
# $seg sub secret-group;
# $per sub person;
# get;
group-ownership sub ownership,
relates group-owner as owner,
relates owned-group as owned;
group-membership sub relation,
has approved-date,
plays approved-group-membership,
relates group-member,
relates membership-grouping;
group-membership-request sub request,
has approved-date,
relates approved-group-membership as approved-subject,
relates group-membership-requester as requester,
relates group-membership-respondent as respondent;
social-group sub entity,
abstract,
key name,
plays owned-group,
plays membership-grouping,
plays shared-in;
public-group sub social-group;
closed-group sub social-group;
secret-group sub social-group;
person sub entity,
plays group-owner,
plays group-member,
plays group-membership-requester,
plays group-membership-respondent;
#####################################
## public group membership request ##
#####################################
public-group-membership-is-automatically-approved sub rule,
when {
$group isa public-group;
(group-owner: $owner, owned-group: $group) isa group-ownership;
$membership (group-member: $member, membership-grouping: $group) isa group-membership;
}, then {
(approved-group-membership: $membership, group-membership-requester: $member, group-membership-respondent: $owner) isa group-membership-request;
};
###################################
## group owner is always member ##
###################################
group-owner-is-always-member sub rule,
when {
$group isa social-group;
(group-owner: $owner, owned-group: $group) isa group-ownership;
}, then {
(group-member: $owner, membership-grouping: $group) isa group-membership;
};
##############
## TIMELINE ##
##############
## query the schema section
# match
# $tow sub timeline-ownership;
# $tim sub timeline;
# $per sub person;
# get;
timeline-ownership sub ownership,
relates timeline-owner as owner,
relates owned-timeline as owned;
timeline sub entity,
key identifier,
plays owned-timeline,
plays shared-in;
person sub entity,
plays timeline-owner;
##########
## POST ##
##########
## query the schema section
# match
# $rep sub reply;
# $tag sub tagging;
# $att sub attachment;
# $rea sub reaction;
# $emo sub emotion;
# $lin sub link;
# $stu sub status-update;
# $com sub comment;
# $mow sub media-ownership;
# $alb sub album;
# $vid sub video;
# $pho sub photo;
# $per sub person;
# get;
reply sub relation,
relates replied-to,
relates reply-content,
relates replied-by;
tagging sub relation,
relates tagged,
relates tagged-in;
attachment sub relation,
relates attached,
relates attached-to;
reaction sub relation,
relates reacted-emotion,
relates reacted-to,
relates reacted-by;
post sub entity,
abstract,
key identifier,
plays permitted-content,
plays shared-content,
plays replied-to,
plays tagged-in,
plays reacted-to;
status-update sub post,
has content,
plays attached-to;
comment sub post,
has content,
plays reply-content,
plays attached-to;
media-ownership sub ownership,
relates media-owner as owner,
relates owned-media as owned;
album sub post,
has title,
has published-date,
plays media-owner;
media sub post,
abstract,
has caption,
has file,
plays owned-media,
plays attached;
video sub media;
photo sub media;
person sub entity,
plays tagged,
plays reacted-by,
plays replied-by;
#############
## SHARING ##
#############
## query the schema section
# match
# $pus sub public-sharing;
# $frs sub friends-sharing;
# $ins sub inclusive-sharing;
# $fes sub friends-with-exclusion-sharing;
# $prs sub private-sharing;
# $pos sub post;
# $pts sub permitted-to-see;
# $per sub person;
# $puu sub public-user;
# get;
sharing sub relation,
abstract,
relates shared-content,
relates shared-by,
relates shared-in;
public-sharing sub sharing,
relates shared-content,
relates shared-by,
relates shared-in;
friends-sharing sub sharing,
relates shared-content,
relates shared-by,
relates shared-in;
inclusive-sharing sub sharing,
relates shared-content,
relates shared-by,
relates shared-in,
relates shared-with;
friends-with-exclusion-sharing sub sharing,
relates shared-content,
relates shared-by,
relates shared-in,
relates hidden-from;
private-sharing sub sharing,
relates shared-content,
relates shared-in,
relates shared-by;
permitted-to-see sub relation,
relates permitted-content,
relates permission-grantee;
person sub entity,
plays shared-by,
plays shared-with,
plays hidden-from,
plays permission-grantee;
public-user sub entity,
plays permission-grantee;
###########################
## posts view permission ##
###########################
public-permission sub rule,
when {
(shared-content: $sc) isa public-sharing;
$pu isa public-user;
}, then {
(permitted-content: $sc, permission-grantee: $pu) isa permitted-to-see;
};
friends-permission sub rule,
when {
(shared-content: $sc, shared-by: $sb) isa friends-sharing;
(friend: $sb, $f) isa friendship;
}, then {
(permitted-content: $sc, permission-grantee: $f) isa permitted-to-see;
};
inclusive-permissions sub rule,
when {
(shared-content: $sc, shared-with: $sw) isa inclusive-sharing;
}, then {
(permitted-content: $sc, permission-grantee: $sw) isa permitted-to-see;
};
friends-excluded-permission sub rule,
when {
(shared-content: $sc, shared-by: $sb, hidden-from: $hf) isa friends-with-exclusion-sharing;
(friend: $sb, $f) isa friendship;
$f != $hf;
}, then {
(permitted-content: $sc, permission-grantee: $f) isa permitted-to-see;
};
private-permission sub rule,
when {
(shared-content: $sc, shared-by: $sb) isa private-sharing;
$pu isa public-user;
}, then {
(permitted-content: $sc, permission-grantee: $sb) isa permitted-to-see;
};
author-permission sub rule,
when {
(shared-content: $sc, shared-by: $sb) isa sharing;
$pu isa public-user;
}, then {
(permitted-content: $sc, permission-grantee: $sb) isa permitted-to-see;
};