Search in sources :

Example 1 with SparqlTypeErrorException

use of com.bigdata.rdf.error.SparqlTypeErrorException 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

SparqlTypeErrorException (com.bigdata.rdf.error.SparqlTypeErrorException)1 LiteralExtensionIV (com.bigdata.rdf.internal.impl.literal.LiteralExtensionIV)1 BigdataLiteral (com.bigdata.rdf.model.BigdataLiteral)1 BigdataURI (com.bigdata.rdf.model.BigdataURI)1 SuppressFBWarnings (edu.umd.cs.findbugs.annotations.SuppressFBWarnings)1 Literal (org.openrdf.model.Literal)1 URI (org.openrdf.model.URI)1