我有一个本体文件,我可以获取其中的所有类(我使用的是OWL-API)。好吧,我应该为每个类检索存在于我的文件.owl中的数据属性和对象属性,有什么方法可以使用OWL-API来获取它们吗?
答案 0 :(得分:3)
public void test(){
File file = new File("Ontology.owl");
OWLOntologyManager manager = OWLManager.createOWLOntologyManager();
OWLOntology ontology;
try {
ontology = manager.loadOntologyFromOntologyDocument(file);
Set<OWLClass> classes;
Set<OWLObjectProperty> prop;
Set<OWLDataProperty> dataProp;
Set<OWLNamedIndividual> individuals;
classes = ontology.getClassesInSignature();
prop = ontology.getObjectPropertiesInSignature();
dataProp = ontology.getDataPropertiesInSignature();
individuals = ontology.getIndividualsInSignature();
//configurator = new OWLAPIOntologyConfigurator(this);
System.out.println("Classes");
System.out.println("--------------------------------");
for (OWLClass cls : classes) {
System.out.println("+: " + cls.getIRI().getShortForm());
System.out.println(" \tObject Property Domain");
for (OWLObjectPropertyDomainAxiom op : ontology.getAxioms(AxiomType.OBJECT_PROPERTY_DOMAIN)) {
if (op.getDomain().equals(cls)) {
for(OWLObjectProperty oop : op.getObjectPropertiesInSignature()){
System.out.println("\t\t +: " + oop.getIRI().getShortForm());
}
//System.out.println("\t\t +: " + op.getProperty().getNamedProperty().getIRI().getShortForm());
}
}
System.out.println(" \tData Property Domain");
for (OWLDataPropertyDomainAxiom dp : ontology.getAxioms(AxiomType.DATA_PROPERTY_DOMAIN)) {
if (dp.getDomain().equals(cls)) {
for(OWLDataProperty odp : dp.getDataPropertiesInSignature()){
System.out.println("\t\t +: " + odp.getIRI().getShortForm());
}
//System.out.println("\t\t +:" + dp.getProperty());
}
}
}
} catch (OWLOntologyCreationException ex) {
Logger.getLogger(OntologyAPI.class.getName()).log(Level.SEVERE, null, ex);
}
}
答案 1 :(得分:0)
我认为这应该是一个答案,而不是评论。
要获取类的属性,只需使用getSuperClasses即可。所以,如果你有一个类似的课程
A
:subClassOf (r some B)
然后(getSuperClasses A)
将返回一个包含OWLClassExpression
的{{1}}的集合,该集合将是OWLObjectSomeValuesFrom
的实例。反过来,您可以使用getProperty
获取该属性。