Search in sources :

Example 31 with Attribute

use of ai.grakn.concept.Attribute in project grakn by graknlabs.

the class TxObserver method getAttributesByValue.

private void getAttributesByValue(AttributeValue attributeValue) {
    Collection<Attribute<Object>> attributes = tx().getAttributesByValue(GrpcUtil.convert(attributeValue));
    Iterator<TxResponse> iterator = attributes.stream().map(GrpcUtil::conceptResponse).iterator();
    IteratorId iteratorId = grpcIterators.add(iterator);
    responseObserver.onNext(TxResponse.newBuilder().setIteratorId(iteratorId).build());
}
Also used : IteratorId(ai.grakn.rpc.generated.GrpcIterator.IteratorId) Attribute(ai.grakn.concept.Attribute) TxResponse(ai.grakn.rpc.generated.GrpcGrakn.TxResponse)

Example 32 with Attribute

use of ai.grakn.concept.Attribute in project grakn by graknlabs.

the class MatchTest method testMatchAllResourcesUsingResourceName.

@Test
public void testMatchAllResourcesUsingResourceName() {
    Match match = qb.match(var().has("title", "Godfather").has(Schema.MetaSchema.ATTRIBUTE.getLabel().getValue(), x));
    Thing godfather = movieKB.tx().getAttributeType("title").getAttribute("Godfather").owner();
    Set<Attribute<?>> expected = godfather.attributes().collect(toSet());
    Set<Attribute<?>> results = match.get(x).map(Concept::asAttribute).collect(toSet());
    assertEquals(expected, results);
}
Also used : Attribute(ai.grakn.concept.Attribute) Thing(ai.grakn.concept.Thing) Match(ai.grakn.graql.Match) Test(org.junit.Test)

Example 33 with Attribute

use of ai.grakn.concept.Attribute in project grakn by graknlabs.

the class AttributeTypeTest method whenGettingTheResourceFromAResourceType_ReturnTheResource.

@Test
public void whenGettingTheResourceFromAResourceType_ReturnTheResource() {
    AttributeType<String> t1 = tx.putAttributeType("t1", AttributeType.DataType.STRING);
    AttributeType<String> t2 = tx.putAttributeType("t2", AttributeType.DataType.STRING);
    Attribute c1 = t1.putAttribute("1");
    Attribute c2 = t2.putAttribute("2");
    assertEquals(c1, t1.getAttribute("1"));
    assertNull(t1.getAttribute("2"));
    assertEquals(c2, t2.getAttribute("2"));
    assertNull(t2.getAttribute("1"));
}
Also used : Attribute(ai.grakn.concept.Attribute) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) Test(org.junit.Test)

Example 34 with Attribute

use of ai.grakn.concept.Attribute in project grakn by graknlabs.

the class SchemaMutationTest method whenAddingResourceToSubTypeOfEntityType_EnsureNoValidationErrorsOccur.

@Test
public void whenAddingResourceToSubTypeOfEntityType_EnsureNoValidationErrorsOccur() {
    // Create initial Schema
    AttributeType<String> name = tx.putAttributeType("name", AttributeType.DataType.STRING);
    EntityType person = tx.putEntityType("perspn").attribute(name);
    EntityType animal = tx.putEntityType("animal").sup(person);
    Attribute bob = name.putAttribute("Bob");
    person.addEntity().attribute(bob);
    tx.commit();
    // Now make animal have the same resource type
    tx = EmbeddedGraknSession.create(tx.keyspace(), Grakn.IN_MEMORY).open(GraknTxType.WRITE);
    animal.attribute(name);
    tx.commit();
}
Also used : EntityType(ai.grakn.concept.EntityType) Attribute(ai.grakn.concept.Attribute) Test(org.junit.Test)

Example 35 with Attribute

use of ai.grakn.concept.Attribute in project grakn by graknlabs.

the class EntityTest method checkKeyCreatesCorrectResourceStructure.

@Test
public void checkKeyCreatesCorrectResourceStructure() {
    Label resourceLabel = Label.of("A Attribute Thing");
    EntityType entityType = tx.putEntityType("A Thing");
    AttributeType<String> attributeType = tx.putAttributeType(resourceLabel, AttributeType.DataType.STRING);
    entityType.key(attributeType);
    Entity entity = entityType.addEntity();
    Attribute attribute = attributeType.putAttribute("A attribute thing");
    entity.attribute(attribute);
    Relationship relationship = entity.relationships().iterator().next();
    checkImplicitStructure(attributeType, relationship, entity, Schema.ImplicitType.KEY, Schema.ImplicitType.KEY_OWNER, Schema.ImplicitType.KEY_VALUE);
}
Also used : EntityType(ai.grakn.concept.EntityType) Entity(ai.grakn.concept.Entity) Attribute(ai.grakn.concept.Attribute) Relationship(ai.grakn.concept.Relationship) Label(ai.grakn.concept.Label) Test(org.junit.Test)

Aggregations

Attribute (ai.grakn.concept.Attribute)36 Test (org.junit.Test)26 GraknTx (ai.grakn.GraknTx)15 EntityType (ai.grakn.concept.EntityType)15 Entity (ai.grakn.concept.Entity)14 RelationshipType (ai.grakn.concept.RelationshipType)10 Set (java.util.Set)10 Role (ai.grakn.concept.Role)9 AttributeType (ai.grakn.concept.AttributeType)8 Relationship (ai.grakn.concept.Relationship)8 Label (ai.grakn.concept.Label)7 Thing (ai.grakn.concept.Thing)6 Concept (ai.grakn.concept.Concept)5 HashSet (java.util.HashSet)5 ConceptId (ai.grakn.concept.ConceptId)4 Schema (ai.grakn.util.Schema)4 GraknTxOperationException (ai.grakn.exception.GraknTxOperationException)3 Sets (com.google.common.collect.Sets)3 Collection (java.util.Collection)3 Collectors (java.util.stream.Collectors)3