我正在编写一个模块,它将RDF文件转换为OWL文件,然后处理获得的OWL文件。我使用OWL API将RDF文件转换为OWL文件,如下所示:
OWLOntologyManager man = OWLManager.createOWLOntologyManager();
OWLOntology con = man.loadOntologyFromOntologyDocument(new File(filePath+"/OWL/"+fileName));
try (OutputStream out = new FileOutputStream("OWL/"+fileName.substring(0,fileName.length()-4)+".owl"))
{
man.saveOntology(con, new OWLXMLOntologyFormat(), out);
out.flush();
}
然后我尝试使用Protege API读取OWL文件中存在的类,如下所示:
try {
OWLModel owlModel = ProtegeOWL.createJenaOWLModelFromURI(uri);
//Getting the named classes present in the OWL File
Collection classes = owlModel.getUserDefinedOWLNamedClasses();
for (Iterator it = classes.iterator(); it.hasNext();)
{
DefaultRDFSNamedClass cls = (DefaultRDFSNamedClass) it.next();
token = cls.getBrowserText();
System.out.println(token);
}
}
catch (OntologyLoadException ex)
{
System.out.println("OWL file processing error");
}
这适用于某些OWL文件,但对于某些人,我会收到错误,例如:
SEVERE: An error occurred at parsing the OWL ontology
@A0_f1d2f23a_ce0f_437a_a0a7_2f00f43f198e
at line 5958 and column 88.
Jena parse error message: {E201} Multiple children of property element -- com.hp.hpl.jena.rdf.arp.impl.XMLHandler$1publicId: http://www.w3.org/2002/07/owl; lineNumber: 5958; columnNumber: 88; {E201} Multiple children of property element
at com.hp.hpl.jena.rdf.arp.impl.XMLHandler.warning(XMLHandler.java:199)
at com.hp.hpl.jena.rdf.arp.impl.XMLHandler.warning(XMLHandler.java:194)
at com.hp.hpl.jena.rdf.arp.impl.ParserSupport.warning(ParserSupport.java:214)
at com.hp.hpl.jena.rdf.arp.states.Frame.warning(Frame.java:52)
at com.hp.hpl.jena.rdf.arp.states.WantLiteralValueOrDescription.startElement(WantLiteralValueOrDescription.java:26)
at com.hp.hpl.jena.rdf.arp.impl.XMLHandler.startElement(XMLHandler.java:137)
at org.apache.xerces.parsers.AbstractSAXParser.startElement(Unknown Source)
at org.apache.xerces.impl.XMLNamespaceBinder.handleStartElement(Unknown Source)
at org.apache.xerces.impl.XMLNamespaceBinder.startElement(Unknown Source)
at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanStartElement(Unknown Source)
at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl$FragmentContentDispatcher.dispatch(Unknown Source)
at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unknown Source)
at org.apache.xerces.parsers.DTDConfiguration.parse(Unknown Source)
at org.apache.xerces.parsers.DTDConfiguration.parse(Unknown Source)
at org.apache.xerces.parsers.XMLParser.parse(Unknown Source)
at org.apache.xerces.parsers.AbstractSAXParser.parse(Unknown Source)
at com.hp.hpl.jena.rdf.arp.impl.RDFXMLParser.parse(RDFXMLParser.java:142)
at com.hp.hpl.jena.rdf.arp.ARP.load(ARP.java:143)
at edu.stanford.smi.protegex.owl.jena.parser.ProtegeOWLParser$1.invokeARP(Unknown Source)
at edu.stanford.smi.protegex.owl.jena.parser.ProtegeOWLParser.loadTriples(Unknown Source)
at edu.stanford.smi.protegex.owl.jena.parser.ProtegeOWLParser.run(Unknown Source)
at edu.stanford.smi.protegex.owl.jena.JenaKnowledgeBaseFactory.loadKnowledgeBase(Unknown Source)
at edu.stanford.smi.protege.model.Project.loadDomainKB(Unknown Source)
at edu.stanford.smi.protege.model.Project.createDomainKnowledgeBase(Unknown Source)
at edu.stanford.smi.protegex.owl.jena.creator.OwlProjectFromUriCreator.create(Unknown Source)
at edu.stanford.smi.protegex.owl.ProtegeOWL.createJenaOWLModelFromURI(Unknown Source)
例如,当我处理此文件时会发生这种情况: http://www.w3.org/2004/08/TalkFiles/2005/Talks.rdf
但是当我使用Protege GUI打开转换后的OWL文件时,它完全正常,我能够看到所有类。我无法弄清楚出了什么问题。有人可以帮帮我吗? 谢谢。