use of org.apache.rya.indexing.entity.model.Type in project incubator-rya by apache.
the class EntityIndexSetProvider method getExternalSets.
@Override
public List<EntityQueryNode> getExternalSets(final QuerySegment<EntityQueryNode> node) {
typeMap = HashMultimap.create();
subjectTypeMap = new HashMap<>();
// discover entities
final List<StatementPattern> unused = new ArrayList<>();
for (final QueryModelNode pattern : node.getOrderedNodes()) {
if (pattern instanceof StatementPattern) {
discoverEntities((StatementPattern) pattern, unused);
}
}
final List<EntityQueryNode> nodes = new ArrayList<>();
for (final Type type : typeMap.keySet()) {
// replace all nodes in the tupleExpr of the collection of statement patterns with this node.
final EntityQueryNode entity = new EntityQueryNode(type, typeMap.get(type), entityStorage);
nodes.add(entity);
}
return nodes;
}
use of org.apache.rya.indexing.entity.model.Type in project incubator-rya by apache.
the class MongoEntityStorageIT method search_byFields.
@Test
public void search_byFields() throws Exception {
final EntityStorage storage = new MongoEntityStorage(super.getMongoClient(), RYA_INSTANCE_NAME);
// A Type that defines a Person.
final Type personType = new Type(new RyaURI("urn:person"), ImmutableSet.<RyaURI>builder().add(new RyaURI("urn:name")).add(new RyaURI("urn:age")).add(new RyaURI("urn:eye")).build());
// Some Person typed objects.
final Entity alice = Entity.builder().setSubject(new RyaURI("urn:SSN/111-11-1111")).setExplicitType(new RyaURI("urn:person")).setProperty(new RyaURI("urn:person"), new Property(new RyaURI("urn:name"), new RyaType(XMLSchema.STRING, "Alice"))).setProperty(new RyaURI("urn:person"), new Property(new RyaURI("urn:age"), new RyaType(XMLSchema.INT, "30"))).setProperty(new RyaURI("urn:person"), new Property(new RyaURI("urn:eye"), new RyaType(XMLSchema.STRING, "blue"))).build();
final Entity bob = Entity.builder().setSubject(new RyaURI("urn:SSN/222-22-2222")).setExplicitType(new RyaURI("urn:person")).setProperty(new RyaURI("urn:person"), new Property(new RyaURI("urn:name"), new RyaType(XMLSchema.STRING, "Bob"))).setProperty(new RyaURI("urn:person"), new Property(new RyaURI("urn:age"), new RyaType(XMLSchema.INT, "57"))).setProperty(new RyaURI("urn:person"), new Property(new RyaURI("urn:eye"), new RyaType(XMLSchema.STRING, "blue"))).build();
final Entity charlie = Entity.builder().setSubject(new RyaURI("urn:SSN/333-33-3333")).setExplicitType(new RyaURI("urn:person")).setProperty(new RyaURI("urn:person"), new Property(new RyaURI("urn:name"), new RyaType(XMLSchema.STRING, "Charlie"))).setProperty(new RyaURI("urn:person"), new Property(new RyaURI("urn:age"), new RyaType(XMLSchema.INT, "30"))).setProperty(new RyaURI("urn:person"), new Property(new RyaURI("urn:eye"), new RyaType(XMLSchema.STRING, "blue"))).build();
final Entity david = Entity.builder().setSubject(new RyaURI("urn:SSN/444-44-4444")).setExplicitType(new RyaURI("urn:person")).setProperty(new RyaURI("urn:person"), new Property(new RyaURI("urn:name"), new RyaType(XMLSchema.STRING, "David"))).setProperty(new RyaURI("urn:person"), new Property(new RyaURI("urn:age"), new RyaType(XMLSchema.INT, "30"))).setProperty(new RyaURI("urn:person"), new Property(new RyaURI("urn:eye"), new RyaType(XMLSchema.STRING, "brown"))).build();
final Entity eve = Entity.builder().setSubject(new RyaURI("urn:SSN/555-55-5555")).setExplicitType(new RyaURI("urn:person")).setProperty(new RyaURI("urn:person"), new Property(new RyaURI("urn:name"), new RyaType(XMLSchema.STRING, "Eve"))).setProperty(new RyaURI("urn:person"), new Property(new RyaURI("urn:age"), new RyaType(XMLSchema.INT, "30"))).build();
final Entity frank = Entity.builder().setSubject(new RyaURI("urn:SSN/666-66-6666")).setExplicitType(new RyaURI("urn:person")).setProperty(new RyaURI("urn:person"), new Property(new RyaURI("urn:name"), new RyaType(XMLSchema.STRING, "Frank"))).setProperty(new RyaURI("urn:person"), new Property(new RyaURI("urn:eye"), new RyaType(XMLSchema.STRING, "blue"))).setProperty(new RyaURI("urn:someOtherType"), new Property(new RyaURI("urn:age"), new RyaType(XMLSchema.INT, "30"))).build();
final Entity george = Entity.builder().setSubject(new RyaURI("urn:SSN/777-77-7777")).setProperty(new RyaURI("urn:person"), new Property(new RyaURI("urn:name"), new RyaType(XMLSchema.STRING, "George"))).setProperty(new RyaURI("urn:person"), new Property(new RyaURI("urn:age"), new RyaType(XMLSchema.INT, "30"))).setProperty(new RyaURI("urn:person"), new Property(new RyaURI("urn:eye"), new RyaType(XMLSchema.STRING, "blue"))).build();
// Create the objects in the storage.
storage.create(alice);
storage.create(bob);
storage.create(charlie);
storage.create(david);
storage.create(eve);
storage.create(frank);
storage.create(george);
// Search for all people who are 30 and have blue eyes.
final Set<TypedEntity> objects = new HashSet<>();
final Set<Property> searchValues = Sets.newHashSet(new Property(new RyaURI("urn:eye"), new RyaType(XMLSchema.STRING, "blue")), new Property(new RyaURI("urn:age"), new RyaType(XMLSchema.INT, "30")));
try (final ConvertingCursor<TypedEntity> it = storage.search(Optional.empty(), personType, searchValues)) {
while (it.hasNext()) {
objects.add(it.next());
}
}
// Verify the expected results were returned.
assertEquals(2, objects.size());
assertTrue(objects.contains(alice.makeTypedEntity(new RyaURI("urn:person")).get()));
assertTrue(objects.contains(charlie.makeTypedEntity(new RyaURI("urn:person")).get()));
}
Aggregations