2013-04-25 73 views

回答

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()); 
    } 



} 

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)); 

managerontology是从OWL-API标准的对象。

0

在OWL API(我用4.0.1)的新版本中,使用这些方法

Set<OWLEquivalentAxiom> axioms = localOntology.getEquivalentClassesAxiom(c1); 

代替

Set<OWLClassExpression> c1eqclasses = c1.getEquivalentClasses(localOntology); 

同样,对于其它呼叫。