use of org.apache.jena.ontology.OntProperty in project Vitro by vivo-project.
the class SimpleReasonerInversePropertyTest method addABoxAssertion1.
/*
* basic scenarios around adding abox data
*
* Create a Tbox with property P inverseOf property Q.
* Add a statement a P b, and verify that b Q a is inferred.
* Add a statement c Q d and verify that d Q c is inferred.
*/
public void addABoxAssertion1(boolean sameAs) {
// set up the tbox
OntModel tBox = createTBoxModel();
OntProperty P = createObjectProperty(tBox, "http://test.vivo/P", "property P");
OntProperty Q = createObjectProperty(tBox, "http://test.vivo/Q", "property Q");
setInverse(P, Q);
// this is the model to receive abox inferences
Model inf = ModelFactory.createDefaultModel();
// create an abox and register the SimpleReasoner listener with it
OntModel aBox = ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM);
SimpleReasoner sr = new SimpleReasoner(tBox, aBox, inf);
sr.setSameAsEnabled(sameAs);
aBox.register(sr);
// add assertions to the abox and verify inferences
Resource a = aBox.createResource("http://test.vivo/a");
Resource b = aBox.createResource("http://test.vivo/b");
Resource c = aBox.createResource("http://test.vivo/c");
Resource d = aBox.createResource("http://test.vivo/d");
aBox.add(a, P, b);
Assert.assertTrue(inf.contains(b, Q, a));
aBox.add(c, Q, d);
Assert.assertTrue(inf.contains(d, P, c));
// delete assertions and verify that inferences go away
aBox.remove(c, Q, d);
Assert.assertFalse(inf.contains(d, P, c));
aBox.remove(a, P, b);
Assert.assertFalse(inf.contains(b, Q, a));
}
use of org.apache.jena.ontology.OntProperty in project Vitro by vivo-project.
the class SimpleReasonerInversePropertyTest method addABoxAssertion2.
/*
* don't infer statements already in the abox
* (never infer because it's in the abox already)
*/
public void addABoxAssertion2(boolean sameAs) {
// set up the tbox
OntModel tBox = createTBoxModel();
OntProperty P = createObjectProperty(tBox, "http://test.vivo/P", "property P");
OntProperty Q = createObjectProperty(tBox, "http://test.vivo/Q", "property Q");
setInverse(P, Q);
// this is the model to receive abox inferences
Model inf = ModelFactory.createDefaultModel();
// create an ABox and add data (no inferencing happening yet)
OntModel aBox = ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM);
// Individuals a, b, c and d
Resource a = aBox.createResource("http://test.vivo/a");
Resource b = aBox.createResource("http://test.vivo/b");
aBox.add(b, Q, a);
// register SimpleReasoner
aBox.register(new SimpleReasoner(tBox, aBox, inf));
Assert.assertFalse(inf.contains(b, Q, a));
// add data and verify inferences
aBox.add(a, P, b);
Assert.assertFalse(inf.contains(b, Q, a));
}
use of org.apache.jena.ontology.OntProperty in project Vitro by vivo-project.
the class RestrictionOperationController method processCreate.
private void processCreate(VitroRequest request, EditProcessObject epo, OntModel origModel) {
Model temp = ModelFactory.createDefaultModel();
Model dynamicUnion = ModelFactory.createUnion(temp, origModel);
OntModel ontModel = ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM, dynamicUnion);
OntProperty onProperty = ontModel.getOntProperty((String) request.getParameter("onProperty"));
String conditionTypeStr = request.getParameter("conditionType");
String restrictionTypeStr = (String) epo.getAttribute("restrictionType");
Restriction rest = null;
OntClass ontClass = ontModel.getOntClass((String) epo.getAttribute("VClassURI"));
String roleFillerURIStr = request.getParameter("ValueClass");
Resource roleFiller = null;
if (roleFillerURIStr != null) {
roleFiller = ontModel.getResource(roleFillerURIStr);
}
int cardinality = -1;
String cardinalityStr = request.getParameter("cardinality");
if (cardinalityStr != null) {
cardinality = Integer.decode(cardinalityStr);
}
switch(restrictionTypeStr) {
case "allValuesFrom":
rest = ontModel.createAllValuesFromRestriction(null, onProperty, roleFiller);
break;
case "someValuesFrom":
rest = ontModel.createSomeValuesFromRestriction(null, onProperty, roleFiller);
break;
case "hasValue":
String valueURI = request.getParameter("ValueIndividual");
if (valueURI != null) {
Resource valueRes = ontModel.getResource(valueURI);
if (valueRes != null) {
rest = ontModel.createHasValueRestriction(null, onProperty, valueRes);
}
} else {
String valueLexicalForm = request.getParameter("ValueLexicalForm");
if (valueLexicalForm != null) {
String valueDatatype = request.getParameter("ValueDatatype");
Literal value = null;
if (valueDatatype != null && valueDatatype.length() > 0) {
RDFDatatype dtype = null;
try {
dtype = TypeMapper.getInstance().getSafeTypeByName(valueDatatype);
} catch (Exception e) {
log.warn("Unable to get safe type " + valueDatatype + " using TypeMapper");
}
if (dtype != null) {
value = ontModel.createTypedLiteral(valueLexicalForm, dtype);
} else {
value = ontModel.createLiteral(valueLexicalForm);
}
} else {
value = ontModel.createLiteral(valueLexicalForm);
}
rest = ontModel.createHasValueRestriction(null, onProperty, value);
}
}
break;
case "minCardinality":
rest = ontModel.createMinCardinalityRestriction(null, onProperty, cardinality);
break;
case "maxCardinality":
rest = ontModel.createMaxCardinalityRestriction(null, onProperty, cardinality);
break;
case "cardinality":
rest = ontModel.createCardinalityRestriction(null, onProperty, cardinality);
break;
}
if (conditionTypeStr.equals("necessary")) {
ontClass.addSuperClass(rest);
} else if (conditionTypeStr.equals("necessaryAndSufficient")) {
ontClass.addEquivalentClass(rest);
}
origModel.add(temp);
}
use of org.apache.jena.ontology.OntProperty in project Vitro by vivo-project.
the class ObjectPropertyDaoJena method getObjectPropertiesForObjectPropertyStatements.
public List<ObjectProperty> getObjectPropertiesForObjectPropertyStatements(List<ObjectPropertyStatement> objPropertyStmts) {
if (objPropertyStmts == null || objPropertyStmts.size() < 1)
return new ArrayList();
HashMap<String, ObjectProperty> hash = new HashMap<String, ObjectProperty>();
String uris = "";
getOntModel().enterCriticalSection(Lock.READ);
try {
for (ObjectPropertyStatement objPropertyStmt : objPropertyStmts) {
if (hash.containsKey(objPropertyStmt.getPropertyURI())) {
ObjectProperty p = hash.get(objPropertyStmt.getPropertyURI());
p.addObjectPropertyStatement(objPropertyStmt);
} else {
OntProperty op = getOntModel().getOntProperty(objPropertyStmt.getPropertyURI());
if (op != null) {
ObjectProperty p = propertyFromOntProperty(op);
hash.put(p.getURI(), p);
p.addObjectPropertyStatement(objPropertyStmt);
}
}
}
List<ObjectProperty> props = new ArrayList<ObjectProperty>();
for (String key : hash.keySet()) {
props.add(hash.get(key));
}
return props;
} finally {
getOntModel().leaveCriticalSection();
}
}
use of org.apache.jena.ontology.OntProperty in project Vitro by vivo-project.
the class PropertyDaoJena method getSuperPropertyURIs.
@Override
public List<String> getSuperPropertyURIs(String propertyURI, boolean direct) {
List<String> supURIs = new LinkedList<String>();
getOntModel().enterCriticalSection(Lock.READ);
try {
Iterator supIt = getOntModel().getOntProperty(propertyURI).listSuperProperties(direct);
while (supIt.hasNext()) {
try {
OntProperty prop = (OntProperty) supIt.next();
supURIs.add(prop.getURI());
} catch (Exception cce) {
}
}
} catch (Exception e) {
log.error("Failed to get super-properties for " + propertyURI, e);
} finally {
getOntModel().leaveCriticalSection();
}
return supURIs;
}
Aggregations