Search in sources :

Example 16 with Type

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;
}
Also used : StatementPattern(org.openrdf.query.algebra.StatementPattern) Type(org.apache.rya.indexing.entity.model.Type) EntityQueryNode(org.apache.rya.indexing.entity.query.EntityQueryNode) ArrayList(java.util.ArrayList) QueryModelNode(org.openrdf.query.algebra.QueryModelNode)

Example 17 with Type

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()));
}
Also used : RyaURI(org.apache.rya.api.domain.RyaURI) Entity(org.apache.rya.indexing.entity.model.Entity) TypedEntity(org.apache.rya.indexing.entity.model.TypedEntity) RyaType(org.apache.rya.api.domain.RyaType) Type(org.apache.rya.indexing.entity.model.Type) EntityStorage(org.apache.rya.indexing.entity.storage.EntityStorage) TypedEntity(org.apache.rya.indexing.entity.model.TypedEntity) RyaType(org.apache.rya.api.domain.RyaType) Property(org.apache.rya.indexing.entity.model.Property) HashSet(java.util.HashSet) Test(org.junit.Test)

Aggregations

Type (org.apache.rya.indexing.entity.model.Type)17 RyaURI (org.apache.rya.api.domain.RyaURI)14 Test (org.junit.Test)11 TypeStorage (org.apache.rya.indexing.entity.storage.TypeStorage)9 Entity (org.apache.rya.indexing.entity.model.Entity)6 RyaType (org.apache.rya.api.domain.RyaType)5 Property (org.apache.rya.indexing.entity.model.Property)5 EntityStorage (org.apache.rya.indexing.entity.storage.EntityStorage)5 TypeStorageException (org.apache.rya.indexing.entity.storage.TypeStorage.TypeStorageException)4 ArrayList (java.util.ArrayList)3 HashSet (java.util.HashSet)3 List (java.util.List)3 TypedEntity (org.apache.rya.indexing.entity.model.TypedEntity)3 URIImpl (org.openrdf.model.impl.URIImpl)3 ImmutableList (com.google.common.collect.ImmutableList)2 Date (java.util.Date)2 ReflectionToStringBuilder (org.apache.commons.lang.builder.ReflectionToStringBuilder)2 RyaTypeUtils.booleanRyaType (org.apache.rya.api.domain.RyaTypeUtils.booleanRyaType)2 RyaTypeUtils.byteRyaType (org.apache.rya.api.domain.RyaTypeUtils.byteRyaType)2 RyaTypeUtils.dateRyaType (org.apache.rya.api.domain.RyaTypeUtils.dateRyaType)2