use of org.apache.jena.ontology.OntModel in project Vitro by vivo-project.
the class PropertyGroupDaoJena method deletePropertyGroup.
public void deletePropertyGroup(PropertyGroup group) {
getOntModel().enterCriticalSection(Lock.WRITE);
try {
Individual groupInd = getOntModel().getIndividual(group.getURI());
if (groupInd != null) {
groupInd.remove();
}
} finally {
getOntModel().leaveCriticalSection();
}
OntModel tboxModel = getOntModelSelector().getTBoxModel();
tboxModel.enterCriticalSection(Lock.WRITE);
try {
Resource groupRes = ResourceFactory.createResource(group.getURI());
tboxModel.removeAll(groupRes, null, null);
tboxModel.removeAll(null, null, groupRes);
} finally {
tboxModel.leaveCriticalSection();
}
}
use of org.apache.jena.ontology.OntModel in project Vitro by vivo-project.
the class PropertyInstanceDaoJena method deleteObjectPropertyStatement.
public void deleteObjectPropertyStatement(String subjectURI, String propertyURI, String objectURI, OntModelSelector ontModelSelector) {
OntModel ontModel = ontModelSelector.getABoxModel();
OntModel tboxModel = ontModelSelector.getTBoxModel();
ontModel.enterCriticalSection(Lock.WRITE);
try {
Resource subjRes = ontModel.getResource(subjectURI);
Property pred = tboxModel.getProperty(propertyURI);
OntProperty invPred = null;
if (pred.canAs(OntProperty.class)) {
invPred = pred.as(OntProperty.class).getInverse();
}
Resource objRes = ontModel.getResource(objectURI);
Model baseModel = getOntModel().getBaseModel();
String userUri = getWebappDaoFactory().getUserURI();
if ((subjRes != null) && (pred != null) && (objRes != null)) {
baseModel.notifyEvent(new IndividualUpdateEvent(userUri, true, subjectURI));
try {
ontModel.remove(subjRes, pred, objRes);
} finally {
baseModel.notifyEvent(new IndividualUpdateEvent(userUri, false, subjectURI));
}
try {
baseModel.notifyEvent(new IndividualDeletionEvent(userUri, true, objectURI));
List<Statement> depResStmts = DependentResourceDeleteJena.getDependentResourceDeleteList(ResourceFactory.createStatement(subjRes, pred, objRes), ontModel);
ontModel.remove(depResStmts);
} finally {
baseModel.notifyEvent(new IndividualDeletionEvent(userUri, false, objectURI));
}
if (invPred != null) {
baseModel.notifyEvent(new IndividualUpdateEvent(userUri, true, objectURI));
try {
ontModel.remove(objRes, invPred, subjRes);
} finally {
baseModel.notifyEvent(new IndividualUpdateEvent(userUri, false, subjectURI));
}
}
}
} finally {
ontModel.leaveCriticalSection();
}
}
use of org.apache.jena.ontology.OntModel in project Vitro by vivo-project.
the class ContentModelSetup method initializeApplicationMetadata.
/* ===================================================================== */
/**
* We need to read the RDF files and change the Portal from a blank node to
* one with a URI in the default namespace.
*
* Do this before adding the data to the RDFService-backed model, to avoid
* warnings about editing a blank node.
*/
private void initializeApplicationMetadata(ServletContext ctx, Model applicationMetadataModel) {
OntModel temporaryAMModel = VitroModelFactory.createOntologyModel();
RDFFilesLoader.loadFirstTimeFiles("applicationMetadata", temporaryAMModel, true);
setPortalUriOnFirstTime(temporaryAMModel, ctx);
applicationMetadataModel.add(temporaryAMModel);
}
use of org.apache.jena.ontology.OntModel in project Vitro by vivo-project.
the class FileGraphSetup method contextInitialized.
@Override
public void contextInitialized(ServletContextEvent sce) {
// indicates whether any ABox file graph model has changed
boolean aboxChanged = false;
// indicates whether any TBox file graph model has changed
boolean tboxChanged = false;
ServletContext ctx = sce.getServletContext();
try {
OntDocumentManager.getInstance().setProcessImports(true);
Dataset dataset = ModelAccess.on(ctx).getDataset();
RDFService rdfService = ModelAccess.on(ctx).getRDFService(CONTENT);
// ABox files
Set<Path> paths = getFilegraphPaths(ctx, RDF, ABOX, FILEGRAPH);
cleanupDB(dataset, pathsToURIs(paths, ABOX), ABOX);
// Just update the ABox filegraphs in the DB; don't attach them to a base model.
aboxChanged = readGraphs(paths, rdfService, ABOX, /* aboxBaseModel */
null);
// TBox files
paths = getFilegraphPaths(ctx, RDF, TBOX, FILEGRAPH);
cleanupDB(dataset, pathsToURIs(paths, TBOX), TBOX);
OntModel tboxBaseModel = ModelAccess.on(ctx).getOntModel(ModelNames.TBOX_ASSERTIONS);
tboxChanged = readGraphs(paths, rdfService, TBOX, tboxBaseModel);
} catch (ClassCastException cce) {
String errMsg = "Unable to cast servlet context attribute to the appropriate type " + cce.getLocalizedMessage();
log.error(errMsg);
throw new ClassCastException(errMsg);
} catch (Throwable t) {
log.error(t, t);
} finally {
OntDocumentManager.getInstance().setProcessImports(false);
}
if ((aboxChanged || tboxChanged) && !isUpdateRequired(ctx)) {
log.info("a full recompute of the Abox will be performed because" + " the filegraph abox(s) and/or tbox(s) have changed or are being read for the first time.");
SimpleReasonerSetup.setRecomputeRequired(ctx, SimpleReasonerSetup.RecomputeMode.BACKGROUND);
}
}
use of org.apache.jena.ontology.OntModel in project Vitro by vivo-project.
the class SyncingExcludeBasedOnType method buildClassList.
@Validation
public void buildClassList() {
OntModel model = models.getOntModel(ModelNames.DISPLAY);
this.setExcludedTypes(buildProhibitedClassesList(SEARCH_INDEX_URI, model));
log.debug(this);
}
Aggregations