Search in sources :

Example 76 with Literal

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

the class ModelsTest method testObjectLiteral.

public void testObjectLiteral() {
    Literal lit = VF.createLiteral(1.0);
    model1.add(foo, bar, lit);
    model1.add(foo, bar, foo);
    Value result = Models.objectLiteral(model1).orElse(null);
    assertNotNull(result);
    assertEquals(lit, result);
}
Also used : Literal(org.eclipse.rdf4j.model.Literal) Value(org.eclipse.rdf4j.model.Value)

Example 77 with Literal

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

the class DAWGTestResultSetWriter method startQueryResult.

/*---------*
	 * Methods *
	 *---------*/
@Override
public void startQueryResult(List<String> bindingNames) throws TupleQueryResultHandlerException {
    try {
        rdfHandler.startRDF();
        resultSetNode = vf.createBNode();
        bnodeMap.clear();
        reportStatement(resultSetNode, RDF.TYPE, RESULTSET);
        for (String bindingName : bindingNames) {
            Literal bindingNameLit = vf.createLiteral(bindingName);
            reportStatement(resultSetNode, RESULTVARIABLE, bindingNameLit);
        }
    } catch (RDFHandlerException e) {
        throw new TupleQueryResultHandlerException(e);
    }
}
Also used : RDFHandlerException(org.eclipse.rdf4j.rio.RDFHandlerException) TupleQueryResultHandlerException(org.eclipse.rdf4j.query.TupleQueryResultHandlerException) Literal(org.eclipse.rdf4j.model.Literal)

Example 78 with Literal

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

the class DAWGTestBooleanParser method endRDF.

@Override
public void endRDF() throws RDFHandlerException {
    try {
        Resource resultSetNode = GraphUtil.getUniqueSubject(graph, RDF.TYPE, RESULTSET);
        Literal booleanLit = GraphUtil.getUniqueObjectLiteral(graph, resultSetNode, BOOLEAN);
        if (booleanLit.equals(DAWGTestResultSetSchema.TRUE)) {
            value = true;
        } else if (booleanLit.equals(DAWGTestResultSetSchema.FALSE)) {
            value = false;
        } else {
            throw new RDFHandlerException("Invalid boolean value: " + booleanLit);
        }
    } catch (GraphUtilException e) {
        throw new RDFHandlerException(e.getMessage(), e);
    }
}
Also used : RDFHandlerException(org.eclipse.rdf4j.rio.RDFHandlerException) Literal(org.eclipse.rdf4j.model.Literal) Resource(org.eclipse.rdf4j.model.Resource) GraphUtilException(org.eclipse.rdf4j.model.util.GraphUtilException)

Example 79 with Literal

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

the class LiteralsTest method testCreateLiteralOrFailObjectLong.

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

Example 80 with Literal

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

the class LiteralsTest method testCreateLiteralObjectObject.

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

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