java - Jena NoReaderForLangException: owl -
my problem jena when use turtle ontolgy works fine , when use other ontology owl or rdfs show same error
exception in thread "main" com.hp.hpl.jena.shared.noreaderforlangexception: owl @ com.hp.hpl.jena.rdf.model.impl.rdfreaderfimpl.getreader(rdfreaderfimpl.java:110) @ com.hp.hpl.jena.rdf.model.impl.modelcom.read(modelcom.java:225) @ com.hp.hpl.jena.ontology.impl.ontmodelimpl.read(ontmodelimpl.java:2169) @ symenticweb.symenticweb.main(symenticweb.java:109) java result: 1
line no 109 model.read(inputstream, null, inputfileformat);
my code
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 { /** * program takes 4 parameters input file name * output file name input file format reasoning * level {rdfs, owl-dl} */ public static void main(string[] args) { //validate 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 input stream input file fileinputstream inputstream = null; printwriter writer = null; try { inputstream = new fileinputstream(inputfilename); } catch (filenotfoundexception e) { system.err.println("'" + inputfilename + "' invalid input file."); return; } //create output print writer results try { writer = new printwriter(outputfilename); } catch (filenotfoundexception e) { system.err.println("'" + outputfilename + "' invalid output file."); return; } //create appropriate jena model ontmodel model = null; if("none".equals(reasoninglevel.tolowercase())) { /* * "none" jena model owl_dl * ontologies loaded , no inference enabled */ model = modelfactory.createontologymodel( ontmodelspec.owl_dl_mem); } else if("rdfs".equals(reasoninglevel.tolowercase())) { /* * "rdfs" jena model owl_dl * ontologies loaded , rdfs inference enabled */ model = modelfactory.createontologymodel( ontmodelspec.owl_dl_mem_rdfs_inf); } else if("owl".equals(reasoninglevel.tolowercase())) { /* * "owl" jena model owl_dl ontologies * wrapped around 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 1 of <none|rdfs|owl>."); return; } //load facts model model.read(inputstream, null, inputfileformat); //validate file validityreport validityreport = model.validate(); if(validityreport != null && !validityreport.isvalid()) { iterator = validityreport.getreports(); while(i.hasnext()) { system.err.println( ((validityreport.report)i.next()).getdescription()); } return; } //iterate on individuals, print statements them extendediterator iindividuals = model.listindividuals(); while(iindividuals.hasnext()) { individual = (individual)iindividuals.next(); printindividual(i, writer); } iindividuals.close(); writer.close(); model.close(); } /** * print information individual * @param individual output * @param writer writer output */ public static void printindividual( individual i, printwriter writer) { //print local name of individual (to keep terse) writer.println("individual: " + i.getlocalname()); //print statements 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 serialized rdf, , rdf can serialized in number of different formats. jena rdf-based tool, , you'll need have rdf serialization of ontology in order jena able read it.
fortunately, files ending in .owl typically (though not always) rdf/xml serializations of rdf encoding of owl ontology. haven't shown ontology, can't sure yet, likely, if change
string inputfileformat = "owl"; to
string inputfileformat = "rdf/xml"; you'll fine. (this assuming .owl file rdf/xml.)
Comments
Post a Comment