Search in sources :

Example 1 with Literal

use of org.apache.jena.rdf.model.Literal in project ORCID-Source by ORCID.

the class RDFMessageBodyWriter method describeAccount.

private Individual describeAccount(OrcidProfile orcidProfile, OntModel m, Individual person) {
    String orcidURI = orcidProfile.getOrcidIdentifier().getUri();
    String orcidPublicationsUri = orcidURI + "#workspace-works";
    Individual publications = m.createIndividual(orcidPublicationsUri, FOAF.Document);
    // list of publications
    // (anchor in the HTML rendering - foaf:publications goes to a foaf:Document - not to an
    // RDF list of publications - although we should probably also have that)
    person.addProperty(FOAF.publications, publications);
    String orcidAccountUri = orcidURI + "#orcid-id";
    Individual account = m.createIndividual(orcidAccountUri, FOAF.OnlineAccount);
    person.addProperty(FOAF.account, account);
    Individual webSite = null;
    if (baseUri != null) {
        webSite = m.createIndividual(baseUri, null);
        account.addProperty(FOAF.accountServiceHomepage, webSite);
    }
    String orcId = orcidProfile.getOrcidIdentifier().getPath();
    account.addProperty(FOAF.accountName, orcId);
    account.addLabel(orcId, null);
    // The current page is the foaf:PersonalProfileDocument - this assumes
    // we have done a 303 See Other redirect to the RDF resource, so that it 
    // differs from the ORCID uri. 
    // for example:
    // 
    //     GET http://orcid.org/0000-0003-4654-1403
    //     Accept: text/turtle
    //  
    //     HTTP/1.1 303 See Other
    //     Location: https://pub.orcid.org/experimental_rdf_v1/0000-0001-9842-9718
    String profileUri;
    if (getUriInfo() != null) {
        profileUri = getUriInfo().getAbsolutePath().toASCIIString();
    } else {
        // Some kind of fallback, although the PersonalProfiledocument should be an 
        // information resource without #anchor
        profileUri = orcidURI + "#personalProfileDocument";
    }
    Individual profileDoc = m.createIndividual(profileUri, FOAF.PersonalProfileDocument);
    profileDoc.addProperty(FOAF.primaryTopic, person);
    OrcidHistory history = orcidProfile.getOrcidHistory();
    if (history != null) {
        if (history.isClaimed().booleanValue()) {
            // Set account as PersonalProfileDocument
            profileDoc.addProperty(FOAF.maker, person);
        }
        // Who made the profile?
        switch(history.getCreationMethod()) {
            case DIRECT:
            case MEMBER_REFERRED:
            case WEBSITE:
                profileDoc.addProperty(PAV.createdBy, person);
                profileDoc.addProperty(PROV.wasAttributedTo, person);
                if (webSite != null && (history.getCreationMethod() == CreationMethod.WEBSITE || history.getCreationMethod() == CreationMethod.DIRECT)) {
                    profileDoc.addProperty(PAV.createdWith, webSite);
                }
                break;
            case API:
                Individual api = m.createIndividual(MEMBER_API, PROV.SoftwareAgent);
                profileDoc.addProperty(PAV.importedBy, api);
                if (history.isClaimed().booleanValue()) {
                    profileDoc.addProperty(PAV.curatedBy, person);
                }
                break;
            default:
                // Some unknown agent!
                profileDoc.addProperty(PAV.createdWith, m.createIndividual(null, PROV.Agent));
        }
        if (history.getLastModifiedDate() != null) {
            Literal when = calendarAsLiteral(history.getLastModifiedDate().getValue(), m);
            profileDoc.addLiteral(PAV.lastUpdateOn, when);
            profileDoc.addLiteral(PROV.generatedAtTime, when);
        }
        if (history.getSubmissionDate() != null) {
            profileDoc.addLiteral(PAV.createdOn, calendarAsLiteral(history.getSubmissionDate().getValue(), m));
        }
        if (history.getCompletionDate() != null) {
            profileDoc.addLiteral(PAV.contributedOn, calendarAsLiteral(history.getCompletionDate().getValue(), m));
        }
        if (history.getDeactivationDate() != null) {
            profileDoc.addLiteral(PROV.invalidatedAtTime, calendarAsLiteral(history.getDeactivationDate().getValue(), m));
        }
    }
    return profileDoc;
}
Also used : Individual(org.apache.jena.ontology.Individual) OrcidHistory(org.orcid.jaxb.model.message.OrcidHistory) Literal(org.apache.jena.rdf.model.Literal)

Example 2 with Literal

use of org.apache.jena.rdf.model.Literal in project jena by apache.

the class TestAssembler method model_5.

@Test
public void model_5() {
    Model assem = FileManager.get().loadModel(dir + "graph-assembler.ttl");
    Resource xDft = assem.getResource("http://example/test#graphDft");
    Store store = create(assem);
    // Default graph: Check they are connected to the same place in the store 
    Model model2 = (Model) Assembler.general.open(xDft);
    Model model3 = (Model) Assembler.general.open(xDft);
    Resource s = model2.createResource();
    Property p = model2.createProperty("http://example/p");
    // Check two models connected to the same graph 
    Literal o2 = model2.createLiteral("xyz");
    model2.add(s, p, o2);
    assertTrue(model3.contains(s, p, o2));
}
Also used : Literal(org.apache.jena.rdf.model.Literal) Model(org.apache.jena.rdf.model.Model) Resource(org.apache.jena.rdf.model.Resource) Store(org.apache.jena.sdb.Store) Property(org.apache.jena.rdf.model.Property) Test(org.junit.Test)

Example 3 with Literal

use of org.apache.jena.rdf.model.Literal in project jena by apache.

the class TestAssembler method model_4.

@Test
public void model_4() {
    Model assem = FileManager.get().loadModel(dir + "graph-assembler.ttl");
    Resource xDft = assem.getResource("http://example/test#graphDft");
    Resource xNamed = assem.getResource("http://example/test#graphNamed");
    Store store = create(assem);
    Model model1 = (Model) Assembler.general.open(xDft);
    Model model2 = (Model) Assembler.general.open(xNamed);
    // Check they are not connected to the same place in the store 
    Resource s = model1.createResource();
    Property p = model1.createProperty("http://example/p");
    Literal o = model1.createLiteral("foo");
    model1.add(s, p, o);
    assertTrue(model1.contains(s, p, o));
    assertTrue(model1.size() == 1);
    assertTrue(model2.size() == 0);
    assertFalse(model1.isIsomorphicWith(model2));
}
Also used : Literal(org.apache.jena.rdf.model.Literal) Model(org.apache.jena.rdf.model.Model) Resource(org.apache.jena.rdf.model.Resource) Store(org.apache.jena.sdb.Store) Property(org.apache.jena.rdf.model.Property) Test(org.junit.Test)

Example 4 with Literal

use of org.apache.jena.rdf.model.Literal in project jena by apache.

the class TestDatasetWithLuceneStoredLiterals method doTestSearchWithLiterals.

protected Map<String, Literal> doTestSearchWithLiterals(String turtle, String queryString, Set<String> expectedEntityURIs) {
    Model model = dataset.getDefaultModel();
    Reader reader = new StringReader(turtle);
    dataset.begin(ReadWrite.WRITE);
    model.read(reader, "", "TURTLE");
    dataset.commit();
    Map<String, Literal> literals = new HashMap<>();
    Query query = QueryFactory.create(queryString);
    dataset.begin(ReadWrite.READ);
    try (QueryExecution qexec = QueryExecutionFactory.create(query, dataset)) {
        ResultSet results = qexec.execSelect();
        assertEquals(expectedEntityURIs.size() > 0, results.hasNext());
        int count;
        for (count = 0; results.hasNext(); count++) {
            QuerySolution soln = results.nextSolution();
            String entityUri = soln.getResource("s").getURI();
            assertTrue(expectedEntityURIs.contains(entityUri));
            Literal literal = soln.getLiteral("literal");
            assertNotNull(literal);
            literals.put(entityUri, literal);
        }
        assertEquals(expectedEntityURIs.size(), count);
    } finally {
        dataset.end();
    }
    return literals;
}
Also used : Query(org.apache.jena.query.Query) HashMap(java.util.HashMap) QuerySolution(org.apache.jena.query.QuerySolution) Literal(org.apache.jena.rdf.model.Literal) Model(org.apache.jena.rdf.model.Model) StringReader(java.io.StringReader) ResultSet(org.apache.jena.query.ResultSet) Reader(java.io.Reader) StringReader(java.io.StringReader) QueryExecution(org.apache.jena.query.QueryExecution)

Example 5 with Literal

use of org.apache.jena.rdf.model.Literal in project jena by apache.

the class TestDatasetWithLuceneStoredLiterals method testLiteralValueWithDatatype.

@Test
public void testLiteralValueWithDatatype() {
    // test capturing of the literal value in a variable, with datatype
    final String testName = "testLiteralValueWithDatatype";
    final String turtle = StrUtils.strjoinNL(TURTLE_PROLOG, "<" + RESOURCE_BASE + testName + ">", "  rdfs:comment true", ".");
    String queryString = StrUtils.strjoinNL(QUERY_PROLOG, "SELECT ?s ?literal", "WHERE {", "    (?s ?score ?literal) text:query (rdfs:comment 'true') .", "}");
    Set<String> expectedURIs = new HashSet<>();
    expectedURIs.addAll(Arrays.asList(RESOURCE_BASE + testName));
    Map<String, Literal> literals = doTestSearchWithLiterals(turtle, queryString, expectedURIs);
    Literal value = literals.get(RESOURCE_BASE + testName);
    assertNotNull(value);
    assertEquals(NodeFactory.createLiteral("true", XSDDatatype.XSDboolean), value.asNode());
}
Also used : Literal(org.apache.jena.rdf.model.Literal) HashSet(java.util.HashSet) Test(org.junit.Test)

Aggregations

Literal (org.apache.jena.rdf.model.Literal)42 Resource (org.apache.jena.rdf.model.Resource)17 Test (org.junit.Test)15 Model (org.apache.jena.rdf.model.Model)12 Property (org.apache.jena.rdf.model.Property)9 UpdateBuilder (org.apache.jena.arq.querybuilder.UpdateBuilder)7 RDFNode (org.apache.jena.rdf.model.RDFNode)7 Node (org.apache.jena.graph.Node)6 HashSet (java.util.HashSet)4 QuerySolution (org.apache.jena.query.QuerySolution)4 Store (org.apache.jena.sdb.Store)3 Reader (java.io.Reader)2 StringReader (java.io.StringReader)2 ArrayList (java.util.ArrayList)2 SelectBuilder (org.apache.jena.arq.querybuilder.SelectBuilder)2 SecuredLiteral (org.apache.jena.permissions.model.SecuredLiteral)2 Dataset (org.apache.jena.query.Dataset)2 Query (org.apache.jena.query.Query)2 QueryExecution (org.apache.jena.query.QueryExecution)2 ResultSet (org.apache.jena.query.ResultSet)2