use of org.openrdf.model.impl.LiteralImpl in project wikidata-query-rdf by wikimedia.
the class StatementHelper method randomStatementsAbout.
/**
* Construct a bunch of random statements about the given subject.
*/
public static List<Statement> randomStatementsAbout(String s, int count) {
List<Statement> statements = new ArrayList<>();
for (int i = 0; i < count; i++) {
String p = "P" + randomInt();
LiteralImpl o = randomDate();
statements.add(statement(s, p, o));
}
return statements;
}
use of org.openrdf.model.impl.LiteralImpl in project wikidata-query-rdf by wikimedia.
the class RdfRepositoryIntegrationTest method expandedStatementWithExpandedValue.
@Test
public void expandedStatementWithExpandedValue() throws QueryEvaluationException {
String statementUri = uris.statement() + "someotheruuid";
String valueUri = uris.value() + "someuuid";
cleanupList.add(valueUri);
List<Statement> george = new ArrayList<>();
statement(george, "Q23", "P509", statementUri);
statement(george, statementUri, uris.property(PropertyType.STATEMENT_VALUE) + "P509", valueUri);
statement(george, valueUri, Ontology.Time.VALUE, new LiteralImpl("cat"));
statement(george, valueUri, Ontology.Time.CALENDAR_MODEL, new LiteralImpl("animals"));
rdfRepository.sync("Q23", george);
assertTrue(rdfRepository.ask(Ontology.prefix(uris.prefixes(new StringBuilder())).append("ASK { wd:Q23 p:P509 [ psv:P509 [ ontology:timeValue \"cat\" ] ] }").toString()));
assertTrue(rdfRepository.ask(Ontology.prefix(uris.prefixes(new StringBuilder())).append("ASK { wd:Q23 p:P509 [ psv:P509 [ ontology:timeCalendarModel \"animals\" ] ] }").toString()));
}
use of org.openrdf.model.impl.LiteralImpl in project incubator-rya by apache.
the class FluoStringConverter method toVar.
/**
* Converts the String representation of a {@link Var} back into the object version.
*
* @param varString - The {@link Var} represented as a String. (not null)
* @return A {@link Var} built from the string.
*/
public static Var toVar(final String varString) {
checkNotNull(varString);
final String[] varParts = varString.split(TYPE_DELIM);
final String name = varParts[0];
// The variable is a constant value.
if (varParts.length > 1) {
final String dataTypeString = varParts[1];
if (dataTypeString.equals(URI_TYPE)) {
// Handle a URI object.
Preconditions.checkArgument(varParts.length == 2);
final String valueString = name.substring("-const-".length());
final Var var = new Var(name, new URIImpl(valueString));
var.setConstant(true);
return var;
} else if (dataTypeString.equals(RyaSchema.BNODE_NAMESPACE)) {
// Handle a BNode object
Preconditions.checkArgument(varParts.length == 3);
Var var = new Var(name);
var.setValue(new BNodeImpl(varParts[2]));
return var;
} else {
// Handle a Literal Value.
Preconditions.checkArgument(varParts.length == 2);
final String valueString = name.substring("-const-".length());
final URI dataType = new URIImpl(dataTypeString);
final Literal value = new LiteralImpl(valueString, dataType);
final Var var = new Var(name, value);
var.setConstant(true);
return var;
}
} else {
// The variable is a named variable.
return new Var(varString);
}
}
use of org.openrdf.model.impl.LiteralImpl in project incubator-rya by apache.
the class FluoStringConverterTest method toVar_int.
@Test
public void toVar_int() throws MalformedQueryException {
// Setup the string representation of the variable.
final String varString = "-const-5<<~>>http://www.w3.org/2001/XMLSchema#integer";
// Convert it to a Var object.
final Var result = FluoStringConverter.toVar(varString);
// Ensure it converted to the expected result.
final Var expected = new Var("-const-5", new LiteralImpl("5", XMLSchema.INTEGER));
expected.setConstant(true);
assertEquals(expected, result);
}
use of org.openrdf.model.impl.LiteralImpl in project incubator-rya by apache.
the class FluoStringConverterTest method toVar_string.
@Test
public void toVar_string() {
// Setup the string representation of the variable.
final String varString = "-const-Chipotle<<~>>http://www.w3.org/2001/XMLSchema#string";
// Convert it to a Var object.
final Var result = FluoStringConverter.toVar(varString);
// Ensure it converted to the expected result.
final Var expected = new Var("-const-Chipotle", new LiteralImpl("Chipotle", XMLSchema.STRING));
expected.setConstant(true);
assertEquals(expected, result);
}
Aggregations