[英]parsing owl file
Thanks for the previous posts. 感谢您以前的帖子。 That helped a lot in parsing the owl file.
这对解析owl文件很有帮助。 Please look at the following code.
请看下面的代码。
OWLOntologyManager manager = OWLManager.createOWLOntologyManager();
OWLDataFactory factory = manager.getOWLDataFactory();
File file = new File("sample.owl");
OWLOntology localOntology = manager.loadOntologyFromOntologyDocument(file);
System.out.println("Loaded ontology: " + localOntology);
IRI documentIRI = manager.getOntologyDocumentIRI(localOntology);
System.out.println(" from: " + documentIRI);
OWLClass clsAMethodA = factory.getOWLClass(documentIRI);
The examples stated in the documentation of owl uses IRI that right now doesnot exists. owl文档中所述的示例使用的IRI目前不存在。 I am not understanding how do i extract all classes of the owl file.
我不明白如何提取猫头鹰文件的所有类。 Where should i save the classes.
我应该在哪里保存课程。 How do i go about in saving those classes??
如何保存这些课程? Any help?
有什么帮助吗?
You need to import the OWL API and then follow a code like mine. 您需要导入OWL API,然后遵循类似于我的代码。 I am getting all the logical axioms.
我得到了所有合乎逻辑的公理。 From axioms, you can extract other modelling elements such as classes and individuals.
您可以从公理中提取其他建模元素,例如类和个人。
OWLOntologyManager manager = OWLManager.createOWLOntologyManager(); OWLOntology localOntology=null; File file=new File("ontology/pizza.owl"); if (file == null) return; //loading the ontology try { localOntology = manager.loadOntologyFromOntologyDocument(file); } catch (OWLOntologyCreationException e) { e.printStackTrace(); } //get logical axioms Set<OWLLogicalAxiom> ax = localOntology.getLogicalAxioms();
import com.hp.hpl.jena.ontology.OntClass;
import com.hp.hpl.jena.ontology.OntModel;
import com.hp.hpl.jena.rdf.model.ModelFactory;
import com.hp.hpl.jena.util.FileManager;
import com.hp.hpl.jena.util.iterator.ExtendedIterator;
import java.io.InputStream;
import java.util.Iterator;
import java.util.List;
public class IteratingRDFM {
static final String inputFileName = "D:\\SBIRS.owl";
public static void main(String args[]) {
try {
//create the reasoning model using the base
OntModel inf = ModelFactory.createOntologyModel();
// use the FileManager to find the input file
InputStream in = FileManager.get().open(inputFileName);
if (in == null) {
throw new IllegalArgumentException("File: " + inputFileName + " not found);
}
inf.read(in, "");
String URI = "http://www.semanticweb.org/ontologies/2012/0/SBIRS.owl";
ExtendedIterator classes = inf.listClasses();
while (classes.hasNext()) {
OntClass obj = (OntClass) classes.next();
String className = obj.getLocalName().toString();
if (obj.hasSubClass()) {
for (Iterator i = obj.listSubClasses(true); i.hasNext();) {
OntClass c = (OntClass) i.next();
System.out.print(c.getLocalName().toString() +""+className);
}
}
}
} catch (Exception e) {
System.out.println(e.getMessage());
}
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.