Search in sources :

Example 1 with LiteralExtensionIV

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;
}
Also used : IV(com.bigdata.rdf.internal.IV) AbstractLiteralIV(com.bigdata.rdf.internal.impl.literal.AbstractLiteralIV) LiteralExtensionIV(com.bigdata.rdf.internal.impl.literal.LiteralExtensionIV) BigdataURI(com.bigdata.rdf.model.BigdataURI)

Example 2 with LiteralExtensionIV

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;
}
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 3 with LiteralExtensionIV

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());
}
Also used : GeoUtils.pointLiteral(org.wikidata.query.rdf.blazegraph.geo.GeoUtils.pointLiteral) Literal(org.openrdf.model.Literal) XSDIntegerIV(com.bigdata.rdf.internal.impl.literal.XSDIntegerIV) BigInteger(java.math.BigInteger) LiteralExtensionIV(com.bigdata.rdf.internal.impl.literal.LiteralExtensionIV) LexiconRelation(com.bigdata.rdf.lexicon.LexiconRelation) Test(org.junit.Test)

Example 4 with LiteralExtensionIV

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();
}
Also used : Literal(org.openrdf.model.Literal) BigdataLiteral(com.bigdata.rdf.model.BigdataLiteral) BigdataURI(com.bigdata.rdf.model.BigdataURI) URI(org.openrdf.model.URI) LiteralExtensionIV(com.bigdata.rdf.internal.impl.literal.LiteralExtensionIV) SparqlTypeErrorException(com.bigdata.rdf.error.SparqlTypeErrorException) SuppressFBWarnings(edu.umd.cs.findbugs.annotations.SuppressFBWarnings)

Aggregations

LiteralExtensionIV (com.bigdata.rdf.internal.impl.literal.LiteralExtensionIV)4 BigdataURI (com.bigdata.rdf.model.BigdataURI)2 Literal (org.openrdf.model.Literal)2 SparqlTypeErrorException (com.bigdata.rdf.error.SparqlTypeErrorException)1 IV (com.bigdata.rdf.internal.IV)1 AbstractLiteralIV (com.bigdata.rdf.internal.impl.literal.AbstractLiteralIV)1 XSDIntegerIV (com.bigdata.rdf.internal.impl.literal.XSDIntegerIV)1 XSDNumericIV (com.bigdata.rdf.internal.impl.literal.XSDNumericIV)1 LexiconRelation (com.bigdata.rdf.lexicon.LexiconRelation)1 BigdataLiteral (com.bigdata.rdf.model.BigdataLiteral)1 SuppressFBWarnings (edu.umd.cs.findbugs.annotations.SuppressFBWarnings)1 BigInteger (java.math.BigInteger)1 Test (org.junit.Test)1 URI (org.openrdf.model.URI)1 GeoUtils.pointLiteral (org.wikidata.query.rdf.blazegraph.geo.GeoUtils.pointLiteral)1 WikibaseDate (org.wikidata.query.rdf.common.WikibaseDate)1