Search in sources :

Example 6 with IntegerLiteralImpl

use of org.openrdf.model.impl.IntegerLiteralImpl in project wikidata-query-rdf by wikimedia.

the class RdfRepositoryIntegrationTest method syncJustVersion.

private void syncJustVersion(String entityId, int version) {
    Statement statement = statement(entityId, SchemaDotOrg.VERSION, new IntegerLiteralImpl(new BigInteger(Integer.toString(version))));
    rdfRepository.sync(entityId, ImmutableList.of(statement));
}
Also used : Statement(org.openrdf.model.Statement) IntegerLiteralImpl(org.openrdf.model.impl.IntegerLiteralImpl) BigInteger(java.math.BigInteger)

Example 7 with IntegerLiteralImpl

use of org.openrdf.model.impl.IntegerLiteralImpl in project incubator-rya by apache.

the class CountFunction method update.

@Override
public void update(final AggregationElement aggregation, final AggregationState state, final VisibilityBindingSet childBindingSet) {
    checkArgument(aggregation.getAggregationType() == AggregationType.COUNT, "The CountFunction only accepts COUNT AggregationElements.");
    requireNonNull(state);
    requireNonNull(childBindingSet);
    // Only add one to the count if the child contains the binding that we are counting.
    final String aggregatedName = aggregation.getAggregatedBindingName();
    if (childBindingSet.hasBinding(aggregatedName)) {
        final MapBindingSet result = state.getBindingSet();
        final String resultName = aggregation.getResultBindingName();
        final boolean newBinding = !result.hasBinding(resultName);
        if (newBinding) {
            // Initialize the binding.
            result.addBinding(resultName, new IntegerLiteralImpl(BigInteger.ONE));
        } else {
            // Update the existing binding.
            final Literal count = (Literal) result.getValue(resultName);
            final BigInteger updatedCount = count.integerValue().add(BigInteger.ONE);
            result.addBinding(resultName, new IntegerLiteralImpl(updatedCount));
        }
    }
}
Also used : Literal(org.openrdf.model.Literal) IntegerLiteralImpl(org.openrdf.model.impl.IntegerLiteralImpl) BigInteger(java.math.BigInteger) MapBindingSet(org.openrdf.query.impl.MapBindingSet)

Example 8 with IntegerLiteralImpl

use of org.openrdf.model.impl.IntegerLiteralImpl in project incubator-rya by apache.

the class BindingSetStringConverterTest method toString_Integer.

@Test
public void toString_Integer() throws BindingSetConversionException {
    // Setup the binding set that will be converted.
    final MapBindingSet originalBindingSet = new MapBindingSet();
    originalBindingSet.addBinding("x", new IntegerLiteralImpl(BigInteger.valueOf(5)));
    // Convert it to a String.
    final VariableOrder varOrder = new VariableOrder("x");
    final BindingSetConverter<String> converter = new BindingSetStringConverter();
    final String bindingSetString = converter.convert(originalBindingSet, varOrder);
    // Ensure it converted to the expected result.
    final String expected = "5<<~>>http://www.w3.org/2001/XMLSchema#integer";
    assertEquals(expected, bindingSetString);
}
Also used : IntegerLiteralImpl(org.openrdf.model.impl.IntegerLiteralImpl) MapBindingSet(org.openrdf.query.impl.MapBindingSet) Test(org.junit.Test)

Example 9 with IntegerLiteralImpl

use of org.openrdf.model.impl.IntegerLiteralImpl in project incubator-rya by apache.

the class BindingSetStringConverterTest method fromString_Integer.

@Test
public void fromString_Integer() throws BindingSetConversionException {
    // Setup the String that will be converted.
    final String bindingSetString = "5<<~>>http://www.w3.org/2001/XMLSchema#integer";
    // Convert it to a BindingSet
    final BindingSetConverter<String> converter = new BindingSetStringConverter();
    final BindingSet bindingSet = converter.convert(bindingSetString, new VariableOrder("x"));
    // Ensure it converted to the expected result.
    final MapBindingSet expected = new MapBindingSet();
    expected.addBinding("x", new IntegerLiteralImpl(BigInteger.valueOf(5)));
    assertEquals(expected, bindingSet);
}
Also used : BindingSet(org.openrdf.query.BindingSet) MapBindingSet(org.openrdf.query.impl.MapBindingSet) IntegerLiteralImpl(org.openrdf.model.impl.IntegerLiteralImpl) MapBindingSet(org.openrdf.query.impl.MapBindingSet) Test(org.junit.Test)

Aggregations

IntegerLiteralImpl (org.openrdf.model.impl.IntegerLiteralImpl)9 MapBindingSet (org.openrdf.query.impl.MapBindingSet)5 BigInteger (java.math.BigInteger)4 Test (org.junit.Test)4 Literal (org.openrdf.model.Literal)3 Statement (org.openrdf.model.Statement)3 Value (org.openrdf.model.Value)3 RandomizedTest (com.carrotsearch.randomizedtesting.RandomizedTest)2 ArrayList (java.util.ArrayList)2 TupleQueryResult (org.openrdf.query.TupleQueryResult)2 ValueExprEvaluationException (org.openrdf.query.algebra.evaluation.ValueExprEvaluationException)2 BigDecimal (java.math.BigDecimal)1 DecimalLiteralImpl (org.openrdf.model.impl.DecimalLiteralImpl)1 LiteralImpl (org.openrdf.model.impl.LiteralImpl)1 URIImpl (org.openrdf.model.impl.URIImpl)1 BindingSet (org.openrdf.query.BindingSet)1 PropertyType (org.wikidata.query.rdf.common.uri.WikibaseUris.PropertyType)1