Search in sources :

Example 11 with StatementPatternNode

use of com.bigdata.rdf.sparql.ast.StatementPatternNode 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 12 with StatementPatternNode

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

the class LabelServiceExtractOptimizer method optimizeJoinGroup.

@Override
protected void optimizeJoinGroup(AST2BOpContext ctx, StaticAnalysis sa, IBindingSet[] bSets, JoinGroupNode op) {
    final QueryRoot root = sa.getQueryRoot();
    if (root.getQueryType() == QueryType.ASK) {
        return;
    }
    LabelServiceUtils.getLabelServiceNodes(op).forEach(service -> {
        JoinGroupNode g = (JoinGroupNode) service.getGraphPattern();
        final List<StatementPatternNode> extractedNodes = new ArrayList<>();
        for (BOp st : g.args()) {
            StatementPatternNode sn = (StatementPatternNode) st;
            if (sn.s().isConstant() && BD.SERVICE_PARAM.equals(sn.s().getValue())) {
                if (WikidataServicePlacementOptimizer.DISABLE_REORDERING.equals(sn.p().getValue())) {
                    String flag = sn.o().getValue().stringValue();
                    service.annotations().put(WikidataServicePlacementOptimizer.DISABLE_REORDERING_ANNOTATION, Boolean.valueOf(flag));
                }
                // skip parameters
                continue;
            }
            extractedNodes.add(sn);
        }
        for (BOp node : extractedNodes) {
            g.removeArg(node);
        }
        if (!extractedNodes.isEmpty()) {
            service.annotations().put(EXTRACTOR_ANNOTATION, extractedNodes);
        }
    });
}
Also used : BOp(com.bigdata.bop.BOp) QueryRoot(com.bigdata.rdf.sparql.ast.QueryRoot) ArrayList(java.util.ArrayList) JoinGroupNode(com.bigdata.rdf.sparql.ast.JoinGroupNode) StatementPatternNode(com.bigdata.rdf.sparql.ast.StatementPatternNode)

Example 13 with StatementPatternNode

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

the class GeoService method getPatternNode.

/**
 * Extract pattern node from parameters.
 *
 * Pattern node looks like:
 *  ?place wdt:P625 ?location .
 * Both variables would be bound by the service.
 */
protected StatementPatternNode getPatternNode(ServiceCallCreateParams params) {
    ServiceNode serviceNode = params.getServiceNode();
    if (serviceNode == null)
        throw new IllegalArgumentException();
    List<StatementPatternNode> patterns = getStatementPatterns(serviceNode);
    if (patterns.isEmpty()) {
        throw new IllegalArgumentException("This service requires arguments");
    }
    StatementPatternNode pattern = patterns.get(0);
    if (pattern == null) {
        throw new IllegalArgumentException();
    }
    if (!pattern.s().isVariable()) {
        throw new IllegalArgumentException("Search pattern subject must be a variable");
    }
    if (!pattern.p().isConstant()) {
        // FIXME: may be not necessary?
        throw new IllegalArgumentException("Search pattern predicate must be a constant");
    }
    if (!pattern.o().isVariable()) {
        throw new IllegalArgumentException("Search pattern object must be a variable");
    }
    return pattern;
}
Also used : ServiceNode(com.bigdata.rdf.sparql.ast.service.ServiceNode) StatementPatternNode(com.bigdata.rdf.sparql.ast.StatementPatternNode)

Aggregations

StatementPatternNode (com.bigdata.rdf.sparql.ast.StatementPatternNode)13 JoinGroupNode (com.bigdata.rdf.sparql.ast.JoinGroupNode)8 IVariable (com.bigdata.bop.IVariable)4 TermNode (com.bigdata.rdf.sparql.ast.TermNode)4 BOp (com.bigdata.bop.BOp)3 ConstantNode (com.bigdata.rdf.sparql.ast.ConstantNode)3 VarNode (com.bigdata.rdf.sparql.ast.VarNode)3 ServiceNode (com.bigdata.rdf.sparql.ast.service.ServiceNode)3 ArrayList (java.util.ArrayList)3 IV (com.bigdata.rdf.internal.IV)2 BigdataValueFactory (com.bigdata.rdf.model.BigdataValueFactory)2 DummyConstantNode (com.bigdata.rdf.sparql.ast.DummyConstantNode)2 IGroupMemberNode (com.bigdata.rdf.sparql.ast.IGroupMemberNode)2 QueryRoot (com.bigdata.rdf.sparql.ast.QueryRoot)2 AbstractTripleStore (com.bigdata.rdf.store.AbstractTripleStore)2 Vocabulary (com.bigdata.rdf.vocab.Vocabulary)2 Test (org.junit.Test)2 URI (org.openrdf.model.URI)2 URIImpl (org.openrdf.model.impl.URIImpl)2 SubqueryBase (com.bigdata.rdf.sparql.ast.SubqueryBase)1