rdflib 2.2.22-4e175603 → 2.2.22-53d65d90
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/rdflib.min.js +1 -1
- package/dist/rdflib.min.js.LICENSE.txt +4 -0
- package/dist/rdflib.min.js.map +1 -1
- package/esm/blank-node.js +90 -61
- package/esm/class-order.js +1 -1
- package/esm/collection.js +106 -70
- package/esm/default-graph.js +33 -13
- package/esm/empty.js +26 -8
- package/esm/factories/canonical-data-factory.js +30 -33
- package/esm/factories/extended-term-factory.js +14 -18
- package/esm/factories/factory-types.js +1 -1
- package/esm/factories/rdflib-data-factory.js +11 -9
- package/esm/fetcher.js +1644 -1355
- package/esm/formula.js +740 -632
- package/esm/index.js +51 -31
- package/esm/jsonldparser.js +26 -19
- package/esm/jsonparser.js +1 -1
- package/esm/lists.js +86 -38
- package/esm/literal.js +157 -120
- package/esm/log.js +7 -7
- package/esm/n3parser.js +1085 -1008
- package/esm/named-node.js +99 -69
- package/esm/namespace.js +4 -2
- package/esm/node-internal.js +98 -74
- package/esm/node.js +1 -1
- package/esm/parse.js +3 -3
- package/esm/patch-parser.js +1 -1
- package/esm/query.js +16 -15
- package/esm/rdfaparser.js +846 -781
- package/esm/rdfxmlparser.js +365 -348
- package/esm/serialize.js +4 -20
- package/esm/serializer.js +886 -821
- package/esm/statement.js +72 -52
- package/esm/store.js +924 -822
- package/esm/types.js +21 -21
- package/esm/update-manager.js +983 -882
- package/esm/updates-via.js +134 -104
- package/esm/uri.js +3 -3
- package/esm/utils/default-graph-uri.js +2 -2
- package/esm/utils/terms.js +5 -4
- package/esm/utils-js.js +5 -5
- package/esm/utils.js +6 -6
- package/esm/variable.js +58 -32
- package/esm/xsd.js +2 -2
- package/lib/blank-node.js +88 -60
- package/lib/class-order.js +1 -1
- package/lib/collection.js +104 -69
- package/lib/default-graph.js +32 -13
- package/lib/empty.js +25 -8
- package/lib/factories/canonical-data-factory.js +32 -35
- package/lib/factories/extended-term-factory.js +14 -18
- package/lib/factories/factory-types.js +1 -1
- package/lib/factories/rdflib-data-factory.js +11 -9
- package/lib/fetcher.js +1646 -1385
- package/lib/formula.d.ts +1 -1
- package/lib/formula.js +739 -632
- package/lib/index.js +87 -66
- package/lib/jsonldparser.js +26 -19
- package/lib/jsonparser.js +1 -1
- package/lib/lists.js +86 -54
- package/lib/literal.js +156 -120
- package/lib/log.js +7 -7
- package/lib/n3parser.js +1089 -1010
- package/lib/named-node.js +98 -69
- package/lib/namespace.js +4 -2
- package/lib/node-internal.js +96 -73
- package/lib/node.js +1 -1
- package/lib/parse.js +6 -5
- package/lib/patch-parser.js +1 -1
- package/lib/query.js +18 -19
- package/lib/rdfaparser.js +848 -783
- package/lib/rdfxmlparser.js +366 -350
- package/lib/serialize.d.ts +1 -1
- package/lib/serialize.js +4 -21
- package/lib/serializer.d.ts +1 -0
- package/lib/serializer.js +890 -825
- package/lib/statement.js +74 -54
- package/lib/store.d.ts +1 -1
- package/lib/store.js +926 -844
- package/lib/types.js +21 -21
- package/lib/update-manager.d.ts +1 -1
- package/lib/update-manager.js +959 -865
- package/lib/updates-via.js +134 -105
- package/lib/uri.js +3 -3
- package/lib/utils/default-graph-uri.js +2 -2
- package/lib/utils/terms.js +6 -4
- package/lib/utils-js.js +9 -8
- package/lib/utils.js +6 -6
- package/lib/variable.js +60 -34
- package/lib/xsd.js +2 -2
- package/package.json +6 -6
- package/src/jsonldparser.js +1 -1
- package/src/serialize.ts +4 -14
- package/src/serializer.js +24 -0
- package/src/update-manager.ts +8 -2
package/src/jsonldparser.js
CHANGED
|
@@ -84,7 +84,7 @@ export default function jsonldParser (str, kb, base, callback) {
|
|
|
84
84
|
|
|
85
85
|
function nodeType (kb, obj) {
|
|
86
86
|
if (obj['@id'].startsWith('_:')) {
|
|
87
|
-
// This object is a Blank Node
|
|
87
|
+
// This object is a Blank Node. Pass the id without the `_:` prefix
|
|
88
88
|
return kb.rdfFactory.blankNode(obj['@id'].substring(2));
|
|
89
89
|
} else {
|
|
90
90
|
// This object is a Named Node
|
package/src/serialize.ts
CHANGED
|
@@ -14,7 +14,6 @@ import {
|
|
|
14
14
|
} from './types'
|
|
15
15
|
import IndexedFormula from './store'
|
|
16
16
|
import { BlankNode, NamedNode } from './tf-types'
|
|
17
|
-
import * as jsonld from 'jsonld'
|
|
18
17
|
|
|
19
18
|
/**
|
|
20
19
|
* Serialize to the appropriate format
|
|
@@ -42,7 +41,7 @@ export default function serialize (
|
|
|
42
41
|
*/
|
|
43
42
|
namespaces?: Record<string, string>
|
|
44
43
|
}
|
|
45
|
-
): string | undefined {
|
|
44
|
+
): string | undefined | Promise<string> {
|
|
46
45
|
base = base || target?.value
|
|
47
46
|
const opts = options || {}
|
|
48
47
|
contentType = contentType || TurtleContentType // text/n3 if complex?
|
|
@@ -51,7 +50,6 @@ export default function serialize (
|
|
|
51
50
|
var sz = Serializer(kb)
|
|
52
51
|
if ((opts as any).flags) sz.setFlags((opts as any).flags)
|
|
53
52
|
var newSts = kb!.statementsMatching(undefined, undefined, undefined, target as NamedNode)
|
|
54
|
-
var n3String: string
|
|
55
53
|
|
|
56
54
|
// If an IndexedFormula, use the namespaces from the given graph as suggestions
|
|
57
55
|
if ('namespaces' in kb) {
|
|
@@ -82,10 +80,9 @@ export default function serialize (
|
|
|
82
80
|
documentString = sz.statementsToNTriples(newSts)
|
|
83
81
|
return executeCallback(null, documentString)
|
|
84
82
|
case JSONLDContentType:
|
|
85
|
-
sz.setFlags('
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
return toJsonld(n3String) as any
|
|
83
|
+
sz.setFlags('si') // use turtle parameters
|
|
84
|
+
documentString = sz.statementsToJsonld(newSts) // convert via turtle
|
|
85
|
+
return executeCallback(null, documentString)
|
|
89
86
|
case NQuadsContentType:
|
|
90
87
|
case NQuadsAltContentType: // @@@ just outpout the quads? Does not work for collections
|
|
91
88
|
sz.setFlags('deinprstux q') // Suppress nice parts of N3 to make ntriples
|
|
@@ -110,11 +107,4 @@ export default function serialize (
|
|
|
110
107
|
return result as string
|
|
111
108
|
}
|
|
112
109
|
}
|
|
113
|
-
|
|
114
|
-
function toJsonld (item ) {
|
|
115
|
-
try {
|
|
116
|
-
return jsonld.fromRDF(item, {format: 'application/n-quads'}).then( docJsonld => { return JSON.stringify(docJsonld) })
|
|
117
|
-
// return JSON.stringify(await jsonld.fromRDF(item, {format: 'application/n-quads'}))
|
|
118
|
-
} catch (e) { throw e }
|
|
119
|
-
}
|
|
120
110
|
}
|
package/src/serializer.js
CHANGED
|
@@ -12,6 +12,8 @@ import * as Util from './utils-js'
|
|
|
12
12
|
import CanonicalDataFactory from './factories/canonical-data-factory'
|
|
13
13
|
import { createXSD } from './xsd'
|
|
14
14
|
import solidNs from 'solid-namespace'
|
|
15
|
+
// import * as jsonld from 'jsonld'
|
|
16
|
+
import * as ttl2jsonld from '@frogcat/ttl2jsonld'
|
|
15
17
|
|
|
16
18
|
|
|
17
19
|
export default function createSerializer(store) {
|
|
@@ -1011,6 +1013,28 @@ export class Serializer {
|
|
|
1011
1013
|
var tree2 = [str, tree, '</rdf:RDF>'] // @@ namespace declrations
|
|
1012
1014
|
return XMLtreeToString(tree2, -1)
|
|
1013
1015
|
} // End @@ body
|
|
1016
|
+
|
|
1017
|
+
statementsToJsonld (sts) {
|
|
1018
|
+
// ttl2jsonld creates context keys for all ttl prefix
|
|
1019
|
+
// context keys must be full IRI
|
|
1020
|
+
function findId (itemObj) {
|
|
1021
|
+
if (itemObj['@id']) {
|
|
1022
|
+
const item = itemObj['@id'].split(':')
|
|
1023
|
+
if (keys[item[0]]) itemObj['@id'] = jsonldObj['@context'][item[0]] + item[1]
|
|
1024
|
+
}
|
|
1025
|
+
const itemValues = Object.values(itemObj)
|
|
1026
|
+
for (const i in itemValues) {
|
|
1027
|
+
if (typeof itemValues[i] !== 'string') { // @list contains array
|
|
1028
|
+
findId(itemValues[i])
|
|
1029
|
+
}
|
|
1030
|
+
}
|
|
1031
|
+
}
|
|
1032
|
+
const turtleDoc = this.statementsToN3(sts)
|
|
1033
|
+
const jsonldObj = ttl2jsonld.parse(turtleDoc)
|
|
1034
|
+
|
|
1035
|
+
return JSON.stringify(jsonldObj, null, 2)
|
|
1036
|
+
}
|
|
1037
|
+
|
|
1014
1038
|
}
|
|
1015
1039
|
|
|
1016
1040
|
// String escaping utilities
|
package/src/update-manager.ts
CHANGED
|
@@ -213,7 +213,7 @@ export default class UpdateManager {
|
|
|
213
213
|
* Returns a list of all bnodes occurring in a list of statements
|
|
214
214
|
* @private
|
|
215
215
|
*/
|
|
216
|
-
statementArrayBnodes (sts: Quad
|
|
216
|
+
statementArrayBnodes (sts: ReadonlyArray<Quad>) {
|
|
217
217
|
var bnodes: BlankNode[] = []
|
|
218
218
|
for (let i = 0; i < sts.length; i++) {
|
|
219
219
|
bnodes = bnodes.concat(this.statementBnodes(sts[i]))
|
|
@@ -752,7 +752,13 @@ export default class UpdateManager {
|
|
|
752
752
|
// console.log(message)
|
|
753
753
|
throw new Error(message)
|
|
754
754
|
}
|
|
755
|
-
|
|
755
|
+
if (doc.termType !== 'NamedNode') {
|
|
756
|
+
let message = 'Error patching: document not a NamedNode:' + ds[0] + ', ' + is[0]
|
|
757
|
+
// console.log(message)
|
|
758
|
+
throw new Error(message)
|
|
759
|
+
}
|
|
760
|
+
var control = this.patchControlFor(doc)
|
|
761
|
+
|
|
756
762
|
var startTime = Date.now()
|
|
757
763
|
|
|
758
764
|
var props = ['subject', 'predicate', 'object', 'why']
|