Search in sources :

Example 1 with DummyConstantNode

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

the class GeoAroundService 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 "inCircle" .
    newGroup.addArg(new StatementPatternNode(searchVar, new DummyConstantNode(vf.asValue(GeoSpatial.SEARCH)), new DummyConstantNode(vf.createLiteral(GeoFunction.IN_CIRCLE.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)))));
    // ?var geo:spatialCircleCenter ?parisLoc .
    newGroup.addArg(new StatementPatternNode(searchVar, new DummyConstantNode(vf.asValue(GeoSpatial.SPATIAL_CIRCLE_CENTER)), getParam(serviceParams, CENTER_PARAM)));
    // ?var geo:spatialCircleRadius "1" .
    newGroup.addArg(new StatementPatternNode(searchVar, new DummyConstantNode(vf.asValue(GeoSpatial.SPATIAL_CIRCLE_RADIUS)), getParam(serviceParams, RADIUS_PARAM)));
    // ?var geo:locationValue ?location .
    newGroup.addArg(new StatementPatternNode(searchVar, new DummyConstantNode(vf.asValue(GeoSpatial.LOCATION_VALUE)), locationVar));
    // ?var geo:coordSystem "0" .
    newGroup.addArg(new StatementPatternNode(searchVar, new DummyConstantNode(vf.asValue(GeoSpatial.COORD_SYSTEM)), getGlobeNode(vf, serviceParams)));
    final TermNode distance = serviceParams.get(DISTANCE_PARAM, null);
    if (distance != null) {
        // ?var geo:distanceValue ?distance .
        newGroup.addArg(new StatementPatternNode(searchVar, new DummyConstantNode(vf.asValue(GeoSpatial.DISTANCE_VALUE)), distance));
    }
    return newGroup;
}
Also used : Vocabulary(com.bigdata.rdf.vocab.Vocabulary) AbstractTripleStore(com.bigdata.rdf.store.AbstractTripleStore) BigdataValueFactory(com.bigdata.rdf.model.BigdataValueFactory) ConstantNode(com.bigdata.rdf.sparql.ast.ConstantNode) DummyConstantNode(com.bigdata.rdf.sparql.ast.DummyConstantNode) DummyConstantNode(com.bigdata.rdf.sparql.ast.DummyConstantNode) JoinGroupNode(com.bigdata.rdf.sparql.ast.JoinGroupNode) URIImpl(org.openrdf.model.impl.URIImpl) StatementPatternNode(com.bigdata.rdf.sparql.ast.StatementPatternNode) TermNode(com.bigdata.rdf.sparql.ast.TermNode)

Example 2 with DummyConstantNode

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

the class GeoService method create.

@Override
public BigdataServiceCall create(ServiceCallCreateParams params, ServiceParams serviceParams) {
    if (params == null)
        throw new IllegalArgumentException();
    final JoinGroupNode newGroup = buildServiceNode(params, serviceParams);
    final BigdataValueFactory vf = params.getTripleStore().getValueFactory();
    ServiceNode newServiceNode = new ServiceNode(new DummyConstantNode(vf.asValue(GeoSpatial.SEARCH)), newGroup);
    // Transfer hints
    newServiceNode.setQueryHints(params.getServiceNode().getQueryHints());
    // Call delegate service
    HttpClient client = params.getClientConnectionManager();
    return (BigdataServiceCall) ServiceRegistry.getInstance().toServiceCall(params.getTripleStore(), client, GeoSpatial.SEARCH, newServiceNode, params.getStats());
}
Also used : ServiceNode(com.bigdata.rdf.sparql.ast.service.ServiceNode) BigdataValueFactory(com.bigdata.rdf.model.BigdataValueFactory) DummyConstantNode(com.bigdata.rdf.sparql.ast.DummyConstantNode) HttpClient(org.eclipse.jetty.client.HttpClient) JoinGroupNode(com.bigdata.rdf.sparql.ast.JoinGroupNode) BigdataServiceCall(com.bigdata.rdf.sparql.ast.service.BigdataServiceCall)

Example 3 with DummyConstantNode

use of com.bigdata.rdf.sparql.ast.DummyConstantNode 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;
}
Also used : Vocabulary(com.bigdata.rdf.vocab.Vocabulary) AbstractTripleStore(com.bigdata.rdf.store.AbstractTripleStore) DummyConstantNode(com.bigdata.rdf.sparql.ast.DummyConstantNode) URIImpl(org.openrdf.model.impl.URIImpl) TermNode(com.bigdata.rdf.sparql.ast.TermNode) WikibasePoint(org.wikidata.query.rdf.common.WikibasePoint) BigdataValueFactory(com.bigdata.rdf.model.BigdataValueFactory) DummyConstantNode(com.bigdata.rdf.sparql.ast.DummyConstantNode) ConstantNode(com.bigdata.rdf.sparql.ast.ConstantNode) JoinGroupNode(com.bigdata.rdf.sparql.ast.JoinGroupNode) StatementPatternNode(com.bigdata.rdf.sparql.ast.StatementPatternNode)

Example 4 with DummyConstantNode

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

the class GeoService method getGlobeNode.

/**
 * Create globe node with appropriate value for coordSystem.
 */
protected TermNode getGlobeNode(BigdataValueFactory vf, ServiceParams serviceParams) {
    final TermNode globeNode = serviceParams.get(GLOBE_PARAM, null);
    if (globeNode == null) {
        return new DummyConstantNode(vf.createLiteral(WKTSerializer.NO_GLOBE));
    }
    if (!globeNode.isConstant()) {
        // FIXME: add support for this
        throw new IllegalArgumentException("Non-constant globe value is not supported yet.");
    }
    BigdataValue v = globeNode.getValue();
    if (v instanceof BigdataURI) {
        WKTSerializer ser = new WKTSerializer();
        try {
            return new DummyConstantNode(vf.createLiteral(ser.trimCoordURI(v.stringValue())));
        } catch (GeoSpatialSearchException e) {
            // Unexpectedly wrong URI - still pass it along
            return globeNode;
        }
    }
    return globeNode;
}
Also used : BigdataValue(com.bigdata.rdf.model.BigdataValue) DummyConstantNode(com.bigdata.rdf.sparql.ast.DummyConstantNode) WKTSerializer(org.wikidata.query.rdf.blazegraph.inline.literal.WKTSerializer) GeoSpatialSearchException(com.bigdata.service.geospatial.GeoSpatialSearchException) TermNode(com.bigdata.rdf.sparql.ast.TermNode) BigdataURI(com.bigdata.rdf.model.BigdataURI)

Aggregations

DummyConstantNode (com.bigdata.rdf.sparql.ast.DummyConstantNode)4 BigdataValueFactory (com.bigdata.rdf.model.BigdataValueFactory)3 JoinGroupNode (com.bigdata.rdf.sparql.ast.JoinGroupNode)3 TermNode (com.bigdata.rdf.sparql.ast.TermNode)3 ConstantNode (com.bigdata.rdf.sparql.ast.ConstantNode)2 StatementPatternNode (com.bigdata.rdf.sparql.ast.StatementPatternNode)2 AbstractTripleStore (com.bigdata.rdf.store.AbstractTripleStore)2 Vocabulary (com.bigdata.rdf.vocab.Vocabulary)2 URIImpl (org.openrdf.model.impl.URIImpl)2 BigdataURI (com.bigdata.rdf.model.BigdataURI)1 BigdataValue (com.bigdata.rdf.model.BigdataValue)1 BigdataServiceCall (com.bigdata.rdf.sparql.ast.service.BigdataServiceCall)1 ServiceNode (com.bigdata.rdf.sparql.ast.service.ServiceNode)1 GeoSpatialSearchException (com.bigdata.service.geospatial.GeoSpatialSearchException)1 HttpClient (org.eclipse.jetty.client.HttpClient)1 WKTSerializer (org.wikidata.query.rdf.blazegraph.inline.literal.WKTSerializer)1 WikibasePoint (org.wikidata.query.rdf.common.WikibasePoint)1