Mercurial > code > home > repos > streamed-graph
comparison src/layout/graph_queries.ts @ 106:2468f2227d22
make src/layout/ and src/render/ separation
author | drewp@bigasterisk.com |
---|---|
date | Sun, 13 Mar 2022 22:00:30 -0700 |
parents | src/graph_queries.ts@0c188ed3bcd8 |
children |
comparison
equal
deleted
inserted
replaced
105:4bb8c7775c83 | 106:2468f2227d22 |
---|---|
1 // import { DataFactory, Literal, N3Store, NamedNode, Util } from "n3"; | |
2 // const { literal, namedNode } = DataFactory; | |
3 | |
4 // // i think this one is a worse subset of graphLiteral, below | |
5 // export function getStringValue( | |
6 // store: N3Store | undefined, | |
7 // subj: NamedNode, | |
8 // pred: NamedNode, | |
9 // defaultValue: string = "" | |
10 // ): string { | |
11 // if (store === undefined) { | |
12 // // this is so you can use the function before you have a graph | |
13 // return "..."; | |
14 // } | |
15 // const objs = store.getObjects(subj, pred, null); | |
16 // if (objs.length == 0) { | |
17 // return defaultValue; | |
18 // } | |
19 // return objs[0].value; | |
20 // } | |
21 | |
22 // // workaround for uris that don't have good labels in the graph | |
23 // export function labelFromUri( | |
24 // uri: NamedNode, | |
25 // prefix: string, | |
26 // tailsToLabels: { [key: string]: string }, | |
27 // defaultLabel: string | |
28 // ) { | |
29 // let label = defaultLabel === undefined ? uri.value : defaultLabel; | |
30 // Object.entries(tailsToLabels).forEach(([tail, useLabel]) => { | |
31 // if (uri.equals(namedNode(prefix + tail))) { | |
32 // label = useLabel as string; | |
33 // } | |
34 // }); | |
35 // return label; | |
36 // } | |
37 | |
38 // export function graphLiteral( | |
39 // store: N3Store, | |
40 // subj: NamedNode, | |
41 // pred: string, | |
42 // notFoundResult?: string | |
43 // ): Literal { | |
44 // const keep: Array<Literal> = []; | |
45 // store.forEach( | |
46 // q => { | |
47 // if (!Util.isLiteral(q.object)) { | |
48 // throw new Error("non literal found"); | |
49 // } | |
50 // let seen = false; | |
51 // for (let other of keep) { | |
52 // // why are we getting multiple matches for the same literal? seems like a bug | |
53 // if (other.equals(q.object)) { | |
54 // seen = true; | |
55 // } | |
56 // } | |
57 // if (!seen) { | |
58 // keep.push(q.object as Literal); | |
59 // } | |
60 // }, | |
61 // subj, | |
62 // namedNode(pred), | |
63 // null, | |
64 // null | |
65 // ); | |
66 // if (keep.length == 0) { | |
67 // return literal(notFoundResult || "(missing)"); | |
68 // } | |
69 // if (keep.length == 1) { | |
70 // return keep[0]; | |
71 // } | |
72 // console.log(`${subj.value} ${pred} had ${keep.length} objects:`, keep); | |
73 // return keep[0]; | |
74 // } | |
75 | |
76 // export function graphUriValue( | |
77 // store: N3Store, | |
78 // subj: NamedNode, | |
79 // pred: string | |
80 // ): NamedNode | undefined { | |
81 // const keep: Array<NamedNode> = []; | |
82 // store.forEach( | |
83 // q => { | |
84 // if (!Util.isNamedNode(q.object)) { | |
85 // throw new Error("non uri found"); | |
86 // } | |
87 // keep.push(q.object as NamedNode); | |
88 // }, | |
89 // subj, | |
90 // namedNode(pred), | |
91 // null, | |
92 // null | |
93 // ); | |
94 // if (keep.length == 0) { | |
95 // return undefined; | |
96 // } | |
97 // if (keep.length == 1) { | |
98 // return keep[0]; | |
99 // } | |
100 // throw new Error("found multiple matches for pred"); | |
101 // } |