简体   繁体   English

耶拿NoReaderForLangException:猫头鹰

[英]Jena NoReaderForLangException: owl

My problem is with Jena when I use Turtle Ontolgy it works fine and when I use any other ontology like OWL or RDFS it show the same error 我的问题是Jena,当我使用Turtle Ontolgy时,它工作正常,而当我使用其他任何本体(如OWL或RDFS)时,它也会显示相同的错误

Exception in thread "main" com.hp.hpl.jena.shared.NoReaderForLangException: owl at com.hp.hpl.jena.rdf.model.impl.RDFReaderFImpl.getReader(RDFReaderFImpl.java:110) at com.hp.hpl.jena.rdf.model.impl.ModelCom.read(ModelCom.java:225) at com.hp.hpl.jena.ontology.impl.OntModelImpl.read(OntModelImpl.java:2169) at symenticweb.SymenticWeb.main(SymenticWeb.java:109) Java Result: 1 线程“主要” com.hp.hpl.jena.shared.NoReaderForLangException中的异常:com.hp.hpl.jena.rdf.model.impl.RDFReaderFImpl.getReader(RDFReaderFImpl.java:110)处的猫头鹰com.hp.hpl.jena.ontology.impl.OntModelImpl.read(OntModelImpl.java:2169)上的.jena.rdf.model.impl.ModelCom.read(ModelCom.java:225),在symenticweb.SymenticWeb.main(SymenticWeb .java:109)Java结果:1

Line no 109 is model.read(inputStream, null, inputFileFormat); 第109行是model.read(inputStream,null,inputFileFormat);

My Code is 我的代码是

package symenticweb;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.PrintWriter;
import java.util.Iterator;

import org.mindswap.pellet.jena.PelletReasonerFactory;

import com.hp.hpl.jena.ontology.Individual;
import com.hp.hpl.jena.ontology.OntModel;
import com.hp.hpl.jena.ontology.OntModelSpec;
import com.hp.hpl.jena.rdf.model.Model;
import com.hp.hpl.jena.rdf.model.ModelFactory;
import com.hp.hpl.jena.rdf.model.Statement;
import com.hp.hpl.jena.rdf.model.StmtIterator;
import com.hp.hpl.jena.reasoner.Reasoner;
import com.hp.hpl.jena.reasoner.ValidityReport;
import com.hp.hpl.jena.util.iterator.ExtendedIterator;

public class SymenticWeb
{
   /**
    * This program takes 4 parameters an input file name 
    * an output file name an input file format a reasoning 
    * level {RDFS, OWL-DL}
    */
   public static void main(String[] args)
   {
       //validate the program arguments
//      if(args.length != 4) 
//      {   
//         System.err.println("Usage: java InferenceExample "
//            + "<input file> <input format> <output file> "
//            + "<none|rdfs|owl>");
//         return;
//      }

      String inputFileName;
       inputFileName = "C:\\Users\\Harjinder\\Documents\\NetBeansProjects\\SymenticWeb\\src\\test\\abc.owl";
      String inputFileFormat = "owl";
      String outputFileName = "C:\\New folder\\abc.txt";
      String reasoningLevel = "none";

      //create an input stream for the input file
      FileInputStream inputStream = null;
      PrintWriter writer = null;
      try 
      {
         inputStream = new FileInputStream(inputFileName);
      } catch (FileNotFoundException e) {
         System.err.println("'" + inputFileName 
            + "' is an invalid input file.");
         return;
      }

      //create an output print writer for the results
      try 
      {
         writer = new PrintWriter(outputFileName);
      } catch (FileNotFoundException e) {
         System.err.println("'" + outputFileName 
            + "' is an invalid output file.");
         return;
      }

      //create the appropriate jena model
      OntModel model = null;
      if("none".equals(reasoningLevel.toLowerCase()))
      {
         /*
          * "none" is jena model with OWL_DL
          * ontologies loaded and no inference enabled
          */
         model = ModelFactory.createOntologyModel(
            OntModelSpec.OWL_DL_MEM);
      }
      else if("rdfs".equals(reasoningLevel.toLowerCase()))
      {
         /*
          * "rdfs" is jena model with OWL_DL
          * ontologies loaded and RDFS inference enabled 
          */
         model = ModelFactory.createOntologyModel(
            OntModelSpec.OWL_DL_MEM_RDFS_INF); 
      }
      else if("owl".equals(reasoningLevel.toLowerCase()))
      {
         /*
          * "owl" is jena model with OWL_DL ontologies
          * wrapped around a pellet-based inference model
          */
         Reasoner reasoner = 
            PelletReasonerFactory.theInstance().create();
         Model infModel = ModelFactory.createInfModel(
            reasoner, ModelFactory.createDefaultModel());
         model = ModelFactory.createOntologyModel(
            OntModelSpec.OWL_DL_MEM, infModel);
      }
      else
      {
         //invalid inference setting
         System.err.println("Invalid inference setting, "
            + "choose one of <none|rdfs|owl>.");
         return;
      }

      //load the facts into the model
      model.read(inputStream, null, inputFileFormat);

      //validate the file
      ValidityReport validityReport = model.validate();
      if(validityReport != null && !validityReport.isValid())
      {
         Iterator i = validityReport.getReports();
         while(i.hasNext())
         {
            System.err.println(
               ((ValidityReport.Report)i.next()).getDescription());
         }
         return;
      }

      //Iterate over the individuals, print statements about them
      ExtendedIterator iIndividuals = model.listIndividuals();
      while(iIndividuals.hasNext())
      {
         Individual i = (Individual)iIndividuals.next();
         printIndividual(i, writer);
      }
      iIndividuals.close();

      writer.close();
      model.close();
   }

   /**
    * Print information about the individual
    * @param i The individual to output
    * @param writer The writer to which to output
    */
   public static void printIndividual(
      Individual i, PrintWriter writer)
   {
      //print the local name of the individual (to keep it terse)
      writer.println("Individual: " + i.getLocalName());

      //print the statements about this individual
      StmtIterator iProperties = i.listProperties();
      while(iProperties.hasNext())
      {
         Statement s = (Statement)iProperties.next();
         writer.println("  " + s.getPredicate().getLocalName() 
            + " : " + s.getObject().toString());
      }
      iProperties.close();
      writer.println();
   }
}

OWL can be serialized to RDF, and RDF can be serialized in a number of different formats. OWL可以序列化为RDF,RDF可以多种不同的格式序列化。 Jena is an RDF-based tool, and you'll need to have an RDF serialization of your ontology in order for Jena to be able to read it. Jena是基于RDF的工具,您需要对本体进行RDF序列化才能使Jena能够读取它。

Fortunately, files ending in .owl are typically (though not always) RDF/XML serializations of the RDF encoding of the OWL ontology. 幸运的是,以.owl结尾的文件通常(尽管并非总是)是OWL本体的RDF编码的RDF / XML序列化。 You haven't shown us your ontology, so we can't be sure yet, but most likely, if you change 您尚未向我们展示您的本体,所以我们尚不确定,但是很可能,如果您进行更改

String inputFileFormat = "owl";

to

String inputFileFormat = "RDF/XML";

you'll be fine. 你会没事的。 (This is assuming that your .owl file is RDF/XML.) (这是假设您的.owl文件为RDF / XML。)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM