我們有一個使用OWLAPI解析本體的包裝器。OWLAPI對N-Triple文件錯誤地使用OBO解析器
但是對於一些N-Triples本體,當包裝器作爲jar運行時,OWLAPI解析器失敗。
解析的本體是以下幾點:http://www.cropontology.org/ontology/CO_320/Rice/nt
我們面臨兩種情況:
當通過MVN測試運行: 解析工程正確
當通過罐子運行:它是使用OBO解析器,產生其中整個NT本體被包含在一個oboInOwl字符串中的一個公理本體:HTTP謂詞:
<oboInOwl:http rdf:datatype="http://www.w3.org/2001/XMLSchema#string">//www.cropontology.org/rdf/CO_320:ROOT> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type>
在這兩種情況下,OWLOntologyLoaderConfiguration和輸入文件是相同的。因此,唯一的區別是,一個是使用mvn test
和其他(使用相同的Java版本2)
我試過多次使用的東西跑java -jar
:
取締OBO解析器。我嘗試了多種語法,但都沒有工作;包裝繼續使用OBO解析器)
conf.setBannedParsers("org.obolibrary.oboformat.parser.OBOFormatParser"); conf.setBannedParsers("o.o.oboformat.parser.OBOFormatParser"); conf.setBannedParsers("OBOFormatParser");
避免使用不同的owlapi依賴關係。像這裏記錄OWLAPI: Parser not found if run from Jar我試着只用owlapi分佈,以避免任何衝突
<dependency> <groupId>net.sourceforge.owlapi</groupId> <artifactId>owlapi-distribution</artifactId> <version>4.3.1</version> </dependency>
人有一個想法,其中這種不一致可能是從哪裏來的? 爲什麼OWLAPI loadOntologyFromOntologyDocument在一個case中正常工作,在另一箇中是錯誤的?即使投入是嚴格相同的。
UPDATE1:
的NTriple文件的解析是,有時,因爲三元一些_:genid1
節點的失敗。 問題是以下內容:
- 當應用程序被打包爲一個罐(與包括依賴)和瓶子運行來解析NTriple文件。然後它不能返回
org.semanticweb.owlapi.rdf.turtle.parser.ParseException: Encountered " <PNAME_LN> ":genid1 ""
三重引起的問題是:<http://www.cropontology.org/rdf/CO_320:0001563> <http://www.w3.org/2000/01/rdf-schema#subClassOf> _:genid1.
- 當完全相同的解析器運行,在完全相同的文件,通過一個Maven測試(解析器是通過一個叫jUnit測試,我們使用
mvn test
運行測試)。然後解析進行得很順利。並且由_:genid1
節點提供的信息已成功提取。
它看起來像OWLAPI無法解析第一種情況下的空白節點。 我打印OWLAPI版,採用VersionInfo.getVersionInfo()
,只是運行loadOntologyFromOntologyDocument
前:
- 對於JAR版本(也就是造成問題):
The OWL API (version 4.3.1)
- 對於測試版(即工作):
The OWL API (version 4.3.1.2017-03-27T22:32:37Z)
UPDATE2:
這似乎是問題來自於罐子建設。
當罐子是建立一些依賴被覆蓋,所以不是所有的解析器都包含在conf文件
的org.openrdf.rio.RDFParserFactory在罐子裏只包含以下內容:
org.semanticweb.owlapi.rio.RioFunctionalSyntaxParserFactory
org.semanticweb.owlapi.rio.RioManchesterSyntaxParserFactory
org.semanticweb.owlapi.rio.RioOWLXMLParserFactory
org.semanticweb.owlapi.rio.RioFunctionalSyntaxParserFactory
org.semanticweb.owlapi.rio.RioManchesterSyntaxParserFactory
org.semanticweb.owlapi.rio.RioOWLXMLParserFactory
當通過測試(其中,所述解析作品)運行,按照登錄的本體是在
org.semanticweb.owlapi.formats.RioTurtleDocumentFormat
當通過罐子運行:
由於沒有空白節點(所以解析器運作良好),我們得到了下面的格式NTriples文件:org.semanticweb.owlapi.formats.TurtleDocumentFormat
隨着具有空節點NTriples文件我們得到:
The following parsers were tried:
1) [email protected]
2) [email protected]
3) org.se[email protected]67304a40
4) org.semanticweb.owlapi.rio.RioParserImpl : [email protected]fd655c
5) org.semanticweb.o[email protected]61c9c3fd
6) org.semanticweb.owlapi.rio.RioParserImpl : [email protected]9ad
7) org.semanticweb.owlapi.rio.RioParserImpl : [email protected]8dc3
8) org.semanticweb.owlapi.rio.RioParserImpl : [email protected]ecd36
9) org.semanticweb.owlapi.rio.RioParserImpl : [email protected]
10) org.semanticweb.owlapi.rio.RioParserImpl : [email protected]f24493
11) org.semanticweb.owlapi.rio.RioParserImpl : [email protected]acc47d
12) org.semanticweb.owlapi.rio.RioParserImpl : [email protected]
13) org.semanticweb.owlapi.rio.RioParserImpl : [email protected]b9a3bc
14) org.semanticweb.owlapi.rio.RioTrixParserFactory$TrixParserImpl : org.semanticweb.owlapi.form[email protected]
15) [email protected]3b4ac8
16) [email protected]
17) org.semanticweb.owlapi.rio.RioParserImpl : [email protected]
但對於RioTurtleDocumentFormat它說:
Parser: org.semanticweb.owlapi.rio.RioParserImpl : [email protected]fd655c
Stack trace:
org.openrdf.rio.UnsupportedRDFormatException: No parser factory available for RDF format Turtle (mimeTypes=text/turtle, application/x-turtle; ext=ttl)
org.semanticweb.owlapi.rio.RioParserImpl.parse(RioParserImpl.java:207)
所以看起來好像RioTurtleDocumentFormatFactory
沒有被正確地包含在jar中。
我們如何確定這一點?它可能來自pom.xml build
UPDATE3:
我試着只用owlapi-osgidistribution,我仍然得到了完全同樣的錯誤。
我也嘗試使用maven-shade-plugin打包jar並得到相同的錯誤。
禁止OBO解析器日誌說,之後,它試圖利用這些解析器解析文件:
The following parsers were tried:
1) [email protected]
2) [email protected]
3) org.se[email protected]93cf163
4) org.semanticweb.owlapi.rio.RioParserImpl : [email protected]fd655c
5) org.semanticweb.o[email protected]3d97a632
6) org.semanticweb.owlapi.rio.RioParserImpl : [email protected]9ad
7) org.semanticweb.owlapi.rio.RioParserImpl : [email protected]8dc3
8) org.semanticweb.owlapi.rio.RioParserImpl : [email protected]ecd36
9) org.semanticweb.owlapi.rio.RioParserImpl : [email protected]
10) org.semanticweb.owlapi.rio.RioParserImpl : [email protected]f24493
11) org.semanticweb.owlapi.rio.RioParserImpl : [email protected]acc47d
12) org.semanticweb.owlapi.rio.RioParserImpl : [email protected]
13) org.semanticweb.owlapi.rio.RioParserImpl : [email protected]b9a3bc
14) org.semanticweb.owlapi.rio.RioTrixParserFactory$TrixParserImpl : [email protected]
15) [email protected]4b990c
16) [email protected]
17) org.semanticweb.owlapi.rio.RioParserImpl : [email protected]
下面是RioTurtleDocumentFormatFactory錯誤日誌:
--------------------------------------------------------------------------------
Parser: org.semanticweb.owlapi.rio.RioParserImpl : [email protected]fd655c
Stack trace:
org.openrdf.rio.UnsupportedRDFormatException: No parser factory available for RDF format Turtle (mimeTypes=text/turtle, application/x-turtle; ext=ttl) org.semanticweb.owlapi.rio.RioParserImpl.parse(RioParserImpl.java:207)
uk.ac.manchester.cs.owl.owlapi.OWLOntologyFactoryImpl.loadOWLOntology(OWLOntologyFactoryImpl.java:197)
uk.ac.manchester.cs.owl.owlapi.OWLOntologyManagerImpl.actualParse(OWLOntologyManagerImpl.java:1156)
uk.ac.manchester.cs.owl.owlapi.OWLOntologyManagerImpl.loadOntology(OWLOntologyManagerImpl.java:1112)
uk.ac.manchester.cs.owl.owlapi.OWLOntologyManagerImpl.loadOntologyFromOntologyDocument(OWLOntologyManagerImpl.java:1068)
org.stanford.ncbo.oapiwrapper.OntologyParser.findMasterFile(OntologyParser.java:708)
org.stanford.ncbo.oapiwrapper.OntologyParser.internalParse(OntologyParser.java:651)
org.stanford.ncbo.oapiwrapper.OntologyParser.parse(OntologyParser.java:630)
org.stanford.ncbo.oapiwrapper.OntologyParserCommand.main(OntologyParserCommand.java:51)
No parser factory available for RDF format Turtle (mimeTypes=text/turtle, application/x-turtle; ext=ttl) org.openrdf.rio.Rio.createParser(Rio.java:198)
org.semanticweb.owlapi.rio.RioParserImpl.parseDocumentSource(RioParserImpl.java:241)
org.semanticweb.owlapi.rio.RioParserImpl.parse(RioParserImpl.java:191)
uk.ac.manchester.cs.owl.owlapi.OWLOntologyFactoryImpl.loadOWLOntology(OWLOntologyFactoryImpl.java:197)
uk.ac.manchester.cs.owl.owlapi.OWLOntologyManagerImpl.actualParse(OWLOntologyManagerImpl.java:1156)
uk.ac.manchester.cs.owl.owlapi.OWLOntologyManagerImpl.loadOntology(OWLOntologyManagerImpl.java:1112)
uk.ac.manchester.cs.owl.owlapi.OWLOntologyManagerImpl.loadOntologyFromOntologyDocument(OWLOntologyManagerImpl.java:1068)
org.stanford.ncbo.oapiwrapper.OntologyParser.findMasterFile(OntologyParser.java:708)
org.stanford.ncbo.oapiwrapper.OntologyParser.internalParse(OntologyParser.java:651)
org.stanford.ncbo.oapiwrapper.OntologyParser.parse(OntologyParser.java:630)
在罐子裏,我們可以找到以下類別(無多個副本):
RioTurtleDocumentFormat.class
RioTurtleDocumentFormatFactory.class
RioTurtleParserFactory.class
RioTurtleStorerFactory.class
而在META-INF/services
目錄,我們得到:
META-INF/services/org.openrdf.rio.RDFParserFactory
META-INF/services/org.semanticweb.owlapi.io.LegacyOWLParserFactory
META-INF/services/org.semanticweb.owlapi.model.OWLOntologyManagerFactory
META-INF/services/org.semanticweb.owlapi.io.OWLParserFactory
META-INF/services/org.semanticweb.owlapi.model.OWLStorerFactory
META-INF/services/org.semanticweb.owlapi.model.OWLDocumentFormatFactory
META-INF/services/org.openrdf.rio.LanguageHandler
META-INF/services/org.openrdf.rio.DatatypeHandler
META-INF/services/org.openrdf.rio.RDFWriterFactory
META-INF/services/com.fasterxml.jackson.core.JsonFactory
META-INF/services/com.fasterxml.jackson.core.ObjectCodec
META-INF/services/org.apache.commons.logging.LogFactory
META-INF/services/javax.servlet.ServletContainerInitializer
的META-INF/services/org.openrdf.rio.RDFParserFactory
包含:
org.semanticweb.owlapi.rio.RioFunctionalSyntaxParserFactory
org.semanticweb.owlapi.rio.RioManchesterSyntaxParserFactory
org.semanticweb.owlapi.rio.RioOWLXMLParserFactory
org.semanticweb.owlapi.rio.RioFunctionalSyntaxParserFactory
org.semanticweb.owlapi.rio.RioManchesterSyntaxParserFactory
org.semanticweb.owlapi.rio.RioOWLXMLParserFactory
的META-INF/services/org.semanticweb.owlapi.model.OWLDocumentFormatFactory
包含
org.semanticweb.owlapi.formats.BinaryRDFDocumentFormatFactory
org.semanticweb.owlapi.formats.N3DocumentFormatFactory
org.semanticweb.owlapi.formats.NQuadsDocumentFormatFactory
org.semanticweb.owlapi.formats.NTriplesDocumentFormatFactory
org.semanticweb.owlapi.formats.RDFaDocumentFormatFactory
org.semanticweb.owlapi.formats.RDFJsonLDDocumentFormatFactory
org.semanticweb.owlapi.formats.RDFJsonDocumentFormatFactory
org.semanticweb.owlapi.formats.RioRDFXMLDocumentFormatFactory
org.semanticweb.owlapi.formats.RioTurtleDocumentFormatFactory
org.semanticweb.owlapi.formats.TrigDocumentFormatFactory
org.semanticweb.owlapi.formats.TrixDocumentFormatFactory
org.semanticweb.owlapi.formats.BinaryRDFDocumentFormatFactory
org.semanticweb.owlapi.formats.N3DocumentFormatFactory
org.semanticweb.owlapi.formats.NQuadsDocumentFormatFactory
org.semanticweb.owlapi.formats.NTriplesDocumentFormatFactory
org.semanticweb.owlapi.formats.RDFaDocumentFormatFactory
org.semanticweb.owlapi.formats.RDFJsonLDDocumentFormatFactory
org.semanticweb.owlapi.formats.RDFJsonDocumentFormatFactory
org.semanticweb.owlapi.formats.RioRDFXMLDocumentFormatFactory
org.semanticweb.owlapi.formats.RioTurtleDocumentFormatFactory
org.semanticweb.owlapi.formats.TrigDocumentFormatFactory
org.semanticweb.owlapi.formats.TrixDocumentFormatFactory
所以org.semanticweb.owlapi.formats.RioTurtleDocumentFormatFactory
在一些META-INF/services
文件的實際列出的類都包含在罐子裏。但它仍然像罐子找不到它。
我真的不明白OWLAPI如何定義要使用哪個解析器以及在哪裏找到它們。
UPDATE4:
當我刪除所有排除,並讓包括我還是得到了很多LIB的被排除的罐子,然後得到java.lang.NoClassDefFoundError
。我不得不添加幾個包含來解決這個問題。但它仍然不能解決問題(它只是使日誌消失)
這裏是插件配置使用:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>2.3</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<artifactSet>
<includes>
<include>net.sourceforge.owlapi:owlapi-api</include>
<include>net.sourceforge.owlapi:owlapi-apibinding</include>
<include>net.sourceforge.owlapi:owlapi-fixers</include>
<include>net.sourceforge.owlapi:owlapi-impl</include>
<include>net.sourceforge.owlapi:owlapi-oboformat</include>
<include>net.sourceforge.owlapi:owlapi-parsers</include>
<include>net.sourceforge.owlapi:owlapi-rio</include>
<include>net.sourceforge.owlapi:owlapi-tools</include>
<include>commons-cli:*</include>
<include>commons-io:*</include>
<include>org.slf4j:*</include>
<include>net.sourceforge.owlapi:owlapi-osgidistribution</include>
<include>com.google.inject:*</include>
<include>javax.inject:*</include>
<include>com.google.*</include>
<include>aopalliance:*</include>
<include>org.openrdf.sesame:*</include>
<include>org.tukaani:*</include>
<include>net.sf.trove4j:*</include>
<include>org.apache.commons:commons-csv</include>
</includes>
</artifactSet>
<transformers>
<transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<mainClass>org.stanford.ncbo.oapiwrapper.OntologyParserCommand</mainClass>
</transformer>
</transformers>
</configuration>
</execution>
</executions>
</plugin>
不過,這並不在META-INF/services/org.openrdf.rio.RDFParserFactory
文件中的jar改變什麼
也許這是由於我需要添加<include>net.sourceforge.owlapi:owlapi-osgidistribution</include>
並覆蓋RDFParserFactory文件。但是,如果沒有包括它,我得到了一個java.lang.NoClassDefFoundError: org/semanticweb/owlapi/model/OWLAnnotationValue
謝謝。我們知道不可變的,缺少的是OBO解析器類的名稱。它幫助我解決問題的根源。 我更新了問題以提供有關問題的詳細信息 – vemonet
非常感謝!現在我知道它來自哪裏,我將檢查如何配置pom.xml以確保Rio解析器已加載 – vemonet
我認爲問題可能是您有多個jar提供相同的文件。查看我的更新以獲得修復。 – Ignazio