use of org.apache.jena.ontology.OntProperty in project Vitro by vivo-project.
the class ObjectPropertyDaoJena method propertyFromOntProperty.
protected ObjectProperty propertyFromOntProperty(OntProperty op) {
if (op == null) {
return null;
}
if (op instanceof DatatypeProperty) {
return null;
}
ObjectProperty p = new ObjectProperty();
try {
p.setURI(op.getURI());
p.setNamespace(op.getNameSpace());
p.setLocalName(op.getLocalName());
p.setLocalNameWithPrefix(getWebappDaoFactory().makeLocalNameWithPrefix(p));
if (op.getLabel(null) != null)
p.setDomainPublic(getLabelOrId(op));
else
p.setDomainPublic(op.getLocalName());
if (p.getDomainPublic() == null)
p.setDomainPublic("[related to]");
p.setPickListName(getWebappDaoFactory().makePickListName(p));
if (op.getDomain() != null)
p.setDomainVClassURI((op.getDomain().isAnon()) ? PSEUDO_BNODE_NS + op.getDomain().getId().toString() : op.getDomain().getURI());
if (op.getRange() != null)
p.setRangeVClassURI((op.getRange().isAnon()) ? PSEUDO_BNODE_NS + op.getRange().getId().toString() : op.getRange().getURI());
OntProperty invOp = null;
try {
invOp = op.getInverse();
} catch (ProfileException pe) {
}
try {
if (op.getSuperProperty() != null)
p.setParentURI(op.getSuperProperty().getURI());
} catch (ConversionException ce) {
StmtIterator parentStmtIt = op.listProperties(RDFS.subPropertyOf);
if (parentStmtIt.hasNext()) {
Statement parentStmt = parentStmtIt.nextStatement();
if (parentStmt.getObject().isResource()) {
p.setParentURI(((Resource) parentStmt.getObject()).getURI());
}
}
parentStmtIt.close();
}
if (invOp != null) {
p.setURIInverse(invOp.getURI());
p.setNamespaceInverse(invOp.getNameSpace());
p.setLocalNameInverse(invOp.getLocalName());
p.setRangePublic(getLabelOrId(invOp));
}
try {
if (op.isTransitiveProperty() || (invOp != null && invOp.isTransitiveProperty())) {
p.setTransitive(true);
}
} catch (ProfileException pe) {
}
try {
if (op.isSymmetricProperty() || (invOp != null && invOp.isSymmetricProperty())) {
p.setSymmetric(true);
}
} catch (ProfileException pe) {
}
try {
if (op.isFunctionalProperty()) {
p.setFunctional(true);
}
} catch (ProfileException pe) {
}
try {
if (op.isInverseFunctionalProperty()) {
p.setInverseFunctional(true);
}
} catch (ProfileException pe) {
}
p.setExample(getPropertyStringValue(op, EXAMPLE_ANNOT));
p.setDescription(getPropertyStringValue(op, DESCRIPTION_ANNOT));
p.setPublicDescription(getPropertyStringValue(op, PUBLIC_DESCRIPTION_ANNOT));
p.setDomainDisplayTier(getPropertyNonNegativeIntegerValue(op, DISPLAY_RANK_ANNOT));
p.setRangeDisplayTier(getPropertyNonNegativeIntegerValue(invOp, DISPLAY_RANK_ANNOT));
p.setDomainDisplayLimit(getPropertyNonNegativeIntValue(op, DISPLAY_LIMIT));
p.setRangeDisplayLimit(getPropertyNonNegativeIntValue(invOp, DISPLAY_LIMIT));
RDFNode objectIndividualSortPropertyNode = op.getPropertyValue(PROPERTY_OBJECTINDIVIDUALSORTPROPERTY);
if (objectIndividualSortPropertyNode instanceof Resource) {
p.setObjectIndividualSortPropertyURI(((Resource) objectIndividualSortPropertyNode).getURI());
}
p.setDomainEntitySortDirection(getPropertyStringValue(op, PROPERTY_ENTITYSORTDIRECTION));
p.setRangeEntitySortDirection(getPropertyStringValue(invOp, PROPERTY_ENTITYSORTDIRECTION));
// There might be multiple HIDDEN_FROM_DISPLAY_BELOW_ROLE_LEVEL_ANNOT properties, only use the highest
StmtIterator it = op.listProperties(HIDDEN_FROM_DISPLAY_BELOW_ROLE_LEVEL_ANNOT);
BaseResourceBean.RoleLevel hiddenRoleLevel = null;
while (it.hasNext()) {
Statement stmt = it.nextStatement();
RDFNode obj;
if (stmt != null && (obj = stmt.getObject()) != null && obj.isURIResource()) {
Resource res = obj.as(Resource.class);
if (res != null && res.getURI() != null) {
BaseResourceBean.RoleLevel roleFromModel = BaseResourceBean.RoleLevel.getRoleByUri(res.getURI());
if (roleFromModel != null && (hiddenRoleLevel == null || roleFromModel.compareTo(hiddenRoleLevel) > 0)) {
hiddenRoleLevel = roleFromModel;
}
}
}
}
// this might get set to null
p.setHiddenFromDisplayBelowRoleLevel(hiddenRoleLevel);
// There might be multiple PROHIBITED_FROM_UPDATE_BELOW_ROLE_LEVEL_ANNOT properties, only use the highest
it = op.listProperties(PROHIBITED_FROM_UPDATE_BELOW_ROLE_LEVEL_ANNOT);
BaseResourceBean.RoleLevel prohibitedRoleLevel = null;
while (it.hasNext()) {
Statement stmt = it.nextStatement();
RDFNode obj;
if (stmt != null && (obj = stmt.getObject()) != null && obj.isURIResource()) {
Resource res = obj.as(Resource.class);
if (res != null && res.getURI() != null) {
BaseResourceBean.RoleLevel roleFromModel = BaseResourceBean.RoleLevel.getRoleByUri(res.getURI());
if (roleFromModel != null && (prohibitedRoleLevel == null || roleFromModel.compareTo(prohibitedRoleLevel) > 0)) {
prohibitedRoleLevel = roleFromModel;
}
}
}
}
// this might get set to null
p.setProhibitedFromUpdateBelowRoleLevel(prohibitedRoleLevel);
// There might be multiple HIDDEN_FROM_PUBLISH_BELOW_ROLE_LEVEL_ANNOT properties, only use the highest
it = op.listProperties(HIDDEN_FROM_PUBLISH_BELOW_ROLE_LEVEL_ANNOT);
BaseResourceBean.RoleLevel publishRoleLevel = null;
while (it.hasNext()) {
Statement stmt = it.nextStatement();
RDFNode obj;
if (stmt != null && (obj = stmt.getObject()) != null && obj.isURIResource()) {
Resource res = obj.as(Resource.class);
if (res != null && res.getURI() != null) {
BaseResourceBean.RoleLevel roleFromModel = BaseResourceBean.RoleLevel.getRoleByUri(res.getURI());
if (roleFromModel != null && (publishRoleLevel == null || roleFromModel.compareTo(publishRoleLevel) > 0)) {
publishRoleLevel = roleFromModel;
}
}
}
}
// this might get set to null
p.setHiddenFromPublishBelowRoleLevel(publishRoleLevel);
p.setCustomEntryForm(getPropertyStringValue(op, PROPERTY_CUSTOMENTRYFORMANNOT));
Boolean selectFromObj = getPropertyBooleanValue(op, PROPERTY_SELECTFROMEXISTINGANNOT);
p.setSelectFromExisting(selectFromObj == null ? true : selectFromObj);
Boolean offerCreateObj = getPropertyBooleanValue(op, PROPERTY_OFFERCREATENEWOPTIONANNOT);
p.setOfferCreateNewOption(offerCreateObj == null ? false : offerCreateObj);
Boolean dependencyDeletionObj = getPropertyBooleanValue(op, PROPERTY_STUBOBJECTPROPERTYANNOT);
p.setStubObjectRelation(dependencyDeletionObj == null ? false : dependencyDeletionObj);
Boolean collateBySubclass = getPropertyBooleanValue(op, PROPERTY_COLLATEBYSUBCLASSANNOT);
p.setCollateBySubclass(collateBySubclass == null ? false : collateBySubclass);
Boolean editLinkSuppressed = getPropertyBooleanValue(op, PROPERTY_EDITLINKSUPPRESSED);
p.setEditLinkSuppressed(editLinkSuppressed == null ? false : editLinkSuppressed);
Boolean addLinkSuppressed = getPropertyBooleanValue(op, PROPERTY_ADDLINKSUPPRESSED);
p.setAddLinkSuppressed(addLinkSuppressed == null ? false : addLinkSuppressed);
Boolean deleteLinkSuppressed = getPropertyBooleanValue(op, PROPERTY_DELETELINKSUPPRESSED);
p.setDeleteLinkSuppressed(deleteLinkSuppressed == null ? false : deleteLinkSuppressed);
Resource groupRes = (Resource) op.getPropertyValue(PROPERTY_INPROPERTYGROUPANNOT);
if (groupRes != null) {
p.setGroupURI(groupRes.getURI());
}
} catch (Throwable t) {
log.error(t, t);
}
return p;
}
use of org.apache.jena.ontology.OntProperty in project Vitro by vivo-project.
the class ObjectPropertyDaoJena method getObjectPropertyByURI.
public ObjectProperty getObjectPropertyByURI(String propertyURI) {
if (propertyURI == null)
return null;
OntModel ontModel = getOntModel();
OntModel localModel = ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM);
ontModel.enterCriticalSection(Lock.READ);
try {
Resource prop = ontModel.getResource(propertyURI);
localModel.add(ontModel.listStatements(prop, null, (RDFNode) null));
StmtIterator invit = ontModel.listStatements(prop, OWL.inverseOf, (RDFNode) null);
while (invit.hasNext()) {
Statement invSit = invit.nextStatement();
if (invSit.getObject().isURIResource()) {
Resource invProp = (Resource) invSit.getObject();
localModel.add(ontModel.listStatements(invProp, null, (RDFNode) null));
}
}
OntProperty op = localModel.getObjectProperty(propertyURI);
return propertyFromOntProperty(op);
} finally {
ontModel.leaveCriticalSection();
}
}
use of org.apache.jena.ontology.OntProperty in project Vitro by vivo-project.
the class PropertyInstanceDaoJena method insertProp.
public int insertProp(PropertyInstanceIface prop, OntModelSelector oms) {
OntModel ontModel = oms.getABoxModel();
OntModel tboxModel = oms.getTBoxModel();
ontModel.enterCriticalSection(Lock.WRITE);
try {
tboxModel.enterCriticalSection(Lock.READ);
try {
Resource subjRes = ontModel.getResource(prop.getSubjectEntURI());
OntProperty pred = tboxModel.getOntProperty(prop.getPropertyURI());
Resource objRes = ontModel.getResource(prop.getObjectEntURI());
if ((subjRes != null) && (pred != null) && (objRes != null)) {
getOntModel().getBaseModel().notifyEvent(new IndividualUpdateEvent(getWebappDaoFactory().getUserURI(), true, prop.getSubjectEntURI()));
try {
ontModel.add(subjRes, pred, objRes);
} finally {
getOntModel().getBaseModel().notifyEvent(new IndividualUpdateEvent(getWebappDaoFactory().getUserURI(), false, prop.getSubjectEntURI()));
}
OntProperty invPred = pred.getInverse();
if (invPred != null) {
getOntModel().getBaseModel().notifyEvent(new IndividualUpdateEvent(getWebappDaoFactory().getUserURI(), true, prop.getObjectEntURI()));
try {
ontModel.add(objRes, invPred, subjRes);
} finally {
getOntModel().getBaseModel().notifyEvent(new IndividualUpdateEvent(getWebappDaoFactory().getUserURI(), false, prop.getSubjectEntURI()));
}
}
}
return 0;
} finally {
tboxModel.leaveCriticalSection();
}
} finally {
ontModel.leaveCriticalSection();
}
}
use of org.apache.jena.ontology.OntProperty in project Vitro by vivo-project.
the class VClassDaoJena method getLabelForClass.
/* ************************************************** */
public String getLabelForClass(OntClass cls, boolean withPrefix, boolean forPickList) {
cls.getModel().enterCriticalSection(Lock.READ);
try {
if (cls.isAnon()) {
if (cls.isRestriction()) {
Restriction rest = cls.asRestriction();
OntProperty onProperty = rest.getOnProperty();
StringBuilder labelStr = new StringBuilder();
labelStr.append("restriction on ").append(getLabelOrId(onProperty)).append(": ");
if (rest.isAllValuesFromRestriction() || rest.isSomeValuesFromRestriction()) {
Resource fillerRes = null;
if (rest.isAllValuesFromRestriction()) {
AllValuesFromRestriction avfRest = rest.asAllValuesFromRestriction();
fillerRes = avfRest.getAllValuesFrom();
labelStr.append("all values from ");
} else {
SomeValuesFromRestriction svfRest = rest.asSomeValuesFromRestriction();
fillerRes = svfRest.getSomeValuesFrom();
labelStr.append("some values from ");
}
if (fillerRes.canAs(OntClass.class)) {
OntClass avf = fillerRes.as(OntClass.class);
labelStr.append(getLabelForClass(avf, withPrefix, forPickList));
} else {
try {
labelStr.append(getLabelOrId(fillerRes.as(OntResource.class)));
} catch (Exception e) {
labelStr.append("???");
}
}
} else if (rest.isHasValueRestriction()) {
HasValueRestriction hvRest = rest.asHasValueRestriction();
labelStr.append("has value ");
RDFNode fillerNode = hvRest.getHasValue();
try {
if (fillerNode.isResource()) {
labelStr.append(getLabelOrId(fillerNode.as(OntResource.class)));
} else {
labelStr.append(fillerNode.as(Literal.class).getLexicalForm());
}
} catch (Exception e) {
labelStr.append("???");
}
} else if (rest.isMinCardinalityRestriction()) {
MinCardinalityRestriction mcRest = rest.asMinCardinalityRestriction();
labelStr.append("minimum cardinality ");
labelStr.append(mcRest.getMinCardinality());
} else if (rest.isMaxCardinalityRestriction()) {
MaxCardinalityRestriction mcRest = rest.asMaxCardinalityRestriction();
labelStr.append("maximum cardinality ");
labelStr.append(mcRest.getMaxCardinality());
} else if (rest.isCardinalityRestriction()) {
CardinalityRestriction cRest = rest.asCardinalityRestriction();
labelStr.append("cardinality ");
labelStr.append(cRest.getCardinality());
}
return labelStr.toString();
} else if (isBooleanClassExpression(cls)) {
StringBuilder labelStr = new StringBuilder("(");
if (cls.isComplementClass()) {
labelStr.append("not ");
ComplementClass ccls = cls.as(ComplementClass.class);
labelStr.append(getLabelForClass(ccls.getOperand(), withPrefix, forPickList));
} else if (cls.isIntersectionClass()) {
IntersectionClass icls = cls.as(IntersectionClass.class);
for (Iterator<? extends OntClass> operandIt = icls.listOperands(); operandIt.hasNext(); ) {
OntClass operand = operandIt.next();
labelStr.append(getLabelForClass(operand, withPrefix, forPickList));
if (operandIt.hasNext()) {
labelStr.append(" and ");
}
}
} else if (cls.isUnionClass()) {
UnionClass icls = cls.as(UnionClass.class);
for (Iterator<? extends OntClass> operandIt = icls.listOperands(); operandIt.hasNext(); ) {
OntClass operand = operandIt.next();
labelStr.append(getLabelForClass(operand, withPrefix, forPickList));
if (operandIt.hasNext()) {
labelStr.append(" or ");
}
}
}
return labelStr.append(")").toString();
} else {
// but obviously we need to factor this out into the display layer.
return "<a href=\"vclassEdit?uri=" + URLEncoder.encode(getClassURIStr(cls)) + "\">[anonymous class]</a>";
}
} else {
if (withPrefix || forPickList) {
OntologyDao oDao = getWebappDaoFactory().getOntologyDao();
Ontology o = oDao.getOntologyByURI(cls.getNameSpace());
if (o != null) {
if (withPrefix) {
return (o.getPrefix() == null ? (o.getName() == null ? "unspec:" + getLabelOrId(cls) : o.getName() + ":" + getLabelOrId(cls)) : o.getPrefix() + ":" + getLabelOrId(cls));
} else {
return (getLabelOrId(cls) + (o.getPrefix() == null ? (o.getName() == null ? " (unspec)" : " (" + o.getName() + ")") : " (" + o.getPrefix() + ")"));
}
} else {
return getLabelOrId(cls);
}
}
return getLabelOrId(cls);
}
} catch (Exception e) {
log.error(e, e);
return "???";
} finally {
cls.getModel().leaveCriticalSection();
}
}
Aggregations