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));
}
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));
}
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"))));
}
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();
}
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;
}
Aggregations