1 | import { isBlankNode, isBlankNodeLike } from "./blank-node.js";
|
2 | import { isNamedNode, isNamedNodeLike } from "./named-node.js";
|
3 | import { isVariable, isVariableLike } from "./variable.js";
|
4 | import { isLiteral, isLiteralLike } from "./literal.js";
|
5 | import { isDefaultGraph, isDefaultGraphLike } from "./default-graph.js";
|
6 | import { hasKey } from "./has-key.js";
|
7 | export function isQuadLike(given) {
|
8 | return (hasKey(given, "subject") &&
|
9 | hasKey(given, "predicate") &&
|
10 | hasKey(given, "object") &&
|
11 | hasKey(given, "graph") &&
|
12 | isQuadSubjectLike(given.subject) &&
|
13 | isQuadPredicateLike(given.predicate) &&
|
14 | isQuadObjectLike(given.object) &&
|
15 | isQuadGraphLike(given.graph));
|
16 | }
|
17 | export function isQuad(given) {
|
18 | function isQuadInstance(given) {
|
19 | return typeof given === "object";
|
20 | }
|
21 | if (!isQuadInstance(given)) {
|
22 | return false;
|
23 | }
|
24 | return (isQuadSubject(given.subject) &&
|
25 | isQuadPredicate(given.predicate) &&
|
26 | isQuadObject(given.object) &&
|
27 | isQuadGraph(given.graph));
|
28 | }
|
29 | export function isQuadSubject(value) {
|
30 | return isNamedNode(value) || isBlankNode(value) || isVariable(value);
|
31 | }
|
32 | export function isQuadPredicate(value) {
|
33 | return isNamedNode(value) || isVariable(value);
|
34 | }
|
35 | export function isQuadObject(value) {
|
36 | return isNamedNode(value) || isLiteral(value) || isBlankNode(value) || isVariable(value);
|
37 | }
|
38 | export function isQuadGraph(value) {
|
39 | return isDefaultGraph(value) || isNamedNode(value) || isBlankNode(value) || isVariable(value);
|
40 | }
|
41 | export function isQuadSubjectLike(value) {
|
42 | return isNamedNodeLike(value) || isBlankNodeLike(value) || isVariableLike(value);
|
43 | }
|
44 | export function isQuadPredicateLike(value) {
|
45 | return isNamedNodeLike(value) || isVariableLike(value);
|
46 | }
|
47 | export function isQuadObjectLike(value) {
|
48 | return isNamedNodeLike(value) || isLiteralLike(value) || isBlankNodeLike(value) || isVariableLike(value);
|
49 | }
|
50 | export function isQuadGraphLike(value) {
|
51 | return isDefaultGraphLike(value) || isNamedNodeLike(value) || isBlankNodeLike(value) || isVariableLike(value);
|
52 | }
|
53 | export class Quad {
|
54 | constructor(subject, predicate, object, graph) {
|
55 | this.subject = subject;
|
56 | this.predicate = predicate;
|
57 | this.object = object;
|
58 | this.graph = graph;
|
59 | }
|
60 | equals(other) {
|
61 | return !!(isQuadLike(other) &&
|
62 | this.subject.equals(other.subject) &&
|
63 | this.predicate.equals(other.predicate) &&
|
64 | this.object.equals(other.object) &&
|
65 | this.graph.equals(other.graph));
|
66 | }
|
67 | toJSON() {
|
68 | return {
|
69 | subject: this.subject,
|
70 | predicate: this.predicate,
|
71 | object: this.object,
|
72 | graph: this.graph
|
73 | };
|
74 | }
|
75 | }
|
76 |
|
\ | No newline at end of file |