简体   繁体   中英

Loading resources with FileManager doesn't work in Jena 2.10.1

The following code works in Jena 2.10.0 but fails in Jena 2.10.1:

model = FileManager.get().loadModel(uri, base, "RDF/XML");

The stack trace is:

com.hp.hpl.jena.n3.turtle.ParserTurtle.parse(ParserTurtle.java:67), 
com.hp.hpl.jena.n3.turtle.TurtleReader.readWorker(TurtleReader.java:33), 
com.hp.hpl.jena.n3.JenaReaderBase.readImpl(JenaReaderBase.java:116), 
com.hp.hpl.jena.n3.JenaReaderBase.read(JenaReaderBase.java:81), 
com.hp.hpl.jena.rdf.model.impl.ModelCom.read(ModelCom.java:274), 
com.hp.hpl.jena.util.LocationMapper.initFromPath(LocationMapper.java:158), 
com.hp.hpl.jena.util.LocationMapper.get(LocationMapper.java:71), 
com.hp.hpl.jena.util.FileManager.makeGlobal(FileManager.java:122), 
com.hp.hpl.jena.util.FileManager.get(FileManager.java:88), 
...

From what I can debug, there is a NPE in the initialization of the ParserTurtle class, in some static block. However the exact location does not appear in the stack trace and I can't reproduce it by initializing this class myself.

A fix would be best, but I'd be grateful for any hint on how I can use FileManager in Jena 2.10.1. I need FileManager to load the location-mapping.n3 file.

Piotr


This is related to https://stackoverflow.com/questions/16196069/jena-filemanager-readmodel-cannot-find-file (I'd comment on it but I don't have enough reputation)

After further debugging it turned out that the actual code that worked in 2.10.0 but not in 2.10.1 was related to initializing the LocationMapper, see http://issues.apache.org/jira/browse/JENA-505 . There I attached a minimal example that demonstrates the problem.

The actual error is only signalled by a warning message:

2013.08.09 14:21:00 [main] LocationMapper WARN: Error in configuration file: null

but if you try to later load a file that was mapped in the location mapper, you are likely to a get an error similar to

com.hp.hpl.jena.shared.NotFoundException: Not found: (...)

which is why I related this issue to 16196069.

I solved it by loading an IRI instead of an URI. Examples below:

IRI iri = IRI.create(this.getClass().getResource("/dataset_rdf.owl"));
Model model = FileManager.get().loadModel(iri.getFragment());

using this maven dependency:

<!-- https://mvnrepository.com/artifact/net.sourceforge.owlapi/owlapi-apibinding -->
        <dependency>
            <groupId>net.sourceforge.owlapi</groupId>
            <artifactId>owlapi-apibinding</artifactId>
            <version>3.4</version>
        </dependency>

I hope it helps

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM