You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@jena.apache.org by Alison Callahan <al...@gmail.com> on 2011/10/11 22:37:21 UTC

loading an OWL ontology that imports N3

Hello all,

I am using the Jena API version 2.6.4, in Ubuntu 11.04.

I am trying to load an OWL ontology that imports other N3 files. Here
is the method I have written to do this:

public static OntModel loadModelWithImports(String file, String uri,
String lang) {
	Model baseModel = ModelFactory.createDefaultModel(ReificationStyle.Minimal);
	InputStream input = FileManager.get().open(file);
	baseModel.read(input, uri, lang);
	return ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM, baseModel);
}

I call the method as follows:

OntModel infModel =
ModelLoader.loadModelWithImports("/home/ontologies/my_ontology.n3",
null, "N3");

When I try to use this method, however, I get errors such as the
following, for each file imported in my_ontology.n3 :

*****************************************

ERROR [main] (RDFDefaultErrorHandler.java:44) -
http://localhost/tmp/repress.n3(line 1 column 1): Content is not
allowed in prolog.
 WARN [main] (OntDocumentManager.java:1078) - An error occurred while
attempting to read from http://localhost/tmp/import.n3. Msg was
'org.xml.sax.SAXParseException; systemId:
http://localhost/tmp/import.n3; lineNumber: 1; columnNumber: 1;
Content is not allowed in prolog.'.
com.hp.hpl.jena.shared.JenaException: org.xml.sax.SAXParseException;
systemId: http://localhost/tmp/import.n3; lineNumber: 1; columnNumber:
1; Content is not allowed in prolog.
	at com.hp.hpl.jena.rdf.model.impl.RDFDefaultErrorHandler.fatalError(RDFDefaultErrorHandler.java:45)
	at com.hp.hpl.jena.rdf.arp.impl.ARPSaxErrorHandler.fatalError(ARPSaxErrorHandler.java:35)
	at com.hp.hpl.jena.rdf.arp.impl.XMLHandler.warning(XMLHandler.java:225)
	at com.hp.hpl.jena.rdf.arp.impl.XMLHandler.fatalError(XMLHandler.java:255)
	at org.apache.xerces.util.ErrorHandlerWrapper.fatalError(Unknown Source)
	at org.apache.xerces.impl.XMLErrorReporter.reportError(Unknown Source)
	at org.apache.xerces.impl.XMLErrorReporter.reportError(Unknown Source)
	at org.apache.xerces.impl.XMLScanner.reportFatalError(Unknown Source)
	at org.apache.xerces.impl.XMLDocumentScannerImpl$PrologDispatcher.dispatch(Unknown
Source)
	at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unknown
Source)
	at org.apache.xerces.parsers.DTDConfiguration.parse(Unknown Source)
	at org.apache.xerces.parsers.DTDConfiguration.parse(Unknown Source)
	at org.apache.xerces.parsers.XMLParser.parse(Unknown Source)
	at org.apache.xerces.parsers.AbstractSAXParser.parse(Unknown Source)
	at com.hp.hpl.jena.rdf.arp.impl.RDFXMLParser.parse(RDFXMLParser.java:142)
	at com.hp.hpl.jena.rdf.arp.JenaReader.read(JenaReader.java:158)
	at com.hp.hpl.jena.rdf.arp.JenaReader.read(JenaReader.java:145)
	at com.hp.hpl.jena.rdf.arp.JenaReader.read(JenaReader.java:215)
	at com.hp.hpl.jena.rdf.arp.JenaReader.read(JenaReader.java:84)
	at com.hp.hpl.jena.rdf.model.impl.ModelCom.read(ModelCom.java:187)
	at com.hp.hpl.jena.util.FileManager.readModelWorker(FileManager.java:367)
	at com.hp.hpl.jena.util.FileManager.readModel(FileManager.java:335)
	at com.hp.hpl.jena.util.FileManager.readModel(FileManager.java:319)
	at com.hp.hpl.jena.ontology.OntDocumentManager.read(OntDocumentManager.java:1064)
	at com.hp.hpl.jena.ontology.OntDocumentManager$1.readModel(OntDocumentManager.java:1034)
	at com.hp.hpl.jena.rdf.model.impl.ModelMakerImpl.getModel(ModelMakerImpl.java:78)
	at com.hp.hpl.jena.ontology.OntDocumentManager.fetchLoadedImportModel(OntDocumentManager.java:1031)
	at com.hp.hpl.jena.ontology.OntDocumentManager.fetchPossiblyCachedImportModel(OntDocumentManager.java:1004)
	at com.hp.hpl.jena.ontology.OntDocumentManager.loadImport(OntDocumentManager.java:977)
	at com.hp.hpl.jena.ontology.OntDocumentManager.loadImports(OntDocumentManager.java:771)
	at com.hp.hpl.jena.ontology.OntDocumentManager.loadImports(OntDocumentManager.java:709)
	at com.hp.hpl.jena.ontology.impl.OntModelImpl.loadImports(OntModelImpl.java:1887)
	at com.hp.hpl.jena.ontology.impl.OntModelImpl.<init>(OntModelImpl.java:148)
	at com.hp.hpl.jena.ontology.impl.OntModelImpl.<init>(OntModelImpl.java:120)
	at com.hp.hpl.jena.rdf.model.ModelFactory.createOntologyModel(ModelFactory.java:402)
	at org.semanticscience.hyque.model.ModelLoader.loadModelWithImports(ModelLoader.java:31)
	at org.semanticscience.hyque.SpinInferenceRunnerTest.testOne(SpinInferenceRunnerTest.java:21)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:616)
	at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44)
	at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
	at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41)
	at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
	at org.junit.runners.BlockJUnit4ClassRunner.runNotIgnored(BlockJUnit4ClassRunner.java:79)
	at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:71)
	at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:49)
	at org.junit.runners.ParentRunner$3.run(ParentRunner.java:193)
	at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:52)
	at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:191)
	at org.junit.runners.ParentRunner.access$000(ParentRunner.java:42)
	at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:184)
	at org.junit.runners.ParentRunner.run(ParentRunner.java:236)
	at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:49)
	at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
Caused by: org.xml.sax.SAXParseException; systemId:
http://localhost/tmp/import.n3; lineNumber: 1; columnNumber: 1;
Content is not allowed in prolog.
	at org.apache.xerces.util.ErrorHandlerWrapper.createSAXParseException(Unknown
Source)
	... 56 more

*****************************************

This makes me think that Jena is expecting the imported files to be in
RDF/XML format. Is there any way I can specify otherwise? I had
thought that passing "N3" as the language when calling the
loadModelWithImports() method would be all that was needed, but it
seems not.

Any help is appreciated! Thanks,

Alison

Re: loading an OWL ontology that imports N3

Posted by Dave Reynolds <da...@gmail.com>.
[Sorry to be slow to respond, missed this one.]

On Tue, 2011-10-11 at 16:37 -0400, Alison Callahan wrote: 
> Hello all,
> 
> I am using the Jena API version 2.6.4, in Ubuntu 11.04.
> 
> I am trying to load an OWL ontology that imports other N3 files. Here
> is the method I have written to do this:
> 
> public static OntModel loadModelWithImports(String file, String uri,
> String lang) {
> 	Model baseModel = ModelFactory.createDefaultModel(ReificationStyle.Minimal);
> 	InputStream input = FileManager.get().open(file);
> 	baseModel.read(input, uri, lang);
> 	return ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM, baseModel);
> }
> 
> I call the method as follows:
> 
> OntModel infModel =
> ModelLoader.loadModelWithImports("/home/ontologies/my_ontology.n3",
> null, "N3");
> 
> When I try to use this method, however, I get errors such as the
> following, for each file imported in my_ontology.n3 :

[snip]

> This makes me think that Jena is expecting the imported files to be in
> RDF/XML format. Is there any way I can specify otherwise? I had
> thought that passing "N3" as the language when calling the
> loadModelWithImports() method would be all that was needed, but it
> seems not.

No, there's no reason an imported ontology will be in the same syntax as
the importing one. Typically one imports ontologies from across the web.

In your case you seem to be loading from:
      http://localhost/tmp/import.n3
is that right?

Does whatever web server you have running on localhost respond with the
right Mime type?

In the worst case you might have to explicitly load the import yourself
and use OntDocumentModel.addModel to register it, but that shouldn't
normally be needed.

Dave