我正在尝试使用catalog.rdf
从浏览器解释古腾堡计划的rdflib.js
文件。目前,我能够下载目录的缓存副本,进行解析并match
图书清单。接下来,我尝试全部有关该书的详细信息(书名,作者,主题等)
不幸的是,我的大多数文字值都以[object NodeList]
书籍RDF的示例:
<pgterms:etext rdf:ID="etext27785">
<dc:publisher>&pg;</dc:publisher>
<dc:title rdf:parseType="Literal">A Book About Lawyers</dc:title>
<dc:creator rdf:parseType="Literal">Jeaffreson, John Cordy, 1831-1901</dc:creator>
<pgterms:friendlytitle rdf:parseType="Literal">A Book About Lawyers by John Cordy Jeaffreson</pgterms:friendlytitle>
<dc:language><dcterms:ISO639-2><rdf:value>en</rdf:value></dcterms:ISO639-2></dc:language>
<dc:subject><dcterms:LCSH><rdf:value>Lawyers -- Great Britain -- Anecdotes</rdf:value></dcterms:LCSH></dc:subject>
<dc:subject><dcterms:LCC><rdf:value>KD</rdf:value></dcterms:LCC></dc:subject>
<dc:created><dcterms:W3CDTF><rdf:value>2009-01-12</rdf:value></dcterms:W3CDTF></dc:created>
<pgterms:downloads><xsd:nonNegativeInteger><rdf:value>20</rdf:value></xsd:nonNegativeInteger></pgterms:downloads>
<dc:rights rdf:resource="&lic;" />
</pgterms:etext>
用于解析的代码示例:
let store = $rdf.graph();
$rdf.parse(stm,store,baseUrl,'application/rdf+xml');
let books = store.match(undefined, types.RDF('type') , types.PGb('etext')).map(t=>t.subject);
let lib = books.map(b=>{
let props = store.match(b, null, undefined);
console.debug("Book: " + schema['_id']);
props.forEach(a=>{
console.debug(a);
});
});
这将导致返回所有三元组,但是object
部分通常是尝试序列化NodeList。例如,“ title”谓词:
{
"subject": {
"termType": "NamedNode",
"value": "http://www.gutenberg.org/feeds/catalog.rdf#etext14600"
},
"predicate": {
"termType": "NamedNode",
"value": "http://purl.org/dc/elements/1.1/title"
},
"object": {
"termType": "Literal",
"value": "[object NodeList]",
"datatype": {
"termType": "NamedNode",
"value": "http://www.w3.org/1999/02/22-rdf-syntax-ns#XMLLiteral"
}
},
"why": {
"termType": "NamedNode",
"value": "https://example.com/datasets/gutenberg/catalog.rdf.gz"
}
}
如何从RDF查询中获取文字对象的实际值?
如果那样的话,我也会对其他RDF JS库或其他查询机制(例如SPARQL)开放。
答案 0 :(得分:0)
此行为是库中缺陷的直接结果。
带有parseType='Literal'
的RDF + XML节点始终在浏览器中产生"[ojbect NodeList]"
。