有没有办法将OWL公理转换为曼彻斯特语法?我知道OWL-API将允许您将曼彻斯特语法中的句子解析为OWL功能语法,但我需要做的恰恰相反。
答案 0 :(得分: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());
}
}
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());
}
}
答案 1 :(得分: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的标准对象。
答案 2 :(得分:0)
在新版本的OWL API(我使用4.0.1)中,使用这些方法
Set<OWLClassExpression> c1eqclasses = c1.getEquivalentClasses(localOntology);
代替
<c:import url="/anotherpage"></c:import>
与其他电话类似。