Search in sources :

Example 76 with LiteralImpl

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)));
}
Also used : BindingSet(org.openrdf.query.BindingSet) LiteralImpl(org.openrdf.model.impl.LiteralImpl) TupleQueryResult(org.openrdf.query.TupleQueryResult) Test(org.junit.Test)

Example 77 with LiteralImpl

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)));
}
Also used : BindingSet(org.openrdf.query.BindingSet) LiteralImpl(org.openrdf.model.impl.LiteralImpl) TupleQueryResult(org.openrdf.query.TupleQueryResult) Test(org.junit.Test)

Example 78 with LiteralImpl

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)));
}
Also used : BindingSet(org.openrdf.query.BindingSet) LiteralImpl(org.openrdf.model.impl.LiteralImpl) TupleQueryResult(org.openrdf.query.TupleQueryResult) Test(org.junit.Test)

Example 79 with LiteralImpl

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)));
}
Also used : LiteralImpl(org.openrdf.model.impl.LiteralImpl) BindingSet(org.openrdf.query.BindingSet) Statement(org.openrdf.model.Statement) ArrayList(java.util.ArrayList) TupleQueryResult(org.openrdf.query.TupleQueryResult) Test(org.junit.Test)

Example 80 with LiteralImpl

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);
}
Also used : LiteralImpl(org.openrdf.model.impl.LiteralImpl)

Aggregations

LiteralImpl (org.openrdf.model.impl.LiteralImpl)155 Test (org.junit.Test)124 URIImpl (org.openrdf.model.impl.URIImpl)62 BindingSet (org.openrdf.query.BindingSet)58 Statement (org.openrdf.model.Statement)40 ArrayList (java.util.ArrayList)34 TupleQueryResult (org.openrdf.query.TupleQueryResult)34 QueryBindingSet (org.openrdf.query.algebra.evaluation.QueryBindingSet)33 URI (org.openrdf.model.URI)29 IntegerLiteralImpl (org.openrdf.model.impl.IntegerLiteralImpl)23 QueryEvaluationException (org.openrdf.query.QueryEvaluationException)22 HashSet (java.util.HashSet)21 RyaStatement (org.apache.rya.api.domain.RyaStatement)19 RyaType (org.apache.rya.api.domain.RyaType)19 RyaURI (org.apache.rya.api.domain.RyaURI)19 ParsedQuery (org.openrdf.query.parser.ParsedQuery)19 SPARQLParser (org.openrdf.query.parser.sparql.SPARQLParser)19 StatementMetadata (org.apache.rya.api.domain.StatementMetadata)17 StatementImpl (org.openrdf.model.impl.StatementImpl)16 NumericLiteralImpl (org.openrdf.model.impl.NumericLiteralImpl)15