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;
}
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);
}
});
}
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;
}
Aggregations