Search in sources :

Example 26 with Property

use of org.apache.rya.indexing.entity.model.Property in project incubator-rya by apache.

the class EntityDocumentConverter method fromDocument.

@Override
public Entity fromDocument(final Document document) throws DocumentConverterException {
    requireNonNull(document);
    // Preconditions.
    if (!document.containsKey(SUBJECT)) {
        throw new DocumentConverterException("Could not convert document '" + document + "' because its '" + SUBJECT + "' field is missing.");
    }
    if (!document.containsKey(EXPLICIT_TYPE_IDS)) {
        throw new DocumentConverterException("Could not convert document '" + document + "' because its '" + EXPLICIT_TYPE_IDS + "' field is missing.");
    }
    if (!document.containsKey(PROPERTIES)) {
        throw new DocumentConverterException("Could not convert document '" + document + "' because its '" + PROPERTIES + "' field is missing.");
    }
    if (!document.containsKey(VERSION)) {
        throw new DocumentConverterException("Could not convert document '" + document + "' because its '" + VERSION + "' field is missing.");
    }
    if (!document.containsKey(SMART_URI)) {
        throw new DocumentConverterException("Could not convert document '" + document + "' because its '" + SMART_URI + "' field is missing.");
    }
    // Perform the conversion.
    final Entity.Builder builder = Entity.builder().setSubject(new RyaURI(document.getString(SUBJECT)));
    ((List<String>) document.get(EXPLICIT_TYPE_IDS)).stream().forEach(explicitTypeId -> builder.setExplicitType(new RyaURI(explicitTypeId)));
    final Document propertiesDoc = (Document) document.get(PROPERTIES);
    for (final String typeId : propertiesDoc.keySet()) {
        final Document typePropertiesDoc = (Document) propertiesDoc.get(typeId);
        for (final String propertyName : typePropertiesDoc.keySet()) {
            final String decodedPropertyName = MongoDbSafeKey.decodeKey(propertyName);
            final Document value = (Document) typePropertiesDoc.get(propertyName);
            final RyaType propertyValue = ryaTypeConverter.fromDocument(value);
            builder.setProperty(new RyaURI(typeId), new Property(new RyaURI(decodedPropertyName), propertyValue));
        }
    }
    builder.setVersion(document.getInteger(VERSION));
    builder.setSmartUri(new URIImpl(document.getString(SMART_URI)));
    return builder.build();
}
Also used : Entity(org.apache.rya.indexing.entity.model.Entity) RyaURI(org.apache.rya.api.domain.RyaURI) URIImpl(org.openrdf.model.impl.URIImpl) Document(org.bson.Document) RyaType(org.apache.rya.api.domain.RyaType) Property(org.apache.rya.indexing.entity.model.Property)

Example 27 with Property

use of org.apache.rya.indexing.entity.model.Property in project incubator-rya by apache.

the class MongoEntityIndex2IT method beforeClass.

@Before
public void beforeClass() throws Exception {
    optimizer = new EntityIndexOptimizer();
    optimizer.setConf(conf);
    final TypeStorage typeStorage = optimizer.getTypeStorage();
    typeStorage.create(PERSON_TYPE);
    final Entity entity = Entity.builder().setSubject(new RyaURI("urn:SSN:111-11-1111")).setExplicitType(RYA_PERSON_TYPE).setProperty(RYA_PERSON_TYPE, new Property(new RyaURI("urn:age"), new RyaType("25"))).setProperty(RYA_PERSON_TYPE, new Property(new RyaURI("urn:eye"), new RyaType("blue"))).setProperty(RYA_PERSON_TYPE, new Property(new RyaURI("urn:name"), new RyaType("bob"))).build();
    entityStorage = optimizer.getEntityStorage();
    entityStorage.create(entity);
}
Also used : TypeStorage(org.apache.rya.indexing.entity.storage.TypeStorage) Entity(org.apache.rya.indexing.entity.model.Entity) RyaURI(org.apache.rya.api.domain.RyaURI) EntityIndexOptimizer(org.apache.rya.indexing.entity.EntityIndexOptimizer) RyaType(org.apache.rya.api.domain.RyaType) Property(org.apache.rya.indexing.entity.model.Property) Before(org.junit.Before)

Example 28 with Property

use of org.apache.rya.indexing.entity.model.Property in project incubator-rya by apache.

the class EntityQueryNodeIT method evaluate_variableSubject.

@Test
public void evaluate_variableSubject() throws Exception {
    final EntityStorage storage = new MongoEntityStorage(super.getMongoClient(), "testDB");
    final ValueFactory vf = ValueFactoryImpl.getInstance();
    RyaURI subject = new RyaURI("urn:SSN:111-11-1111");
    final Entity bob = 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();
    subject = new RyaURI("urn:SSN:222-22-2222");
    final Entity fred = Entity.builder().setSubject(subject).setExplicitType(PERSON_TYPE.getId()).setProperty(PERSON_TYPE.getId(), new Property(new RyaURI("urn:age"), RdfToRyaConversions.convertLiteral(vf.createLiteral(25)))).setProperty(PERSON_TYPE.getId(), new Property(new RyaURI("urn:eye"), RdfToRyaConversions.convertLiteral(vf.createLiteral("brown")))).setProperty(PERSON_TYPE.getId(), new Property(new RyaURI("urn:name"), RdfToRyaConversions.convertLiteral(vf.createLiteral("Fred")))).build();
    storage.create(bob);
    storage.create(fred);
    // A set of patterns that match a sepecific Entity subject.
    final List<StatementPattern> patterns = getSPs("SELECT * WHERE { " + "?ssn <" + RDF.TYPE + "> <urn:person> ." + "?ssn <urn:age> ?age . " + "?ssn <urn:eye> ?eye . " + "?ssn <urn:name> ?name . " + "}");
    final EntityQueryNode node = new EntityQueryNode(PERSON_TYPE, patterns, storage);
    final CloseableIteration<BindingSet, QueryEvaluationException> rez = node.evaluate(new MapBindingSet());
    final List<BindingSet> expectedBindings = new ArrayList<>();
    final MapBindingSet expectedBob = new MapBindingSet();
    expectedBob.addBinding("age", vf.createLiteral("20"));
    expectedBob.addBinding("eye", vf.createLiteral("blue"));
    expectedBob.addBinding("name", vf.createLiteral("Bob"));
    final MapBindingSet expectedFred = new MapBindingSet();
    expectedFred.addBinding("age", vf.createLiteral("25"));
    expectedFred.addBinding("eye", vf.createLiteral("brown"));
    expectedFred.addBinding("name", vf.createLiteral("Fred"));
    expectedBindings.add(expectedBob);
    expectedBindings.add(expectedFred);
    while (rez.hasNext()) {
        final BindingSet bs = rez.next();
        assertTrue(expectedBindings.contains(bs));
    }
}
Also used : Entity(org.apache.rya.indexing.entity.model.Entity) MapBindingSet(org.openrdf.query.impl.MapBindingSet) BindingSet(org.openrdf.query.BindingSet) MongoEntityStorage(org.apache.rya.indexing.entity.storage.mongo.MongoEntityStorage) EntityStorage(org.apache.rya.indexing.entity.storage.EntityStorage) MongoEntityStorage(org.apache.rya.indexing.entity.storage.mongo.MongoEntityStorage) ArrayList(java.util.ArrayList) ValueFactory(org.openrdf.model.ValueFactory) RyaURI(org.apache.rya.api.domain.RyaURI) StatementPattern(org.openrdf.query.algebra.StatementPattern) QueryEvaluationException(org.openrdf.query.QueryEvaluationException) MapBindingSet(org.openrdf.query.impl.MapBindingSet) Property(org.apache.rya.indexing.entity.model.Property) Test(org.junit.Test)

Example 29 with Property

use of org.apache.rya.indexing.entity.model.Property in project incubator-rya by apache.

the class EntityQueryNodeIT method evaluate_constantSubject.

@Test
public void evaluate_constantSubject() 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> ?eye . " + "<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("eye", vf.createLiteral("blue"));
    expected.addBinding("name", vf.createLiteral("Bob"));
    while (rez.hasNext()) {
        assertEquals(expected, rez.next());
        break;
    }
}
Also used : Entity(org.apache.rya.indexing.entity.model.Entity) MapBindingSet(org.openrdf.query.impl.MapBindingSet) BindingSet(org.openrdf.query.BindingSet) MongoEntityStorage(org.apache.rya.indexing.entity.storage.mongo.MongoEntityStorage) EntityStorage(org.apache.rya.indexing.entity.storage.EntityStorage) MongoEntityStorage(org.apache.rya.indexing.entity.storage.mongo.MongoEntityStorage) ValueFactory(org.openrdf.model.ValueFactory) RyaURI(org.apache.rya.api.domain.RyaURI) StatementPattern(org.openrdf.query.algebra.StatementPattern) QueryEvaluationException(org.openrdf.query.QueryEvaluationException) MapBindingSet(org.openrdf.query.impl.MapBindingSet) Property(org.apache.rya.indexing.entity.model.Property) Test(org.junit.Test)

Example 30 with Property

use of org.apache.rya.indexing.entity.model.Property 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

Property (org.apache.rya.indexing.entity.model.Property)35 RyaURI (org.apache.rya.api.domain.RyaURI)30 RyaType (org.apache.rya.api.domain.RyaType)25 Entity (org.apache.rya.indexing.entity.model.Entity)24 Test (org.junit.Test)21 EntityStorage (org.apache.rya.indexing.entity.storage.EntityStorage)18 TypedEntity (org.apache.rya.indexing.entity.model.TypedEntity)10 MongoEntityStorage (org.apache.rya.indexing.entity.storage.mongo.MongoEntityStorage)10 TypeStorage (org.apache.rya.indexing.entity.storage.TypeStorage)9 URI (org.openrdf.model.URI)8 URIImpl (org.openrdf.model.impl.URIImpl)8 MongoTypeStorage (org.apache.rya.indexing.entity.storage.mongo.MongoTypeStorage)7 Value (org.openrdf.model.Value)7 RyaStatement (org.apache.rya.api.domain.RyaStatement)6 ImmutableMap (com.google.common.collect.ImmutableMap)5 Type (org.apache.rya.indexing.entity.model.Type)5 BindingSet (org.openrdf.query.BindingSet)5 QueryEvaluationException (org.openrdf.query.QueryEvaluationException)5 ArrayList (java.util.ArrayList)4 LinkedHashMap (java.util.LinkedHashMap)4