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;
}
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);
}
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));
}
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);
}
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));
}
Aggregations