1 | import { DefaultDataFactory, isQuad, isQuadLike, isTermLike } from "@opennetwork/rdf-data-model";
|
2 | function hasKey(value, key) {
|
3 | return (typeof value === "object" &&
|
4 | value.hasOwnProperty(key));
|
5 | }
|
6 | export function isQuadFind(value) {
|
7 | return (isQuadLike(value) ||
|
8 | (hasKey(value, "subject") &&
|
9 | isTermLike(value)) ||
|
10 | (hasKey(value, "predicate") &&
|
11 | isTermLike(value)) ||
|
12 | (hasKey(value, "object") &&
|
13 | isTermLike(value)) ||
|
14 | (hasKey(value, "graph") &&
|
15 | isTermLike(value)));
|
16 | }
|
17 | export function isSingleMatcher(find) {
|
18 | return !!(find.subject &&
|
19 | find.predicate &&
|
20 | find.object &&
|
21 | find.graph);
|
22 | }
|
23 | export function isMatch(quad, find) {
|
24 | const quadInstance = isQuad(quad) ? quad : DefaultDataFactory.fromQuad(quad);
|
25 | return ((!find.subject || quadInstance.subject.equals(find.subject)) &&
|
26 | (!find.predicate || quadInstance.predicate.equals(find.predicate)) &&
|
27 | (!find.object || quadInstance.object.equals(find.object)) &&
|
28 | (!find.graph || quadInstance.graph.equals(find.graph)));
|
29 | }
|
30 |
|
\ | No newline at end of file |