Mercurial > code > home > repos > streamed-graph
comparison src/graph_queries.ts @ 79:0c188ed3bcd8
starting lit upgrade. total mess right now
author | drewp@bigasterisk.com |
---|---|
date | Wed, 17 Nov 2021 13:01:08 -0800 |
parents | 601a604c097a |
children |
comparison
equal
deleted
inserted
replaced
78:ea9c9db282d6 | 79:0c188ed3bcd8 |
---|---|
1 import { N3Store, NamedNode } from "n3"; | 1 // import { DataFactory, Literal, N3Store, NamedNode, Util } from "n3"; |
2 // const { literal, namedNode } = DataFactory; | |
2 | 3 |
3 export function getStringValue( | 4 // // i think this one is a worse subset of graphLiteral, below |
4 store: N3Store | undefined, | 5 // export function getStringValue( |
5 subj: NamedNode, | 6 // store: N3Store | undefined, |
6 pred: NamedNode, | 7 // subj: NamedNode, |
7 defaultValue: string = "" | 8 // pred: NamedNode, |
8 ): string { | 9 // defaultValue: string = "" |
9 if (store === undefined) { | 10 // ): string { |
10 // this is so you can use the function before you have a graph | 11 // if (store === undefined) { |
11 return "..."; | 12 // // this is so you can use the function before you have a graph |
12 } | 13 // return "..."; |
13 const objs = store.getObjects(subj, pred, null); | 14 // } |
14 if (objs.length == 0) { | 15 // const objs = store.getObjects(subj, pred, null); |
15 return defaultValue; | 16 // if (objs.length == 0) { |
16 } | 17 // return defaultValue; |
17 return objs[0].value; | 18 // } |
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 // } |