rdflib 2.2.22-2cea0982 → 2.2.22-2f49e8ef

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.
@@ -22,7 +22,7 @@ export function jsonldObjectToTerm (kb, obj) {
22
22
  }
23
23
 
24
24
  if (Object.prototype.hasOwnProperty.call(obj, '@id')) {
25
- return nodeType(kb, obj)
25
+ return kb.rdfFactory.namedNode(obj['@id'])
26
26
  }
27
27
 
28
28
  if (Object.prototype.hasOwnProperty.call(obj, '@language')) {
@@ -44,7 +44,7 @@ export function jsonldObjectToTerm (kb, obj) {
44
44
  * Adds the statements in a json-ld list object to {kb}.
45
45
  */
46
46
  function listToStatements (kb, obj) {
47
- const listId = obj['@id'] ? nodeType(kb, obj) : kb.rdfFactory.blankNode()
47
+ const listId = obj['@id'] ? kb.rdfFactory.namedNode(obj['@id']) : kb.rdfFactory.blankNode()
48
48
 
49
49
  const items = obj['@list'].map((listItem => jsonldObjectToTerm(kb, listItem)))
50
50
  const statements = arrayToStatements(kb.rdfFactory, listId, items)
@@ -82,19 +82,10 @@ export default function jsonldParser (str, kb, base, callback) {
82
82
  .catch(callback)
83
83
  }
84
84
 
85
- function nodeType (kb, obj) {
86
- if (obj['@id'].startsWith('_:')) {
87
- // This object is a Blank Node. Pass the id without the `_:` prefix
88
- return kb.rdfFactory.blankNode(obj['@id'].substring(2));
89
- } else {
90
- // This object is a Named Node
91
- return kb.rdfFactory.namedNode(obj['@id']);
92
- }
93
- }
94
85
 
95
86
  function processResource(kb, base, flatResource) {
96
87
  const id = flatResource['@id']
97
- ? nodeType(kb, flatResource)
88
+ ? kb.rdfFactory.namedNode(flatResource['@id'])
98
89
  : kb.rdfFactory.blankNode()
99
90
 
100
91
  for (const property of Object.keys(flatResource)) {
@@ -145,4 +136,4 @@ function createStatement(kb, id, property, value, base) {
145
136
  object = jsonldObjectToTerm(kb, value)
146
137
  }
147
138
  return kb.rdfFactory.quad(id, predicate, object, kb.rdfFactory.namedNode(base))
148
- }
139
+ }
package/src/serialize.ts CHANGED
@@ -1,3 +1,4 @@
1
+ import * as convert from './convert'
1
2
  import Formula from './formula'
2
3
  import Serializer from './serializer'
3
4
  import {
@@ -41,7 +42,7 @@ export default function serialize (
41
42
  */
42
43
  namespaces?: Record<string, string>
43
44
  }
44
- ): string | undefined | Promise<string> {
45
+ ): string | undefined {
45
46
  base = base || target?.value
46
47
  const opts = options || {}
47
48
  contentType = contentType || TurtleContentType // text/n3 if complex?
@@ -50,6 +51,7 @@ export default function serialize (
50
51
  var sz = Serializer(kb)
51
52
  if ((opts as any).flags) sz.setFlags((opts as any).flags)
52
53
  var newSts = kb!.statementsMatching(undefined, undefined, undefined, target as NamedNode)
54
+ var n3String: string
53
55
 
54
56
  // If an IndexedFormula, use the namespaces from the given graph as suggestions
55
57
  if ('namespaces' in kb) {
@@ -80,14 +82,19 @@ export default function serialize (
80
82
  documentString = sz.statementsToNTriples(newSts)
81
83
  return executeCallback(null, documentString)
82
84
  case JSONLDContentType:
83
- sz.setFlags('si') // use turtle parameters
84
- documentString = sz.statementsToJsonld(newSts) // convert via turtle
85
- return executeCallback(null, documentString)
85
+ sz.setFlags('deinprstux') // Use adapters to connect to incmpatible parser
86
+ n3String = sz.statementsToNTriples(newSts)
87
+ // n3String = sz.statementsToN3(newSts)
88
+ convert.convertToJson(n3String, callback)
89
+ break
86
90
  case NQuadsContentType:
87
91
  case NQuadsAltContentType: // @@@ just outpout the quads? Does not work for collections
88
92
  sz.setFlags('deinprstux q') // Suppress nice parts of N3 to make ntriples
89
93
  documentString = sz.statementsToNTriples(newSts) // q in flag means actually quads
90
94
  return executeCallback(null, documentString)
95
+ // n3String = sz.statementsToN3(newSts)
96
+ // documentString = convert.convertToNQuads(n3String, callback)
97
+ // break
91
98
  default:
92
99
  throw new Error('Serialize: Content-type ' + contentType + ' not supported for data write.')
93
100
  }
package/src/serializer.js CHANGED
@@ -12,8 +12,6 @@ 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'
17
15
 
18
16
 
19
17
  export default function createSerializer(store) {
@@ -1013,28 +1011,6 @@ export class Serializer {
1013
1011
  var tree2 = [str, tree, '</rdf:RDF>'] // @@ namespace declrations
1014
1012
  return XMLtreeToString(tree2, -1)
1015
1013
  } // 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
-
1038
1014
  }
1039
1015
 
1040
1016
  // String escaping utilities