Skip to content

Commit e662211

Browse files
authored
Use shared filter helpers across queries (#1256)
* Add shared filterHelpers * Use filterHelpers in neighbor expansion query * Use filterHelpers in neighbor count queries * User filterHelpers in keyword search query * Remove old helpers * Simplify conditional logic
1 parent 239b6a4 commit e662211

File tree

14 files changed

+359
-370
lines changed

14 files changed

+359
-370
lines changed

packages/graph-explorer/src/connector/sparql/fetchBlankNodeNeighbors/blankNodeOneHopNeighborsTemplate.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { query } from "@/utils";
22
import { idParam } from "../idParam";
33
import { rdfTypeUri } from "../types";
4+
import { getNeighborsFilter } from "../filterHelpers";
45

56
/**
67
* Fetch all neighbors and their predicates, values, and classes
@@ -25,15 +26,15 @@ export default function blankNodeOneHopNeighborsTemplate(subQuery: string) {
2526
SELECT DISTINCT ?bNode ?neighbor
2627
WHERE {
2728
{
28-
?neighbor ?p ?bNode .
29+
?neighbor ?predicate ?bNode .
2930
?neighbor a ?class .
30-
FILTER(!isLiteral(?neighbor) && ?p != ${rdfTypeUriTemplate})
31+
${getNeighborsFilter()}
3132
}
3233
UNION
3334
{
34-
?bNode ?p ?neighbor .
35+
?bNode ?predicate ?neighbor .
3536
?neighbor a ?class .
36-
FILTER(!isLiteral(?neighbor) && ?p != ${rdfTypeUriTemplate})
37+
${getNeighborsFilter()}
3738
}
3839
}
3940
}

packages/graph-explorer/src/connector/sparql/fetchNeighbors/helpers.test.ts

Lines changed: 0 additions & 62 deletions
This file was deleted.

packages/graph-explorer/src/connector/sparql/fetchNeighbors/helpers.ts

Lines changed: 0 additions & 34 deletions
This file was deleted.

packages/graph-explorer/src/connector/sparql/fetchNeighbors/oneHopNeighborsTemplate.test.ts

Lines changed: 16 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -32,23 +32,18 @@ describe("oneHopNeighborsTemplate", () => {
3232
SELECT DISTINCT ?neighbor
3333
WHERE {
3434
BIND(<http://www.example.com/soccer/resource#EPL> AS ?resource)
35-
VALUES ?class { <http://www.example.com/soccer/ontology/Team> }
3635
{
3736
?neighbor ?predicate ?resource .
3837
?neighbor a ?class .
39-
FILTER(
40-
?predicate != <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> &&
41-
!isLiteral(?neighbor)
42-
)
38+
FILTER(!isLiteral(?neighbor) && ?predicate != <http://www.w3.org/1999/02/22-rdf-syntax-ns#type>)
39+
FILTER (?class IN (<http://www.example.com/soccer/ontology/Team>))
4340
}
4441
UNION
4542
{
4643
?resource ?predicate ?neighbor .
4744
?neighbor a ?class .
48-
FILTER(
49-
?predicate != <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> &&
50-
!isLiteral(?neighbor)
51-
)
45+
FILTER(!isLiteral(?neighbor) && ?predicate != <http://www.w3.org/1999/02/22-rdf-syntax-ns#type>)
46+
FILTER (?class IN (<http://www.example.com/soccer/ontology/Team>))
5247
}
5348
?neighbor ?pValue ?object .
5449
FILTER(
@@ -85,19 +80,13 @@ describe("oneHopNeighborsTemplate", () => {
8580
{
8681
?neighbor ?predicate ?resource .
8782
?neighbor a ?class .
88-
FILTER(
89-
?predicate != <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> &&
90-
!isLiteral(?neighbor)
91-
)
83+
FILTER(!isLiteral(?neighbor) && ?predicate != <http://www.w3.org/1999/02/22-rdf-syntax-ns#type>)
9284
}
9385
UNION
9486
{
9587
?resource ?predicate ?neighbor .
9688
?neighbor a ?class .
97-
FILTER(
98-
?predicate != <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> &&
99-
!isLiteral(?neighbor)
100-
)
89+
FILTER(!isLiteral(?neighbor) && ?predicate != <http://www.w3.org/1999/02/22-rdf-syntax-ns#type>)
10190
}
10291
}
10392
LIMIT 10
@@ -125,23 +114,18 @@ describe("oneHopNeighborsTemplate", () => {
125114
SELECT DISTINCT ?neighbor
126115
WHERE {
127116
BIND(<http://www.example.com/soccer/resource#EPL> AS ?resource)
128-
VALUES ?class { <http://www.example.com/soccer/ontology/Team> <http://www.example.com/soccer/ontology/Player> }
129117
{
130118
?neighbor ?predicate ?resource .
131119
?neighbor a ?class .
132-
FILTER(
133-
?predicate != <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> &&
134-
!isLiteral(?neighbor)
135-
)
120+
FILTER(!isLiteral(?neighbor) && ?predicate != <http://www.w3.org/1999/02/22-rdf-syntax-ns#type>)
121+
FILTER (?class IN (<http://www.example.com/soccer/ontology/Team>, <http://www.example.com/soccer/ontology/Player>))
136122
}
137123
UNION
138124
{
139125
?resource ?predicate ?neighbor .
140126
?neighbor a ?class .
141-
FILTER(
142-
?predicate != <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> &&
143-
!isLiteral(?neighbor)
144-
)
127+
FILTER(!isLiteral(?neighbor) && ?predicate != <http://www.w3.org/1999/02/22-rdf-syntax-ns#type>)
128+
FILTER (?class IN (<http://www.example.com/soccer/ontology/Team>, <http://www.example.com/soccer/ontology/Player>))
145129
}
146130
}
147131
}
@@ -169,19 +153,13 @@ describe("oneHopNeighborsTemplate", () => {
169153
{
170154
?neighbor ?predicate ?resource .
171155
?neighbor a ?class .
172-
FILTER(
173-
?predicate != <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> &&
174-
!isLiteral(?neighbor)
175-
)
156+
FILTER(!isLiteral(?neighbor) && ?predicate != <http://www.w3.org/1999/02/22-rdf-syntax-ns#type>)
176157
}
177158
UNION
178159
{
179160
?resource ?predicate ?neighbor .
180161
?neighbor a ?class .
181-
FILTER(
182-
?predicate != <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> &&
183-
!isLiteral(?neighbor)
184-
)
162+
FILTER(!isLiteral(?neighbor) && ?predicate != <http://www.w3.org/1999/02/22-rdf-syntax-ns#type>)
185163
}
186164
}
187165
}
@@ -210,19 +188,13 @@ describe("oneHopNeighborsTemplate", () => {
210188
{
211189
?neighbor ?predicate ?resource .
212190
?neighbor a ?class .
213-
FILTER(
214-
?predicate != <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> &&
215-
!isLiteral(?neighbor)
216-
)
191+
FILTER(!isLiteral(?neighbor) && ?predicate != <http://www.w3.org/1999/02/22-rdf-syntax-ns#type>)
217192
}
218193
UNION
219194
{
220195
?resource ?predicate ?neighbor .
221196
?neighbor a ?class .
222-
FILTER(
223-
?predicate != <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> &&
224-
!isLiteral(?neighbor)
225-
)
197+
FILTER(!isLiteral(?neighbor) && ?predicate != <http://www.w3.org/1999/02/22-rdf-syntax-ns#type>)
226198
}
227199
}
228200
LIMIT 10 OFFSET 5
@@ -255,8 +227,8 @@ describe("oneHopNeighborsTemplate", () => {
255227
?neighbor ?predicate ?resource .
256228
?neighbor a ?class .
257229
FILTER(
258-
?predicate != <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> &&
259230
!isLiteral(?neighbor) &&
231+
?predicate != <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> &&
260232
?neighbor NOT IN (
261233
<http://www.example.com/soccer/resource#EFL>,
262234
<http://www.example.com/soccer/resource#EFL2>
@@ -268,8 +240,8 @@ describe("oneHopNeighborsTemplate", () => {
268240
?resource ?predicate ?neighbor .
269241
?neighbor a ?class .
270242
FILTER(
271-
?predicate != <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> &&
272243
!isLiteral(?neighbor) &&
244+
?predicate != <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> &&
273245
?neighbor NOT IN (
274246
<http://www.example.com/soccer/resource#EFL>,
275247
<http://www.example.com/soccer/resource#EFL2>

0 commit comments

Comments
 (0)