use of ai.grakn.concept.Label in project grakn by graknlabs.
the class MigratorTestUtils method assertRelationBetweenInstancesExists.
public static void assertRelationBetweenInstancesExists(GraknTx graph, Thing thing1, Thing thing2, Label relation) {
RelationshipType relationshipType = graph.getSchemaConcept(relation);
Role role1 = thing1.plays().filter(r -> r.relationshipTypes().anyMatch(rel -> rel.equals(relationshipType))).findFirst().get();
assertTrue(thing1.relationships(role1).anyMatch(rel -> rel.rolePlayers().anyMatch(r -> r.equals(thing2))));
}
use of ai.grakn.concept.Label in project grakn by graknlabs.
the class GraknTxPutPropertyTest method whenCallingPutResourceTypeWithThePropertiesOfAnExistingResourceType_ItReturnsThatType.
@Property
public void whenCallingPutResourceTypeWithThePropertiesOfAnExistingResourceType_ItReturnsThatType(@Open GraknTx graph, @FromTx AttributeType<?> attributeType) {
assumeFalse(attributeType.equals(graph.admin().getMetaAttributeType()));
Label label = attributeType.getLabel();
AttributeType.DataType<?> dataType = attributeType.getDataType();
AttributeType<?> newType = graph.putAttributeType(label, dataType);
assertEquals(attributeType, newType);
}
use of ai.grakn.concept.Label in project grakn by graknlabs.
the class RemoteGraknTxTest method whenGettingNonExistentSchemaConceptViaLabel_ReturnNull.
@Test
public void whenGettingNonExistentSchemaConceptViaLabel_ReturnNull() {
Label label = Label.of("foo");
try (RemoteGraknTx tx = RemoteGraknTx.create(session, GrpcUtil.openRequest(KEYSPACE, GraknTxType.READ))) {
// The open request
verify(server.requests()).onNext(any());
server.setResponse(GrpcUtil.getSchemaConceptRequest(label), GrpcUtil.optionalConceptResponse(Optional.empty()));
assertNull(tx.getSchemaConcept(label));
}
}
use of ai.grakn.concept.Label in project grakn by graknlabs.
the class RemoteGraknTxTest method whenPuttingEntityType_EnsureCorrectRequestIsSent.
@Test
public void whenPuttingEntityType_EnsureCorrectRequestIsSent() {
ConceptId id = ConceptId.of(V123.getValue());
Label label = Label.of("foo");
try (RemoteGraknTx tx = RemoteGraknTx.create(session, GrpcUtil.openRequest(KEYSPACE, GraknTxType.READ))) {
// The open request
verify(server.requests()).onNext(any());
Concept concept = RemoteConcepts.createEntityType(tx, id);
server.setResponse(GrpcUtil.putEntityTypeRequest(label), GrpcUtil.conceptResponse(concept));
assertEquals(concept, tx.putEntityType(label));
}
}
use of ai.grakn.concept.Label in project grakn by graknlabs.
the class RelationshipProperty method mapToAtom.
@Override
public Atomic mapToAtom(VarPatternAdmin var, Set<VarPatternAdmin> vars, ReasonerQuery parent) {
// set varName as user defined if reified
// reified if contains more properties than the RelationshipProperty itself and potential IsaProperty
boolean isReified = var.getProperties().filter(prop -> !RelationshipProperty.class.isInstance(prop)).anyMatch(prop -> !AbstractIsaProperty.class.isInstance(prop));
VarPattern relVar = isReified ? var.var().asUserDefined() : var.var();
for (RelationPlayer rp : relationPlayers()) {
VarPattern rolePattern = rp.getRole().orElse(null);
VarPattern rolePlayer = rp.getRolePlayer();
if (rolePattern != null) {
Var roleVar = rolePattern.admin().var();
// look for indirect role definitions
IdPredicate roleId = getUserDefinedIdPredicate(roleVar, vars, parent);
if (roleId != null) {
Concept concept = parent.tx().getConcept(roleId.getPredicate());
if (concept != null) {
if (concept.isRole()) {
Label roleLabel = concept.asSchemaConcept().getLabel();
rolePattern = roleVar.label(roleLabel);
} else {
throw GraqlQueryException.nonRoleIdAssignedToRoleVariable(var);
}
}
}
relVar = relVar.rel(rolePattern, rolePlayer);
} else
relVar = relVar.rel(rolePlayer);
}
// isa part
AbstractIsaProperty isaProp = var.getProperty(AbstractIsaProperty.class).orElse(null);
IdPredicate predicate = null;
// if no isa property present generate type variable
Var typeVariable = isaProp != null ? isaProp.type().var() : Graql.var();
// Isa present
if (isaProp != null) {
VarPatternAdmin isaVar = isaProp.type();
Label label = isaVar.getTypeLabel().orElse(null);
if (label != null) {
predicate = IdPredicate.create(typeVariable, label, parent);
} else {
typeVariable = isaVar.var();
predicate = getUserDefinedIdPredicate(typeVariable, vars, parent);
}
}
ConceptId predicateId = predicate != null ? predicate.getPredicate() : null;
relVar = isaProp instanceof DirectIsaProperty ? relVar.directIsa(typeVariable.asUserDefined()) : relVar.isa(typeVariable.asUserDefined());
return RelationshipAtom.create(relVar.admin(), typeVariable, predicateId, parent);
}
Aggregations