Search in sources :

Example 51 with RyaType

use of org.apache.rya.api.domain.RyaType 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;
}
Also used : Entity(org.apache.rya.indexing.entity.model.Entity) RyaURI(org.apache.rya.api.domain.RyaURI) Value(org.openrdf.model.Value) RyaType(org.apache.rya.api.domain.RyaType) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) HashBiMap(com.google.common.collect.HashBiMap) URI(org.openrdf.model.URI) RyaURI(org.apache.rya.api.domain.RyaURI) Property(org.apache.rya.indexing.entity.model.Property)

Example 52 with RyaType

use of org.apache.rya.api.domain.RyaType 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);
}
Also used : BasicNameValuePair(org.apache.http.message.BasicNameValuePair) NameValuePair(org.apache.http.NameValuePair) ArrayList(java.util.ArrayList) URIImpl(org.openrdf.model.impl.URIImpl) URISyntaxException(java.net.URISyntaxException) RyaType(org.apache.rya.api.domain.RyaType) URIBuilder(org.apache.http.client.utils.URIBuilder) RyaURI(org.apache.rya.api.domain.RyaURI) BasicNameValuePair(org.apache.http.message.BasicNameValuePair) Value(org.openrdf.model.Value) Property(org.apache.rya.indexing.entity.model.Property)

Example 53 with RyaType

use of org.apache.rya.api.domain.RyaType in project incubator-rya by apache.

the class MongoEntityStorageIT method search_byDataType.

@Test
public void search_byDataType() throws Exception {
    final EntityStorage storage = new MongoEntityStorage(super.getMongoClient(), RYA_INSTANCE_NAME);
    // The Type we will search by.
    final Type icecreamType = new Type(new RyaURI("urn:icecream"), ImmutableSet.<RyaURI>builder().add(new RyaURI("urn:brand")).add(new RyaURI("urn:flavor")).add(new RyaURI("urn:cost")).build());
    // Some Person typed entities.
    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();
    // Some Icecream typed objects.
    final Entity chocolateIcecream = Entity.builder().setSubject(new RyaURI("urn:GTIN-14/00012345600012")).setExplicitType(new RyaURI("urn:icecream")).setProperty(new RyaURI("urn:icecream"), new Property(new RyaURI("urn:brand"), new RyaType(XMLSchema.STRING, "Awesome Icecream"))).setProperty(new RyaURI("urn:icecream"), new Property(new RyaURI("urn:flavor"), new RyaType(XMLSchema.STRING, "Chocolate"))).build();
    final Entity vanillaIcecream = Entity.builder().setSubject(new RyaURI("urn:GTIN-14/22356325213432")).setExplicitType(new RyaURI("urn:icecream")).setProperty(new RyaURI("urn:icecream"), new Property(new RyaURI("urn:brand"), new RyaType(XMLSchema.STRING, "Awesome Icecream"))).setProperty(new RyaURI("urn:icecream"), new Property(new RyaURI("urn:flavor"), new RyaType(XMLSchema.STRING, "Vanilla"))).build();
    final Entity strawberryIcecream = Entity.builder().setSubject(new RyaURI("urn:GTIN-14/77544325436721")).setProperty(new RyaURI("urn:icecream"), new Property(new RyaURI("urn:brand"), new RyaType(XMLSchema.STRING, "Awesome Icecream"))).setProperty(new RyaURI("urn:icecream"), new Property(new RyaURI("urn:flavor"), new RyaType(XMLSchema.STRING, "Strawberry"))).build();
    // Create the objects in the storage.
    storage.create(alice);
    storage.create(bob);
    storage.create(chocolateIcecream);
    storage.create(vanillaIcecream);
    storage.create(strawberryIcecream);
    // Search for all icecreams.
    final Set<TypedEntity> objects = new HashSet<>();
    try (final ConvertingCursor<TypedEntity> it = storage.search(Optional.empty(), icecreamType, new HashSet<>())) {
        while (it.hasNext()) {
            objects.add(it.next());
        }
    }
    // Verify the expected results were returned.
    final Set<TypedEntity> expected = Sets.newHashSet(chocolateIcecream.makeTypedEntity(new RyaURI("urn:icecream")).get(), vanillaIcecream.makeTypedEntity(new RyaURI("urn:icecream")).get());
    assertEquals(expected, objects);
}
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)

Example 54 with RyaType

use of org.apache.rya.api.domain.RyaType in project incubator-rya by apache.

the class MongoEntityStorageIT method create_and_get.

@Test
public void create_and_get() throws Exception {
    // An Entity that will be stored.
    final Entity entity = Entity.builder().setSubject(new RyaURI("urn:GTIN-14/00012345600012")).setExplicitType(new RyaURI("urn:icecream")).setProperty(new RyaURI("urn:icecream"), new Property(new RyaURI("urn:brand"), new RyaType(XMLSchema.STRING, "Awesome Icecream"))).setProperty(new RyaURI("urn:icecream"), new Property(new RyaURI("urn:flavor"), new RyaType(XMLSchema.STRING, "Chocolate"))).build();
    // Create it.
    final EntityStorage storage = new MongoEntityStorage(super.getMongoClient(), RYA_INSTANCE_NAME);
    storage.create(entity);
    // Get it.
    final Optional<Entity> storedEntity = storage.get(new RyaURI("urn:GTIN-14/00012345600012"));
    // Verify the correct value was returned.
    assertEquals(entity, storedEntity.get());
}
Also used : Entity(org.apache.rya.indexing.entity.model.Entity) TypedEntity(org.apache.rya.indexing.entity.model.TypedEntity) RyaURI(org.apache.rya.api.domain.RyaURI) EntityStorage(org.apache.rya.indexing.entity.storage.EntityStorage) RyaType(org.apache.rya.api.domain.RyaType) Property(org.apache.rya.indexing.entity.model.Property) Test(org.junit.Test)

Example 55 with RyaType

use of org.apache.rya.api.domain.RyaType in project incubator-rya by apache.

the class MongoEntityStorageIT method can_not_create_with_same_subject.

@Test
public void can_not_create_with_same_subject() throws Exception {
    // A Type that will be stored.
    final Entity entity = Entity.builder().setSubject(new RyaURI("urn:GTIN-14/00012345600012")).setExplicitType(new RyaURI("urn:icecream")).setProperty(new RyaURI("urn:icecream"), new Property(new RyaURI("urn:brand"), new RyaType(XMLSchema.STRING, "Awesome Icecream"))).setProperty(new RyaURI("urn:icecream"), new Property(new RyaURI("urn:flavor"), new RyaType(XMLSchema.STRING, "Chocolate"))).build();
    // Create it.
    final EntityStorage storage = new MongoEntityStorage(super.getMongoClient(), RYA_INSTANCE_NAME);
    storage.create(entity);
    // Try to create it again. This will fail.
    boolean failed = false;
    try {
        storage.create(entity);
    } catch (final EntityAlreadyExistsException e) {
        failed = true;
    }
    assertTrue(failed);
}
Also used : Entity(org.apache.rya.indexing.entity.model.Entity) TypedEntity(org.apache.rya.indexing.entity.model.TypedEntity) RyaURI(org.apache.rya.api.domain.RyaURI) EntityAlreadyExistsException(org.apache.rya.indexing.entity.storage.EntityStorage.EntityAlreadyExistsException) EntityStorage(org.apache.rya.indexing.entity.storage.EntityStorage) RyaType(org.apache.rya.api.domain.RyaType) Property(org.apache.rya.indexing.entity.model.Property) Test(org.junit.Test)

Aggregations

RyaType (org.apache.rya.api.domain.RyaType)178 RyaURI (org.apache.rya.api.domain.RyaURI)146 RyaStatement (org.apache.rya.api.domain.RyaStatement)115 Test (org.junit.Test)109 BindingSet (org.openrdf.query.BindingSet)42 QueryBindingSet (org.openrdf.query.algebra.evaluation.QueryBindingSet)42 ArrayList (java.util.ArrayList)35 StatementPattern (org.openrdf.query.algebra.StatementPattern)35 ParsedQuery (org.openrdf.query.parser.ParsedQuery)35 SPARQLParser (org.openrdf.query.parser.sparql.SPARQLParser)35 StatementMetadata (org.apache.rya.api.domain.StatementMetadata)34 QueryEvaluationException (org.openrdf.query.QueryEvaluationException)34 RyaDAOException (org.apache.rya.api.persist.RyaDAOException)28 Property (org.apache.rya.indexing.entity.model.Property)23 URIImpl (org.openrdf.model.impl.URIImpl)23 HashSet (java.util.HashSet)22 Entity (org.apache.rya.indexing.entity.model.Entity)20 Value (org.openrdf.model.Value)19 LiteralImpl (org.openrdf.model.impl.LiteralImpl)19 BatchWriter (org.apache.accumulo.core.client.BatchWriter)18