Search in sources :

Example 1 with XSDNumericIV

use of com.bigdata.rdf.internal.impl.literal.XSDNumericIV in project wikidata-query-rdf by wikimedia.

the class WikibaseDateExtension method datePlusDuration.

/**
 * Add Duration to date.
 * @param iv
 * @param d
 * @param vf
 * @return
 */
@SuppressWarnings({ "rawtypes", "unchecked" })
private IV datePlusDuration(LiteralExtensionIV iv, Duration d, BigdataValueFactory vf) {
    long ts = iv.getDelegate().longValue();
    WikibaseDate newdate = WikibaseDate.fromSecondsSinceEpoch(ts).addDuration(d);
    LiteralExtensionIV result = new LiteralExtensionIV(new XSDNumericIV(newdate.secondsSinceEpoch()), iv.getExtensionIV());
    result.setValue(safeAsValue(result, vf, getDataType(iv)));
    return result;
}
Also used : WikibaseDate(org.wikidata.query.rdf.common.WikibaseDate) XSDNumericIV(com.bigdata.rdf.internal.impl.literal.XSDNumericIV) LiteralExtensionIV(com.bigdata.rdf.internal.impl.literal.LiteralExtensionIV)

Example 2 with XSDNumericIV

use of com.bigdata.rdf.internal.impl.literal.XSDNumericIV in project wikidata-query-rdf by wikimedia.

the class MWApiServiceCallUnitTest method testResults.

@Test
public void testResults() throws Exception {
    List<OutputVariable> outputVars = ImmutableList.of(new OutputVariable(makeVariable("var"), "@name"), new OutputVariable(makeVariable("header"), "/api/header/@value"), new OutputVariable(OutputVariable.Type.ITEM, makeVariable("item"), "@id"), new OutputVariable(OutputVariable.Type.ORDINAL, makeVariable("num"), "@id"));
    when(template.getItemsPath()).thenReturn("/api/result");
    InputStream responseStream = new ByteArrayInputStream("<api><header value=\"heading\"></header><result name=\"result1\" id=\"Q1\"></result><result name=\"result2\"></result></api>".getBytes("UTF-8"));
    Iterator<IBindingSet> results = createCall(outputVars).parseResponse(responseStream, binding, 3).getResultIterator();
    assertTrue(results.hasNext());
    IBindingSet result = results.next();
    assertThat(result, binds("var", "result1"));
    assertThat(result, binds("header", "heading"));
    assertThat(result, bindsItem("item", "Q1"));
    assertThat(result, binds("num", new XSDNumericIV<>(3)));
    result = results.next();
    assertThat(result, binds("var", "result2"));
    assertThat(result, binds("header", "heading"));
    assertThat(result, binds("num", new XSDNumericIV<>(4)));
    assertFalse(results.hasNext());
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) IBindingSet(com.bigdata.bop.IBindingSet) XSDNumericIV(com.bigdata.rdf.internal.impl.literal.XSDNumericIV) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) OutputVariable(org.wikidata.query.rdf.blazegraph.mwapi.ApiTemplate.OutputVariable) Test(org.junit.Test)

Aggregations

XSDNumericIV (com.bigdata.rdf.internal.impl.literal.XSDNumericIV)2 IBindingSet (com.bigdata.bop.IBindingSet)1 LiteralExtensionIV (com.bigdata.rdf.internal.impl.literal.LiteralExtensionIV)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 InputStream (java.io.InputStream)1 Test (org.junit.Test)1 OutputVariable (org.wikidata.query.rdf.blazegraph.mwapi.ApiTemplate.OutputVariable)1 WikibaseDate (org.wikidata.query.rdf.common.WikibaseDate)1