rdflib 2.2.20 → 2.2.21-23b2ead1
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 +9 -1
- package/dist/rdflib.min.js.map +1 -1
- package/esm/blank-node.js +61 -114
- package/esm/class-order.js +1 -1
- package/esm/collection.js +70 -126
- package/esm/default-graph.js +14 -48
- package/esm/empty.js +8 -39
- package/esm/factories/canonical-data-factory.js +33 -65
- package/esm/factories/extended-term-factory.js +18 -25
- package/esm/factories/factory-types.js +3 -2
- package/esm/factories/rdflib-data-factory.js +9 -19
- package/esm/fetcher.js +1341 -1854
- package/esm/formula.js +639 -846
- package/esm/index.js +40 -77
- package/esm/jsonldparser.js +34 -50
- package/esm/jsonparser.js +1 -8
- package/esm/lists.js +105 -0
- package/esm/literal.js +120 -189
- package/esm/log.js +7 -7
- package/esm/n3parser.js +1015 -1412
- package/esm/named-node.js +70 -119
- package/esm/namespace.js +2 -5
- package/esm/node-internal.js +73 -110
- package/esm/node.js +2 -7
- package/esm/parse.js +12 -19
- package/esm/patch-parser.js +10 -30
- package/esm/query-to-sparql.js +0 -18
- package/esm/query.js +63 -147
- package/esm/rdfaparser.js +794 -997
- package/esm/rdfxmlparser.js +347 -461
- package/esm/serialize.js +7 -33
- package/esm/serializer.js +886 -1036
- package/esm/sparql-to-query.js +44 -134
- package/esm/statement.js +54 -78
- package/esm/store.js +831 -1102
- package/esm/types.js +22 -21
- package/esm/update-manager.js +869 -1104
- package/esm/updates-via.js +104 -161
- package/esm/uri.js +9 -53
- package/esm/utils/default-graph-uri.js +3 -2
- package/esm/utils/termValue.js +0 -1
- package/esm/utils/terms.js +28 -19
- package/esm/utils-js.js +20 -61
- package/esm/utils.js +10 -21
- package/esm/variable.js +32 -78
- package/esm/xsd.js +2 -2
- package/lib/blank-node.js +60 -113
- package/lib/class-order.js +1 -2
- package/lib/collection.js +69 -129
- package/lib/default-graph.js +13 -52
- package/lib/empty.js +8 -43
- package/lib/factories/canonical-data-factory.js +35 -79
- package/lib/factories/extended-term-factory.js +18 -32
- package/lib/factories/factory-types.d.ts +6 -6
- package/lib/factories/factory-types.js +1 -4
- package/lib/factories/rdflib-data-factory.js +9 -23
- package/lib/fetcher.d.ts +6 -6
- package/lib/fetcher.js +1370 -1843
- package/lib/formula.d.ts +1 -1
- package/lib/formula.js +640 -855
- package/lib/index.d.ts +1 -2
- package/lib/index.js +67 -156
- package/lib/jsonldparser.js +33 -54
- package/lib/jsonparser.js +1 -10
- package/lib/lists.d.ts +13 -0
- package/lib/lists.js +113 -0
- package/lib/literal.js +120 -195
- package/lib/log.d.ts +0 -6
- package/lib/log.js +7 -8
- package/lib/n3parser.js +1030 -1436
- package/lib/named-node.js +69 -126
- package/lib/namespace.js +2 -7
- package/lib/node-internal.js +74 -107
- package/lib/node.js +2 -12
- package/lib/parse.d.ts +1 -1
- package/lib/parse.js +12 -32
- package/lib/patch-parser.js +11 -34
- package/lib/query-to-sparql.js +0 -23
- package/lib/query.js +62 -167
- package/lib/rdfaparser.js +796 -1009
- package/lib/rdfxmlparser.js +349 -466
- package/lib/serialize.d.ts +1 -1
- package/lib/serialize.js +7 -43
- package/lib/serializer.d.ts +1 -0
- package/lib/serializer.js +889 -1051
- package/lib/sparql-to-query.js +42 -167
- package/lib/statement.js +55 -84
- package/lib/store.d.ts +2 -2
- package/lib/store.js +850 -1112
- package/lib/tf-types.d.ts +4 -4
- package/lib/types.d.ts +8 -8
- package/lib/types.js +23 -23
- package/lib/update-manager.d.ts +1 -1
- package/lib/update-manager.js +865 -1101
- package/lib/updates-via.js +105 -164
- package/lib/uri.js +8 -61
- package/lib/utils/default-graph-uri.js +3 -5
- package/lib/utils/termValue.js +0 -2
- package/lib/utils/terms.d.ts +6 -1
- package/lib/utils/terms.js +29 -35
- package/lib/utils-js.js +23 -88
- package/lib/utils.js +10 -27
- package/lib/variable.js +34 -85
- package/lib/xsd-internal.js +0 -3
- package/lib/xsd.js +2 -6
- package/package.json +38 -40
- package/src/collection.ts +2 -0
- package/src/fetcher.ts +2 -2
- package/src/index.ts +0 -2
- package/src/jsonldparser.js +13 -4
- package/src/lists.ts +121 -0
- package/src/serialize.ts +2 -10
- package/src/serializer.js +78 -0
- package/src/statement.ts +7 -0
- package/src/store.ts +7 -7
- package/src/update-manager.ts +15 -9
- package/src/utils/terms.ts +23 -1
- package/changes.txt +0 -59
- package/esm/convert.js +0 -61
- package/lib/convert.d.ts +0 -2
- package/lib/convert.js +0 -77
- package/src/convert.js +0 -70
package/src/serializer.js
CHANGED
|
@@ -12,6 +12,7 @@ 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'
|
|
15
16
|
|
|
16
17
|
|
|
17
18
|
export default function createSerializer(store) {
|
|
@@ -1011,6 +1012,83 @@ export class Serializer {
|
|
|
1011
1012
|
var tree2 = [str, tree, '</rdf:RDF>'] // @@ namespace declrations
|
|
1012
1013
|
return XMLtreeToString(tree2, -1)
|
|
1013
1014
|
} // End @@ body
|
|
1015
|
+
|
|
1016
|
+
statementsToJsonld (sts) {
|
|
1017
|
+
// find all @context prefix except base
|
|
1018
|
+
function contextMethod (n3String) {
|
|
1019
|
+
let prefixes = new Set()
|
|
1020
|
+
const regex = /<(.*?)>/g
|
|
1021
|
+
n3String.match(regex).map(string => {
|
|
1022
|
+
const uri = string.slice(1).slice(0, -1)
|
|
1023
|
+
if (uri.includes('//') && (!this.base || !uri.includes(this.base))) prefixes.add(addPrefix(uri))
|
|
1024
|
+
})
|
|
1025
|
+
let context = `{ `
|
|
1026
|
+
const test = [...prefixes].map(term => {
|
|
1027
|
+
context += `${term},`
|
|
1028
|
+
})
|
|
1029
|
+
return context.slice(0, -1) + `}`
|
|
1030
|
+
}
|
|
1031
|
+
|
|
1032
|
+
function addPrefixMethod (uri) {
|
|
1033
|
+
var j = uri.indexOf('#')
|
|
1034
|
+
if (j < 0 ) {
|
|
1035
|
+
j = uri.lastIndexOf('/')
|
|
1036
|
+
}
|
|
1037
|
+
if (j >= 0 &&
|
|
1038
|
+
// Can split at namespace but only if http[s]: URI or file: or ws[s] (why not others?)
|
|
1039
|
+
(uri.indexOf('http') === 0 || uri.indexOf('ws') === 0 || uri.indexOf('file') === 0)) {
|
|
1040
|
+
var canSplit = true
|
|
1041
|
+
for (var k = j + 1; k < uri.length; k++) {
|
|
1042
|
+
if (this._notNameChars.indexOf(uri[k]) >= 0) {
|
|
1043
|
+
canSplit = false
|
|
1044
|
+
break
|
|
1045
|
+
}
|
|
1046
|
+
}
|
|
1047
|
+
if (canSplit) {
|
|
1048
|
+
var localid = uri.slice(j + 1)
|
|
1049
|
+
var namesp = uri.slice(0, j + 1)
|
|
1050
|
+
var prefix = this.prefixes[namesp]
|
|
1051
|
+
if (!prefix) prefix = this.makeUpPrefix(namesp)
|
|
1052
|
+
if (prefix) {
|
|
1053
|
+
return `"${prefix}": "${namesp}"`
|
|
1054
|
+
}
|
|
1055
|
+
}
|
|
1056
|
+
}
|
|
1057
|
+
}
|
|
1058
|
+
|
|
1059
|
+
function makeRelativeMethod(jsonldString) {
|
|
1060
|
+
if (this.base.includes('#')) throw new Error(`${this.base} must be an URL, it is an URI`)
|
|
1061
|
+
const id = '"@id": "' // find URI
|
|
1062
|
+
const regex = new RegExp(id + this.base, 'g')
|
|
1063
|
+
let result, indices = [];
|
|
1064
|
+
// store indices at begin and end of URI
|
|
1065
|
+
while ( (result = regex.exec(jsonldString)) ) {
|
|
1066
|
+
indices.push(result.index + id.length);
|
|
1067
|
+
indices.push(jsonldString.indexOf('"', result.index + id.length ))
|
|
1068
|
+
}
|
|
1069
|
+
for (let i = indices.length - 2; i >= 0; i = i - 2) {
|
|
1070
|
+
const idUri = jsonldString.substring(indices[i], indices[i + 1])
|
|
1071
|
+
jsonldString = jsonldString.replace(idUri, Uri.refTo(this.base, idUri))
|
|
1072
|
+
}
|
|
1073
|
+
|
|
1074
|
+
return jsonldString
|
|
1075
|
+
}
|
|
1076
|
+
|
|
1077
|
+
const addPrefix = addPrefixMethod.bind(this)
|
|
1078
|
+
const context = contextMethod.bind(this)
|
|
1079
|
+
const makeRelative = makeRelativeMethod.bind(this)
|
|
1080
|
+
|
|
1081
|
+
const n3String = this.statementsToNTriples(sts)
|
|
1082
|
+
let contextObj = JSON.parse(context(n3String))
|
|
1083
|
+
|
|
1084
|
+
return jsonld.fromRDF(n3String, {format: 'application/n-quads'})
|
|
1085
|
+
.then( jsonldObj => { return jsonld.compact(jsonldObj, contextObj) })
|
|
1086
|
+
// TODO collections, compact do not do it on rdf:first rdf:rest
|
|
1087
|
+
.then( jsonldCompactObj => { return JSON.stringify(jsonldCompactObj, null, 2) })
|
|
1088
|
+
.then( jsonldString => { return makeRelative(jsonldString)})
|
|
1089
|
+
.catch( e => { throw e })
|
|
1090
|
+
|
|
1091
|
+
}
|
|
1014
1092
|
}
|
|
1015
1093
|
|
|
1016
1094
|
// String escaping utilities
|
package/src/statement.ts
CHANGED
|
@@ -137,6 +137,13 @@ export default class Statement<
|
|
|
137
137
|
|
|
138
138
|
/** Creates a string representation of this statement */
|
|
139
139
|
toString (): string {
|
|
140
|
+
/*
|
|
141
|
+
return [
|
|
142
|
+
this.subject.toString(),
|
|
143
|
+
this.predicate.toString(),
|
|
144
|
+
this.object.toString(),
|
|
145
|
+
].join(' ') + ' .'
|
|
146
|
+
*/
|
|
140
147
|
return this.toNT()
|
|
141
148
|
}
|
|
142
149
|
}
|
package/src/store.ts
CHANGED
|
@@ -23,12 +23,14 @@ import Formula, { FormulaOpts } from './formula'
|
|
|
23
23
|
import { ArrayIndexOf } from './utils'
|
|
24
24
|
import { RDFArrayRemove } from './utils-js'
|
|
25
25
|
import {
|
|
26
|
+
isRDFlibSubject,
|
|
27
|
+
isRDFlibPredicate,
|
|
26
28
|
isRDFlibObject,
|
|
27
29
|
isStore,
|
|
28
30
|
isGraph,
|
|
29
|
-
isPredicate,
|
|
31
|
+
// isPredicate,
|
|
30
32
|
isQuad,
|
|
31
|
-
isSubject
|
|
33
|
+
// isSubject
|
|
32
34
|
} from './utils/terms'
|
|
33
35
|
import Node from './node'
|
|
34
36
|
import Variable from './variable'
|
|
@@ -429,10 +431,10 @@ export default class IndexedFormula extends Formula { // IN future - allow pass
|
|
|
429
431
|
pred = Node.fromValue(pred)
|
|
430
432
|
const objNode = Node.fromValue(obj) as Term
|
|
431
433
|
why = Node.fromValue(why)
|
|
432
|
-
if (!
|
|
434
|
+
if (!isRDFlibSubject(subj)) {
|
|
433
435
|
throw new Error('Subject is not a subject type')
|
|
434
436
|
}
|
|
435
|
-
if (!
|
|
437
|
+
if (!isRDFlibPredicate(pred)) {
|
|
436
438
|
throw new Error(`Predicate ${pred} is not a predicate type`)
|
|
437
439
|
}
|
|
438
440
|
if (!isRDFlibObject(objNode)) {
|
|
@@ -920,9 +922,7 @@ export default class IndexedFormula extends Formula { // IN future - allow pass
|
|
|
920
922
|
object?: Quad_Object | null,
|
|
921
923
|
graph?: Quad_Graph | null
|
|
922
924
|
): IndexedFormula {
|
|
923
|
-
this.
|
|
924
|
-
this.statementsMatching(subject, predicate, object, graph)
|
|
925
|
-
)
|
|
925
|
+
this.removeMany(subject, predicate, object, graph)
|
|
926
926
|
return this
|
|
927
927
|
}
|
|
928
928
|
|
package/src/update-manager.ts
CHANGED
|
@@ -689,7 +689,7 @@ export default class UpdateManager {
|
|
|
689
689
|
thisUpdater.update(deletions.filter(st => st.why.equals(doc)),
|
|
690
690
|
insertions.filter(st => st.why.equals(doc))))
|
|
691
691
|
if (updates.length > 1) {
|
|
692
|
-
console.log(`@@ updateMany to ${updates.length}: ${uniqueDocs}`)
|
|
692
|
+
// console.log(`@@ updateMany to ${updates.length}: ${uniqueDocs}`)
|
|
693
693
|
}
|
|
694
694
|
return Promise.all(updates)
|
|
695
695
|
}
|
|
@@ -752,7 +752,7 @@ export default class UpdateManager {
|
|
|
752
752
|
// console.log(message)
|
|
753
753
|
throw new Error(message)
|
|
754
754
|
}
|
|
755
|
-
var control = this.patchControlFor(doc)
|
|
755
|
+
var control = this.patchControlFor(doc as NamedNode)
|
|
756
756
|
var startTime = Date.now()
|
|
757
757
|
|
|
758
758
|
var props = ['subject', 'predicate', 'object', 'why']
|
|
@@ -781,7 +781,7 @@ export default class UpdateManager {
|
|
|
781
781
|
throw new Error('Update: Loaded ' + doc + "but stil can't figure out what editing protcol it supports.")
|
|
782
782
|
}
|
|
783
783
|
// console.log(`Update: have not loaded ${doc} before: loading now...`);
|
|
784
|
-
(this.store.fetcher.load(doc) as Promise<Response>).then(response => {
|
|
784
|
+
(this.store.fetcher.load(doc as NamedNode) as Promise<Response>).then(response => {
|
|
785
785
|
this.update(deletions, insertions, callback, true, options)
|
|
786
786
|
}, err => {
|
|
787
787
|
if (err.response.status === 404) { // nonexistent files are fine
|
|
@@ -793,8 +793,13 @@ export default class UpdateManager {
|
|
|
793
793
|
return
|
|
794
794
|
} else if ((protocol as string).indexOf('SPARQL') >= 0) {
|
|
795
795
|
var bnodes: BlankNode[] = []
|
|
796
|
-
|
|
797
|
-
|
|
796
|
+
// change ReadOnly type to Mutable type
|
|
797
|
+
type Mutable<Type> = {
|
|
798
|
+
-readonly [Key in keyof Type]: Type[Key];
|
|
799
|
+
}
|
|
800
|
+
|
|
801
|
+
if (ds.length) bnodes = this.statementArrayBnodes(ds as Mutable<typeof ds>)
|
|
802
|
+
if (is.length) bnodes = bnodes.concat(this.statementArrayBnodes(is as Mutable<typeof is>))
|
|
798
803
|
var context = this.bnodeContext(bnodes, doc)
|
|
799
804
|
var whereClause = this.contextWhere(context)
|
|
800
805
|
var query = ''
|
|
@@ -840,12 +845,13 @@ export default class UpdateManager {
|
|
|
840
845
|
|
|
841
846
|
this.fire(doc.value, query, (uri, success, body, response) => {
|
|
842
847
|
(response as any).elapsedTimeMs = Date.now() - startTime
|
|
843
|
-
console.log(' UpdateManager: Return ' +
|
|
848
|
+
/* console.log(' UpdateManager: Return ' +
|
|
844
849
|
(success ? 'success ' : 'FAILURE ') + (response as Response).status +
|
|
845
850
|
' elapsed ' + (response as any).elapsedTimeMs + 'ms')
|
|
851
|
+
*/
|
|
846
852
|
if (success) {
|
|
847
853
|
try {
|
|
848
|
-
kb.remove(ds)
|
|
854
|
+
kb.remove(ds as Mutable<typeof ds>)
|
|
849
855
|
} catch (e) {
|
|
850
856
|
success = false
|
|
851
857
|
body = 'Remote Ok BUT error deleting ' + ds.length + ' from store!!! ' + e
|
|
@@ -866,11 +872,11 @@ export default class UpdateManager {
|
|
|
866
872
|
}
|
|
867
873
|
}, options)
|
|
868
874
|
} else if ((protocol as string).indexOf('DAV') >= 0) {
|
|
869
|
-
this.updateDav(doc, ds, is, callback, options)
|
|
875
|
+
this.updateDav(doc as NamedNode, ds, is, callback, options)
|
|
870
876
|
} else {
|
|
871
877
|
if ((protocol as string).indexOf('LOCALFILE') >= 0) {
|
|
872
878
|
try {
|
|
873
|
-
this.updateLocalFile(doc, ds, is, callback, options)
|
|
879
|
+
this.updateLocalFile(doc as NamedNode, ds, is, callback, options)
|
|
874
880
|
} catch (e) {
|
|
875
881
|
callback(doc.value, false,
|
|
876
882
|
'Exception trying to write back file <' + doc.value + '>\n'
|
package/src/utils/terms.ts
CHANGED
|
@@ -33,7 +33,7 @@ export function isCollection(obj: any): obj is Collection<any> {
|
|
|
33
33
|
&& (obj as Term).termType === CollectionTermType
|
|
34
34
|
}
|
|
35
35
|
|
|
36
|
-
/** TypeGuard for valid RDFlib Object types, also allows Collections */
|
|
36
|
+
/** TypeGuard for valid RDFlib Object types, also allows Collections, Graphs */
|
|
37
37
|
export function isRDFlibObject(obj: any): obj is ObjectType {
|
|
38
38
|
return obj && Object.prototype.hasOwnProperty.call(obj, 'termType') && (
|
|
39
39
|
obj.termType === NamedNodeTermType ||
|
|
@@ -45,6 +45,28 @@ export function isRDFlibObject(obj: any): obj is ObjectType {
|
|
|
45
45
|
)
|
|
46
46
|
}
|
|
47
47
|
|
|
48
|
+
/** TypeGuard for valid RDFlib Subject types, same as Object as RDFLib symmetrical.
|
|
49
|
+
*/
|
|
50
|
+
export function isRDFlibSubject(obj: any): obj is ObjectType {
|
|
51
|
+
return obj && Object.prototype.hasOwnProperty.call(obj, 'termType') && (
|
|
52
|
+
obj.termType === NamedNodeTermType ||
|
|
53
|
+
obj.termType === VariableTermType ||
|
|
54
|
+
obj.termType === BlankNodeTermType ||
|
|
55
|
+
obj.termType === CollectionTermType ||
|
|
56
|
+
obj.termType === LiteralTermType ||
|
|
57
|
+
obj.termType === GraphTermType
|
|
58
|
+
)
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/** TypeGuard for valid RDF/JS spec Predicate types */
|
|
62
|
+
export function isRDFlibPredicate(obj: any): obj is Quad_Predicate {
|
|
63
|
+
return isTerm(obj) && (
|
|
64
|
+
obj.termType === NamedNodeTermType ||
|
|
65
|
+
obj.termType === BlankNodeTermType ||
|
|
66
|
+
obj.termType === VariableTermType
|
|
67
|
+
)
|
|
68
|
+
}
|
|
69
|
+
|
|
48
70
|
/** TypeGuard for RDFLib Variables */
|
|
49
71
|
export function isVariable(obj: any): obj is Variable {
|
|
50
72
|
return isTerm(obj)
|
package/changes.txt
DELETED
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
REMOVED FILES:
|
|
2
|
-
|
|
3
|
-
plistClosure.js -> no refs to about() or pickOne.
|
|
4
|
-
unify.js -> contained _no_ code !
|
|
5
|
-
remote.js -> remoteQuery ref'd in query.js, but commented out.
|
|
6
|
-
parser.js -> not used anymore.
|
|
7
|
-
|
|
8
|
-
LOGGING:
|
|
9
|
-
|
|
10
|
-
Without assuming that there is a global log var, logging can be weird. What do we do?
|
|
11
|
-
(bring in the log js)
|
|
12
|
-
|
|
13
|
-
ORDERING:
|
|
14
|
-
|
|
15
|
-
util.js - done (util-nonlib.js) - FIGURE OUT AJAR_HandleNew (should be in sources probably..) for now in util class.
|
|
16
|
-
uri.js - done (REMOVED URIjoin, uri_docpart, uri_protocol
|
|
17
|
-
term.js - done..
|
|
18
|
-
rdfparser.js -done..
|
|
19
|
-
n3parser.js -ew, but done.
|
|
20
|
-
identity.js 21k -RDFArrayRemove now in Util.RDFArrayRemove.
|
|
21
|
-
query.js 21k -NEEDS MORE WORK.
|
|
22
|
-
sources.js 37k -ok??
|
|
23
|
-
serialize.js 24k -OK!
|
|
24
|
-
sparqlUpdate.js 8k -ok, seemingly.
|
|
25
|
-
sparql.js 21k -SPARQLtoQuery needs kb in calls to it now.. isbnode: /^[]$/ -> /^$/ NO! Take it back.
|
|
26
|
-
|
|
27
|
-
TODO: Add the minor sources bugfix into sources.js!
|
|
28
|
-
|
|
29
|
-
HANGING GLOBALS:
|
|
30
|
-
|
|
31
|
-
isExtension
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
=========================================================================
|
|
37
|
-
extension code!
|
|
38
|
-
|
|
39
|
-
KILLED GLOBALS:
|
|
40
|
-
string_startswith
|
|
41
|
-
kb
|
|
42
|
-
sf
|
|
43
|
-
qs
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
NAMESPACE GLOBALS DELETED:
|
|
47
|
-
mo
|
|
48
|
-
contact
|
|
49
|
-
xsd
|
|
50
|
-
rss
|
|
51
|
-
dc
|
|
52
|
-
owl
|
|
53
|
-
rdfs
|
|
54
|
-
rdf
|
|
55
|
-
tabont
|
|
56
|
-
foaf
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
WEBDAV.js -- WHERE IS IT NEEDED.
|
package/esm/convert.js
DELETED
|
@@ -1,61 +0,0 @@
|
|
|
1
|
-
import asyncLib from 'async'; // @@ Goal: remove this dependency
|
|
2
|
-
|
|
3
|
-
import jsonld from 'jsonld';
|
|
4
|
-
import { Parser, Writer } from 'n3'; // @@ Goal: remove this dependency
|
|
5
|
-
|
|
6
|
-
export function convertToJson(n3String, jsonCallback) {
|
|
7
|
-
var jsonString;
|
|
8
|
-
var n3Parser = new Parser();
|
|
9
|
-
var n3Writer = new Writer({
|
|
10
|
-
format: 'N-Quads'
|
|
11
|
-
});
|
|
12
|
-
asyncLib.waterfall([function (callback) {
|
|
13
|
-
n3Parser.parse(n3String, function (error, quad, prefixes) {
|
|
14
|
-
if (error) {
|
|
15
|
-
callback(error);
|
|
16
|
-
} else if (quad !== null) {
|
|
17
|
-
n3Writer.addQuad(quad);
|
|
18
|
-
} else {
|
|
19
|
-
n3Writer.end(callback);
|
|
20
|
-
}
|
|
21
|
-
});
|
|
22
|
-
}, function (result, callback) {
|
|
23
|
-
try {
|
|
24
|
-
jsonld.fromRDF(result, {
|
|
25
|
-
format: 'application/nquads'
|
|
26
|
-
}).then(function (result) {
|
|
27
|
-
callback(null, result);
|
|
28
|
-
});
|
|
29
|
-
} catch (err) {
|
|
30
|
-
callback(err);
|
|
31
|
-
}
|
|
32
|
-
}, function (json, callback) {
|
|
33
|
-
jsonString = JSON.stringify(json);
|
|
34
|
-
jsonCallback(null, jsonString);
|
|
35
|
-
}], function (err, result) {
|
|
36
|
-
jsonCallback(err, jsonString);
|
|
37
|
-
});
|
|
38
|
-
}
|
|
39
|
-
export function convertToNQuads(n3String, nquadCallback) {
|
|
40
|
-
var nquadString;
|
|
41
|
-
var n3Parser = new Parser();
|
|
42
|
-
var n3Writer = new Writer({
|
|
43
|
-
format: 'N-Quads'
|
|
44
|
-
});
|
|
45
|
-
asyncLib.waterfall([function (callback) {
|
|
46
|
-
n3Parser.parse(n3String, function (error, triple, prefixes) {
|
|
47
|
-
if (error) {
|
|
48
|
-
callback(error);
|
|
49
|
-
} else if (quad !== null) {
|
|
50
|
-
n3Writer.addQuad(quad);
|
|
51
|
-
} else {
|
|
52
|
-
n3Writer.end(callback);
|
|
53
|
-
}
|
|
54
|
-
});
|
|
55
|
-
}, function (result, callback) {
|
|
56
|
-
nquadString = result;
|
|
57
|
-
nquadCallback(null, nquadString);
|
|
58
|
-
}], function (err, result) {
|
|
59
|
-
nquadCallback(err, nquadString);
|
|
60
|
-
});
|
|
61
|
-
}
|
package/lib/convert.d.ts
DELETED
package/lib/convert.js
DELETED
|
@@ -1,77 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
-
|
|
5
|
-
Object.defineProperty(exports, "__esModule", {
|
|
6
|
-
value: true
|
|
7
|
-
});
|
|
8
|
-
exports.convertToJson = convertToJson;
|
|
9
|
-
exports.convertToNQuads = convertToNQuads;
|
|
10
|
-
|
|
11
|
-
var _async = _interopRequireDefault(require("async"));
|
|
12
|
-
|
|
13
|
-
var _jsonld = _interopRequireDefault(require("jsonld"));
|
|
14
|
-
|
|
15
|
-
var _n = require("n3");
|
|
16
|
-
|
|
17
|
-
// @@ Goal: remove this dependency
|
|
18
|
-
// @@ Goal: remove this dependency
|
|
19
|
-
function convertToJson(n3String, jsonCallback) {
|
|
20
|
-
var jsonString;
|
|
21
|
-
var n3Parser = new _n.Parser();
|
|
22
|
-
var n3Writer = new _n.Writer({
|
|
23
|
-
format: 'N-Quads'
|
|
24
|
-
});
|
|
25
|
-
|
|
26
|
-
_async.default.waterfall([function (callback) {
|
|
27
|
-
n3Parser.parse(n3String, function (error, quad, prefixes) {
|
|
28
|
-
if (error) {
|
|
29
|
-
callback(error);
|
|
30
|
-
} else if (quad !== null) {
|
|
31
|
-
n3Writer.addQuad(quad);
|
|
32
|
-
} else {
|
|
33
|
-
n3Writer.end(callback);
|
|
34
|
-
}
|
|
35
|
-
});
|
|
36
|
-
}, function (result, callback) {
|
|
37
|
-
try {
|
|
38
|
-
_jsonld.default.fromRDF(result, {
|
|
39
|
-
format: 'application/nquads'
|
|
40
|
-
}).then(function (result) {
|
|
41
|
-
callback(null, result);
|
|
42
|
-
});
|
|
43
|
-
} catch (err) {
|
|
44
|
-
callback(err);
|
|
45
|
-
}
|
|
46
|
-
}, function (json, callback) {
|
|
47
|
-
jsonString = JSON.stringify(json);
|
|
48
|
-
jsonCallback(null, jsonString);
|
|
49
|
-
}], function (err, result) {
|
|
50
|
-
jsonCallback(err, jsonString);
|
|
51
|
-
});
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
function convertToNQuads(n3String, nquadCallback) {
|
|
55
|
-
var nquadString;
|
|
56
|
-
var n3Parser = new _n.Parser();
|
|
57
|
-
var n3Writer = new _n.Writer({
|
|
58
|
-
format: 'N-Quads'
|
|
59
|
-
});
|
|
60
|
-
|
|
61
|
-
_async.default.waterfall([function (callback) {
|
|
62
|
-
n3Parser.parse(n3String, function (error, triple, prefixes) {
|
|
63
|
-
if (error) {
|
|
64
|
-
callback(error);
|
|
65
|
-
} else if (quad !== null) {
|
|
66
|
-
n3Writer.addQuad(quad);
|
|
67
|
-
} else {
|
|
68
|
-
n3Writer.end(callback);
|
|
69
|
-
}
|
|
70
|
-
});
|
|
71
|
-
}, function (result, callback) {
|
|
72
|
-
nquadString = result;
|
|
73
|
-
nquadCallback(null, nquadString);
|
|
74
|
-
}], function (err, result) {
|
|
75
|
-
nquadCallback(err, nquadString);
|
|
76
|
-
});
|
|
77
|
-
}
|
package/src/convert.js
DELETED
|
@@ -1,70 +0,0 @@
|
|
|
1
|
-
import asyncLib from 'async' // @@ Goal: remove this dependency
|
|
2
|
-
import jsonld from 'jsonld'
|
|
3
|
-
import { Parser, Writer } from 'n3' // @@ Goal: remove this dependency
|
|
4
|
-
|
|
5
|
-
export function convertToJson (n3String, jsonCallback) {
|
|
6
|
-
var jsonString
|
|
7
|
-
var n3Parser = new Parser()
|
|
8
|
-
var n3Writer = new Writer({
|
|
9
|
-
format: 'N-Quads'
|
|
10
|
-
})
|
|
11
|
-
asyncLib.waterfall([
|
|
12
|
-
function (callback) {
|
|
13
|
-
n3Parser.parse(n3String, function (error, quad, prefixes) {
|
|
14
|
-
if (error) {
|
|
15
|
-
callback(error);
|
|
16
|
-
} else if (quad !== null) {
|
|
17
|
-
n3Writer.addQuad(quad);
|
|
18
|
-
} else {
|
|
19
|
-
n3Writer.end(callback);
|
|
20
|
-
}
|
|
21
|
-
});
|
|
22
|
-
},
|
|
23
|
-
function (result, callback) {
|
|
24
|
-
try {
|
|
25
|
-
jsonld.fromRDF(result, {
|
|
26
|
-
format: 'application/nquads'
|
|
27
|
-
}).then((result) => {
|
|
28
|
-
callback(null, result)
|
|
29
|
-
})
|
|
30
|
-
} catch (err) {
|
|
31
|
-
callback(err)
|
|
32
|
-
}
|
|
33
|
-
},
|
|
34
|
-
function (json, callback) {
|
|
35
|
-
jsonString = JSON.stringify(json)
|
|
36
|
-
jsonCallback(null, jsonString)
|
|
37
|
-
}
|
|
38
|
-
], function (err, result) {
|
|
39
|
-
jsonCallback(err, jsonString)
|
|
40
|
-
}
|
|
41
|
-
)
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
export function convertToNQuads (n3String, nquadCallback) {
|
|
45
|
-
var nquadString
|
|
46
|
-
var n3Parser = new Parser()
|
|
47
|
-
var n3Writer = new Writer({
|
|
48
|
-
format: 'N-Quads'
|
|
49
|
-
})
|
|
50
|
-
asyncLib.waterfall([
|
|
51
|
-
function (callback) {
|
|
52
|
-
n3Parser.parse(n3String, function (error, triple, prefixes) {
|
|
53
|
-
if (error) {
|
|
54
|
-
callback(error);
|
|
55
|
-
} else if (quad !== null) {
|
|
56
|
-
n3Writer.addQuad(quad);
|
|
57
|
-
} else {
|
|
58
|
-
n3Writer.end(callback);
|
|
59
|
-
}
|
|
60
|
-
});
|
|
61
|
-
},
|
|
62
|
-
function (result, callback) {
|
|
63
|
-
nquadString = result
|
|
64
|
-
nquadCallback(null, nquadString)
|
|
65
|
-
}
|
|
66
|
-
], function (err, result) {
|
|
67
|
-
nquadCallback(err, nquadString)
|
|
68
|
-
}
|
|
69
|
-
)
|
|
70
|
-
}
|