【发布时间】:2019-09-24 07:32:22
【问题描述】:
我尝试使用 jsonld-streaming-parser.js 库通过 Nodejs 解析 JSON-LD 文件。
该文件是结构化的 JSON-LD,因此我感兴趣的所有元素都位于 @graph 的根目录下:
{
"@context": {
"@vocab": "https://www.datatourisme.gouv.fr/ontology/core#",
"schema": "http://schema.org/",
"bd": "http://www.bigdata.com/rdf#",
(...)
},
"@graph": [{
"@id": "https://data.datatourisme.gouv.fr/3/06a7f439-3e02-3aa2-8301-f850bb5b792f",
"dc:date": [{
"@value": "2013-10-30",
"@type": "xsd:date"
},{
"@value": "2019-08-30",
"@type": "xsd:date"
}],
"dc:identifier": "eudonet:52945",
"@type": ["schema:Landform","NaturalHeritage","PlaceOfInterest","PointOfInterest","urn:resource"],
"rdfs:label": {
"@value": "L'arbre du Pied Cornier",
"@language": "fr"
},
(...)
}]
}
我可以使用以下代码解析文件:
const JsonLdParser = require('jsonld-streaming-parser').JsonLdParser;
const parser = new JsonLdParser();
const getStream = () => {
const jsonData = 'flux-5339-201909240851.partial.jsonld';
const stream = fs.createReadStream(jsonData, {encoding: 'utf8'});
return stream.pipe(parser);
};
getStream()
.on('data', (data) => {
console.log('data = ', data);
})
.on('error', () => {
console.error(error);
})
.on('end', () => {
console.log('All triples were parsed!');
});
我希望在data 回调中包含一个元素的全面内容,但得到了这个:
{
"subject": {
"value": "https://data.datatourisme.gouv.fr/3/06a7f439-3e02-3aa2-8301-f850bb5b792f"
},
"predicate": {
"value": "http://purl.org/dc/elements/1.1/date"
},
"object": {
"value": "2013-10-30",
"datatype": {
"value": "http://www.w3.org/2001/XMLSchema#date"
},
"language": ""
},
"graph": {
"value": ""
}
}
感谢您的帮助! 蒂埃里
【问题讨论】:
-
comprehensive content是什么意思? -
我的意思是我在文件中的所有元素字段。例如:标签、类型、日期……感谢您的留言!
标签: node.js semantic-web json-ld