我们有一个使用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