Search in sources :

Example 6 with IV

use of com.bigdata.rdf.internal.IV in project wikidata-query-rdf by wikimedia.

the class WikibaseDistanceBOp method get.

@Override
public IV get(IBindingSet bindingSet) {
    final IV left = getAndCheckLiteral(0, bindingSet);
    final IV right = getAndCheckLiteral(1, bindingSet);
    final CoordinateDD leftPoint = getCoordinateFromIV(left);
    final CoordinateDD rightPoint = getCoordinateFromIV(right);
    // TODO: allow to supply Units
    final double distance;
    if (leftPoint.equals(rightPoint) || veryClose(leftPoint, rightPoint)) {
        distance = 0;
    } else {
        distance = leftPoint.distance(rightPoint, UNITS.Kilometers);
    }
    final BigdataLiteral dist = getValueFactory().createLiteral(distance);
    return super.asIV(dist, bindingSet);
}
Also used : CoordinateDD(com.bigdata.rdf.internal.gis.CoordinateDD) IV(com.bigdata.rdf.internal.IV) BigdataLiteral(com.bigdata.rdf.model.BigdataLiteral)

Example 7 with IV

use of com.bigdata.rdf.internal.IV in project wikidata-query-rdf by wikimedia.

the class EmptyLabelServiceOptimizer method addResolutions.

/**
 * Infer that the user wanted to resolve some variables using the label
 * service.
 */
private void addResolutions(AST2BOpContext ctx, JoinGroupNode g, ProjectionNode p) {
    if (p == null) {
        return;
    }
    for (AssignmentNode a : p) {
        IVariable<IV> v = a.getVar();
        if (a.getValueExpression() != v) {
            continue;
        }
        /*
             * Try and match a variable name we can resolve via labels. Note
             * that we should match AltLabel before Label because Label is a
             * suffix of it....
             */
        boolean replaced = addResolutionIfSuffix(ctx, g, "AltLabel", SKOS.ALT_LABEL, v) || addResolutionIfSuffix(ctx, g, "Label", RDFS.LABEL, v) || addResolutionIfSuffix(ctx, g, "Description", DESCRIPTION, v);
        if (replaced && log.isDebugEnabled()) {
            log.debug("Resolving {} using a label lookup.", v);
        }
    }
}
Also used : AssignmentNode(com.bigdata.rdf.sparql.ast.AssignmentNode) IV(com.bigdata.rdf.internal.IV)

Example 8 with IV

use of com.bigdata.rdf.internal.IV in project wikidata-query-rdf by wikimedia.

the class EmptyLabelServiceOptimizer method addResolutionIfSuffix.

/**
 * Add the join group to resolve a variable if it matches a suffix,
 * returning true if it matched, false otherwise.
 */
@SuppressFBWarnings(value = "OCP_OVERLY_CONCRETE_PARAMETER", justification = "Using AST2BOpContext makes sense since it is the only type that will ever be passed")
private boolean addResolutionIfSuffix(AST2BOpContext ctx, JoinGroupNode g, String suffix, URI labelType, IVariable<IV> iVar) {
    if (!iVar.getName().endsWith(suffix)) {
        return false;
    }
    String source = iVar.getName().substring(0, iVar.getName().length() - suffix.length());
    IConstant<IV> labelTypeAsConstant = ctx.getAbstractTripleStore().getVocabulary().getConstant(labelType);
    g.addArg(new StatementPatternNode(new VarNode(source), new ConstantNode(labelTypeAsConstant), new VarNode(iVar)));
    return true;
}
Also used : VarNode(com.bigdata.rdf.sparql.ast.VarNode) ConstantNode(com.bigdata.rdf.sparql.ast.ConstantNode) StatementPatternNode(com.bigdata.rdf.sparql.ast.StatementPatternNode) IV(com.bigdata.rdf.internal.IV) SuppressFBWarnings(edu.umd.cs.findbugs.annotations.SuppressFBWarnings)

Example 9 with IV

use of com.bigdata.rdf.internal.IV in project wikidata-query-rdf by wikimedia.

the class ApiTemplate method getOutputVars.

/**
 * Create map of output variables from template and service params.
 */
public List<OutputVariable> getOutputVars(final ServiceNode serviceNode) {
    List<OutputVariable> vars = new ArrayList<>(outputVars.size());
    final GraphPatternGroup<IGroupMemberNode> group = serviceNode.getGraphPattern();
    requireNonNull(serviceNode, "Group node is null?");
    String prefix = paramNameToURI("").stringValue();
    group.iterator().forEachRemaining(node -> {
        // ?variable wikibase:output "x/path"
        if (node instanceof StatementPatternNode) {
            final StatementPatternNode sp = (StatementPatternNode) node;
            if (sp.s().isVariable() && sp.o().isConstant() && sp.p().isConstant()) {
                for (OutputVariable.Type varType : OutputVariable.Type.values()) {
                    if (varType.predicate.equals(sp.p().getValue())) {
                        IVariable v = (IVariable) sp.s().getValueExpression();
                        if (varType == ORDINAL) {
                            // Ordinal values ignore the object
                            vars.add(new OutputVariable(varType, v, "."));
                            break;
                        }
                        IV value = sp.o().getValueExpression().get();
                        if (value.isURI()) {
                            String paramName = value.stringValue().substring(prefix.length());
                            vars.add(new OutputVariable(varType, v, outputVars.get(paramName)));
                        } else {
                            vars.add(new OutputVariable(varType, v, value.stringValue()));
                        }
                        break;
                    }
                }
            }
        }
    });
    return vars;
}
Also used : IGroupMemberNode(com.bigdata.rdf.sparql.ast.IGroupMemberNode) IVariable(com.bigdata.bop.IVariable) ArrayList(java.util.ArrayList) StatementPatternNode(com.bigdata.rdf.sparql.ast.StatementPatternNode) IV(com.bigdata.rdf.internal.IV)

Example 10 with IV

use of com.bigdata.rdf.internal.IV in project wikidata-query-rdf by wikimedia.

the class CoordinatePartBOp method get.

@Override
public IV get(IBindingSet bindingSet) {
    final IV coord = getAndCheckLiteral(0, bindingSet);
    final WikibasePoint point = pointFromIV(coord);
    final BigdataValue result;
    switch(part()) {
        case GLOBE:
            String globe = point.getGlobe();
            if (globe == null) {
                result = getValueFactory().createLiteral("");
            } else {
                result = getValueFactory().createURI(point.getGlobe());
            }
            break;
        case LON:
            result = getValueFactory().createLiteral(Double.parseDouble(point.getLongitude()));
            break;
        case LAT:
            result = getValueFactory().createLiteral(Double.parseDouble(point.getLatitude()));
            break;
        default:
            throw new IllegalArgumentException("Unknown part specified");
    }
    return super.asIV(result, bindingSet);
}
Also used : BigdataValue(com.bigdata.rdf.model.BigdataValue) IV(com.bigdata.rdf.internal.IV) GeoUtils.pointFromIV(org.wikidata.query.rdf.blazegraph.geo.GeoUtils.pointFromIV) WikibasePoint(org.wikidata.query.rdf.common.WikibasePoint)

Aggregations

IV (com.bigdata.rdf.internal.IV)11 URIImpl (org.openrdf.model.impl.URIImpl)3 XSDIntegerIV (com.bigdata.rdf.internal.impl.literal.XSDIntegerIV)2 URIExtensionIV (com.bigdata.rdf.internal.impl.uri.URIExtensionIV)2 VocabURIByteIV (com.bigdata.rdf.internal.impl.uri.VocabURIByteIV)2 BigdataLiteral (com.bigdata.rdf.model.BigdataLiteral)2 StatementPatternNode (com.bigdata.rdf.sparql.ast.StatementPatternNode)2 BigInteger (java.math.BigInteger)2 Test (org.junit.Test)2 GeoUtils.pointFromIV (org.wikidata.query.rdf.blazegraph.geo.GeoUtils.pointFromIV)2 WikibasePoint (org.wikidata.query.rdf.common.WikibasePoint)2 IVariable (com.bigdata.bop.IVariable)1 IVariableOrConstant (com.bigdata.bop.IVariableOrConstant)1 IsBNodeBOp (com.bigdata.rdf.internal.constraints.IsBNodeBOp)1 CoordinateDD (com.bigdata.rdf.internal.gis.CoordinateDD)1 AbstractLiteralIV (com.bigdata.rdf.internal.impl.literal.AbstractLiteralIV)1 LiteralExtensionIV (com.bigdata.rdf.internal.impl.literal.LiteralExtensionIV)1 LexiconRelation (com.bigdata.rdf.lexicon.LexiconRelation)1 BigdataURI (com.bigdata.rdf.model.BigdataURI)1 BigdataValue (com.bigdata.rdf.model.BigdataValue)1