Search in sources :

Example 1 with WikibasePoint

use of org.wikidata.query.rdf.common.WikibasePoint in project wikidata-query-rdf by wikimedia.

the class WikibaseCornerBOp method get.

@Override
public IV get(IBindingSet bindingSet) {
    final IV east = getAndCheckLiteral(0, bindingSet);
    final IV west = getAndCheckLiteral(1, bindingSet);
    final GeoUtils.Box box = new GeoUtils.Box(pointFromIV(east), pointFromIV(west));
    WikibasePoint wp;
    if (corner() == Corners.NE) {
        if (!box.switched()) {
            return east;
        }
        wp = box.northEast();
    } else {
        if (!box.switched()) {
            return west;
        }
        wp = box.southWest();
    }
    final BigdataLiteral newpoint = getValueFactory().createLiteral(wp.toString(), new URIImpl(GeoSparql.WKT_LITERAL));
    return super.asIV(newpoint, bindingSet);
}
Also used : GeoUtils(org.wikidata.query.rdf.blazegraph.geo.GeoUtils) URIImpl(org.openrdf.model.impl.URIImpl) IV(com.bigdata.rdf.internal.IV) GeoUtils.pointFromIV(org.wikidata.query.rdf.blazegraph.geo.GeoUtils.pointFromIV) BigdataLiteral(com.bigdata.rdf.model.BigdataLiteral) WikibasePoint(org.wikidata.query.rdf.common.WikibasePoint)

Example 2 with WikibasePoint

use of org.wikidata.query.rdf.common.WikibasePoint in project wikidata-query-rdf by wikimedia.

the class WKTSerializer method toComponents.

@Override
public String[] toComponents(String literalString) {
    if (literalString == null) {
        return new String[0];
    }
    String[] comps = new String[3];
    WikibasePoint point = new WikibasePoint(literalString);
    // Should be in sync with RWStore.properties config
    // and AbstractRandomizedBlazegraphStorageTestCase.java
    comps[0] = point.getLongitude();
    comps[1] = point.getLatitude();
    String globe = point.getGlobe();
    comps[2] = globe != null ? trimCoordURI(globe) : NO_GLOBE;
    return comps;
}
Also used : WikibasePoint(org.wikidata.query.rdf.common.WikibasePoint)

Example 3 with WikibasePoint

use of org.wikidata.query.rdf.common.WikibasePoint in project wikidata-query-rdf by wikimedia.

the class WKTSerializer method fromComponents.

@Override
public String fromComponents(Object[] components) {
    if (components == null)
        return "";
    if (components.length != 3)
        throw new GeoSpatialSearchException("Expected component string of lenth 3, but was " + components.length);
    String[] strComponents = new String[3];
    strComponents[0] = components[0].toString();
    strComponents[1] = components[1].toString();
    strComponents[2] = components[2].toString();
    WikibasePoint point;
    if (strComponents[2].equals(NO_GLOBE)) {
        point = new WikibasePoint(strComponents, null, CoordinateOrder.LONG_LAT);
    } else {
        point = new WikibasePoint(strComponents, URL_PREFIX + strComponents[2], CoordinateOrder.LONG_LAT);
    }
    return point.toString();
}
Also used : GeoSpatialSearchException(com.bigdata.service.geospatial.GeoSpatialSearchException) WikibasePoint(org.wikidata.query.rdf.common.WikibasePoint)

Example 4 with WikibasePoint

use of org.wikidata.query.rdf.common.WikibasePoint in project wikidata-query-rdf by wikimedia.

the class CoordinatePartBOp method get.

@Override
public IV get(IBindingSet bindingSet) {
    final IV coord = getAndCheckLiteral(0, bindingSet);
    final WikibasePoint point = pointFromIV(coord);
    final BigdataValue result;
    switch(part()) {
        case GLOBE:
            String globe = point.getGlobe();
            if (globe == null) {
                result = getValueFactory().createLiteral("");
            } else {
                result = getValueFactory().createURI(point.getGlobe());
            }
            break;
        case LON:
            result = getValueFactory().createLiteral(Double.parseDouble(point.getLongitude()));
            break;
        case LAT:
            result = getValueFactory().createLiteral(Double.parseDouble(point.getLatitude()));
            break;
        default:
            throw new IllegalArgumentException("Unknown part specified");
    }
    return super.asIV(result, bindingSet);
}
Also used : BigdataValue(com.bigdata.rdf.model.BigdataValue) IV(com.bigdata.rdf.internal.IV) GeoUtils.pointFromIV(org.wikidata.query.rdf.blazegraph.geo.GeoUtils.pointFromIV) WikibasePoint(org.wikidata.query.rdf.common.WikibasePoint)

Example 5 with WikibasePoint

use of org.wikidata.query.rdf.common.WikibasePoint 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)

Aggregations

WikibasePoint (org.wikidata.query.rdf.common.WikibasePoint)6 IV (com.bigdata.rdf.internal.IV)2 URIImpl (org.openrdf.model.impl.URIImpl)2 GeoUtils (org.wikidata.query.rdf.blazegraph.geo.GeoUtils)2 GeoUtils.pointFromIV (org.wikidata.query.rdf.blazegraph.geo.GeoUtils.pointFromIV)2 BigdataLiteral (com.bigdata.rdf.model.BigdataLiteral)1 BigdataValue (com.bigdata.rdf.model.BigdataValue)1 BigdataValueFactory (com.bigdata.rdf.model.BigdataValueFactory)1 ConstantNode (com.bigdata.rdf.sparql.ast.ConstantNode)1 DummyConstantNode (com.bigdata.rdf.sparql.ast.DummyConstantNode)1 JoinGroupNode (com.bigdata.rdf.sparql.ast.JoinGroupNode)1 StatementPatternNode (com.bigdata.rdf.sparql.ast.StatementPatternNode)1 TermNode (com.bigdata.rdf.sparql.ast.TermNode)1 AbstractTripleStore (com.bigdata.rdf.store.AbstractTripleStore)1 Vocabulary (com.bigdata.rdf.vocab.Vocabulary)1 GeoSpatialSearchException (com.bigdata.service.geospatial.GeoSpatialSearchException)1