I am attempting to parse a Project Gutenberg catalog.rdf
for an in browser eReader. Therefore rdflib.js
My initial idea was to use SPARQL queries to extract the data, however, I can’t seem to get rdflib.js
to execute the queries and return results (assuming I just don’t know how to wire them up).
Following the tutorials I seem to have figured out the basic use of the match routines, and have managed to get a list of the books in the catalogue. Unfortunately, when I then attempt to get the corresponding properties (title and author) they are coming back as [object NodeList]
Extremely stripped down example of book RDF:
<pgterms:etext rdf:ID="etext27785">
<dc:title rdf:parseType="Literal">A Book About Lawyers</dc:title>
</pgterms:etext>
My code:
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);
});
});
Resulting triple (note object.value
is "[object NodeList]"
):
{
"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"
}
}
Am I using the library incorrectly?