Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
end: function () {
jsonld.fromRDF(triples, { format: true, useNativeTypes: true, rdfParser:
// Converts the N3.js library triple representation to the JSON-LD library representation
function fromN3Representation(triples) {
return { '@default': triples.map(function (triple) {
var subject = triple.subject, predicate = triple.predicate, object = triple.object;
return {
subject: { value: subject, type: getTypeName(object) },
predicate: { value: predicate, type: getTypeName(object) },
object: !N3Util.isLiteral(object) ? { value: object, type: getTypeName(object) }
: { value: N3Util.getLiteralValue(object),
datatype: N3Util.getLiteralType(object),
language: N3Util.getLiteralLanguage(object) }
};
})};
}},
function (error, json) {
jsonld.compact(error ? {} : json, context, function (err, compacted) {
done: function(errors, window) {
if(errors && errors.length > 0) {
return callback({
message: 'DOM Errors:',
errors: errors,
url: loc
});
}
try {
// extract JSON-LD from RDFa
RDFa.attach(window.document);
jsonld.fromRDF(window.document.data,
{format: 'rdfa-api'}, callback);
} catch(ex) {
// FIXME: expose RDFa/jsonld ex?
callback({
message: 'RDFa extraction error.',
contentType: type,
url: loc
});
}
}
});
nodes[result[0].toString()] = true;
resultGraph.add(reportNode, T("sh:result"), result[0]);
}
resultGraph.add(result[0], result[1], result[2]);
}
// Unsupported bug in JSON parser bug workaround
var oldToString = resultGraph.toString;
resultGraph.toString = function () {
var text = oldToString.call(resultGraph);
text = text.replace(/^\{/, "").replace(/\}$/, "");
return text;
};
//////////////////
jsonld.fromRDF(resultGraph.toNT(), {}, function (err, doc) {
if (err != null) {
cb(err);
} else {
jsonld.flatten(doc, function (err, result) {
if (err != null) {
cb(err);
} else {
cb(null, new ValidationReport(result));
}
});
}
});
}
};
label: 'rdfs:label',
altLabel: 'skos:altLabel',
status: 'vs:term_status',
subPropertyOf: {
'@id': 'rdfs:subPropertyOf',
'@type': '@id'
},
source: {
'@id': 'dc:source',
'@type': '@id'
},
defines: { '@reverse': 'rdfs:isDefinedBy' }
}
};
jsonld.fromRDF(
'http://schema.org/docs/schema_org_rdfa.html',
{ format: 'text/html' },
function(err, data) {
if (err) throw err;
jsonld.compact(data, context, function(err, data) {
if (err) throw err;
fs.writeFile(
path.resolve(path.dirname(__dirname), 'src', 'schema_org.json'),
JSON.stringify(data, null, 2),
function(err) {
if (err) throw err;
// grab schema.org context
request.get(
{
url: 'http://schema.org',
return new Promise((resolve, reject) => {
jsonld.fromRDF(ntdata, { format: 'application/nquads' }, (error, ntdoc) => {
if (error) {
reject(error)
}
// We need to add a class to the work 'in focus', in case there are other works
// in the graph (for example work as subject of work), and use this class
// for framing.
//
// We also delete the class migration:Work, as it trips up the framing.
ntdoc = ntdoc.map(el => {
if (el[ '@type' ] && el[ '@type' ].includes('http://data.deichman.no/ontology#Work') && el[ '@id' ] === `http://data.deichman.no/work/${workId}`) {
el[ '@type' ].push('http://data.deichman.no/ontology#WorkInFocus')
}
if (el[ '@type' ]) {
const i = el[ '@type' ].indexOf('http://migration.deichman.no/Work')
if (i !== -1) {
* fromRDF() test
*/
jsonld.fromRDF(docNQuads, (err, res) => {
log(res);
});
jsonld.fromRDF(docNQuads, {format: 'application/n-quads'}, (err, res) => {
log(res);
});
jsonld.fromRDF(docRDF)
.then((res) => {
log(res);
});
jsonld.fromRDF(docRDF, {useRdfType: false})
.then((res) => {
log(res);
});
/**
* toRDF() test
*/
jsonld.toRDF(doc, (err, res) => {
log(res);
});
jsonld.toRDF(doc, {format: 'application/n-quads'}, (err, res) => {
log(res);
});
jsonld.toRDF(doc)
writer.end(function (error, output) {
if (error) {
console.error("Problem: " + error);
} else {
if (format !== "json") {
console.log(output);
} else {
jsonld.fromRDF(output, {format: 'application/nquads'}, function(err, doc) {
jsonld.compact(doc, context, function(err, compacted) {
var jsonresult = JSON.stringify(compacted);
//ugly fix for https://github.com/iRail/stations/issues/8
jsonresult = jsonresult.replace(/"alternative":({.*?})/gi,"\"alternative\":[$1]");
console.log(jsonresult);
});
});
}
}
});
});
.then(response => jsonld.fromRDF(makeNQuad(response), studioData))
.then(json => jsonld.frame(json, studioFrame, { embed: '@always' }))
end: function () {
jsonld.fromRDF(quads, { format: false, useNativeTypes: true },
function (error, json) {
jsonld.compact(error ? {} : json, context, function (error, compacted) {
response.write(JSON.stringify(compacted, null, ' ') + '\n');
done(error);
});
});
},
};
rawFile.onreadystatechange = function()
{
if(rawFile.readyState === 4)
{
if(rawFile.status === 200 || rawFile.status == 0)
{
var allText = rawFile.responseText;
jsonLD.fromRDF(allText,{format:'application/trig'},function(err,doc){
$log.debug(doc);
});
}
}
}
}