use of ai.grakn.concept.Concept 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);
}
use of ai.grakn.concept.Concept in project grakn by graknlabs.
the class GraknKeyspaceStoreTest method cleanSystemKeySpaceGraph.
@After
public void cleanSystemKeySpaceGraph() {
try (GraknTx tx = graknFactory.tx(SYSTEM_KB_KEYSPACE, GraknTxType.WRITE)) {
tx.getEntityType("keyspace").instances().forEach(Concept::delete);
tx.getAttributeType("keyspace-name").instances().forEach(Concept::delete);
tx.commit();
}
transactions.forEach(GraknTx::close);
}
use of ai.grakn.concept.Concept in project grakn by graknlabs.
the class ElementFactory method buildConcept.
public <X extends Concept> X buildConcept(VertexElement vertexElement) {
Schema.BaseType type;
try {
type = getBaseType(vertexElement);
} catch (IllegalStateException e) {
throw TemporaryWriteException.indexOverlap(vertexElement.element(), e);
}
ConceptId conceptId = ConceptId.of(vertexElement.property(Schema.VertexProperty.ID));
if (!tx.txCache().isConceptCached(conceptId)) {
Concept concept;
switch(type) {
case RELATIONSHIP:
concept = RelationshipImpl.create(RelationshipReified.get(vertexElement));
break;
case TYPE:
concept = new TypeImpl(vertexElement);
break;
case ROLE:
concept = RoleImpl.get(vertexElement);
break;
case RELATIONSHIP_TYPE:
concept = RelationshipTypeImpl.get(vertexElement);
break;
case ENTITY:
concept = EntityImpl.get(vertexElement);
break;
case ENTITY_TYPE:
concept = EntityTypeImpl.get(vertexElement);
break;
case ATTRIBUTE_TYPE:
concept = AttributeTypeImpl.get(vertexElement);
break;
case ATTRIBUTE:
concept = AttributeImpl.get(vertexElement);
break;
case RULE:
concept = RuleImpl.get(vertexElement);
break;
default:
throw GraknTxOperationException.unknownConcept(type.name());
}
tx.txCache().cacheConcept(concept);
}
return tx.txCache().getCachedConcept(conceptId);
}
use of ai.grakn.concept.Concept in project grakn by graknlabs.
the class ElementFactory method buildConcept.
public <X extends Concept> X buildConcept(EdgeElement edgeElement) {
Schema.EdgeLabel label = Schema.EdgeLabel.valueOf(edgeElement.label().toUpperCase(Locale.getDefault()));
ConceptId conceptId = ConceptId.of(edgeElement.id().getValue());
if (!tx.txCache().isConceptCached(conceptId)) {
Concept concept;
switch(label) {
case ATTRIBUTE:
concept = RelationshipImpl.create(RelationshipEdge.get(edgeElement));
break;
default:
throw GraknTxOperationException.unknownConcept(label.name());
}
tx.txCache().cacheConcept(concept);
}
return tx.txCache().getCachedConcept(conceptId);
}
use of ai.grakn.concept.Concept in project grakn by graknlabs.
the class TxObserver method runConceptMethod.
private void runConceptMethod(RunConceptMethod runConceptMethod) {
Concept concept = nonNull(tx().getConcept(GrpcUtil.getConceptId(runConceptMethod)));
GrpcConceptConverter converter = grpcConcept -> tx().getConcept(GrpcUtil.convert(grpcConcept.getId()));
ConceptMethod<?> conceptMethod = ConceptMethods.fromGrpc(converter, runConceptMethod.getConceptMethod());
TxResponse response = conceptMethod.run(grpcIterators, concept);
responseObserver.onNext(response);
}
Aggregations