use of org.apache.jena.ontology.OntModel in project Vitro by vivo-project.
the class VClassDaoJena method isSubClassOf.
public boolean isSubClassOf(String vclassURI1, String vclassURI2) {
if (vclassURI1 == null || vclassURI2 == null) {
return false;
}
OntModel ontModel = getOntModel();
try {
ontModel.enterCriticalSection(Lock.READ);
Resource oc1 = ontModel.getResource(vclassURI1);
Resource oc2 = ontModel.getResource(vclassURI2);
return ontModel.contains(oc1, RDFS.subClassOf, oc2);
} finally {
ontModel.leaveCriticalSection();
}
}
use of org.apache.jena.ontology.OntModel in project Vitro by vivo-project.
the class VClassDaoJena method getOntologyRootClasses.
public List<VClass> getOntologyRootClasses(String ontologyURI) {
if (ontologyURI == null) {
throw new RuntimeException("can't find root classes for null ontology URI");
}
// return getRootClasses(ontologyURI);
List<VClass> ontologyRootClasses = new ArrayList<VClass>();
OntModel ontModel = getOntModel();
ontModel.enterCriticalSection(Lock.READ);
try {
Iterator<Resource> ontClassIt = ontModel.listResourcesWithProperty(RDF.type, OWL.Class);
while (ontClassIt.hasNext()) {
Resource ontClass = ontClassIt.next();
if (ontologyURI.equals(ontClass.getNameSpace())) {
boolean root = true;
StmtIterator superStmtIt = ontModel.listStatements(ontClass, RDFS.subClassOf, (RDFNode) null);
try {
while (superStmtIt.hasNext()) {
Statement superStmt = superStmtIt.nextStatement();
if (superStmt.getObject().isResource() && ontologyURI.equals(((Resource) superStmt.getObject()).getNameSpace())) {
root = false;
break;
}
}
} finally {
superStmtIt.close();
}
if (root && ontClass.canAs(OntClass.class)) {
ontologyRootClasses.add(new VClassJena((OntClass) ontClass.as(OntClass.class), getWebappDaoFactory()));
}
}
}
} finally {
ontModel.leaveCriticalSection();
}
return ontologyRootClasses;
}
use of org.apache.jena.ontology.OntModel in project Vitro by vivo-project.
the class WebappDaoFactoryJena method getCommentsForResource.
@Override
public List<String> getCommentsForResource(String resourceURI) {
List<String> commentList = new LinkedList<String>();
OntModel ontModel = ontModelSelector.getFullModel();
ontModel.enterCriticalSection(Lock.READ);
try {
OntResource res = ontModel.getOntResource(resourceURI);
if (res != null) {
ClosableIterator<RDFNode> closeIt = res.listComments(null);
try {
for (Iterator<RDFNode> commIt = closeIt; commIt.hasNext(); ) {
Literal lit = (Literal) commIt.next();
commentList.add(lit.getLexicalForm());
}
} finally {
closeIt.close();
}
}
} finally {
ontModel.leaveCriticalSection();
}
return commentList;
}
use of org.apache.jena.ontology.OntModel in project Vitro by vivo-project.
the class WebappDaoFactoryJena method makeInMemoryDataset.
public static Dataset makeInMemoryDataset(Model assertions, Model inferences) {
Dataset dataset = DatasetFactory.createMem();
OntModel union = ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM);
if (assertions != null) {
dataset.addNamedModel(ModelNames.ABOX_ASSERTIONS, assertions);
union.addSubModel(assertions);
}
if (inferences != null) {
dataset.addNamedModel(ModelNames.ABOX_INFERENCES, inferences);
union.addSubModel(inferences);
}
dataset.setDefaultModel(union);
return dataset;
}
use of org.apache.jena.ontology.OntModel in project Vitro by vivo-project.
the class WebappDaoFactoryJena method setSpecialDataModel.
/**
* Method for using a special model, such as the display model, with the
* WebappDaoFactory. The goal here is to modify this WebappDaoFactory so
* that it is using specialModel, specialTboxModel and specialDisplayModel
* for individual editing.
*
* DAOs related to the application configuration and user accounts
* should remain unchanged.
*/
public void setSpecialDataModel(OntModel specialModel, OntModel specialTboxModel, OntModel specialDisplayModel) {
if (specialModel == null)
throw new IllegalStateException("specialModel must not be null");
// Can we get the "original" models here from somewhere?
OntModelSelector originalSelector = this.getOntModelSelector();
// Set up model selector for this special WDF
// The selector is used by the object property DAO, therefore should be
// set up even though we use the new webapp dao factory object to
// generate portions to overwrite the regular webapp dao factory.
// The WDF expects the full model in the OntModelSelect that has
// both the ABox and TBox. This is used to run SPARQL queries against.
OntModel unionModel = ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM);
unionModel.addSubModel(specialModel);
OntModelSelectorImpl specialSelector = new OntModelSelectorImpl();
specialSelector.setFullModel(unionModel);
// Keeping original application metadata model and adding special model.
// Adding both allows us to prevent errors in ApplicationDao which may
// depend on a specific individual from the regular application metadata
// model to pick the theme. Adding the new model would take care of
// special situations where the switch model may contain important
// information.
OntModel newApplicationModel = ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM);
newApplicationModel.add(specialModel);
newApplicationModel.add(originalSelector.getApplicationMetadataModel());
specialSelector.setApplicationMetadataModel(newApplicationModel);
if (specialDisplayModel != null) {
specialSelector.setDisplayModel(specialDisplayModel);
unionModel.addSubModel(specialDisplayModel);
} else {
OntModel selectorDisplayModel = originalSelector.getDisplayModel();
if (selectorDisplayModel != null) {
specialSelector.setDisplayModel(originalSelector.getDisplayModel());
}
}
if (specialTboxModel != null) {
unionModel.addSubModel(specialTboxModel);
specialSelector.setTBoxModel(specialTboxModel);
} else {
OntModel selectorTboxModel = originalSelector.getTBoxModel();
if (selectorTboxModel != null) {
specialSelector.setTBoxModel(originalSelector.getTBoxModel());
}
}
specialSelector.setABoxModel(specialModel);
specialSelector.setUserAccountsModel(specialModel);
// Although we're only using part of the new wadf and copy over below,
// the object property dao utilizes methods that will employ the display
// model returned from the simple ontmodel selector, so if the object
// property dao is to be copied over we need to ensure we have the
// correct display model and tbox model.
WebappDaoFactoryJena specialWadfj = new WebappDaoFactoryJena(specialSelector);
entityWebappDao = specialWadfj.getIndividualDao();
vClassGroupDao = specialWadfj.getVClassGroupDao();
// To allow for testing, add a property group, this will allow
// the unassigned group method section to be executed and main Image to
// be assigned to that group. Otherwise, the dummy group does not allow
// for the unassigned group to be executed.
propertyGroupDao = specialWadfj.getPropertyGroupDao();
objectPropertyDao = specialWadfj.getObjectPropertyDao();
objectPropertyStatementDao = specialWadfj.getObjectPropertyStatementDao();
dataPropertyDao = specialWadfj.getDataPropertyDao();
dataPropertyStatementDao = specialWadfj.getDataPropertyStatementDao();
// Why can't we set the selector to be the same?
ontModelSelector = specialSelector;
}
Aggregations