Search in sources :

Example 46 with URIImpl

use of org.openrdf.model.impl.URIImpl in project incubator-rya by apache.

the class GeoTemporalMongoDBStorageStrategyTest method equalsInstantAfterInterval_onlyGeos.

@Test
public void equalsInstantAfterInterval_onlyGeos() throws Exception {
    /*
         * TODO: change filter functions for coverage
         */
    final String query = "PREFIX geo: <http://www.opengis.net/ont/geosparql#>" + "PREFIX geof: <http://www.opengis.net/def/function/geosparql/>" + "SELECT ?point ?wkt " + "WHERE { " + "  ?point geo:asWKT ?wkt . " + "  FILTER(geof:sfIntersects(?wkt, \"POLYGON((-3 -2, -3 2, 1 2, 1 -2, -3 -2))\"^^geo:wktLiteral)) " + "  FILTER(geof:sfEquals(?wkt, \"POLYGON((-4 -3, -4 3, 2 3, 2 -3, -4 -3))\"^^geo:wktLiteral)) " + "}";
    final List<IndexingExpr> geoFilters = new ArrayList<>();
    final List<StatementPattern> sps = getSps(query);
    final List<FunctionCall> filters = getFilters(query);
    for (final FunctionCall filter : filters) {
        final Var objVar = IndexingFunctionRegistry.getResultVarFromFunctionCall(new URIImpl(filter.getURI()), filter.getArgs());
        final IndexingExpr expr = new IndexingExpr(new URIImpl(filter.getURI()), sps.get(0), extractArguments(objVar.getName(), filter));
        geoFilters.add(expr);
    }
    final List<IndexingExpr> temporalFilters = new ArrayList<>();
    final DBObject actual = adapter.getFilterQuery(geoFilters, temporalFilters);
    final String expectedString = "{ " + "\"$and\" : [ { " + "\"location\" : {" + " \"coordinates\" : [ [ [ -4.0 , -3.0] , [ -4.0 , 3.0] , [ 2.0 , 3.0] , [ 2.0 , -3.0] , [ -4.0 , -3.0]]] ," + " \"type\" : \"Polygon\"" + "}" + "} , { " + "\"location\" : { " + "\"$geoIntersects\" : {" + " \"$geometry\" : {" + " \"coordinates\" : [ [ [ -3.0 , -2.0] , [ -3.0 , 2.0] , [ 1.0 , 2.0] , [ 1.0 , -2.0] , [ -3.0 , -2.0]]] ," + " \"type\" : \"Polygon\"" + "}" + "}" + "}" + "}]}";
    final DBObject expected = (DBObject) JSON.parse(expectedString);
    assertEqualMongo(expected, actual);
}
Also used : StatementPattern(org.openrdf.query.algebra.StatementPattern) Var(org.openrdf.query.algebra.Var) ArrayList(java.util.ArrayList) URIImpl(org.openrdf.model.impl.URIImpl) FunctionCall(org.openrdf.query.algebra.FunctionCall) DBObject(com.mongodb.DBObject) IndexingExpr(org.apache.rya.indexing.IndexingExpr) Test(org.junit.Test)

Example 47 with URIImpl

use of org.openrdf.model.impl.URIImpl in project incubator-rya by apache.

the class GeoTemporalMongoDBStorageStrategyTest method equalsInstantAfterInterval_GeoTemporalOneEach.

@Test
public void equalsInstantAfterInterval_GeoTemporalOneEach() throws Exception {
    final String query = "PREFIX time: <http://www.w3.org/2006/time#> \n" + "PREFIX tempo: <tag:rya-rdf.org,2015:temporal#> \n" + "PREFIX geo: <http://www.opengis.net/ont/geosparql#>" + "PREFIX geof: <http://www.opengis.net/def/function/geosparql/>" + "SELECT ?event ?time ?point ?wkt " + "WHERE { " + "  ?event time:atTime ?time . " + "  ?point geo:asWKT ?wkt . " + "  FILTER(geof:sfWithin(?wkt, \"POLYGON((-3 -2, -3 2, 1 2, 1 -2, -3 -2))\"^^geo:wktLiteral)) " + "  FILTER(tempo:after(?time, \"2015-12-30T12:00:00Z\")) " + "}";
    final List<IndexingExpr> geoFilters = new ArrayList<>();
    final List<IndexingExpr> temporalFilters = new ArrayList<>();
    final List<StatementPattern> sps = getSps(query);
    final List<FunctionCall> filters = getFilters(query);
    for (final FunctionCall filter : filters) {
        final URI filterURI = new URIImpl(filter.getURI());
        final Var objVar = IndexingFunctionRegistry.getResultVarFromFunctionCall(filterURI, filter.getArgs());
        final IndexingExpr expr = new IndexingExpr(filterURI, sps.get(0), extractArguments(objVar.getName(), filter));
        if (IndexingFunctionRegistry.getFunctionType(filterURI) == FUNCTION_TYPE.GEO) {
            geoFilters.add(expr);
        } else {
            temporalFilters.add(expr);
        }
    }
    final DBObject actual = adapter.getFilterQuery(geoFilters, temporalFilters);
    final String expectedString = "{ " + "\"$and\" : [ { " + "\"location\" : { " + "\"$geoWithin\" : { " + "\"$geometry\" : { " + "\"coordinates\" : [ [ [ -3.0 , -2.0] , [ -3.0 , 2.0] , [ 1.0 , 2.0] , [ 1.0 , -2.0] , [ -3.0 , -2.0]]] , " + "\"type\" : \"Polygon\"" + "}" + "}" + "}" + "} , { " + "\"instant\" : { " + "\"$gt\" : { " + "\"$date\" : \"2015-12-30T12:00:00.000Z\"" + "}" + "}" + "}]" + "}";
    final DBObject expected = (DBObject) JSON.parse(expectedString);
    assertEqualMongo(expected, actual);
}
Also used : StatementPattern(org.openrdf.query.algebra.StatementPattern) Var(org.openrdf.query.algebra.Var) ArrayList(java.util.ArrayList) URIImpl(org.openrdf.model.impl.URIImpl) FunctionCall(org.openrdf.query.algebra.FunctionCall) URI(org.openrdf.model.URI) DBObject(com.mongodb.DBObject) IndexingExpr(org.apache.rya.indexing.IndexingExpr) Test(org.junit.Test)

Example 48 with URIImpl

use of org.openrdf.model.impl.URIImpl in project incubator-rya by apache.

the class SmartUriAdapter method serializeUriEntity.

/**
 * Serializes an {@link Entity} into a Smart {@link URI}.
 * @param entity the {@link Entity} to serialize into a Smart URI.
 * @return the Smart {@link URI}.
 * @throws SmartUriException
 */
public static URI serializeUriEntity(final Entity entity) throws SmartUriException {
    final Map<URI, Value> objectMap = new LinkedHashMap<>();
    // Adds the entity's types to the Smart URI
    final List<RyaURI> typeIds = entity.getExplicitTypeIds();
    final Map<RyaURI, String> ryaTypeMap = createTypeMap(typeIds);
    final URI ryaTypeMapUri = createTypeMapUri(typeIds);
    final RyaType valueRyaType = new RyaType(XMLSchema.ANYURI, ryaTypeMapUri.stringValue());
    final Value typeValue = RyaToRdfConversions.convertValue(valueRyaType);
    objectMap.put(RYA_TYPES_URI, typeValue);
    final RyaURI subject = entity.getSubject();
    final Map<RyaURI, ImmutableMap<RyaURI, Property>> typeMap = entity.getProperties();
    for (final Entry<RyaURI, ImmutableMap<RyaURI, Property>> typeEntry : typeMap.entrySet()) {
        final RyaURI type = typeEntry.getKey();
        String typeShortName = ryaTypeMap.get(type);
        typeShortName = typeShortName != null ? typeShortName + "." : "";
        final ImmutableMap<RyaURI, Property> typeProperties = typeEntry.getValue();
        for (final Entry<RyaURI, Property> properties : typeProperties.entrySet()) {
            final RyaURI key = properties.getKey();
            final Property property = properties.getValue();
            final String valueString = property.getValue().getData();
            final RyaType ryaType = property.getValue();
            // final RyaType ryaType = new RyaType(new URIImpl(key.getData()), valueString);
            final Value value = RyaToRdfConversions.convertValue(ryaType);
            String formattedKey = key.getData();
            if (StringUtils.isNotBlank(typeShortName)) {
                formattedKey = addTypePrefixToUri(formattedKey, typeShortName);
            }
            final URI uri = new URIImpl(formattedKey);
            objectMap.put(uri, value);
        }
    }
    return serializeUri(subject, objectMap);
}
Also used : URIImpl(org.openrdf.model.impl.URIImpl) RyaType(org.apache.rya.api.domain.RyaType) URI(org.openrdf.model.URI) RyaURI(org.apache.rya.api.domain.RyaURI) ImmutableMap(com.google.common.collect.ImmutableMap) LinkedHashMap(java.util.LinkedHashMap) RyaURI(org.apache.rya.api.domain.RyaURI) Value(org.openrdf.model.Value) Property(org.apache.rya.indexing.entity.model.Property)

Example 49 with URIImpl

use of org.openrdf.model.impl.URIImpl in project incubator-rya by apache.

the class SmartUriAdapter method addTypePrefixToUri.

private static String addTypePrefixToUri(final String uriString, final String typePrefix) {
    final String localName = new URIImpl(uriString).getLocalName();
    final String beginning = StringUtils.removeEnd(uriString, localName);
    final String formattedUriString = beginning + typePrefix + localName;
    return formattedUriString;
}
Also used : URIImpl(org.openrdf.model.impl.URIImpl)

Example 50 with URIImpl

use of org.openrdf.model.impl.URIImpl in project incubator-rya by apache.

the class SmartUriAdapter method entityToValueMap.

public static Map<URI, Value> entityToValueMap(final Entity entity) {
    final Map<URI, Value> map = new LinkedHashMap<>();
    for (final Entry<RyaURI, ImmutableMap<RyaURI, Property>> entry : entity.getProperties().entrySet()) {
        for (final Entry<RyaURI, Property> property : entry.getValue().entrySet()) {
            final RyaURI propertyKey = property.getKey();
            final URI uri = new URIImpl(propertyKey.getData());
            final Property propertyValue = property.getValue();
            final Value value = RyaToRdfConversions.convertValue(propertyValue.getValue());
            map.put(uri, value);
        }
    }
    return map;
}
Also used : RyaURI(org.apache.rya.api.domain.RyaURI) Value(org.openrdf.model.Value) URIImpl(org.openrdf.model.impl.URIImpl) URI(org.openrdf.model.URI) RyaURI(org.apache.rya.api.domain.RyaURI) Property(org.apache.rya.indexing.entity.model.Property) ImmutableMap(com.google.common.collect.ImmutableMap) LinkedHashMap(java.util.LinkedHashMap)

Aggregations

URIImpl (org.openrdf.model.impl.URIImpl)170 Test (org.junit.Test)120 LiteralImpl (org.openrdf.model.impl.LiteralImpl)62 URI (org.openrdf.model.URI)58 BindingSet (org.openrdf.query.BindingSet)50 MapBindingSet (org.openrdf.query.impl.MapBindingSet)36 RyaURI (org.apache.rya.api.domain.RyaURI)33 HashSet (java.util.HashSet)31 Statement (org.openrdf.model.Statement)30 QueryBindingSet (org.openrdf.query.algebra.evaluation.QueryBindingSet)30 ArrayList (java.util.ArrayList)29 RyaType (org.apache.rya.api.domain.RyaType)25 VisibilityBindingSet (org.apache.rya.api.model.VisibilityBindingSet)24 RyaStatement (org.apache.rya.api.domain.RyaStatement)23 Value (org.openrdf.model.Value)22 NumericLiteralImpl (org.openrdf.model.impl.NumericLiteralImpl)22 QueryEvaluationException (org.openrdf.query.QueryEvaluationException)21 StatementPattern (org.openrdf.query.algebra.StatementPattern)20 StatementImpl (org.openrdf.model.impl.StatementImpl)19 PcjMetadata (org.apache.rya.indexing.pcj.storage.PcjMetadata)16