本文整理汇总了Java中org.semanticweb.owlapi.apibinding.OWLManager.getOWLDataFactory方法的典型用法代码示例。如果您正苦于以下问题:Java OWLManager.getOWLDataFactory方法的具体用法?Java OWLManager.getOWLDataFactory怎么用?Java OWLManager.getOWLDataFactory使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.semanticweb.owlapi.apibinding.OWLManager
的用法示例。
在下文中一共展示了OWLManager.getOWLDataFactory方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: loadVariables
import org.semanticweb.owlapi.apibinding.OWLManager; //导入方法依赖的package包/类
static Set<OWLClass> loadVariables(String filename) {
try {
if (filename.isEmpty()) {
return Collections.emptySet();
}
OWLDataFactory factory = OWLManager.getOWLDataFactory();
Set<OWLClass> variables = new HashSet<>();
for (String line : Files.readAllLines(Paths.get(filename))) {
if (!line.isEmpty()) {
variables.add(factory.getOWLClass(IRI.create(line)));
}
}
return variables;
} catch (IOException e) {
System.err.println("Error while reading file '" + filename + "'.");
System.err.println(e.getMessage());
return null;
}
}
示例2: testUnsatifiabilityDueToClashInABoxAssertions
import org.semanticweb.owlapi.apibinding.OWLManager; //导入方法依赖的package包/类
/**
* Atomic clash
*/
public void testUnsatifiabilityDueToClashInABoxAssertions() {
OWLDataFactory factory = OWLManager.getOWLDataFactory();
OWLOntologyManager manager = OWLManager.createOWLOntologyManager();
OWLClassExpression expr1 = factory.getOWLClass(IRI.create(String.format("%s#%s", PREFIX, "A")));
OWLClassExpression expr2 = factory.getOWLObjectComplementOf(expr1);
OWLNamedIndividual indiv = factory.getOWLNamedIndividual(IRI.create(String.format("%s#%s", PREFIX, "a")));
OWLIndividualAxiom fact1 = factory.getOWLClassAssertionAxiom(expr1, indiv);
OWLIndividualAxiom fact2 = factory.getOWLClassAssertionAxiom(expr2, indiv);
try {
OWLOntology ontology = manager.createOntology();
manager.addAxiom(ontology, fact1);
manager.addAxiom(ontology, fact2);
Wolpertinger wolpertinger = new Wolpertinger(ontology);
assertFalse(wolpertinger.isConsistent());
} catch (OWLOntologyCreationException e) {
e.printStackTrace();
fail();
}
}
示例3: setupGoal
import org.semanticweb.owlapi.apibinding.OWLManager; //导入方法依赖的package包/类
/**
* Initializes the unification goal with the given ontologies and axioms.
*
* @param bgOntologies
* a set of background ontologies with definitions
* @param subsumptions
* the goal subsumptions, as OWLSubClassOfAxioms
* @param equations
* the goal equations, as binary OWLEquivalentClassesAxioms
* @param dissubsumptions
* the goal dissubsumptions, as OWLSubClassOfAxioms
* @param disequations
* the goal disequations, as binary OWLEquivalentClassesAxioms
* @param owlThingAlias
* (optional) an alias for owl:Thing, e.g., 'SNOMED CT Concept'
* @param resetShortFormCache
* reset short form cache
*/
public void setupGoal(Set<OWLOntology> bgOntologies, Set<OWLSubClassOfAxiom> subsumptions,
Set<OWLEquivalentClassesAxiom> equations, Set<OWLSubClassOfAxiom> dissubsumptions,
Set<OWLEquivalentClassesAxiom> disequations, OWLClass owlThingAlias, boolean resetShortFormCache) {
algorithm = null;
unifierList = new ArrayList<>();
currentUnifierIndex = -1;
allUnifiersFound = false;
atomManager = new AtomManagerImpl();
if (resetShortFormCache) {
resetShortFormCache();
}
OWLClass top = (owlThingAlias != null) ? owlThingAlias : OWLManager.getOWLDataFactory().getOWLThing();
goal = new UelOntologyGoal(atomManager, new UelOntology(atomManager, bgOntologies, top));
goal.addPositiveAxioms(subsumptions);
goal.addPositiveAxioms(equations);
goal.addNegativeAxioms(dissubsumptions);
goal.addNegativeAxioms(disequations);
// define top as the empty conjunction
OWLDataFactory factory = OWLManager.getOWLDataFactory();
goal.addEquation(factory.getOWLEquivalentClassesAxiom(top, factory.getOWLObjectIntersectionOf()));
Integer topId = atomManager.createConceptName(top.toStringID());
atomManager.makeDefinitionVariable(topId);
goal.disposeOntology();
if (resetShortFormCache) {
cacheShortForms();
}
}
示例4: main
import org.semanticweb.owlapi.apibinding.OWLManager; //导入方法依赖的package包/类
static public void main (String[] args) throws OWLException,
InstantiationException, IllegalAccessException,
ClassNotFoundException {
String reasonerFactoryClassName = null;
String pathToOwlOntology = "/Users/piek/Desktop/NWR/NWR-ontology/version-0.6/ESO_version_0.6.owl";
OWLOntologyManager m = (OWLOntologyManager) OWLManager.getOWLDataFactory();
@SuppressWarnings("null")
//@Nonnull
IRI documentIRI = IRI.create(pathToOwlOntology);
OWLOntology ontology = m
.loadOntologyFromOntologyDocument(documentIRI);
// Report information about the ontology
System.out.println("Ontology Loaded...");
System.out.println("Document IRI: " + documentIRI);
System.out.println("Ontology : " + ontology.getOntologyID());
System.out.println("Format : "
+ m.getOntologyFormat(ontology));
@SuppressWarnings("null")
OwlReader2 simpleHierarchy = new OwlReader2(
(OWLReasonerFactory) Class.forName(reasonerFactoryClassName)
.newInstance(), ontology);
// Get Thing
OWLClass clazz = m.getOWLDataFactory().getOWLThing();
System.out.println("Class : " + clazz);
// Print the hierarchy below thing
simpleHierarchy.printHierarchy(clazz);
}
示例5: init
import org.semanticweb.owlapi.apibinding.OWLManager; //导入方法依赖的package包/类
@Before
public void init() throws Exception {
o = OWLManager.createOWLOntologyManager()
.createOntology(IRI.create("http://examp.le/"));
f = OWLManager.getOWLDataFactory();
cls1 = f.getOWLClass(IRI.create("http://examp.le/c1"));
op = f.getOWLObjectProperty(IRI.create("http://examp.le/p"));
cls2 = f.getOWLClass(IRI.create("http://examp.le/c2"));
ics = new IntegrityConstraintSet();
}
示例6: getEntailment
import org.semanticweb.owlapi.apibinding.OWLManager; //导入方法依赖的package包/类
private static OWLAxiom getEntailment() {
// Let's pick some class subsumption we want to explain
OWLDataFactory factory = OWLManager.getOWLDataFactory();
OWLClass subsumee = factory.getOWLClass(IRI.create("http://www.co-ode.org/ontologies/galen#LiquidFood"));
OWLClass subsumer = factory.getOWLClass(IRI.create("http://www.co-ode.org/ontologies/galen#Food"));
return factory.getOWLSubClassOfAxiom(subsumee, subsumer);
}
示例7: testUnsatisfiabilityDuetoSimpleSubsumptionViolation
import org.semanticweb.owlapi.apibinding.OWLManager; //导入方法依赖的package包/类
public void testUnsatisfiabilityDuetoSimpleSubsumptionViolation() {
OWLDataFactory factory = OWLManager.getOWLDataFactory();
OWLOntologyManager manager = OWLManager.createOWLOntologyManager();
OWLClassExpression classA = factory.getOWLClass(IRI.create(String.format("%s#%s", PREFIX, "A")));
OWLClassExpression classB = factory.getOWLClass(IRI.create(String.format("%s#%s", PREFIX, "B")));
OWLClassExpression complClassB = factory.getOWLObjectComplementOf(classB);
OWLNamedIndividual indiv = factory.getOWLNamedIndividual(IRI.create(String.format("%s#%s", PREFIX, "a")));
OWLIndividualAxiom fact1 = factory.getOWLClassAssertionAxiom(classA, indiv);
OWLIndividualAxiom fact2 = factory.getOWLClassAssertionAxiom(complClassB, indiv);
OWLSubClassOfAxiom subClOf = factory.getOWLSubClassOfAxiom(classA, classB);
try {
OWLOntology ontology = manager.createOntology();
manager.addAxiom(ontology, fact1);
manager.addAxiom(ontology, fact2);
manager.addAxiom(ontology, subClOf);
Wolpertinger wolpertinger = new Wolpertinger(ontology);
assertFalse(wolpertinger.isConsistent());
} catch (OWLOntologyCreationException e) {
e.printStackTrace();
fail();
}
}
示例8: testUnsatisfiabilityDueToConflictingAxioms1
import org.semanticweb.owlapi.apibinding.OWLManager; //导入方法依赖的package包/类
/**
* Smth like:
* A subClassOf B
* A subClassOf C
* C disjoint with B
* ...
*/
public void testUnsatisfiabilityDueToConflictingAxioms1() {
OWLDataFactory factory = OWLManager.getOWLDataFactory();
OWLOntologyManager manager = OWLManager.createOWLOntologyManager();
OWLClassExpression classA = factory.getOWLClass(IRI.create(String.format("%s#%s", PREFIX, "A")));
OWLClassExpression classB = factory.getOWLClass(IRI.create(String.format("%s#%s", PREFIX, "B")));
OWLClassExpression classC = factory.getOWLClass(IRI.create(String.format("%s#%s", PREFIX, "C")));
OWLNamedIndividual indiv = factory.getOWLNamedIndividual(IRI.create(String.format("%s#%s", PREFIX, "a")));
OWLIndividualAxiom fact1 = factory.getOWLClassAssertionAxiom(classA, indiv);
OWLSubClassOfAxiom axmAsubB = factory.getOWLSubClassOfAxiom(classA, classB);
OWLSubClassOfAxiom axmAsubC = factory.getOWLSubClassOfAxiom(classA, classC);
OWLDisjointClassesAxiom axmBdisC = factory.getOWLDisjointClassesAxiom(classB, classC);
try {
OWLOntology ontology = manager.createOntology();
manager.addAxiom(ontology, fact1);
manager.addAxiom(ontology, axmAsubB);
manager.addAxiom(ontology, axmAsubC);
manager.addAxiom(ontology, axmBdisC);
Wolpertinger wolpertinger = new Wolpertinger(ontology);
assertFalse(wolpertinger.isConsistent());
} catch (OWLOntologyCreationException e) {
e.printStackTrace();
fail();
}
}
示例9: testUnsatisfiabilityDoToFixedDomain1
import org.semanticweb.owlapi.apibinding.OWLManager; //导入方法依赖的package包/类
/**
* Smth like
* A subClassOf r min 5 B
* But we have only a domain with 4 elements ...
*/
public void testUnsatisfiabilityDoToFixedDomain1() {
OWLDataFactory factory = OWLManager.getOWLDataFactory();
OWLOntologyManager manager = OWLManager.createOWLOntologyManager();
OWLClassExpression classA = factory.getOWLClass(IRI.create(String.format("%s#%s", PREFIX, "A")));
OWLClassExpression classB = factory.getOWLClass(IRI.create(String.format("%s#%s", PREFIX, "B")));
OWLObjectPropertyExpression roleR = factory.getOWLObjectProperty(IRI.create(String.format("%s#%s", PREFIX, "r")));
OWLNamedIndividual indA = factory.getOWLNamedIndividual(IRI.create(String.format("%s#%s", PREFIX, "a")));
OWLNamedIndividual indB = factory.getOWLNamedIndividual(IRI.create(String.format("%s#%s", PREFIX, "b")));
OWLNamedIndividual indC = factory.getOWLNamedIndividual(IRI.create(String.format("%s#%s", PREFIX, "c")));
OWLNamedIndividual indD = factory.getOWLNamedIndividual(IRI.create(String.format("%s#%s", PREFIX, "d")));
OWLIndividualAxiom fact1 = factory.getOWLClassAssertionAxiom(classA, indA);
OWLIndividualAxiom fact2 = factory.getOWLClassAssertionAxiom(classA, indB);
OWLIndividualAxiom fact3 = factory.getOWLClassAssertionAxiom(classA, indC);
OWLIndividualAxiom fact4 = factory.getOWLClassAssertionAxiom(classA, indD);
OWLObjectMinCardinality exprRmin5B = factory.getOWLObjectMinCardinality(5, roleR, classB);
OWLSubClassOfAxiom axmAsubRsomeB = factory.getOWLSubClassOfAxiom(classA, exprRmin5B);
try {
OWLOntology ontology = manager.createOntology();
manager.addAxiom(ontology, fact1);
manager.addAxiom(ontology, fact2);
manager.addAxiom(ontology, fact3);
manager.addAxiom(ontology, fact4);
manager.addAxiom(ontology, axmAsubRsomeB);
Wolpertinger wolpertinger = new Wolpertinger(ontology);
assertFalse(wolpertinger.isConsistent());
} catch (OWLOntologyCreationException e) {
e.printStackTrace();
fail();
}
}
示例10: dataFactory
import org.semanticweb.owlapi.apibinding.OWLManager; //导入方法依赖的package包/类
@Bean
public OWLDataFactory dataFactory() {
return OWLManager.getOWLDataFactory();
}
示例11: createTempEvent
import org.semanticweb.owlapi.apibinding.OWLManager; //导入方法依赖的package包/类
public static SemanticEvent createTempEvent() {
String ONT_IRI = "http://IBCNServices.github.io/Accio-Ontology/SSNiot#";
String ONT_DUL_IRI = "http://IBCNServices.github.io/Accio-Ontology/ontologies/DUL.owl#";
String ONT_SSN_IRI = "http://IBCNServices.github.io/Accio-Ontology/ontologies/ssn#";
OWLDataFactory dfactory = OWLManager.getOWLDataFactory();
/**
* Construct OWL Individuals
*/
double value = 90;
String location = "testLocation";
long counterTemp = 1;
OWLClass tempObservationCls = dfactory.getOWLClass(ONT_IRI + "TemperatureObservation");
OWLClass tempSensingDeviceCls = dfactory.getOWLClass(ONT_IRI + "TemperatureSensor");
OWLClass tempSensorOutputCls = dfactory.getOWLClass(ONT_IRI + "TemperatureSensorOutput");
OWLClass tempObservationValCls = dfactory
.getOWLClass(ONT_IRI + "TemperatureObservationValue");
OWLClass tempPropCls = dfactory.getOWLClass(ONT_IRI + "Temperature");
OWLClass eventClass = dfactory.getOWLClass(ONT_IRI + "Event");
OWLClass placeClass = dfactory.getOWLClass(ONT_DUL_IRI + "Place");
// Create the individuals
OWLNamedIndividual tempObservation = dfactory
.getOWLNamedIndividual(ONT_IRI + "temperatureObservation_" + counterTemp);
OWLNamedIndividual tempSensingDevice = dfactory
.getOWLNamedIndividual(ONT_IRI + "temperatureSensor_" + counterTemp);
OWLNamedIndividual tempSensorOutput = dfactory
.getOWLNamedIndividual(ONT_IRI + "temperatureSensorOutput_" + counterTemp);
OWLNamedIndividual tempObservationVal = dfactory
.getOWLNamedIndividual(ONT_IRI + "temperatureObservationValue_" + counterTemp);
OWLNamedIndividual tempProperty = dfactory
.getOWLNamedIndividual(ONT_IRI + "temperatureProperty_" + counterTemp);
OWLNamedIndividual locationInd = dfactory
.getOWLNamedIndividual(ONT_IRI + "Place" + location);
OWLNamedIndividual eventInd = dfactory
.getOWLNamedIndividual(ONT_IRI + "Event_" + counterTemp);
// Create the data properties
OWLDataProperty hasDataValueProp = dfactory
.getOWLDataProperty(ONT_DUL_IRI + "hasDataValue");
// Create the object properties
OWLObjectProperty hasContextProp = dfactory.getOWLObjectProperty(ONT_IRI + "hasContext");
OWLObjectProperty hasValueProp = dfactory.getOWLObjectProperty(ONT_SSN_IRI + "hasValue");
OWLObjectProperty observedBy = dfactory.getOWLObjectProperty(ONT_SSN_IRI + "observedBy");
OWLObjectProperty observationResult = dfactory
.getOWLObjectProperty(ONT_SSN_IRI + "observationResult");
OWLObjectProperty observedProperty = dfactory
.getOWLObjectProperty(ONT_SSN_IRI + "observedProperty");
OWLObjectProperty hasLocationProp = dfactory
.getOWLObjectProperty(ONT_DUL_IRI + "hasLocation");
// Create the message
SemanticEvent message = new SemanticEvent(eventInd, "1", System.currentTimeMillis(), "TempStream");
// add the axioms
message.addAxiom(dfactory.getOWLClassAssertionAxiom(eventClass, eventInd));
message.addAxiom(dfactory.getOWLClassAssertionAxiom(tempObservationCls, tempObservation));
message.addAxiom(dfactory.getOWLClassAssertionAxiom(tempSensorOutputCls, tempSensorOutput));
message.addAxiom(dfactory.getOWLClassAssertionAxiom(tempObservationValCls, tempObservationVal));
message.addAxiom(dfactory.getOWLClassAssertionAxiom(tempSensingDeviceCls, tempSensingDevice));
message.addAxiom(dfactory.getOWLClassAssertionAxiom(placeClass, locationInd));
message.addAxiom(dfactory.getOWLClassAssertionAxiom(tempPropCls, tempProperty));
message.addAxiom(dfactory.getOWLDataPropertyAssertionAxiom(hasDataValueProp, tempObservationVal,
(double) value));
message.addAxiom(dfactory.getOWLObjectPropertyAssertionAxiom(hasValueProp, tempSensorOutput,
tempObservationVal));
message.addAxiom(dfactory.getOWLObjectPropertyAssertionAxiom(observationResult, tempObservation,
tempSensorOutput));
message.addAxiom(
dfactory.getOWLObjectPropertyAssertionAxiom(observedBy, tempObservation, tempSensingDevice));
message.addAxiom(
dfactory.getOWLObjectPropertyAssertionAxiom(observedProperty, tempObservation, tempProperty));
message.addAxiom(
dfactory.getOWLObjectPropertyAssertionAxiom(hasLocationProp, tempSensingDevice, locationInd));
message.addAxiom(dfactory.getOWLDataPropertyAssertionAxiom(hasDataValueProp, locationInd, location));
message.addAxiom(
dfactory.getOWLObjectPropertyAssertionAxiom(hasContextProp, eventInd, tempObservation));
return message;
}
示例12: createSmokeEvent
import org.semanticweb.owlapi.apibinding.OWLManager; //导入方法依赖的package包/类
public static SemanticEvent createSmokeEvent() {
String ONT_IRI = "http://IBCNServices.github.io/Accio-Ontology/SSNiot#";
String ONT_DUL_IRI = "http://IBCNServices.github.io/Accio-Ontology/ontologies/DUL.owl#";
String ONT_SSN_IRI = "http://IBCNServices.github.io/Accio-Ontology/ontologies/ssn#";
OWLDataFactory dfactory = OWLManager.getOWLDataFactory();
/**
* Construct OWL Individuals
*/
double value = 99;
String location = "testLocation";
long counterTemp = 1;
OWLClass tempObservationCls = dfactory.getOWLClass(ONT_IRI + "SmokeObservation");
OWLClass tempSensingDeviceCls = dfactory.getOWLClass(ONT_IRI + "SmokeSensor");
OWLClass tempSensorOutputCls = dfactory.getOWLClass(ONT_IRI + "SmokeSensorOutput");
OWLClass tempObservationValCls = dfactory
.getOWLClass(ONT_IRI + "SmokeObservationValue");
OWLClass tempPropCls = dfactory.getOWLClass(ONT_IRI + "Smoke");
OWLClass eventClass = dfactory.getOWLClass(ONT_IRI + "Event");
OWLClass placeClass = dfactory.getOWLClass(ONT_DUL_IRI + "Place");
// Create the individuals
OWLNamedIndividual tempObservation = dfactory
.getOWLNamedIndividual(ONT_IRI + "smokeObservation_" + counterTemp);
OWLNamedIndividual tempSensingDevice = dfactory
.getOWLNamedIndividual(ONT_IRI + "smokeSensor_" + counterTemp);
OWLNamedIndividual tempSensorOutput = dfactory
.getOWLNamedIndividual(ONT_IRI + "smokeSensorOutput_" + counterTemp);
OWLNamedIndividual tempObservationVal = dfactory
.getOWLNamedIndividual(ONT_IRI + "smokeObservationValue_" + counterTemp);
OWLNamedIndividual tempProperty = dfactory
.getOWLNamedIndividual(ONT_IRI + "smokeProperty_" + counterTemp);
OWLNamedIndividual locationInd = dfactory
.getOWLNamedIndividual(ONT_IRI + "Place" + location);
OWLNamedIndividual eventInd = dfactory
.getOWLNamedIndividual(ONT_IRI + "Event_" + counterTemp);
// Create the data properties
OWLDataProperty hasDataValueProp = dfactory
.getOWLDataProperty(ONT_DUL_IRI + "hasDataValue");
// Create the object properties
OWLObjectProperty hasContextProp = dfactory.getOWLObjectProperty(ONT_IRI + "hasContext");
OWLObjectProperty hasValueProp = dfactory.getOWLObjectProperty(ONT_SSN_IRI + "hasValue");
OWLObjectProperty observedBy = dfactory.getOWLObjectProperty(ONT_SSN_IRI + "observedBy");
OWLObjectProperty observationResult = dfactory
.getOWLObjectProperty(ONT_SSN_IRI + "observationResult");
OWLObjectProperty observedProperty = dfactory
.getOWLObjectProperty(ONT_SSN_IRI + "observedProperty");
OWLObjectProperty hasLocationProp = dfactory
.getOWLObjectProperty(ONT_DUL_IRI + "hasLocation");
// Create the message
SemanticEvent message = new SemanticEvent(eventInd, "2", System.currentTimeMillis(), "smokeStream");
// add the axioms
message.addAxiom(dfactory.getOWLClassAssertionAxiom(eventClass, eventInd));
message.addAxiom(dfactory.getOWLClassAssertionAxiom(tempObservationCls, tempObservation));
message.addAxiom(dfactory.getOWLClassAssertionAxiom(tempSensorOutputCls, tempSensorOutput));
message.addAxiom(dfactory.getOWLClassAssertionAxiom(tempObservationValCls, tempObservationVal));
message.addAxiom(dfactory.getOWLClassAssertionAxiom(tempSensingDeviceCls, tempSensingDevice));
message.addAxiom(dfactory.getOWLClassAssertionAxiom(placeClass, locationInd));
message.addAxiom(dfactory.getOWLClassAssertionAxiom(tempPropCls, tempProperty));
message.addAxiom(dfactory.getOWLDataPropertyAssertionAxiom(hasDataValueProp, tempObservationVal,
(double) value));
message.addAxiom(dfactory.getOWLObjectPropertyAssertionAxiom(hasValueProp, tempSensorOutput,
tempObservationVal));
message.addAxiom(dfactory.getOWLObjectPropertyAssertionAxiom(observationResult, tempObservation,
tempSensorOutput));
message.addAxiom(
dfactory.getOWLObjectPropertyAssertionAxiom(observedBy, tempObservation, tempSensingDevice));
message.addAxiom(
dfactory.getOWLObjectPropertyAssertionAxiom(observedProperty, tempObservation, tempProperty));
message.addAxiom(
dfactory.getOWLObjectPropertyAssertionAxiom(hasLocationProp, tempSensingDevice, locationInd));
message.addAxiom(dfactory.getOWLDataPropertyAssertionAxiom(hasDataValueProp, locationInd, location));
message.addAxiom(
dfactory.getOWLObjectPropertyAssertionAxiom(hasContextProp, eventInd, tempObservation));
return message;
}
示例13: SyntacticLocalityChecker
import org.semanticweb.owlapi.apibinding.OWLManager; //导入方法依赖的package包/类
public SyntacticLocalityChecker(boolean dualClasses, boolean dualProperties, boolean considerAnnotations, boolean ignoreAssertions){
this(dualClasses, dualProperties, considerAnnotations, ignoreAssertions, OWLManager.getOWLDataFactory());
}
示例14: initialize
import org.semanticweb.owlapi.apibinding.OWLManager; //导入方法依赖的package包/类
@Before
public void initialize() {
factory = OWLManager.getOWLDataFactory();
}
示例15: createSimpleGraphColoring
import org.semanticweb.owlapi.apibinding.OWLManager; //导入方法依赖的package包/类
private OWLOntology createSimpleGraphColoring() {
OWLOntology ontoColoring = null;
OWLDataFactory factory = OWLManager.getOWLDataFactory();
OWLOntologyManager manager = OWLManager.createOWLOntologyManager();
OWLObjectPropertyExpression edgeProp = factory.getOWLObjectProperty(IRI.create(String.format("%s#%s", PREFIX, "edge")));
OWLClassExpression classNode = factory.getOWLClass(IRI.create(String.format("%s#%s", PREFIX, "Node")));
OWLClassExpression classBlue = factory.getOWLClass(IRI.create(String.format("%s#%s", PREFIX, "Blue")));
OWLClassExpression classRed = factory.getOWLClass(IRI.create(String.format("%s#%s", PREFIX, "Red")));
OWLClassExpression classGreen = factory.getOWLClass(IRI.create(String.format("%s#%s", PREFIX, "Green")));
OWLNamedIndividual indNode1 = factory.getOWLNamedIndividual(IRI.create(String.format("%s#%s", PREFIX, "node1")));
OWLNamedIndividual indNode2 = factory.getOWLNamedIndividual(IRI.create(String.format("%s#%s", PREFIX, "node2")));
OWLNamedIndividual indNode3 = factory.getOWLNamedIndividual(IRI.create(String.format("%s#%s", PREFIX, "node3")));
OWLNamedIndividual indNode4 = factory.getOWLNamedIndividual(IRI.create(String.format("%s#%s", PREFIX, "node4")));
// now the facts
// nodes
OWLIndividualAxiom axmNodeInst4 =factory.getOWLClassAssertionAxiom(classNode, indNode4);
OWLIndividualAxiom axmNodeInst3 =factory.getOWLClassAssertionAxiom(classNode, indNode3);
OWLIndividualAxiom axmNodeInst2 =factory.getOWLClassAssertionAxiom(classNode, indNode2);
OWLIndividualAxiom axmNodeInst1 =factory.getOWLClassAssertionAxiom(classNode, indNode1);
// 1
// | \
// | 3 - 4
// | /
// 2
//
OWLIndividualAxiom axmEdge12 = factory.getOWLObjectPropertyAssertionAxiom(edgeProp, indNode1, indNode2);
OWLIndividualAxiom axmEdge13 = factory.getOWLObjectPropertyAssertionAxiom(edgeProp, indNode1, indNode3);
OWLIndividualAxiom axmEdge23 = factory.getOWLObjectPropertyAssertionAxiom(edgeProp, indNode2, indNode3);
OWLIndividualAxiom axmEdge34 = factory.getOWLObjectPropertyAssertionAxiom(edgeProp, indNode3, indNode4);
// symmetry of edge property
OWLObjectPropertyAxiom axmEdgeSym = factory.getOWLSymmetricObjectPropertyAxiom(edgeProp);
// axioms
OWLObjectUnionOf exprColorUnion = factory.getOWLObjectUnionOf(classBlue, classRed, classGreen);
OWLSubClassOfAxiom axmNodeColorings = factory.getOWLSubClassOfAxiom(classNode, exprColorUnion);
// coloring constraints
OWLSubClassOfAxiom axmRedConstraint = factory.getOWLSubClassOfAxiom(classRed, factory.getOWLObjectAllValuesFrom(edgeProp, factory.getOWLObjectUnionOf(classGreen, classBlue)));
OWLSubClassOfAxiom axmBlueConstraint = factory.getOWLSubClassOfAxiom(classBlue, factory.getOWLObjectAllValuesFrom(edgeProp, factory.getOWLObjectUnionOf(classGreen, classRed)));
OWLSubClassOfAxiom axmGreenConstraint = factory.getOWLSubClassOfAxiom(classGreen, factory.getOWLObjectAllValuesFrom(edgeProp, factory.getOWLObjectUnionOf(classRed, classBlue)));
OWLDisjointClassesAxiom axmDisColors = factory.getOWLDisjointClassesAxiom(classRed, classBlue, classGreen);
try {
ontoColoring = manager.createOntology();
manager.addAxiom(ontoColoring, axmNodeInst1);
manager.addAxiom(ontoColoring, axmNodeInst2);
manager.addAxiom(ontoColoring, axmNodeInst3);
manager.addAxiom(ontoColoring, axmNodeInst4);
manager.addAxiom(ontoColoring, axmEdge12);
manager.addAxiom(ontoColoring, axmEdge13);
manager.addAxiom(ontoColoring, axmEdge23);
manager.addAxiom(ontoColoring, axmEdge34);
manager.addAxiom(ontoColoring, axmEdgeSym);
manager.addAxiom(ontoColoring, axmNodeColorings);
manager.addAxiom(ontoColoring, axmRedConstraint);
manager.addAxiom(ontoColoring, axmBlueConstraint);
manager.addAxiom(ontoColoring, axmGreenConstraint);
manager.addAxiom(ontoColoring, axmDisColors);
} catch (OWLOntologyCreationException e) {
e.printStackTrace();
}
return ontoColoring;
}