use of com.bigdata.rdf.sparql.ast.JoinGroupNode in project wikidata-query-rdf by wikimedia.
the class LabelService method findResolutions.
/**
* Create the resolutions list from the service call parameters.
*/
static List<Resolution> findResolutions(final ServiceNode params) {
JoinGroupNode g = (JoinGroupNode) params.getGraphPattern();
List<Resolution> resolutions = new ArrayList<>(g.args().size());
for (BOp st : g.args()) {
StatementPatternNode sn = (StatementPatternNode) st;
if (sn.s().isConstant() && BD.SERVICE_PARAM.equals(sn.s().getValue())) {
// skip service params
continue;
}
resolutions.add(new Resolution(sn));
}
return resolutions;
}
use of com.bigdata.rdf.sparql.ast.JoinGroupNode in project wikidata-query-rdf by wikimedia.
the class GeoBoxService method buildServiceNode.
@Override
protected JoinGroupNode buildServiceNode(ServiceCallCreateParams params, ServiceParams serviceParams) {
final AbstractTripleStore store = params.getTripleStore();
final Vocabulary voc = store.getVocabulary();
BigdataValueFactory vf = store.getValueFactory();
final StatementPatternNode pattern = getPatternNode(params);
final TermNode searchVar = pattern.s();
final TermNode predicate = pattern.p();
final TermNode locationVar = pattern.o();
final JoinGroupNode newGroup = new JoinGroupNode();
// ?var geo:search "inRectangle" .
newGroup.addArg(new StatementPatternNode(searchVar, new DummyConstantNode(vf.asValue(GeoSpatial.SEARCH)), new DummyConstantNode(vf.createLiteral(GeoFunction.IN_RECTANGLE.toString()))));
// ?var geo:predicate wdt:P625 .
newGroup.addArg(new StatementPatternNode(searchVar, new DummyConstantNode(vf.asValue(GeoSpatial.PREDICATE)), predicate));
// ?var geo:searchDatatype ogc:wktLiteral .
newGroup.addArg(new StatementPatternNode(searchVar, new DummyConstantNode(vf.asValue(GeoSpatial.SEARCH_DATATYPE)), new ConstantNode(voc.getConstant(new URIImpl(GeoSparql.WKT_LITERAL)))));
if (serviceParams.contains(NE_PARAM)) {
// ?var geo:spatialRectangleNorthEast ?ne .
newGroup.addArg(new StatementPatternNode(searchVar, new DummyConstantNode(vf.asValue(GeoSpatial.SPATIAL_RECTANGLE_NORTH_EAST)), getParam(serviceParams, NE_PARAM)));
// ?var geo:spatialRectangleNorthEast ?sw .
newGroup.addArg(new StatementPatternNode(searchVar, new DummyConstantNode(vf.asValue(GeoSpatial.SPATIAL_RECTANGLE_SOUTH_WEST)), getParam(serviceParams, SW_PARAM)));
} else if (serviceParams.contains(EAST_PARAM)) {
final TermNode east = getParam(serviceParams, EAST_PARAM);
final TermNode west = getParam(serviceParams, WEST_PARAM);
if (east instanceof ConstantNode && west instanceof ConstantNode) {
// Easy case - both constants
final WikibasePoint eastWP = pointFromIV(((ConstantNode) east).getValue().getIV());
final WikibasePoint westWP = pointFromIV(((ConstantNode) west).getValue().getIV());
final GeoUtils.Box box = new GeoUtils.Box(eastWP, westWP);
TermNode ne;
TermNode sw;
if (box.switched()) {
ne = new DummyConstantNode(vf.asValue(vf.createLiteral(box.northEast().toString(), new URIImpl(GeoSparql.WKT_LITERAL))));
sw = new DummyConstantNode(vf.asValue(vf.createLiteral(box.southWest().toString(), new URIImpl(GeoSparql.WKT_LITERAL))));
} else {
ne = east;
sw = west;
}
// ?var geo:spatialRectangleNorthEast ?ne .
newGroup.addArg(new StatementPatternNode(searchVar, new DummyConstantNode(vf.asValue(GeoSpatial.SPATIAL_RECTANGLE_NORTH_EAST)), ne));
// ?var geo:spatialRectangleNorthEast ?sw .
newGroup.addArg(new StatementPatternNode(searchVar, new DummyConstantNode(vf.asValue(GeoSpatial.SPATIAL_RECTANGLE_SOUTH_WEST)), sw));
} else {
// Hard case - non-constants
// Add dummy var to the node
serviceParams.add(WRAP_PARAM, VarNode.freshVarNode());
// ?var geo:spatialRectangleNorthEast ?ne .
newGroup.addArg(new StatementPatternNode(searchVar, new DummyConstantNode(vf.asValue(GeoSpatial.SPATIAL_RECTANGLE_NORTH_EAST)), getSubstituteVar(east)));
// ?var geo:spatialRectangleNorthEast ?sw .
newGroup.addArg(new StatementPatternNode(searchVar, new DummyConstantNode(vf.asValue(GeoSpatial.SPATIAL_RECTANGLE_SOUTH_WEST)), getSubstituteVar(west)));
}
} else {
throw new IllegalArgumentException("Box corner parameters are required");
}
// ?var geo:locationValue ?location .
newGroup.addArg(new StatementPatternNode(searchVar, new DummyConstantNode(vf.asValue(GeoSpatial.LOCATION_VALUE)), locationVar));
// ?var geo:coordSystem "2" .
newGroup.addArg(new StatementPatternNode(searchVar, new DummyConstantNode(vf.asValue(GeoSpatial.COORD_SYSTEM)), getGlobeNode(vf, serviceParams)));
return newGroup;
}
use of com.bigdata.rdf.sparql.ast.JoinGroupNode in project wikidata-query-rdf by wikimedia.
the class EmptyLabelServiceOptimizer method restoreExtracted.
/**
* Restore extracted statement from label service node.
*/
@SuppressWarnings("unchecked")
private boolean restoreExtracted(ServiceNode service) {
boolean found = false;
JoinGroupNode g = (JoinGroupNode) service.getGraphPattern();
final List<StatementPatternNode> extractedList = (List<StatementPatternNode>) service.annotations().get(LabelServiceExtractOptimizer.EXTRACTOR_ANNOTATION);
if (extractedList != null && !extractedList.isEmpty()) {
for (StatementPatternNode st : extractedList) {
g.addArg(st);
}
found = true;
}
service.annotations().remove(LabelServiceExtractOptimizer.EXTRACTOR_ANNOTATION);
return found;
}
use of com.bigdata.rdf.sparql.ast.JoinGroupNode 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);
}
});
}
Aggregations