use of ai.grakn.concept.Concept 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.Concept in project grakn by graknlabs.
the class GetQueryPropertyTest method joinAnswer.
private Optional<Answer> joinAnswer(Answer answerA, Answer answerB) {
Map<Var, Concept> answer = Maps.newHashMap(answerA.map());
answer.putAll(answerB.map());
for (Var var : Sets.intersection(answerA.vars(), answerB.vars())) {
if (!answerA.get(var).equals(answerB.get(var))) {
return Optional.empty();
}
}
return Optional.of(new QueryAnswer(answer));
}
use of ai.grakn.concept.Concept in project grakn by graknlabs.
the class RemoteGraknTxTest method whenGettingConceptViaID_EnsureCorrectRequestIsSent.
@Test
public void whenGettingConceptViaID_EnsureCorrectRequestIsSent() {
ConceptId id = ConceptId.of(V123.getValue());
try (RemoteGraknTx tx = RemoteGraknTx.create(session, GrpcUtil.openRequest(KEYSPACE, GraknTxType.READ))) {
// The open request
verify(server.requests()).onNext(any());
Concept concept = RemoteConcepts.createEntity(tx, id);
server.setResponse(GrpcUtil.getConceptRequest(id), GrpcUtil.optionalConceptResponse(Optional.of(concept)));
assertEquals(concept, tx.getConcept(id));
}
}
use of ai.grakn.concept.Concept 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.Concept in project grakn by graknlabs.
the class QueryAnswer method merge.
@Override
public Answer merge(Answer a2, boolean mergeExplanation) {
if (a2.isEmpty())
return this;
if (this.isEmpty())
return a2;
Sets.SetView<Var> varUnion = Sets.union(this.vars(), a2.vars());
Set<Var> varIntersection = Sets.intersection(this.vars(), a2.vars());
Map<Var, Concept> entryMap = Sets.union(this.entrySet(), a2.entrySet()).stream().filter(e -> !varIntersection.contains(e.getKey())).collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));
varIntersection.forEach(var -> {
Concept concept = this.get(var);
Concept otherConcept = a2.get(var);
if (concept.equals(otherConcept))
entryMap.put(var, concept);
else {
if (concept.isSchemaConcept() && otherConcept.isSchemaConcept() && !ReasonerUtils.areDisjointTypes(concept.asSchemaConcept(), otherConcept.asSchemaConcept())) {
entryMap.put(var, Iterables.getOnlyElement(ReasonerUtils.topOrMeta(Sets.newHashSet(concept.asSchemaConcept(), otherConcept.asSchemaConcept()))));
}
}
});
if (!entryMap.keySet().equals(varUnion))
return new QueryAnswer();
return new QueryAnswer(entryMap, mergeExplanation ? this.mergeExplanation(a2) : this.getExplanation());
}
Aggregations