use of com.vaticle.typedb.core.concept.answer.ConceptMapGroup in project grakn by graknlabs.
the class TypeQLSteps method answer_groups_are.
@Then("answer groups are")
public void answer_groups_are(List<Map<String, String>> answerIdentifierTable) {
Set<AnswerIdentifierGroup> answerIdentifierGroups = answerIdentifierTable.stream().collect(Collectors.groupingBy(x -> x.get(AnswerIdentifierGroup.GROUP_COLUMN_NAME))).values().stream().map(AnswerIdentifierGroup::new).collect(Collectors.toSet());
assertEquals(String.format("Expected [%d] answer groups, but found [%d].", answerIdentifierGroups.size(), answerGroups.size()), answerIdentifierGroups.size(), answerGroups.size());
for (AnswerIdentifierGroup answerIdentifierGroup : answerIdentifierGroups) {
String[] identifier = answerIdentifierGroup.ownerIdentifier.split(":", 2);
UniquenessCheck checker;
switch(identifier[0]) {
case "label":
checker = new LabelUniquenessCheck(identifier[1]);
break;
case "key":
checker = new KeyUniquenessCheck(identifier[1]);
break;
case "value":
checker = new ValueUniquenessCheck(identifier[1]);
break;
default:
throw new IllegalStateException("Unexpected value: " + identifier[0]);
}
ConceptMapGroup answerGroup = answerGroups.stream().filter(ag -> checker.check(ag.owner())).findAny().orElse(null);
assertNotNull(String.format("The group identifier [%s] does not match any of the answer group owners.", answerIdentifierGroup.ownerIdentifier), answerGroup);
List<Map<String, String>> answersIdentifiers = answerIdentifierGroup.answersIdentifiers;
for (ConceptMap answer : answerGroup.conceptMaps()) {
List<Map<String, String>> matchingIdentifiers = new ArrayList<>();
for (Map<String, String> answerIdentifiers : answersIdentifiers) {
if (matchAnswerConcept(answerIdentifiers, answer)) {
matchingIdentifiers.add(answerIdentifiers);
}
}
assertEquals(String.format("An identifier entry (row) should match 1-to-1 to an answer, but there were [%d] matching identifier entries for answer with variables %s.", matchingIdentifiers.size(), answer.concepts().keySet().toString()), 1, matchingIdentifiers.size());
}
}
}
Aggregations