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