forked from ldbc/ldbc_snb_interactive_v1_impls
-
Notifications
You must be signed in to change notification settings - Fork 0
/
bi-22.sparql
140 lines (129 loc) · 5.78 KB
/
bi-22.sparql
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
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
PREFIX sn: <http://www.ldbc.eu/ldbc_socialnet/1.0/data/>
PREFIX snvoc: <http://www.ldbc.eu/ldbc_socialnet/1.0/vocabulary/>
PREFIX sntag: <http://www.ldbc.eu/ldbc_socialnet/1.0/tag/>
PREFIX foaf: <http://xmlns.com/foaf/0.1/>
PREFIX dbpedia: <http://dbpedia.org/resource/>
PREFIX dbpedia-owl: <http://dbpedia.org/ontology/>
SELECT ?person1Id ?person2Id ?city1Name ?score
WHERE
{
{
SELECT ?person1Id ?person2Id ?city1Name (MAX(COALESCE(?case1InnerScore,0)) + MAX(COALESCE(?case2InnerScore,0)) + MAX(?case3InnerScore) + MAX(COALESCE(?case4InnerScore,0)) + MAX(COALESCE(?case5InnerScore,0)) AS ?score)
WHERE
{
?person1Id a snvoc:Person .
?person1Id snvoc:isLocatedIn ?city1 .
?city1 foaf:name ?city1Name .
?city1 snvoc:isPartOf/foaf:name $country1 .
?person2Id a snvoc:Person .
?person2Id snvoc:isLocatedIn/snvoc:isPartOf/foaf:name $country2 .
OPTIONAL {
VALUES (?type1) {(snvoc:Comment) (snvoc:Post)}
?message1 a ?type1 .
?message1 snvoc:hasCreator ?person2Id .
?comment1 a snvoc:Comment .
?comment1 snvoc:hasCreator ?person1Id .
?comment1 snvoc:replyOf ?message1 .
BIND( 4 AS ?case1InnerScore )
}
OPTIONAL {
VALUES (?type2) {(snvoc:Comment) (snvoc:Post)}
?message2 a ?type2 .
?message2 snvoc:hasCreator ?person1Id .
?comment2 a snvoc:Comment .
?comment2 snvoc:hasCreator ?person2Id .
?comment2 snvoc:replyOf ?message2 .
BIND( 1 AS ?case2InnerScore )
}
BIND( IF( EXISTS {
{
?person1Id snvoc:knows/snvoc:hasPerson ?person2Id
} UNION {
?person2Id snvoc:knows/snvoc:hasPerson ?person1Id
}
}, 15, 0 ) AS ?case3InnerScore )
OPTIONAL {
VALUES (?type4) {(snvoc:Comment) (snvoc:Post)}
?message4 a ?type4 .
?message4 snvoc:hasCreator ?person2Id .
?person1Id snvoc:likes/(snvoc:hasPost|snvoc:hasComment) ?message4
BIND( 10 AS ?case4InnerScore )
}
OPTIONAL {
VALUES (?type5) {(snvoc:Comment) (snvoc:Post)}
?message5 a ?type5 .
?message5 snvoc:hasCreator ?person1Id .
?person2Id snvoc:likes/(snvoc:hasPost|snvoc:hasComment) ?message5
BIND( 1 AS ?case5InnerScore )
}
}
GROUP BY ?person1Id ?person2Id ?city1Name
}
{
SELECT ?person1IdHelper ?person2IdHelper ?city1NameHelper (MAX(COALESCE(?case1InnerScore,0)) + MAX(COALESCE(?case2InnerScore,0)) + MAX(?case3InnerScore) + MAX(COALESCE(?case4InnerScore,0)) + MAX(COALESCE(?case5InnerScore,0)) AS ?scoreHelper)
WHERE
{
?person1IdHelper a snvoc:Person .
?person1IdHelper snvoc:isLocatedIn ?city1 .
?city1 foaf:name ?city1NameHelper .
?city1 snvoc:isPartOf/foaf:name $country1 .
?person2IdHelper a snvoc:Person .
?person2IdHelper snvoc:isLocatedIn/snvoc:isPartOf/foaf:name $country2 .
OPTIONAL {
VALUES (?type1) {(snvoc:Comment) (snvoc:Post)}
?message1 a ?type1 .
?message1 snvoc:hasCreator ?person2IdHelper .
?comment1 a snvoc:Comment .
?comment1 snvoc:hasCreator ?person1IdHelper .
?comment1 snvoc:replyOf ?message1 .
BIND( 4 AS ?case1InnerScore )
}
OPTIONAL {
VALUES (?type2) {(snvoc:Comment) (snvoc:Post)}
?message2 a ?type2 .
?message2 snvoc:hasCreator ?person1IdHelper .
?comment2 a snvoc:Comment .
?comment2 snvoc:hasCreator ?person2IdHelper .
?comment2 snvoc:replyOf ?message2 .
BIND( 1 AS ?case2InnerScore )
}
BIND( IF( EXISTS {
{
?person1IdHelper snvoc:knows/snvoc:hasPerson ?person2IdHelper
} UNION {
?person2IdHelper snvoc:knows/snvoc:hasPerson ?person1IdHelper
}
}, 15, 0 ) AS ?case3InnerScore )
OPTIONAL {
VALUES (?type4) {(snvoc:Comment) (snvoc:Post)}
?message4 a ?type4 .
?message4 snvoc:hasCreator ?person2IdHelper .
?person1IdHelper snvoc:likes/(snvoc:hasPost|snvoc:hasComment) ?message4
BIND( 10 AS ?case4InnerScore )
}
OPTIONAL {
VALUES (?type5) {(snvoc:Comment) (snvoc:Post)}
?message5 a ?type5 .
?message5 snvoc:hasCreator ?person1IdHelper .
?person2IdHelper snvoc:likes/(snvoc:hasPost|snvoc:hasComment) ?message5
BIND( 1 AS ?case5InnerScore )
}
}
GROUP BY ?person1IdHelper ?person2IdHelper ?city1NameHelper
}
?person1Id snvoc:id ?p1Id .
?person2Id snvoc:id ?p2Id .
?person1IdHelper snvoc:id ?p1IdHelper .
?person2IdHelper snvoc:id ?p2IdHelper .
FILTER( ?city1NameHelper = ?city1Name )
BIND( ?score = ?scoreHelper AS ?scoreEQ )
BIND( ?p1Id = ?p1IdHelper AS ?person1IdEQ )
BIND( IF( ?scoreEQ, IF( ?person1IdEQ, ?p2Id >= ?p2IdHelper, ?p1Id >= ?p1IdHelper ), ?score <= ?scoreHelper ) AS ?isSmaller )
FILTER( ?isSmaller )
}
GROUP BY ?person1Id ?person2Id ?city1Name ?score
HAVING (COUNT(*) = 1)
ORDER BY DESC(?score) ?person1Id ?person2Id