Search in sources :

Example 6 with Literal

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

the class TestStatisticsAggregates method test.

private static void test(Query query, double expected, DatasetGraph dsg) {
    try (QueryExecution qExec = QueryExecutionFactory.create(query, DatasetFactory.wrap(dsg))) {
        Literal literal = qExec.execSelect().next().getLiteral("X");
        double result = literal.getDouble();
        assertEquals(expected, result, 0.001);
    }
}
Also used : Literal(org.apache.jena.rdf.model.Literal)

Example 7 with Literal

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

the class TestLiteralImpl method testInModel.

public void testInModel() {
    final Model m1 = createModel();
    final Model m2 = createModel();
    final Literal l1 = m1.createLiteral("17");
    final Literal l2 = l1.inModel(m2);
    Assert.assertEquals(l1, l2);
    Assert.assertSame(m2, l2.getModel());
}
Also used : Literal(org.apache.jena.rdf.model.Literal) Model(org.apache.jena.rdf.model.Model)

Example 8 with Literal

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

the class TestLiteralImpl method testTypedLiteralTypesAndValues.

// Tests are not necessarily run in order so use UniqueValueClass2
public void testTypedLiteralTypesAndValues() {
    // Resource r = model.createResource( "eh:/rhubarb" );
    final UniqueValueClass2 r = new UniqueValueClass2("rhubarb");
    Assert.assertNull("not expecting registered RDF Datatype", TypeMapper.getInstance().getTypeByValue(r));
    // Sets the type
    final Literal typed = model.createTypedLiteral(r);
    // mapper -
    // contaminates it
    // with
    // UniqueValueClass2
    final Literal string = model.createLiteral(r.value);
    Assert.assertEquals(string.getLexicalForm(), typed.getLexicalForm());
    Assert.assertEquals(string.getLanguage(), typed.getLanguage());
    JenaTestBase.assertDiffer(string.getDatatypeURI(), typed.getDatatypeURI());
    Assert.assertNotNull("a datatype should have been invented for Resource[Impl]", typed.getDatatype());
    JenaTestBase.assertDiffer(typed, string);
    JenaTestBase.assertDiffer(typed.getValue(), string.getValue());
    Assert.assertEquals(r, typed.getValue());
    JenaTestBase.assertDiffer(typed.hashCode(), string.hashCode());
}
Also used : Literal(org.apache.jena.rdf.model.Literal)

Example 9 with Literal

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

the class TestLiterals method testLanguagedString.

protected void testLanguagedString(final Model model, final String tv, final String lang) {
    final Literal l = model.createLiteral(tv, lang);
    Assert.assertEquals(tv, l.getString());
    Assert.assertEquals(tv, l.getLexicalForm());
    Assert.assertEquals(lang, l.getLanguage());
}
Also used : Literal(org.apache.jena.rdf.model.Literal)

Example 10 with Literal

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

the class TestLiterals method testByte.

protected void testByte(final Model model, final byte tv) {
    final Literal l = model.createTypedLiteral(tv);
    Assert.assertEquals(tv, l.getByte());
    Assert.assertEquals(tv, l.getShort());
    Assert.assertEquals(tv, l.getInt());
    Assert.assertEquals(tv, l.getLong());
}
Also used : Literal(org.apache.jena.rdf.model.Literal)

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