2017-05-03 102 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