use of org.openrdf.model.impl.LiteralImpl in project wikidata-query-rdf by wikimedia.
the class WikibaseGeoExtensionIntegrationTest method distanceWithUnits.
@Test
public void distanceWithUnits() throws QueryEvaluationException {
// FIXME: for now, we just accept anything as units and ignore it. We
// need to do better.
TupleQueryResult results = rdfRepository.query("SELECT * WHERE {BIND ( geof:distance(\"Point(0 0)\"^^geo:wktLiteral, \"Point(-1 -1)\"^^geo:wktLiteral, wd:Q2) AS ?distance)}");
BindingSet result = results.next();
// distance between two points
assertThat(result, binds("distance", new LiteralImpl("157.2418158675294", XMLSchema.DOUBLE)));
}
use of org.openrdf.model.impl.LiteralImpl in project wikidata-query-rdf by wikimedia.
the class WikibaseDateExtensionIntegrationTest method dateNow.
@Test
public void dateNow() throws QueryEvaluationException {
TupleQueryResult results = rdfRepository.query("SELECT (year(now()) as ?year) WHERE { }");
BindingSet result = results.next();
int year = Calendar.getInstance(TimeZone.getTimeZone("UTC"), Locale.ROOT).get(Calendar.YEAR);
assertThat(result, binds("year", new LiteralImpl(String.valueOf(year), XMLSchema.INTEGER)));
}
use of org.openrdf.model.impl.LiteralImpl in project wikidata-query-rdf by wikimedia.
the class WikibaseDateExtensionIntegrationTest method dateMathMore.
@Test
public void dateMathMore() throws QueryEvaluationException {
String query = "prefix schema: <http://schema.org/>\n" + "INSERT {\n" + "<http://test.com/a> schema:lastModified \"0001-01-01T00:00:00\"^^xsd:dateTime .\n" + "<http://test.com/a> schema:lastModified \"-0001-01-01\"^^xsd:date .\n" + "<http://test.com/a> schema:lastModified \"-13798000000-01-01T00:00:00\"^^xsd:dateTime .\n" + "<http://test.com/b> schema:lastModified \"0000-01-01T00:00:00\"^^xsd:dateTime .\n" + "} WHERE {}";
rdfRepository.update(query);
TupleQueryResult results = rdfRepository.query("prefix schema: <http://schema.org/>\n" + "SELECT (?a - ?b as ?diff) WHERE { <http://test.com/a> schema:lastModified ?a . <http://test.com/b> schema:lastModified ?b } ORDER BY DESC(?diff)");
BindingSet result = results.next();
assertThat(result, binds("diff", new LiteralImpl("366.0", XMLSchema.DOUBLE)));
result = results.next();
assertThat(result, binds("diff", new LiteralImpl("-365.0", XMLSchema.DOUBLE)));
result = results.next();
assertThat(result, binds("diff", new LiteralImpl("-5.039616015E12", XMLSchema.DOUBLE)));
}
use of org.openrdf.model.impl.LiteralImpl in project wikidata-query-rdf by wikimedia.
the class WikibaseDateExtensionIntegrationTest method dateFunctions.
@Test
public void dateFunctions() throws QueryEvaluationException {
List<Statement> statements = new ArrayList<>();
statements.add(statement("Q23", "P569", new LiteralImpl("0000-01-01T00:00:00Z", XMLSchema.DATETIME)));
rdfRepository.sync("Q23", statements);
TupleQueryResult results = rdfRepository.query("SELECT (year(?date) as ?year) WHERE { ?s ?p ?date }");
BindingSet result = results.next();
assertThat(result, binds("year", new LiteralImpl("0", XMLSchema.INTEGER)));
results = rdfRepository.query("SELECT (day(?date) as ?day) WHERE { ?s ?p ?date FILTER (year(?date) != year(now())) }");
result = results.next();
assertThat(result, binds("day", new LiteralImpl("1", XMLSchema.INTEGER)));
}
use of org.openrdf.model.impl.LiteralImpl in project wikidata-query-rdf by wikimedia.
the class ExpandedStatementBuilder method buildBasicEntityIfNeeded.
/**
* Build the basic entity for the subject if includeBasicEntityForSubject.
*/
private void buildBasicEntityIfNeeded() {
if (!includeBasicEntityForSubject) {
return;
}
if (version == null) {
version = new LiteralImpl("a revision number I promise");
}
if (dateModified == null) {
dateModified = new LiteralImpl("a date I promise");
}
String entityDataUri = uris.entityData() + entity;
entityDataAboutDecl = statement(statements, entityDataUri, SchemaDotOrg.ABOUT, entity);
entityDataVersionDecl = statement(statements, entityDataUri, SchemaDotOrg.VERSION, version);
entityDataDateModifiedDecl = statement(statements, entityDataUri, SchemaDotOrg.DATE_MODIFIED, dateModified);
}
Aggregations