有没有办法将 OWL 公理转换为曼彻斯特语法?我知道 OWL-API 将允许您将曼彻斯特语法中的句子解析为 OWL 函数式语法,但我需要完全相反。
问问题
1076 次
3 回答
3
非常感谢您为我指明了正确的方向,这就是我解决问题的方法。
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-26T15:42:01.373 回答
2
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 的标准对象。
于 2013-04-25T19:16:21.447 回答
0
在新版本的OWL API(我用的是4.0.1)中,使用这些方法
Set<OWLEquivalentAxiom> axioms = localOntology.getEquivalentClassesAxiom(c1);
反而
Set<OWLClassExpression> c1eqclasses = c1.getEquivalentClasses(localOntology);
对于其他呼叫也是如此。
于 2015-10-27T22:35:43.033 回答