Search in sources :

Example 21 with OntModel

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();
    }
}
Also used : Individual(org.apache.jena.ontology.Individual) Resource(org.apache.jena.rdf.model.Resource) OntModel(org.apache.jena.ontology.OntModel)

Example 22 with OntModel

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();
    }
}
Also used : IndividualDeletionEvent(edu.cornell.mannlib.vitro.webapp.dao.jena.event.IndividualDeletionEvent) OntProperty(org.apache.jena.ontology.OntProperty) Statement(org.apache.jena.rdf.model.Statement) ObjectPropertyStatement(edu.cornell.mannlib.vitro.webapp.beans.ObjectPropertyStatement) Resource(org.apache.jena.rdf.model.Resource) OntModel(org.apache.jena.ontology.OntModel) Model(org.apache.jena.rdf.model.Model) OntModel(org.apache.jena.ontology.OntModel) IndividualUpdateEvent(edu.cornell.mannlib.vitro.webapp.dao.jena.event.IndividualUpdateEvent) OntProperty(org.apache.jena.ontology.OntProperty) Property(org.apache.jena.rdf.model.Property)

Example 23 with OntModel

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);
}
Also used : OntModel(org.apache.jena.ontology.OntModel)

Example 24 with OntModel

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);
    }
}
Also used : Path(java.nio.file.Path) RDFService(edu.cornell.mannlib.vitro.webapp.rdfservice.RDFService) Dataset(org.apache.jena.query.Dataset) RDFServiceDataset(edu.cornell.mannlib.vitro.webapp.dao.jena.RDFServiceDataset) ServletContext(javax.servlet.ServletContext) OntModel(org.apache.jena.ontology.OntModel)

Example 25 with OntModel

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);
}
Also used : OntModel(org.apache.jena.ontology.OntModel) Validation(edu.cornell.mannlib.vitro.webapp.utils.configuration.Validation)

Aggregations

OntModel (org.apache.jena.ontology.OntModel)272 Model (org.apache.jena.rdf.model.Model)112 Resource (org.apache.jena.rdf.model.Resource)92 Test (org.junit.Test)51 Statement (org.apache.jena.rdf.model.Statement)41 OntClass (org.apache.jena.ontology.OntClass)33 StmtIterator (org.apache.jena.rdf.model.StmtIterator)31 ArrayList (java.util.ArrayList)29 OntProperty (org.apache.jena.ontology.OntProperty)29 OntResource (org.apache.jena.ontology.OntResource)26 Literal (org.apache.jena.rdf.model.Literal)26 RDFNode (org.apache.jena.rdf.model.RDFNode)26 IOException (java.io.IOException)24 Individual (org.apache.jena.ontology.Individual)22 Property (org.apache.jena.rdf.model.Property)21 QueryExecution (org.apache.jena.query.QueryExecution)16 StringReader (java.io.StringReader)15 DatatypeProperty (org.apache.jena.ontology.DatatypeProperty)14 InputStream (java.io.InputStream)12 DataProperty (edu.cornell.mannlib.vitro.webapp.beans.DataProperty)11