Search in sources :

Example 66 with Literal

use of org.eclipse.rdf4j.model.Literal in project rdf4j by eclipse.

the class LiteralsTest method testCreateLiteralObjectInteger.

/**
 * Test method for
 * {@link org.eclipse.rdf4j.model.util.Literals#createLiteral(org.eclipse.rdf4j.model.ValueFactory, java.lang.Object)}
 * .
 */
@Test
public void testCreateLiteralObjectInteger() throws Exception {
    Object obj = new Integer(4);
    Literal l = Literals.createLiteral(SimpleValueFactory.getInstance(), obj);
    assertNotNull(l);
    assertEquals(l.getDatatype(), XMLSchema.INT);
    assertEquals(l.getLabel(), "4");
}
Also used : Literal(org.eclipse.rdf4j.model.Literal) Test(org.junit.Test)

Example 67 with Literal

use of org.eclipse.rdf4j.model.Literal in project rdf4j by eclipse.

the class LiteralsTest method testCreateLiteralObjectString.

/**
 * Test method for
 * {@link org.eclipse.rdf4j.model.util.Literals#createLiteral(org.eclipse.rdf4j.model.ValueFactory, java.lang.Object)}
 * .
 */
@Test
public void testCreateLiteralObjectString() throws Exception {
    Object obj = "random unique string";
    Literal l = Literals.createLiteral(SimpleValueFactory.getInstance(), obj);
    assertNotNull(l);
    assertEquals(l.getDatatype(), XMLSchema.STRING);
    assertEquals(l.getLabel(), "random unique string");
}
Also used : Literal(org.eclipse.rdf4j.model.Literal) Test(org.junit.Test)

Example 68 with Literal

use of org.eclipse.rdf4j.model.Literal in project rdf4j by eclipse.

the class LiteralsTest method testCreateLiteralObjectBoolean.

/**
 * Test method for
 * {@link org.eclipse.rdf4j.model.util.Literals#createLiteral(org.eclipse.rdf4j.model.ValueFactory, java.lang.Object)}
 * .
 */
@Test
public void testCreateLiteralObjectBoolean() throws Exception {
    Object obj = Boolean.TRUE;
    Literal l = Literals.createLiteral(SimpleValueFactory.getInstance(), obj);
    assertNotNull(l);
    assertEquals(l.getDatatype(), XMLSchema.BOOLEAN);
    assertTrue(l.booleanValue());
}
Also used : Literal(org.eclipse.rdf4j.model.Literal) Test(org.junit.Test)

Example 69 with Literal

use of org.eclipse.rdf4j.model.Literal in project rdf4j by eclipse.

the class LiteralsTest method testCreateLiteralOrFailObjectByte.

/**
 * Test method for
 * {@link org.eclipse.rdf4j.model.util.Literals#createLiteralOrFail(org.eclipse.rdf4j.model.ValueFactory, java.lang.Object)}
 * .
 */
@Test
public void testCreateLiteralOrFailObjectByte() throws Exception {
    Object obj = new Integer(42).byteValue();
    Literal l = Literals.createLiteralOrFail(SimpleValueFactory.getInstance(), obj);
    assertNotNull(l);
    assertEquals(l.getDatatype(), XMLSchema.BYTE);
    assertEquals(l.getLabel(), "42");
}
Also used : Literal(org.eclipse.rdf4j.model.Literal) Test(org.junit.Test)

Example 70 with Literal

use of org.eclipse.rdf4j.model.Literal in project rdf4j by eclipse.

the class DAWGTestResultSetParser method getBindingNames.

private List<String> getBindingNames(Resource resultSetNode) throws RDFHandlerException {
    List<String> bindingNames = new ArrayList<String>(16);
    Iterator<Value> varIter = GraphUtil.getObjectIterator(graph, resultSetNode, RESULTVARIABLE);
    while (varIter.hasNext()) {
        Value varName = varIter.next();
        if (varName instanceof Literal) {
            bindingNames.add(((Literal) varName).getLabel());
        } else {
            throw new RDFHandlerException("Value for " + RESULTVARIABLE + " is not a literal: " + varName);
        }
    }
    return bindingNames;
}
Also used : RDFHandlerException(org.eclipse.rdf4j.rio.RDFHandlerException) Literal(org.eclipse.rdf4j.model.Literal) ArrayList(java.util.ArrayList) Value(org.eclipse.rdf4j.model.Value)

Aggregations

Literal (org.eclipse.rdf4j.model.Literal)96 Test (org.junit.Test)52 IRI (org.eclipse.rdf4j.model.IRI)34 Value (org.eclipse.rdf4j.model.Value)17 BNode (org.eclipse.rdf4j.model.BNode)14 Model (org.eclipse.rdf4j.model.Model)13 Statement (org.eclipse.rdf4j.model.Statement)13 Resource (org.eclipse.rdf4j.model.Resource)9 LinkedHashModel (org.eclipse.rdf4j.model.impl.LinkedHashModel)8 RDFHandlerException (org.eclipse.rdf4j.rio.RDFHandlerException)7 InputStream (java.io.InputStream)6 Date (java.util.Date)6 BindingSet (org.eclipse.rdf4j.query.BindingSet)5 IOException (java.io.IOException)4 ValueFactory (org.eclipse.rdf4j.model.ValueFactory)4 SimpleValueFactory (org.eclipse.rdf4j.model.impl.SimpleValueFactory)4 AbstractQueryResultIOTupleTest (org.eclipse.rdf4j.query.resultio.AbstractQueryResultIOTupleTest)4 QueryResultCollector (org.eclipse.rdf4j.query.resultio.helpers.QueryResultCollector)4 SPARQLResultsJSONParser (org.eclipse.rdf4j.query.resultio.sparqljson.SPARQLResultsJSONParser)4 ArrayList (java.util.ArrayList)3