use of com.bigdata.rdf.internal.impl.literal.LiteralExtensionIV in project wikidata-query-rdf by wikimedia.
the class AbstractMultiTypeExtension method resolveDataType.
/**
* Convert the literal into a uri as resolved by the resolve this extension
* received on construction.
*/
@SuppressWarnings("rawtypes")
protected BigdataURI resolveDataType(LiteralExtensionIV literal) {
IV extensionIV = literal.getExtensionIV();
BigdataURI dt = dataTypes.get(extensionIV);
if (dt == null) {
throw new IllegalArgumentException("Unrecognized datatype: " + extensionIV);
}
return dt;
}
use of com.bigdata.rdf.internal.impl.literal.LiteralExtensionIV 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;
}
use of com.bigdata.rdf.internal.impl.literal.LiteralExtensionIV in project wikidata-query-rdf by wikimedia.
the class WikibaseGeoUnitTest method testInteger.
@Test
@SuppressWarnings("rawtypes")
public void testInteger() {
LexiconRelation rel = store().getLexiconRelation();
Literal l = pointLiteral("Point(40.4426 -80.0068)");
LiteralExtensionIV iv = (LiteralExtensionIV) rel.getInlineIV(l);
assertEquals(GeoSparql.WKT_LITERAL, iv.getExtensionIV().getValue().toString());
assertEquals(new XSDIntegerIV(new BigInteger("1008819921758573694187894119050371595694851885687493623808")), iv.getDelegate());
}
use of com.bigdata.rdf.internal.impl.literal.LiteralExtensionIV in project wikidata-query-rdf by wikimedia.
the class WikibaseDateExtension method doMathOp.
@SuppressWarnings({ "rawtypes", "checkstyle:cyclomaticcomplexity", "checkstyle:NPathComplexity" })
@SuppressFBWarnings(value = "LEST_LOST_EXCEPTION_STACK_TRACE", justification = "Cause is really not needed here.")
@Override
public IV doMathOp(final Literal l1, final IV iv1, final Literal l2, final IV iv2, final MathOp op, final BigdataValueFactory vf) {
URI dt1 = l1.getDatatype();
URI dt2 = l2.getDatatype();
boolean d1 = isWikibaseDateURI(dt1);
boolean d2 = isWikibaseDateURI(dt2);
if (!d1 && !d2) {
throw new SparqlTypeErrorException();
}
LiteralExtensionIV liv1 = d1 ? normalizeIV(l1, iv1) : null;
LiteralExtensionIV liv2 = d2 ? normalizeIV(l2, iv2) : null;
if (d1 && d2) {
return handleTwoDates(liv1, liv2, op);
}
try {
// Now we have one date and one duration
if (op == MathOp.PLUS) {
LiteralExtensionIV iv = d1 ? liv1 : liv2;
Literal lduration = d1 ? l2 : l1;
return datePlusDuration(iv, DATATYPE_FACTORY.newDuration(lduration.getLabel()), vf);
}
if (op == MathOp.MINUS) {
return datePlusDuration(liv1, DATATYPE_FACTORY.newDuration(l2.getLabel()).negate(), vf);
}
} catch (IllegalArgumentException e) {
// If we had trouble converting any arguments, make it SPARQL error
throw new SparqlTypeErrorException();
}
throw new SparqlTypeErrorException();
}
Aggregations