Search in sources :

Example 71 with Literal

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

the class TupleExprs method getConstVarName.

public static String getConstVarName(Value value) {
    if (value == null) {
        throw new IllegalArgumentException("value can not be null");
    }
    // We use toHexString to get a more compact stringrep.
    String uniqueStringForValue = Integer.toHexString(value.stringValue().hashCode());
    if (value instanceof Literal) {
        uniqueStringForValue += "_lit";
        // we need to append datatype and/or language tag to ensure a unique
        // var name (see SES-1927)
        Literal lit = (Literal) value;
        if (lit.getDatatype() != null) {
            uniqueStringForValue += "_" + Integer.toHexString(lit.getDatatype().hashCode());
        }
        if (lit.getLanguage() != null) {
            uniqueStringForValue += "_" + Integer.toHexString(lit.getLanguage().hashCode());
        }
    } else if (value instanceof BNode) {
        uniqueStringForValue += "_node";
    } else {
        uniqueStringForValue += "_uri";
    }
    return "_const_" + uniqueStringForValue;
}
Also used : BNode(org.eclipse.rdf4j.model.BNode) Literal(org.eclipse.rdf4j.model.Literal)

Example 72 with Literal

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

the class ModelsTest method testGetPropertyLiteral.

@Test
public void testGetPropertyLiteral() {
    Literal lit1 = VF.createLiteral(1.0);
    model1.add(foo, bar, lit1);
    model1.add(foo, bar, foo);
    Literal l = Models.getPropertyLiteral(model1, foo, bar).orElse(null);
    assertNotNull(l);
    assertEquals(lit1, l);
}
Also used : Literal(org.eclipse.rdf4j.model.Literal) Test(org.junit.Test)

Example 73 with Literal

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

the class ModelsTest method testGetProperties.

@Test
public void testGetProperties() {
    Literal lit1 = VF.createLiteral(1.0);
    model1.add(foo, bar, lit1);
    model1.add(foo, bar, foo);
    Set<Value> values = Models.getProperties(model1, foo, bar);
    assertNotNull(values);
    assertEquals(2, values.size());
    assertTrue(values.contains(lit1));
    assertTrue(values.contains(foo));
}
Also used : Literal(org.eclipse.rdf4j.model.Literal) Value(org.eclipse.rdf4j.model.Value) Test(org.junit.Test)

Example 74 with Literal

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

the class ModelsTest method testGetPropertyIRI2.

@Test
public void testGetPropertyIRI2() {
    Literal lit1 = VF.createLiteral(1.0);
    model1.add(foo, bar, lit1);
    Optional<IRI> iri = Models.getPropertyIRI(model1, foo, bar);
    assertEquals(Optional.empty(), iri);
}
Also used : IRI(org.eclipse.rdf4j.model.IRI) Literal(org.eclipse.rdf4j.model.Literal) Test(org.junit.Test)

Example 75 with Literal

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

the class ModelsTest method testSetPropertyWithContext2.

@Test
public void testSetPropertyWithContext2() {
    Literal lit1 = VF.createLiteral(1.0);
    IRI graph1 = VF.createIRI("urn:g1");
    IRI graph2 = VF.createIRI("urn:g2");
    model1.add(foo, bar, lit1, graph1);
    model1.add(foo, bar, bar);
    model1.add(foo, bar, foo, graph2);
    Literal lit2 = VF.createLiteral(2.0);
    Model m = Models.setProperty(model1, foo, bar, lit2);
    assertNotNull(m);
    assertEquals(model1, m);
    assertFalse(model1.contains(foo, bar, lit1));
    assertFalse(model1.contains(foo, bar, lit1, graph1));
    assertFalse(model1.contains(foo, bar, foo));
    assertFalse(model1.contains(foo, bar, bar));
    assertFalse(model1.contains(foo, bar, foo, graph2));
    assertTrue(model1.contains(foo, bar, lit2));
}
Also used : IRI(org.eclipse.rdf4j.model.IRI) Literal(org.eclipse.rdf4j.model.Literal) LinkedHashModel(org.eclipse.rdf4j.model.impl.LinkedHashModel) Model(org.eclipse.rdf4j.model.Model) 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