-
Notifications
You must be signed in to change notification settings - Fork 8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Clarify need to define baseIRI #46
Comments
This document requires a I'll leave this issue open as a note to myself to document this better, as this not clear enough. |
Hi Ruben - yeah, that was the problem alright. Setting the Unfortunately, now the issue I have is that I was instantiating my RDF/XML parser just once and registering it in an RDF/JS SinkMap of parsers for processing multiple resources. I can't do that anymore, because I now need to instantiate just the RDF/XML parser on every resource I parse, just in case that resource is RDF/XML, and might need a My workaround code below works now, but just the RDF/XML parser is making it kinda ugly :( ! Would it be valid to have the parser default the const rdf = require("rdf-ext");
const rdfFetch = require("@rdfjs/fetch-lite");
const rdfFormats = require("@rdfjs/formats-common");
const ParserN3 = require("@rdfjs/parser-n3");
const ParserJsonld = require("@rdfjs/parser-jsonld");
const ParserRdfXml = require("rdfxml-streaming-parser").RdfXmlParser;
const SinkMap = require("@rdfjs/sink-map");
const formats = {
parsers: new SinkMap([
["text/turtle", new ParserN3()],
["application/ld+json", new ParserJsonld()],
// NO POINT DOING THIS ANYMORE - SINCE I'LL HAVE TO CONSTRUCT
// AN INSTANCE PER RESOURCE TO ALLOW ME SET THE `baseIRI`!
// ["application/rdf+xml", new ParserRdfXml()]
]),
};
function parseResource(resource) {
// I NEED TO CONSTRUCT JUST THE RDF/XML PARSER PER RESOURCE,
// JUST TO SET THE `baseIRI`, EVEN THOUGH THE RESOURCE COULD
// BE Turtle OR JSON-LD - D'OH!
formats.parsers.set(
"application/rdf+xml",
new ParserRdfXml({ baseIRI: resource })
);
rdfFetch(resource, { factory: rdf, formats })
.then((resource) => {
return resource.dataset();
})
.then((dataset) => {
console.log(`Parsed [${dataset.size}] triples from resource [${resource}]...`);
});
}
const resources = [ "http://www.w3.org/2002/01/bookmark#", "http://www.w3.org/1999/02/22-rdf-syntax-ns#" ];
resources.map((resource) => { parseResource(resource) }); |
@pmcb55 I'm not very familiar with the I typically re-create parsers upon every request (they are very lightweight anyways). This is abstracted in
|
Well, I don't think you (or I) need to know how This seems like acceptable generic behaviour for a parser (although I would say that any vocabulary setting the 'baseIRI' to 'nothing' (i.e. the empty string) is kinda weird, but that's the weird and wonderful world of the InterWeb I suppose). This difference in parser behaviour is why (I assume) EasyRDF has no problem parsing this Bookmark vocab, whereas your parser blows up on it (see screenshot). |
You're right, but this is what is parser is already doing (as specified by the RDF/XML spec, which this parser complies to). This is because the parser only receives a string stream as input, while libraries such as For example, the following playground uses |
Hi,
This error might be related to issue: #20, but it's super-easy to reproduce when attempting to parse the W3C Bookmark vocabulary here.
To reproduce the error, simply save the trivial JavaScript below as
index.js
and then execute:Index.js:
I see the following error:
I'm using RdfXmlParser in a generic vocab processing library, which parses a user-configurable list of vocabularies, so configuring RdfXmlParser just to specifically handle this particular vocabulary wouldn't be pretty (i.e., the out-of-box RdfXmlParser has worked fine for any RDF/XML vocabs I've encountered so far, so getting it to work with http://www.w3.org/2002/01/bookmark# without changing anything would be really good!).
BTW, I assume http://www.w3.org/2002/01/bookmark# is a valid RDF/XML vocab (I refuse to even try to grok RDF/XML!), as EasyRDF converts that URL to Turtle without any complaint. (So my workaround right now is to copy that converted Turtle to a local file, and configure my tool to parse that local Turtle instead of the official RDF/XML served up from http://www.w3.org/2002/01/bookmark# :( !)
The text was updated successfully, but these errors were encountered: