Search in sources :

Example 96 with OntModel

use of org.apache.jena.ontology.OntModel in project Vitro by vivo-project.

the class ApplicationDaoJena method getExternallyLinkedNamespaces.

private synchronized List<String> getExternallyLinkedNamespaces(boolean clearCache) {
    if (clearCache || externallyLinkedNamespaces == null) {
        externallyLinkedNamespaces = new ArrayList<String>();
        OntModel ontModel = getOntModelSelector().getDisplayModel();
        NodeIterator nodes = ontModel.listObjectsOfProperty(LINKED_NAMESPACE_PROP);
        while (nodes.hasNext()) {
            RDFNode node = nodes.next();
            if (node.isLiteral()) {
                String namespace = ((Literal) node).getLexicalForm();
                // It also accords with the way the default namespace is defined.
                if (!namespace.endsWith("/")) {
                    namespace += "/";
                }
                externallyLinkedNamespaces.add(namespace);
            }
        }
    }
    return externallyLinkedNamespaces;
}
Also used : NodeIterator(org.apache.jena.rdf.model.NodeIterator) Literal(org.apache.jena.rdf.model.Literal) OntModel(org.apache.jena.ontology.OntModel) RDFNode(org.apache.jena.rdf.model.RDFNode)

Example 97 with OntModel

use of org.apache.jena.ontology.OntModel in project Vitro by vivo-project.

the class ApplicationDaoJena method updateApplicationBean.

public void updateApplicationBean(ApplicationBean application) {
    // TODO migrate to "application" in the resource URI
    OntModel ontModel = getOntModelSelector().getApplicationMetadataModel();
    Individual appInd = ontModel.getIndividual(getApplicationResourceURI());
    if (appInd == null) {
        appInd = ontModel.createIndividual(getApplicationResourceURI(), PORTAL);
    }
    ontModel.enterCriticalSection(Lock.WRITE);
    try {
        appInd.setLabel(application.getApplicationName(), null);
        updatePropertyStringValue(appInd, APPLICATION_ABOUTTEXT, application.getAboutText(), ontModel);
        updatePropertyStringValue(appInd, APPLICATION_ACKNOWLEGETEXT, application.getAcknowledgeText(), ontModel);
        updatePropertyStringValue(appInd, APPLICATION_CONTACTMAIL, application.getContactMail(), ontModel);
        updatePropertyStringValue(appInd, APPLICATION_CORRECTIONMAIL, application.getCorrectionMail(), ontModel);
        updatePropertyStringValue(appInd, APPLICATION_COPYRIGHTANCHOR, application.getCopyrightAnchor(), ontModel);
        updatePropertyStringValue(appInd, APPLICATION_COPYRIGHTURL, application.getCopyrightURL(), ontModel);
        updatePropertyStringValue(appInd, APPLICATION_THEMEDIR, application.getThemeDir(), ontModel);
    } catch (Exception e) {
        log.error(e, e);
    } finally {
        ontModel.leaveCriticalSection();
    }
}
Also used : Individual(org.apache.jena.ontology.Individual) OntModel(org.apache.jena.ontology.OntModel)

Example 98 with OntModel

use of org.apache.jena.ontology.OntModel in project Vitro by vivo-project.

the class IndividualRdfAssemblerTest method modelDifference.

private List<Statement> modelDifference(OntModel first, OntModel second) {
    OntModel temp = ModelFactory.createOntologyModel(OWL_MEM);
    temp.add(first);
    temp.remove(statementList(second));
    return statementList(temp);
}
Also used : OntModel(org.apache.jena.ontology.OntModel)

Example 99 with OntModel

use of org.apache.jena.ontology.OntModel in project Vitro by vivo-project.

the class IndividualRdfAssemblerTest method runGetRdf.

private OntModel runGetRdf() {
    try {
        Method m = IndividualRdfAssembler.class.getDeclaredMethod("getRdf");
        m.setAccessible(true);
        return (OntModel) m.invoke(ira);
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
Also used : OntModel(org.apache.jena.ontology.OntModel) Method(java.lang.reflect.Method) IOException(java.io.IOException)

Example 100 with OntModel

use of org.apache.jena.ontology.OntModel in project Vitro by vivo-project.

the class PrimitiveRdfEditTest method testProcessChanges.

@Test
public void testProcessChanges() throws Exception {
    OntModel writeModel = ModelFactory.createOntologyModel();
    int totalStmts = 3;
    PrimitiveRdfEdit pre = new PrimitiveRdfEdit();
    String[] params = { testN3a, testN3b };
    Set<Model> models = pre.parseRdfParam(params, "N3");
    Assert.assertNotNull(models);
    Assert.assertTrue(models.size() == 2);
    Assert.assertNotNull(writeModel);
    long size = writeModel.size();
    pre.processChanges("uri:fakeEditorUri", writeModel, pre.mergeModels(models), ModelFactory.createDefaultModel());
    Assert.assertEquals(size + totalStmts, writeModel.size());
    String[] params3 = { testN3b };
    Set<Model> retracts = pre.parseRdfParam(params3, "N3");
    pre.processChanges("uri:fakeEditorUri", writeModel, ModelFactory.createDefaultModel(), pre.mergeModels(retracts));
    Assert.assertEquals(size + totalStmts - 1, writeModel.size());
}
Also used : Model(org.apache.jena.rdf.model.Model) OntModel(org.apache.jena.ontology.OntModel) OntModel(org.apache.jena.ontology.OntModel) Test(org.junit.Test)

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