Search in sources :

Example 31 with Thing

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

the class RemoteConceptsTest method whenCallingOwnerInstances_GetTheExpectedResult.

@Test
public void whenCallingOwnerInstances_GetTheExpectedResult() {
    Thing a = RemoteConcepts.createEntity(tx, A);
    Thing b = RemoteConcepts.createRelationship(tx, A);
    Thing c = RemoteConcepts.createAttribute(tx, A);
    mockConceptMethod(ConceptMethods.GET_OWNERS, Stream.of(a, b, c));
    assertThat(attribute.ownerInstances().collect(toSet()), containsInAnyOrder(a, b, c));
}
Also used : Thing(ai.grakn.concept.Thing) Test(org.junit.Test)

Example 32 with Thing

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

the class RemoteConceptsTest method whenCallingRolePlayersWithRoles_GetTheExpectedResult.

@Test
public void whenCallingRolePlayersWithRoles_GetTheExpectedResult() {
    Role foo = RemoteConcepts.createRole(tx, ConceptId.of("foo"));
    Role bar = RemoteConcepts.createRole(tx, ConceptId.of("bar"));
    Role baz = RemoteConcepts.createRole(tx, ConceptId.of("baz"));
    Thing a = RemoteConcepts.createEntity(tx, A);
    Thing b = RemoteConcepts.createRelationship(tx, B);
    Thing c = RemoteConcepts.createAttribute(tx, C);
    mockConceptMethod(ConceptMethods.getRolePlayersByRoles(foo, bar, baz), Stream.of(a, b, c));
    assertThat(relationship.rolePlayers(foo, bar, baz).collect(toSet()), containsInAnyOrder(a, b, c));
}
Also used : Role(ai.grakn.concept.Role) Thing(ai.grakn.concept.Thing) Test(org.junit.Test)

Example 33 with Thing

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

the class MatchTest method testLookupResourcesOnId.

@Test
public void testLookupResourcesOnId() {
    Thing godfather = movieKB.tx().getAttributeType("title").getAttribute("Godfather").owner();
    ConceptId id = godfather.getId();
    Match query = qb.match(var().id(id).has("title", x));
    assertThat(query, variable(x, contains(hasValue("Godfather"))));
}
Also used : Thing(ai.grakn.concept.Thing) ConceptId(ai.grakn.concept.ConceptId) Match(ai.grakn.graql.Match) Test(org.junit.Test)

Example 34 with Thing

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

the class ThingImpl method deleteAttribute.

@Override
public T deleteAttribute(Attribute attribute) {
    Role roleHasOwner = vertex().tx().getSchemaConcept(Schema.ImplicitType.HAS_OWNER.getLabel(attribute.type().getLabel()));
    Role roleKeyOwner = vertex().tx().getSchemaConcept(Schema.ImplicitType.KEY_OWNER.getLabel(attribute.type().getLabel()));
    Role roleHasValue = vertex().tx().getSchemaConcept(Schema.ImplicitType.HAS_VALUE.getLabel(attribute.type().getLabel()));
    Role roleKeyValue = vertex().tx().getSchemaConcept(Schema.ImplicitType.KEY_VALUE.getLabel(attribute.type().getLabel()));
    Stream<Relationship> relationships = relationships(filterNulls(roleHasOwner, roleKeyOwner));
    relationships.filter(relationship -> {
        Stream<Thing> rolePlayers = relationship.rolePlayers(filterNulls(roleHasValue, roleKeyValue));
        return rolePlayers.anyMatch(rolePlayer -> rolePlayer.equals(attribute));
    }).forEach(Concept::delete);
    return getThis();
}
Also used : Role(ai.grakn.concept.Role) Arrays(java.util.Arrays) Role(ai.grakn.concept.Role) Concept(ai.grakn.concept.Concept) Type(ai.grakn.concept.Type) Cacheable(ai.grakn.kb.internal.cache.Cacheable) Attribute(ai.grakn.concept.Attribute) HashSet(java.util.HashSet) Label(ai.grakn.concept.Label) AttributeType(ai.grakn.concept.AttributeType) LabelId(ai.grakn.concept.LabelId) RelationshipType(ai.grakn.concept.RelationshipType) Cache(ai.grakn.kb.internal.cache.Cache) ConceptId(ai.grakn.concept.ConceptId) Relationship(ai.grakn.concept.Relationship) EdgeElement(ai.grakn.kb.internal.structure.EdgeElement) P(org.apache.tinkerpop.gremlin.process.traversal.P) GraknTxOperationException(ai.grakn.exception.GraknTxOperationException) Set(java.util.Set) org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.__(org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.__) Vertex(org.apache.tinkerpop.gremlin.structure.Vertex) GraphTraversal(org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal) Collectors(java.util.stream.Collectors) Sets(com.google.common.collect.Sets) Objects(java.util.Objects) VertexElement(ai.grakn.kb.internal.structure.VertexElement) Direction(org.apache.tinkerpop.gremlin.structure.Direction) Stream(java.util.stream.Stream) Thing(ai.grakn.concept.Thing) Casting(ai.grakn.kb.internal.structure.Casting) Optional(java.util.Optional) Schema(ai.grakn.util.Schema) Concept(ai.grakn.concept.Concept) Relationship(ai.grakn.concept.Relationship) Stream(java.util.stream.Stream)

Example 35 with Thing

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

the class MigratorTestUtils method getProperties.

public static Collection<Thing> getProperties(GraknTx graph, Thing thing, String label) {
    RelationshipType relation = graph.getRelationshipType(label);
    Set<Thing> things = new HashSet<>();
    relation.instances().filter(i -> i.rolePlayers().anyMatch(t -> t.equals(thing))).forEach(i -> i.rolePlayers().forEach(things::add));
    things.remove(thing);
    return things;
}
Also used : InvalidKBException(ai.grakn.exception.InvalidKBException) Role(ai.grakn.concept.Role) Concept(ai.grakn.concept.Concept) Entity(ai.grakn.concept.Entity) Attribute(ai.grakn.concept.Attribute) HashSet(java.util.HashSet) Label(ai.grakn.concept.Label) AttributeType(ai.grakn.concept.AttributeType) RelationshipType(ai.grakn.concept.RelationshipType) Files(com.google.common.io.Files) GraknTx(ai.grakn.GraknTx) Relationship(ai.grakn.concept.Relationship) GraknTxType(ai.grakn.GraknTxType) Assert.assertNotNull(org.junit.Assert.assertNotNull) Collection(java.util.Collection) GraknSession(ai.grakn.GraknSession) Set(java.util.Set) Assert.assertTrue(org.junit.Assert.assertTrue) IOException(java.io.IOException) Collectors(java.util.stream.Collectors) File(java.io.File) StandardCharsets(java.nio.charset.StandardCharsets) Collectors.joining(java.util.stream.Collectors.joining) Stream(java.util.stream.Stream) Thing(ai.grakn.concept.Thing) Schema(ai.grakn.util.Schema) TestCase.assertEquals(junit.framework.TestCase.assertEquals) RelationshipType(ai.grakn.concept.RelationshipType) Thing(ai.grakn.concept.Thing) HashSet(java.util.HashSet)

Aggregations

Thing (ai.grakn.concept.Thing)47 Role (ai.grakn.concept.Role)30 Test (org.junit.Test)29 RelationshipType (ai.grakn.concept.RelationshipType)17 EntityType (ai.grakn.concept.EntityType)14 Relationship (ai.grakn.concept.Relationship)12 HashSet (java.util.HashSet)9 Set (java.util.Set)9 GraknTx (ai.grakn.GraknTx)7 Attribute (ai.grakn.concept.Attribute)7 ConceptId (ai.grakn.concept.ConceptId)7 AttributeType (ai.grakn.concept.AttributeType)6 Concept (ai.grakn.concept.Concept)6 Entity (ai.grakn.concept.Entity)6 Collectors (java.util.stream.Collectors)5 Label (ai.grakn.concept.Label)4 Schema (ai.grakn.util.Schema)4 Collection (java.util.Collection)4 Map (java.util.Map)4 GraknSession (ai.grakn.GraknSession)3