use of org.apache.rya.api.domain.RyaURI in project incubator-rya by apache.
the class SmartUriAdapter method createTypePropertiesUri.
private static URI createTypePropertiesUri(final ImmutableMap<RyaURI, ImmutableMap<RyaURI, Property>> typeProperties) throws SmartUriException {
final List<NameValuePair> nameValuePairs = new ArrayList<>();
for (final Entry<RyaURI, ImmutableMap<RyaURI, Property>> typeProperty : typeProperties.entrySet()) {
final RyaURI type = typeProperty.getKey();
final Map<RyaURI, Property> propertyMap = typeProperty.getValue();
final URI typeUri = createIndividualTypeWithPropertiesUri(type, propertyMap);
final String keyString = type.getDataType().getLocalName();
final String valueString = typeUri.getLocalName();
nameValuePairs.add(new BasicNameValuePair(keyString, valueString));
}
final URIBuilder uriBuilder = new URIBuilder();
uriBuilder.addParameters(nameValuePairs);
String uriString;
try {
final java.net.URI uri = uriBuilder.build();
final String queryString = uri.getRawSchemeSpecificPart();
uriString = "urn:test" + queryString;
} catch (final URISyntaxException e) {
throw new SmartUriException("Unable to create type properties for the Smart URI", e);
}
return new URIImpl(uriString);
}
use of org.apache.rya.api.domain.RyaURI in project incubator-rya by apache.
the class SmartUriAdapter method convertMapToEntity.
private static Entity convertMapToEntity(final RyaURI subject, final Map<RyaURI, Map<URI, Value>> map) {
final Entity.Builder entityBuilder = Entity.builder();
entityBuilder.setSubject(subject);
for (final Entry<RyaURI, Map<URI, Value>> typeEntry : map.entrySet()) {
final RyaURI type = typeEntry.getKey();
final Map<URI, Value> subMap = typeEntry.getValue();
entityBuilder.setExplicitType(type);
for (final Entry<URI, Value> entry : subMap.entrySet()) {
final URI uri = entry.getKey();
final Value value = entry.getValue();
final RyaURI ryaUri = new RyaURI(uri.stringValue());
final RyaURI ryaName = new RyaURI(uri.stringValue());
final RyaType ryaType = new RyaType(value.stringValue());
final Property property = new Property(ryaName, ryaType);
entityBuilder.setProperty(ryaUri, property);
}
}
final Entity entity = entityBuilder.build();
return entity;
}
use of org.apache.rya.api.domain.RyaURI in project incubator-rya by apache.
the class SmartUriAdapter method createIndividualTypeWithPropertiesUri.
private static URI createIndividualTypeWithPropertiesUri(final RyaURI type, final Map<RyaURI, Property> map) throws SmartUriException {
final List<NameValuePair> nameValuePairs = new ArrayList<>();
for (final Entry<RyaURI, Property> entry : map.entrySet()) {
final RyaURI key = entry.getKey();
final Property property = entry.getValue();
final RyaType ryaType = property.getValue();
final String keyString = (new URIImpl(key.getData())).getLocalName();
final Value value = RyaToRdfConversions.convertValue(ryaType);
final String valueString = value.stringValue();
nameValuePairs.add(new BasicNameValuePair(keyString, valueString));
}
final URIBuilder uriBuilder = new URIBuilder();
uriBuilder.addParameters(nameValuePairs);
String uriString;
try {
final java.net.URI uri = uriBuilder.build();
final String queryString = uri.getRawSchemeSpecificPart();
uriString = type.getData() + /*new URIImpl(type.getData()).getLocalName()*/
queryString;
} catch (final URISyntaxException e) {
throw new SmartUriException("Unable to create type URI with all its properties for the Smart URI", e);
}
return new URIImpl(uriString);
}
use of org.apache.rya.api.domain.RyaURI in project incubator-rya by apache.
the class MongoGeoTemporalIndexer method updateEvent.
private void updateEvent(final RyaURI subject, final RyaStatement statement) throws IndexingException, ParseException {
final EventStorage eventStore = events.get();
checkState(events != null, "Must set this indexers configuration before storing statements.");
new EventUpdater(eventStore).update(subject, old -> {
final Event.Builder updated;
if (!old.isPresent()) {
updated = Event.builder().setSubject(subject);
} else {
updated = Event.builder(old.get());
}
final URI pred = statement.getObject().getDataType();
if (pred.equals(GeoConstants.GEO_AS_WKT) || pred.equals(GeoConstants.GEO_AS_GML) || pred.equals(GeoConstants.XMLSCHEMA_OGC_WKT) || pred.equals(GeoConstants.XMLSCHEMA_OGC_GML)) {
// is geo
try {
final Statement geoStatement = RyaToRdfConversions.convertStatement(statement);
final Geometry geometry = GeoParseUtils.getGeometry(geoStatement, new GmlParser());
updated.setGeometry(geometry);
} catch (final ParseException e) {
LOG.error(e.getMessage(), e);
}
} else {
// is time
final String dateTime = statement.getObject().getData();
final Matcher matcher = TemporalInstantRfc3339.PATTERN.matcher(dateTime);
if (matcher.find()) {
final TemporalInterval interval = TemporalInstantRfc3339.parseInterval(dateTime);
updated.setTemporalInterval(interval);
} else {
final TemporalInstant instant = new TemporalInstantRfc3339(DateTime.parse(dateTime));
updated.setTemporalInstant(instant);
}
}
return Optional.of(updated.build());
});
}
use of org.apache.rya.api.domain.RyaURI in project incubator-rya by apache.
the class EntityQueryNodeIT method evaluate_constantObject.
@Test
public void evaluate_constantObject() throws Exception {
final EntityStorage storage = new MongoEntityStorage(super.getMongoClient(), "testDB");
final ValueFactory vf = ValueFactoryImpl.getInstance();
final RyaURI subject = new RyaURI("urn:SSN:111-11-1111");
final Entity entity = Entity.builder().setSubject(subject).setExplicitType(PERSON_TYPE.getId()).setProperty(PERSON_TYPE.getId(), new Property(new RyaURI("urn:age"), RdfToRyaConversions.convertLiteral(vf.createLiteral(20)))).setProperty(PERSON_TYPE.getId(), new Property(new RyaURI("urn:eye"), RdfToRyaConversions.convertLiteral(vf.createLiteral("blue")))).setProperty(PERSON_TYPE.getId(), new Property(new RyaURI("urn:name"), RdfToRyaConversions.convertLiteral(vf.createLiteral("Bob")))).build();
storage.create(entity);
// A set of patterns that match a sepecific Entity subject.
final List<StatementPattern> patterns = getSPs("SELECT * WHERE { " + "<urn:SSN:111-11-1111> <" + RDF.TYPE + "> <urn:person> ." + "<urn:SSN:111-11-1111> <urn:age> ?age . " + "<urn:SSN:111-11-1111> <urn:eye> \"blue\" . " + "<urn:SSN:111-11-1111> <urn:name> ?name . " + "}");
final EntityQueryNode node = new EntityQueryNode(PERSON_TYPE, patterns, storage);
final CloseableIteration<BindingSet, QueryEvaluationException> rez = node.evaluate(new MapBindingSet());
final MapBindingSet expected = new MapBindingSet();
expected.addBinding("age", vf.createLiteral("20"));
expected.addBinding("-const-blue", vf.createLiteral("blue"));
expected.addBinding("name", vf.createLiteral("Bob"));
while (rez.hasNext()) {
assertEquals(expected, rez.next());
break;
}
}
Aggregations