Search in sources :

Example 1 with IGroupMemberNode

use of com.bigdata.rdf.sparql.ast.IGroupMemberNode in project wikidata-query-rdf by wikimedia.

the class MWApiServiceFactory method serviceParamsFromNode.

/**
 * Get service params from Service Node.
 * FIXME: copypaste from ServiceParams.java, should be integrated there
 */
private ServiceParams serviceParamsFromNode(final ServiceNode serviceNode) {
    requireNonNull(serviceNode, "Service node is null?");
    final GraphPatternGroup<IGroupMemberNode> group = serviceNode.getGraphPattern();
    requireNonNull(group, "Group node is null?");
    final ServiceParams serviceParams = new ServiceParams();
    for (IGroupMemberNode node : group) {
        if (node instanceof StatementPatternNode) {
            final StatementPatternNode sp = (StatementPatternNode) node;
            final TermNode s = sp.s();
            if (s.isConstant() && BD.SERVICE_PARAM.equals(s.getValue())) {
                if (sp.p().isVariable()) {
                    throw new RuntimeException("not a valid service param triple pattern, " + "predicate must be constant: " + sp);
                }
                final URI param = (URI) sp.p().getValue();
                serviceParams.add(param, sp.o());
            }
        }
    }
    return serviceParams;
}
Also used : IGroupMemberNode(com.bigdata.rdf.sparql.ast.IGroupMemberNode) ServiceParams(com.bigdata.rdf.sparql.ast.eval.ServiceParams) StatementPatternNode(com.bigdata.rdf.sparql.ast.StatementPatternNode) TermNode(com.bigdata.rdf.sparql.ast.TermNode) URI(org.openrdf.model.URI)

Example 2 with IGroupMemberNode

use of com.bigdata.rdf.sparql.ast.IGroupMemberNode in project wikidata-query-rdf by wikimedia.

the class EmptyLabelServiceOptimizer method getProjectionNode.

@SuppressFBWarnings(value = "OCP_OVERLY_CONCRETE_PARAMETER", justification = "We only process ServiceNode's so that's the appropriate type")
private ProjectionNode getProjectionNode(ServiceNode service) {
    IGroupNode<IGroupMemberNode> parent = service.getParent();
    while (parent != null) {
        ProjectionNode projection = (ProjectionNode) parent.annotations().get(LABEL_SERVICE_PROJECTION);
        if (projection != null) {
            return projection;
        }
        parent = parent.getParent();
    }
    return null;
}
Also used : IGroupMemberNode(com.bigdata.rdf.sparql.ast.IGroupMemberNode) ProjectionNode(com.bigdata.rdf.sparql.ast.ProjectionNode) SuppressFBWarnings(edu.umd.cs.findbugs.annotations.SuppressFBWarnings)

Example 3 with IGroupMemberNode

use of com.bigdata.rdf.sparql.ast.IGroupMemberNode 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)

Aggregations

IGroupMemberNode (com.bigdata.rdf.sparql.ast.IGroupMemberNode)3 StatementPatternNode (com.bigdata.rdf.sparql.ast.StatementPatternNode)2 IVariable (com.bigdata.bop.IVariable)1 IV (com.bigdata.rdf.internal.IV)1 ProjectionNode (com.bigdata.rdf.sparql.ast.ProjectionNode)1 TermNode (com.bigdata.rdf.sparql.ast.TermNode)1 ServiceParams (com.bigdata.rdf.sparql.ast.eval.ServiceParams)1 SuppressFBWarnings (edu.umd.cs.findbugs.annotations.SuppressFBWarnings)1 ArrayList (java.util.ArrayList)1 URI (org.openrdf.model.URI)1