Skip to content
This repository was archived by the owner on May 21, 2019. It is now read-only.

Update jsonld to 1.0.2 #9

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,14 @@ sudo: false
language: node_js
node_js:
- "6"
cache:
directories:
- node_modules
addons:
apt:
sources:
- ubuntu-toolchain-r-test
packages:
- g++-4.9
install:
- CC=gcc-4.9 CXX=g++-4.9 npm install
46 changes: 21 additions & 25 deletions lib/ParserStream.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
const concat = require('concat-stream')
const jsonld = require('jsonld')
const rdf = require('rdf-data-model')
const Readable = require('readable-stream')
const rdf = require('@rdfjs/data-model')
const RdfTerms = require('rdf-terms')

class ParserStream extends Readable {
constructor (input, options) {
Expand Down Expand Up @@ -38,20 +39,21 @@ class ParserStream extends Readable {
})
}

term (options) {
if (options.type === 'IRI') {
return this.factory.namedNode(options.value)
/**
* Function rewrite with term.termType.
* This is done to fix issue #243, see https://github.com/digitalbazaar/jsonld.js/issues/243 .
* **/
term (term) {
switch (term.termType) {
case 'NamedNode':
return this.factory.namedNode(term.value)
case 'BlankNode':
return this.factory.blankNode(term.value.substr(2)) // Remove the '_:' prefix. see https://github.com/digitalbazaar/jsonld.js/issues/244
case 'Literal':
return this.factory.literal(term.value, term.language || term.datatype)
case 'DefaultGraph':
return this.factory.defaultGraph()
}

if (options.type === 'blank node') {
if (!(options.value in this.blankNodes)) {
this.blankNodes[options.value] = this.factory.blankNode()
}

return this.blankNodes[options.value]
}

return this.factory.literal(options.value, options.language || options.datatype)
}

parse (data) {
Expand All @@ -72,17 +74,11 @@ class ParserStream extends Readable {

return jsonld.promises().toRDF(json, toRdfOptions)
}).then((rawGraph) => {
Object.keys(rawGraph).forEach((graphIri) => {
const graph = graphIri !== '@default' ? this.factory.namedNode(graphIri) : null

rawGraph[graphIri].forEach((triple) => {
this.push(this.factory.quad(
this.term(triple.subject),
this.term(triple.predicate),
this.term(triple.object),
graph))
})
})
for (let index in rawGraph) {
this.push(RdfTerms.mapTerms(rawGraph[index], (value) => this.term(value), this.factory))
}
}).catch((error) => {
this.emit('error', error)
})
}

Expand Down
Loading