Java OWLAPI错误地使用N-Triple文件的OBO解析器
我们有一个使用OWLAPI解析本体的包装器 但是对于一些N-Triples本体,当包装器作为jar运行时,OWLAPI解析器失败 解析的本体如下所示: 我们试图在这里对其进行分析: 我们面临两种情况:Java OWLAPI错误地使用N-Triple文件的OBO解析器,java,maven,parsing,owl-api,Java,Maven,Parsing,Owl Api,我们有一个使用OWLAPI解析本体的包装器 但是对于一些N-Triples本体,当包装器作为jar运行时,OWLAPI解析器失败 解析的本体如下所示: 我们试图在这里对其进行分析: 我们面临两种情况: 当运行mvn测试时:解析工作正常 当运行jar:它使用OBO解析器,生成一个单公理本体,其中整个nt本体作为字符串包含在oboInOwl:http谓词中: //www.cropontology.org/rdf/CO_320:ROOThttp://www.w3.org/1999/02/22-rdf
- 当运行mvn测试时:解析工作正常
- 当运行jar:它使用OBO解析器,生成一个单公理本体,其中整个nt本体作为字符串包含在oboInOwl:http谓词中:
//www.cropontology.org/rdf/CO_320:ROOThttp://www.w3.org/1999/02/22-rdf-syntax-ns#type
mvn测试运行,另一个使用java-jar
(2个使用相同的java版本)
我尝试了多种方法:
- 禁止使用OBO解析器。我尝试了多种语法,但都不起作用;包装器(继续使用OBO解析器)
- 避免使用不同的owlapi依赖项。正如本文所述,我尝试只使用owlapi发行版来避免任何冲突
<dependency>
<groupId>net.sourceforge.owlapi</groupId>
<artifactId>owlapi-distribution</artifactId>
<version>4.3.1</version>
</dependency>
- 运行测试时(解析工作的地方),根据日志,本体位于
org.semanticweb.owlapi.formats.RioTurtleDocumentFormat
- 当运行jar时:
对于没有空白节点的NTriples文件(因此解析器工作正常),我们得到了以下格式:org.semanticweb.owlapi.formats.TurtleDocumentFormat
对于具有空白节点的NTriples文件,我们得到:
The following parsers were tried:
1) org.semanticweb.owlapi.rdf.rdfxml.parser.RDFXMLParser@a4add54
2) org.semanticweb.owlapi.owlxml.parser.OWLXMLParser@71454b9d
3) org.semanticweb.owlapi.functional.parser.OWLFunctionalSyntaxOWLParser@67304a40
4) org.semanticweb.owlapi.rio.RioParserImpl : org.semanticweb.owlapi.formats.RioTurtleDocumentFormatFactory@95fd655c
5) org.semanticweb.owlapi.manchestersyntax.parser.ManchesterOWLSyntaxOntologyParser@61c9c3fd
6) org.semanticweb.owlapi.rio.RioParserImpl : org.semanticweb.owlapi.formats.NQuadsDocumentFormatFactory@6f9c39ad
7) org.semanticweb.owlapi.rio.RioParserImpl : org.semanticweb.owlapi.formats.RDFJsonDocumentFormatFactory@cd748dc3
8) org.semanticweb.owlapi.rio.RioParserImpl : org.semanticweb.owlapi.formats.NTriplesDocumentFormatFactory@937ecd36
9) org.semanticweb.owlapi.rio.RioParserImpl : org.semanticweb.owlapi.formats.TrigDocumentFormatFactory@27e81c
10) org.semanticweb.owlapi.rio.RioParserImpl : org.semanticweb.owlapi.formats.BinaryRDFDocumentFormatFactory@3bf24493
11) org.semanticweb.owlapi.rio.RioParserImpl : org.semanticweb.owlapi.formats.RDFJsonLDDocumentFormatFactory@dcacc47d
12) org.semanticweb.owlapi.rio.RioParserImpl : org.semanticweb.owlapi.formats.N3DocumentFormatFactory@9a5
13) org.semanticweb.owlapi.rio.RioParserImpl : org.semanticweb.owlapi.formats.RioRDFXMLDocumentFormatFactory@69b9a3bc
14) org.semanticweb.owlapi.rio.RioTrixParserFactory$TrixParserImpl : org.semanticweb.owlapi.formats.TrixDocumentFormatFactory@27e82d
15) org.semanticweb.owlapi.rdf.turtle.parser.TurtleOntologyParser@463b4ac8
16) org.semanticweb.owlapi.krss2.parser.KRSS2OWLParser@11981797
17) org.semanticweb.owlapi.rio.RioParserImpl : org.semanticweb.owlapi.formats.RDFaDocumentFormatFactory@264e8d
但对于RioTurtleDocumentFormat,它说:
Parser: org.semanticweb.owlapi.rio.RioParserImpl : org.semanticweb.owlapi.formats.RioTurtleDocumentFormatFactory@95fd655c
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中
我们怎么能确定呢?它可能来自
更新3:
我只尝试了owlapi osgidistribution,但仍然得到了完全相同的错误
我还尝试使用maven shade插件打包jar,但得到了相同的错误
禁止海外建筑运营管理局解析器后,日志显示它试图使用这些解析器解析文件:
The following parsers were tried:
1) org.semanticweb.owlapi.rdf.rdfxml.parser.RDFXMLParser@2bb3058
2) org.semanticweb.owlapi.owlxml.parser.OWLXMLParser@6bbe2511
3) org.semanticweb.owlapi.functional.parser.OWLFunctionalSyntaxOWLParser@93cf163
4) org.semanticweb.owlapi.rio.RioParserImpl : org.semanticweb.owlapi.formats.RioTurtleDocumentFormatFactory@95fd655c
5) org.semanticweb.owlapi.manchestersyntax.parser.ManchesterOWLSyntaxOntologyParser@3d97a632
6) org.semanticweb.owlapi.rio.RioParserImpl : org.semanticweb.owlapi.formats.NQuadsDocumentFormatFactory@6f9c39ad
7) org.semanticweb.owlapi.rio.RioParserImpl : org.semanticweb.owlapi.formats.RDFJsonDocumentFormatFactory@cd748dc3
8) org.semanticweb.owlapi.rio.RioParserImpl : org.semanticweb.owlapi.formats.NTriplesDocumentFormatFactory@937ecd36
9) org.semanticweb.owlapi.rio.RioParserImpl : org.semanticweb.owlapi.formats.TrigDocumentFormatFactory@27e81c
10) org.semanticweb.owlapi.rio.RioParserImpl : org.semanticweb.owlapi.formats.BinaryRDFDocumentFormatFactory@3bf24493
11) org.semanticweb.owlapi.rio.RioParserImpl : org.semanticweb.owlapi.formats.RDFJsonLDDocumentFormatFactory@dcacc47d
12) org.semanticweb.owlapi.rio.RioParserImpl : org.semanticweb.owlapi.formats.N3DocumentFormatFactory@9a5
13) org.semanticweb.owlapi.rio.RioParserImpl : org.semanticweb.owlapi.formats.RioRDFXMLDocumentFormatFactory@69b9a3bc
14) org.semanticweb.owlapi.rio.RioTrixParserFactory$TrixParserImpl : org.semanticweb.owlapi.formats.TrixDocumentFormatFactory@27e82d
15) org.semanticweb.owlapi.rdf.turtle.parser.TurtleOntologyParser@784b990c
16) org.semanticweb.owlapi.krss2.parser.KRSS2OWLParser@13f17eb4
17) org.semanticweb.owlapi.rio.RioParserImpl : org.semanticweb.owlapi.formats.RDFaDocumentFormatFactory@264e8d
以下是RioTurtleDocumentFormatFactory的错误日志:
--------------------------------------------------------------------------------
Parser: org.semanticweb.owlapi.rio.RioParserImpl : org.semanticweb.owlapi.formats.RioTurtleDocumentFormatFactory@95fd655c
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)
在jar中,我们可以找到以下类(没有多个副本):
在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
文件中,类包含在jar中。但看起来罐子还是找不到
我真的不知道OWLAPI如何定义要使用的解析器以及在哪里找到它们
更新4:
当我删除所有排除项并让包含项包含时,我仍然得到了许多从jar中排除的库,然后得到java.lang.NoClassDefFoundError
。我不得不添加几个include来修复这个问题。但它仍然无法解决问题(它只是使日志消失)
以下是我使用的插件配置:
<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>
org.apache.maven.plugins
maven阴影插件
2.3
包裹
阴凉处
owlapi:owlapi
owlapi:owlapi-apibling
owlapi:owlapi修复程序
owlapi:owlapi impl
owlapi:owlapi格式
owlapi:owlapi解析器
owlapi:owlapi rio
owlapi:owlapi工具
commons cli:*
公地io:*
org.slf4j:*
owlapi:owlapi osgidistribution
com.google.inject:*
javax.inject:*
com.google*
A.效忠:*
org.openrdf.sesame:*
org.tukaani:*
net.sf.trove4j:*
org.apache.commons:commons csv
org.stanford.ncbo.oapiwrapper.OntologyParserCommand
但是它不会改变jar中的META-INF/services/org.openrdf.rio.RDFParserFactory
文件中的任何内容
可能是因为我需要添加net.sourceforge.owlapi:owlapi-osgidistribution
,这会覆盖RDFParserFactory文件。但是没有包括它,我得到了一个java.lang.NoClassDefFoundError:org/semanticweb/owlapi/model/OWLAnnotationValue
这里有几个问题:
owletologyLoaderConfiguration
是一个不可变的类。setter生成修改的对象,而不是调用它们的对象中的更改
- 有两个OBO解析器
要解决此问题,请使用:
conf = conf.setBannedParsers(
"org.coode.owlapi.obo12.parser.OBO12ParserFactory org.semanticweb.owlapi.oboformat.OBOFormatOWLAPIParserFactory");
如果您使用的是OWLAPI 5.1.0,则可以在经理级别设置禁止:
manager.getOntologyConfigurator().withBannedParsers("...");
另一种只使用您知道必须用于文档的解析器的方法是在本体源上设置格式:
OWLOntologyDocumentSource source =
new FileDocumentSource(fileName, new NTriplesDocumentFormat());
这将只使用与请求的格式匹配的解析器,而不是所有可用的解析器,直到一个解析器没有失败为止
更新:根错误与尝试使用turtle解析器解析NTriples有关。应该选择Rio ntriples解析器——我认为这是maven测试的结果。
最可能的问题:由于meta inf/services文件夹中的问题,Rio解析器未包含或其声明被跳过。检查jar中是否有存储列表的多个副本;将只加载一个(跨多个文件夹或多个文件夹加载多个副本)
conf = conf.setBannedParsers(
"org.coode.owlapi.obo12.parser.OBO12ParserFactory org.semanticweb.owlapi.oboformat.OBOFormatOWLAPIParserFactory");
manager.getOntologyConfigurator().withBannedParsers("...");
OWLOntologyDocumentSource source =
new FileDocumentSource(fileName, new NTriplesDocumentFormat());
<dependency>
<groupId>net.sourceforge.owlapi</groupId>
<artifactId>owlapi-distribution</artifactId>
<version>4.3.1</version>
</dependency>
<dependency>
<groupId>net.sourceforge.owlapi</groupId>
<artifactId>owlapi-rio</artifactId>
<version>4.3.1</version>
</dependency>
<dependency>
<groupId>net.sourceforge.owlapi</groupId>
<artifactId>owlapi-compatibility</artifactId>
<version>4.3.1</version>
</dependency>
<dependency>
<groupId>net.sourceforge.owlapi</groupId>
<artifactId>owlapi-osgidistribution</artifactId>
<version>4.3.1</version>
</dependency>
<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>
</includes>
<excludes>
<exclude>org.apache.felix:org.osgi.core</exclude>
<exclude>org.openrdf.sesame:*</exclude>
<exclude>com.fasterxml.jackson.core:*</exclude>
<exclude>com.github.jsonld-java:*</exclude>
<exclude>com.fasterxml.jackson.core:*</exclude>
<exclude>org.apache.httpcomponents:*</exclude>
<exclude>commons-codec:commons-codec:*</exclude>
<exclude>org.slf4j:*</exclude>
<exclude>org.semarglproject:*</exclude>
<exclude>com.google.guava:*</exclude>
<exclude>com.google.inject:*</exclude>
<exclude>javax.inject:*</exclude>
<exclude>aopalliance:*</exclude>
<exclude>com.google.inject.extensions:*</exclude>
<exclude>com.google.code.findbugs:*</exclude>
<exclude>org.slf4j:slf4j-api</exclude>
<exclude>commons-io:*</exclude>
<exclude>org.tukaani:*</exclude>
<exclude>net.sf.trove4j:*</exclude>
</excludes>
</artifactSet>
<transformers>
<transformer
implementation="org.apache.maven.plugins.shade.resource.ServicesResourceTransformer" />
</transformers>
</configuration>
</execution>
</executions>
</plugin>