如何使用 owl API 在一行中打印 class、sub 属性 和范围?
How do I Print class,sub property and range at one row using owl API?
我需要打印 [Class] - [Class sub-属性] - [Class range] also [Class super 属性] 在一行中使用 owl API.
我试过了,但我只得到 [class],而且是 [sub-属性]
下面是我的代码:
package com.ifour.example.owl;
import java.io.File;
import org.semanticweb.owlapi.apibinding.OWLManager;
import org.semanticweb.owlapi.model.AxiomType;
import org.semanticweb.owlapi.model.IRI;
import org.semanticweb.owlapi.model.OWLClass;
import org.semanticweb.owlapi.model.OWLDataProperty;
import org.semanticweb.owlapi.model.OWLDataPropertyDomainAxiom;
import org.semanticweb.owlapi.model.OWLNamedIndividual;
import org.semanticweb.owlapi.model.OWLObjectProperty;
import org.semanticweb.owlapi.model.OWLObjectPropertyDomainAxiom;
import org.semanticweb.owlapi.model.OWLOntology;
import org.semanticweb.owlapi.model.OWLOntologyManager;
public class IterateOWLDetails2 {
public static void main(String args[]) {
try {
OWLOntologyManager manager = OWLManager.createOWLOntologyManager();
IRI iri = IRI.create(new File("src/main/webapp/resources/inputfile/owlfile/pizza.owl"));
OWLOntology moduleOWL = manager.loadOntologyFromOntologyDocument(iri);
java.util.Set<OWLClass> classes;
java.util.Set<OWLObjectProperty> prop;
java.util.Set<OWLDataProperty> dataProp;
java.util.Set<OWLNamedIndividual> individuals;
classes = moduleOWL.getClassesInSignature();
prop = moduleOWL.getObjectPropertiesInSignature();
dataProp = moduleOWL.getDataPropertiesInSignature();
individuals = moduleOWL.getIndividualsInSignature();
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 : moduleOWL.getAxioms(AxiomType.OBJECT_PROPERTY_DOMAIN)) {
if (op.getDomain().equals(cls)) {
for (OWLObjectProperty oop : op.getObjectPropertiesInSignature()) {
if (cls.getIRI().getShortForm().equals(oop.getIRI().getShortForm()))
continue;
System.out.println("\t\t +: " + oop.getIRI().getShortForm() + "==Object Property");
}
}
}
System.out.println(" \tData Property Domain");
for (OWLDataPropertyDomainAxiom dp : moduleOWL.getAxioms(AxiomType.DATA_PROPERTY_DOMAIN)) {
if (dp.getDomain().equals(cls)) {
for (OWLDataProperty odp : dp.getDataPropertiesInSignature()) {
System.out.println("\t\t +: " + odp.getIRI().getShortForm() + "==Data Property");
}
}
}
}
} // end try
catch (Exception e) {
System.out.println("Failed to load ontology/ies");
e.getLocalizedMessage();
e.printStackTrace();
} // end catch`
}
}
我有如下数据
<owl:ObjectProperty rdf:about="http://www.co-ode.org/ontologies/pizza/pizza.owl#hasBase">
<rdfs:subPropertyOf rdf:resource="http://www.co-ode.org/ontologies/pizza/pizza.owl#hasIngredient"/>
<owl:inverseOf rdf:resource="http://www.co-ode.org/ontologies/pizza/pizza.owl#isBaseOf"/>
<rdf:type rdf:resource="http://www.w3.org/2002/07/owl#FunctionalProperty"/>
<rdf:type rdf:resource="http://www.w3.org/2002/07/owl#InverseFunctionalProperty"/>
<rdfs:domain rdf:resource="http://www.co-ode.org/ontologies/pizza/pizza.owl#Pizza"/>
<rdfs:range rdf:resource="http://www.co-ode.org/ontologies/pizza/pizza.owl#PizzaBase"/>
</owl:ObjectProperty>
我需要从文件中获取域、范围、子 属性。我的文件中没有 subclass 属性 所以请不要使用 ontology 的列表 subclass 方法给出解决方案。
我已经迭代了所有 classes,现在我必须得到 class 的各种 属性,例如迭代 [=] 的域、范围、sub-属性 等31=].
我已经使用下面的代码打印了我的输出,现在我的问题已经解决了
像这样使用 属性 getObjectPropertyRangeAxioms(oop)
for(OWLObjectPropertyRangeAxiom range:moduleOWL.getObjectPropertyRangeAxioms(oop)) {
for(OWLEntity rangeStr : range.getSignature()) {
//System.out.println("\t\t ==========: " + rangeStr );
if(!rangeStr.containsEntityInSignature(oop)) {
System.out.println("\t\t -: " + rangeStr.toString().replaceAll("<|>", "") );
str = rangeStr.toString().replaceAll("<|>", "");
}
}
}
我需要打印 [Class] - [Class sub-属性] - [Class range] also [Class super 属性] 在一行中使用 owl API.
我试过了,但我只得到 [class],而且是 [sub-属性]
下面是我的代码:
package com.ifour.example.owl;
import java.io.File;
import org.semanticweb.owlapi.apibinding.OWLManager;
import org.semanticweb.owlapi.model.AxiomType;
import org.semanticweb.owlapi.model.IRI;
import org.semanticweb.owlapi.model.OWLClass;
import org.semanticweb.owlapi.model.OWLDataProperty;
import org.semanticweb.owlapi.model.OWLDataPropertyDomainAxiom;
import org.semanticweb.owlapi.model.OWLNamedIndividual;
import org.semanticweb.owlapi.model.OWLObjectProperty;
import org.semanticweb.owlapi.model.OWLObjectPropertyDomainAxiom;
import org.semanticweb.owlapi.model.OWLOntology;
import org.semanticweb.owlapi.model.OWLOntologyManager;
public class IterateOWLDetails2 {
public static void main(String args[]) {
try {
OWLOntologyManager manager = OWLManager.createOWLOntologyManager();
IRI iri = IRI.create(new File("src/main/webapp/resources/inputfile/owlfile/pizza.owl"));
OWLOntology moduleOWL = manager.loadOntologyFromOntologyDocument(iri);
java.util.Set<OWLClass> classes;
java.util.Set<OWLObjectProperty> prop;
java.util.Set<OWLDataProperty> dataProp;
java.util.Set<OWLNamedIndividual> individuals;
classes = moduleOWL.getClassesInSignature();
prop = moduleOWL.getObjectPropertiesInSignature();
dataProp = moduleOWL.getDataPropertiesInSignature();
individuals = moduleOWL.getIndividualsInSignature();
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 : moduleOWL.getAxioms(AxiomType.OBJECT_PROPERTY_DOMAIN)) {
if (op.getDomain().equals(cls)) {
for (OWLObjectProperty oop : op.getObjectPropertiesInSignature()) {
if (cls.getIRI().getShortForm().equals(oop.getIRI().getShortForm()))
continue;
System.out.println("\t\t +: " + oop.getIRI().getShortForm() + "==Object Property");
}
}
}
System.out.println(" \tData Property Domain");
for (OWLDataPropertyDomainAxiom dp : moduleOWL.getAxioms(AxiomType.DATA_PROPERTY_DOMAIN)) {
if (dp.getDomain().equals(cls)) {
for (OWLDataProperty odp : dp.getDataPropertiesInSignature()) {
System.out.println("\t\t +: " + odp.getIRI().getShortForm() + "==Data Property");
}
}
}
}
} // end try
catch (Exception e) {
System.out.println("Failed to load ontology/ies");
e.getLocalizedMessage();
e.printStackTrace();
} // end catch`
}
}
我有如下数据
<owl:ObjectProperty rdf:about="http://www.co-ode.org/ontologies/pizza/pizza.owl#hasBase">
<rdfs:subPropertyOf rdf:resource="http://www.co-ode.org/ontologies/pizza/pizza.owl#hasIngredient"/>
<owl:inverseOf rdf:resource="http://www.co-ode.org/ontologies/pizza/pizza.owl#isBaseOf"/>
<rdf:type rdf:resource="http://www.w3.org/2002/07/owl#FunctionalProperty"/>
<rdf:type rdf:resource="http://www.w3.org/2002/07/owl#InverseFunctionalProperty"/>
<rdfs:domain rdf:resource="http://www.co-ode.org/ontologies/pizza/pizza.owl#Pizza"/>
<rdfs:range rdf:resource="http://www.co-ode.org/ontologies/pizza/pizza.owl#PizzaBase"/>
</owl:ObjectProperty>
我需要从文件中获取域、范围、子 属性。我的文件中没有 subclass 属性 所以请不要使用 ontology 的列表 subclass 方法给出解决方案。 我已经迭代了所有 classes,现在我必须得到 class 的各种 属性,例如迭代 [=] 的域、范围、sub-属性 等31=].
我已经使用下面的代码打印了我的输出,现在我的问题已经解决了 像这样使用 属性 getObjectPropertyRangeAxioms(oop)
for(OWLObjectPropertyRangeAxiom range:moduleOWL.getObjectPropertyRangeAxioms(oop)) {
for(OWLEntity rangeStr : range.getSignature()) {
//System.out.println("\t\t ==========: " + rangeStr );
if(!rangeStr.containsEntityInSignature(oop)) {
System.out.println("\t\t -: " + rangeStr.toString().replaceAll("<|>", "") );
str = rangeStr.toString().replaceAll("<|>", "");
}
}
}