有没有办法将OWL公理转换为曼彻斯特语法?我知道OWL-API将允许您将曼彻斯特语法中的句子解析为OWL函数式语法,但我需要做的恰恰相反。
发布于 2013-04-26 23:42:01
非常感谢你为我指明了正确的方向,这就是我解决问题的方法。
public static void main(String[] args) throws ParserException, OWLOntologyCreationException {
File file=new File("ontology/pizza.owl");
OWLOntologyManager manager;
OWLOntology localOntology=null;
OWLDataFactory factory ;
try {
//loading the ontology
manager=OWLManager.createOWLOntologyManager();
try {
localOntology = manager.loadOntologyFromOntologyDocument(file);
} catch (OWLOntologyCreationException e) {
e.printStackTrace();
}
factory = localOntology.getOWLOntologyManager().getOWLDataFactory();
OWLOntologyFormat format = manager.getOntologyFormat(localOntology);
System.out.println(" format: " + format);
ManchesterOWLSyntaxOntologyFormat manSyntaxFormat = new ManchesterOWLSyntaxOntologyFormat();
if(format.isPrefixOWLOntologyFormat()) {
manSyntaxFormat.copyPrefixesFrom(format.asPrefixOWLOntologyFormat());
}
manager.setOntologyFormat(localOntology, manSyntaxFormat);
manager.saveOntology(localOntology, manSyntaxFormat);
System.out.println("Manchester syntax: --- saved in Manchester.owl");
ManchesterOWLSyntaxOWLObjectRendererImpl rendering = new ManchesterOWLSyntaxOWLObjectRendererImpl();
OWLClass c1 = factory.getOWLClass(IRI.create("http://www.co-ode.org/ontologies/pizza/pizza.owl#IceCream"));
Set<OWLClassExpression> c1eqclasses = c1.getEquivalentClasses(localOntology);
for(OWLClassExpression c1e : c1eqclasses)
System.out.println("Equivalent: "+rendering.render(c1e));
c1eqclasses = c1.getDisjointClasses(localOntology);
for(OWLClassExpression c1e : c1eqclasses)
System.out.println("Disjoint: "+rendering.render(c1e));
c1eqclasses = c1.getSubClasses(localOntology);
for(OWLClassExpression c1e : c1eqclasses)
System.out.println("Subclass: "+rendering.render(c1e));
c1eqclasses = c1.getSuperClasses(localOntology);
for(OWLClassExpression c1e : c1eqclasses)
System.out.println("Superclass: "+rendering.render(c1e));
}
catch (OWLOntologyStorageException e) {
System.out.println("Could not save ontology: " + e.getMessage());
}
}
发布于 2013-04-26 03:16:21
OWL-API还允许您读取以函数式语法编写的本体,并将其转换为曼彻斯特语法。
将本体编写为以曼彻斯特语法序列化的文件的代码示例:
File file = new File("/home/foo/bar.owl");
OWLOntologyFormat format = manager.getOntologyFormat(ontology);
ManchesterOWLSyntaxOntologyFormat manSyntaxFormat =
new ManchesterOWLSyntaxOntologyFormat();
manager.saveOntology(ontology, manSyntaxFormat, IRI.create(file));manager和ontology是来自OWL-API的标准对象。
发布于 2015-10-28 06:35:43
在新版本的OWL API (我使用4.0.1)中,使用以下方法
Set<OWLEquivalentAxiom> axioms = localOntology.getEquivalentClassesAxiom(c1);相反,
Set<OWLClassExpression> c1eqclasses = c1.getEquivalentClasses(localOntology);其他调用也是如此。
https://stackoverflow.com/questions/16218139
复制相似问题