2016-04-27 19 views
0

使用我们用来获取classexpressions这样如何在更新OWL API 3.X到4.X之后获取子类,超类?

cls.getSuperClasses(ont) 

更新版本4.X我们试图用EntitySearcher但它返回空套3.x版本。

EntitySearcher.getSuperClasses(cls, ontology) 

全码:

public static void test() throws OWLOntologyCreationException { 

    OWLOntologyManager manager = OWLManager.createOWLOntologyManager(); 
    OWLDataFactory factory = manager.getOWLDataFactory(); 
    OWLOntology ontology; 

    File file = new File("assets/ontologies/zebra.owl"); 
    ontology = manager.loadOntologyFromOntologyDocument(file); 

    OWLClass cls = factory.getOWLClass(IRI.create(ontology.getOntologyID().getOntologyIRI() + "#" + "Color")); 
    Set<OWLClassExpression> parentClasses = collect(EntitySearcher.getSuperClasses(cls, ontology).iterator()); 

    System.out.println(parentClasses.size()); 
} 

public static Set<OWLClassExpression> collect(Iterator<OWLClassExpression> i) { 

    Set<OWLClassExpression> set = new HashSet<OWLClassExpression>(); 
    while (i.hasNext()) { 
     OWLClassExpression res = i.next(); 
     set.add(res); 
    } 
    return set; 
} 

使用本体是zebra.owl /斑马里德尔或爱因斯坦谜语 - DB link

预期结果(3.X或门徒):

inverse (has_color) some House 

回答

1

问题是这里:

ontology.getOntologyID().getOntologyIRI()

在OWLAPI 4 getOntologyIRI不返回IRI而是Optional<IRI>代表事实的本体可能没有一个IRI。

如果你的代码更改为

ontology.getOntologyID().getOntologyIRI().get()

代码作品和版画1

我已将此修复程序添加到the migration suggestions

+0

对我感到羞耻:/。谢谢。 –