Node.js 使用nodejs解析结构化JSON-LD文件时出现问题
我尝试使用库解析带有Nodejs的JSON-LD文件 该文件是一个结构化的JSON-LD,因此我感兴趣的所有元素都位于Node.js 使用nodejs解析结构化JSON-LD文件时出现问题,node.js,semantic-web,json-ld,Node.js,Semantic Web,Json Ld,我尝试使用库解析带有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#", (...) }, "@grap
@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": ""
}
}
谢谢你的帮助!
Thierry您正在使用的JsonLd流解析程序库似乎只将JsonLd转换为RDF三元组(有关详细信息,请参阅) 我想你想从你的描述中得到的是一个JsonLd图的例子。您可以使用标准来实现这一点 在您的情况下,框架应尽可能简单
{
"@context": {
"@vocab": "https://www.datatourisme.gouv.fr/ontology/core#",
"schema": "http://schema.org/",
"bd": "http://www.bigdata.com/rdf#",
(...)
},
"@id": "https://data.datatourisme.gouv.fr/3/06a7f439-3e02-3aa2-8301-f850bb5b792f"
}
这将为您提供compact JsonLd中第一项的属性。如果图形中有多个项,则可以将
@id
更改为@type
,并返回与特定类型匹配的所有项。您使用的JsonLd流解析程序库似乎只将JsonLd转换为RDF三元组(有关详细信息,请参阅)
我想你想从你的描述中得到的是一个JsonLd图的例子。您可以使用标准来实现这一点
在您的情况下,框架应尽可能简单
{
"@context": {
"@vocab": "https://www.datatourisme.gouv.fr/ontology/core#",
"schema": "http://schema.org/",
"bd": "http://www.bigdata.com/rdf#",
(...)
},
"@id": "https://data.datatourisme.gouv.fr/3/06a7f439-3e02-3aa2-8301-f850bb5b792f"
}
这将为您提供compact JsonLd中第一项的属性。如果图形中有多个项目,您可以将
@id
更改为@type
,并返回与特定类型匹配的所有项目。您所说的综合内容
是什么意思?我指的是文件中元素的所有字段。例如:标签、类型、日期。。。谢谢你的留言!您所说的综合内容是什么意思?我指的是文件中元素的所有字段。例如:标签、类型、日期。。。谢谢你的留言!