Search in sources :

Example 41 with Literal

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

the class TestDatasetWithLuceneStoredLiterals method testLiteralValue.

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

Example 42 with Literal

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

the class TestDatasetWithLuceneStoredLiterals method testLiteralValueNonDefaultField.

@Test
public void testLiteralValueNonDefaultField() {
    // test basic capturing of the literal value in a variable
    final String testName = "testLiteralValueNonDefaultField";
    final String turtle = StrUtils.strjoinNL(TURTLE_PROLOG, "<" + RESOURCE_BASE + testName + ">", "  rdfs:comment 'a text comment'", ".");
    String queryString = StrUtils.strjoinNL(QUERY_PROLOG, "SELECT ?s ?literal", "WHERE {", "    (?s ?score ?literal) text:query (rdfs:comment 'text') .", "}");
    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("a text comment"), 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