use of ai.grakn.concept.Concept in project grakn by graknlabs.
the class ReasonerQueryImpl method getSubstitution.
/**
* @return substitution obtained from all id predicates (including internal) in the query
*/
public Answer getSubstitution() {
if (substitution == null) {
Set<Var> varNames = getVarNames();
Set<IdPredicate> predicates = getAtoms(IsaAtomBase.class).map(IsaAtomBase::getTypePredicate).filter(Objects::nonNull).filter(p -> varNames.contains(p.getVarName())).collect(Collectors.toSet());
getAtoms(IdPredicate.class).forEach(predicates::add);
HashMap<Var, Concept> answerMap = new HashMap<>();
predicates.forEach(p -> {
Concept concept = tx().getConcept(p.getPredicate());
if (concept == null)
throw GraqlQueryException.idNotFound(p.getPredicate());
answerMap.put(p.getVarName(), concept);
});
substitution = new QueryAnswer(answerMap);
}
return substitution;
}
use of ai.grakn.concept.Concept in project grakn by graknlabs.
the class QueryAnswerStream method joinWithInverse.
/**
* lazy stream join with fast lookup from inverse answer map
* @param stream left stream operand
* @param stream2 right stream operand
* @param stream2InverseMap inverse map of right operand from cache
* @param joinVars intersection on variables of two streams
* @return joined stream
*/
static Stream<Answer> joinWithInverse(Stream<Answer> stream, Stream<Answer> stream2, Map<Pair<Var, Concept>, Set<Answer>> stream2InverseMap, ImmutableSet<Var> joinVars) {
if (joinVars.isEmpty()) {
LazyAnswerIterator l2 = new LazyAnswerIterator(stream2);
return stream.flatMap(a1 -> l2.stream().map(a -> a.merge(a1)));
}
return stream.flatMap(a1 -> {
Iterator<Var> vit = joinVars.iterator();
Set<Answer> matchAnswers = findMatchingAnswers(a1, stream2InverseMap, vit.next());
while (vit.hasNext()) {
matchAnswers = Sets.intersection(matchAnswers, findMatchingAnswers(a1, stream2InverseMap, vit.next()));
}
return matchAnswers.stream().map(a -> a.merge(a1));
});
}
use of ai.grakn.concept.Concept in project grakn by graknlabs.
the class ConceptTest method whenAConceptIsNotDeleted_CallingIsDeletedReturnsFalse.
@Test
public void whenAConceptIsNotDeleted_CallingIsDeletedReturnsFalse() {
Concept stillAlive = tx.putEntityType("still-alive");
assertFalse(stillAlive.isDeleted());
}
use of ai.grakn.concept.Concept in project grakn by graknlabs.
the class ConceptTest method whenCastingToCorrectType_ReturnCorrectType.
@Test
public void whenCastingToCorrectType_ReturnCorrectType() {
Concept concept = tx.putEntityType("Test");
assertTrue("Concept is not of type [" + EntityType.class.getName() + "]", concept.isEntityType());
EntityType type = concept.asEntityType();
assertEquals(type, concept);
}
use of ai.grakn.concept.Concept in project grakn by graknlabs.
the class ConceptTest method whenComparingConcepts_EnsureEqualityIsBasedOnConceptID.
@Test
public void whenComparingConcepts_EnsureEqualityIsBasedOnConceptID() {
Concept v1_1 = tx.putEntityType("Value_1");
Concept v1_2 = tx.getEntityType("Value_1");
Concept v1_3 = tx.putEntityType("Value_1");
Concept v2_1 = tx.putEntityType("Value_2");
assertEquals(v1_1, v1_2);
assertNotEquals(v1_1, v2_1);
assertNotEquals(v1_1.getId(), v2_1.getId());
HashSet<Concept> concepts = new HashSet<>();
concepts.add(v1_1);
concepts.add(v1_2);
concepts.add(v1_3);
assertEquals(1, concepts.size());
concepts.add(v2_1);
assertEquals(2, concepts.size());
}
Aggregations