2017-05-03 13 views
0

我们有一个使用OWLAPI解析本体的包装器。OWLAPI对N-Triple文件错误地使用OBO解析器

但是对于一些N-Triples本体,当包装器作为jar运行时,OWLAPI解析器失败。

解析的本体是以下几点:http://www.cropontology.org/ontology/CO_320/Rice/nt

我们正试图在这里解析它:https://github.com/ncbo/owlapi_wrapper/blob/master/src/main/java/org/stanford/ncbo/oapiwrapper/OntologyParser.java#L637

我们面临两种情况:

  • 当通过MVN测试运行: 解析工程正确

  • 当通过罐子运行:它是使用OBO解析器,产生其中整个NT本体被包含在一个oboInOwl字符串中的一个公理本体:HTTP谓词:
    <oboInOwl:http rdf:datatype="http://www.w3.org/2001/XMLSchema#string">//www.cropontology.org/rdf/CO_320:ROOT&gt; &lt;http://www.w3.org/1999/02/22-rdf-syntax-ns#type&gt;

在这两种情况下,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

回答

0

这里有阴谋的几个问题:

  • OWLOntologyLoaderConfiguration是不可变的类。 Setters产生一个修改后的对象,而不是它们被调用的对象的变化。
  • 有两种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()); 

这将只使用匹配所需格式的解析器,而不是所有可用的解析器,直到不会失败。

更新:根错误与试图用解析器分析NTriples有关。应该选择Rio ntriples解析器 - 这是我认为正在进行的maven测试。 最有可能的问题:由于meta-inf/services文件夹中存在问题,Rio解析器未被包含或者其声明被跳过。检查jar中存储的列表是否有多个副本;只有一个会被加载(跨多个文件夹或多个jar的多个副本适用于ServiceLoader,但同一个jar中的多个不是)。

第二次更新:您的POM有多个包含解析器列表的罐子。试着用

<dependency> 
    <groupId>net.sourceforge.owlapi</groupId> 
    <artifactId>owlapi-osgidistribution</artifactId> 
    <version>4.3.1</version> 
</dependency> 

更新替换

<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> 

:我已经签出你使用复制的问题的项目。为了调试它,我已经试过一次添加的OWLAPI依赖一个直到故障而停止发生 - 这样做,我发现这个文件的内容:

META-INF/services/org.openrdf.rio.RDFParserFactory

应包括

org.openrdf.rio.turtle.TurtleParserFactory

但它没有 - 它包含了owlapi-distribution/META-INF/services/org.openrdf.rio.RDFParserFactory内容。但是,当你使用Maven解析依赖关系运行这个Maven项目时,文件org.openrdf.rio.RDFParserFactory出现两次:一次在owlapi-distribution中,一次在sesame-rio-turtle(本例中为2.7.16);第二个文件包含正确的工厂。

问题是,在重新包装owlapi-distribution及其依赖项时,服务中的文件未按预期合并。

您应该可以通过在重新包装中使用阴影插件来解决该问题。举例来说,我在这里粘贴owlapi-distribution的内容 - 您需要更改排除列表,因为您可能不想排除任何依赖关系。

 <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> 
+0

谢谢。我们知道不可变的,缺少的是OBO解析器类的名称。它帮助我解决问题的根源。 我更新了问题以提供有关问题的详细信息 – vemonet

+0

非常感谢!现在我知道它来自哪里,我将检查如何配置pom.xml以确保Rio解析器已加载 – vemonet

+0

我认为问题可能是您有多个jar提供相同的文件。查看我的更新以获得修复。 – Ignazio