use of com.vaticle.typedb.core.reasoner.resolution.answer.AnswerState.Partial in project grakn by graknlabs.
the class AnswerStateTest method test_root_partially_mapped_to_downstream_and_back.
@Test
public void test_root_partially_mapped_to_downstream_and_back() {
Map<Identifier.Variable.Retrievable, Identifier.Variable.Retrievable> mapping = new HashMap<>();
mapping.put(Identifier.Variable.name("a"), Identifier.Variable.name("x"));
mapping.put(Identifier.Variable.name("b"), Identifier.Variable.name("y"));
Map<Identifier.Variable.Retrievable, Concept> concepts = new HashMap<>();
concepts.put(Identifier.Variable.name("a"), new MockConcept(0));
Set<Identifier.Variable.Retrievable> filter = set(Identifier.Variable.name("a"), Identifier.Variable.name("b"));
Concludable.Match<?> mapped = InitialImpl.create(filter, new ConceptMap(), null, false).toDownstream().with(new ConceptMap(concepts)).toDownstream(Mapping.of(mapping), null);
Map<Identifier.Variable.Retrievable, Concept> expectedMapped = new HashMap<>();
expectedMapped.put(Identifier.Variable.name("x"), new MockConcept(0));
assertEquals(new ConceptMap(expectedMapped), mapped.conceptMap());
Map<Identifier.Variable.Retrievable, Concept> downstreamConcepts = new HashMap<>();
downstreamConcepts.put(Identifier.Variable.name("x"), new MockConcept(0));
downstreamConcepts.put(Identifier.Variable.name("y"), new MockConcept(1));
Partial.Compound<?, ?> partial = mapped.toUpstreamLookup(new ConceptMap(downstreamConcepts), false);
Map<Identifier.Variable.Retrievable, Concept> expectedWithInitial = new HashMap<>();
expectedWithInitial.put(Identifier.Variable.name("a"), new MockConcept(0));
expectedWithInitial.put(Identifier.Variable.name("b"), new MockConcept(1));
assertEquals(new ConceptMap(expectedWithInitial), partial.conceptMap());
}
use of com.vaticle.typedb.core.reasoner.resolution.answer.AnswerState.Partial in project grakn by graknlabs.
the class ConcludableResolver method nextAnswer.
private void nextAnswer(Request fromUpstream, CachingRequestState<?, ConceptMap> requestState, int iteration) {
Optional<Partial.Compound<?, ?>> upstreamAnswer = requestState.nextAnswer().map(Partial::asCompound);
if (upstreamAnswer.isPresent()) {
answerFound(upstreamAnswer.get(), fromUpstream, iteration);
} else {
Exploration exploration;
if (requestState.isExploration() && !requestState.answerCache().isComplete()) {
if ((exploration = requestState.asExploration()).downstreamManager().hasDownstream()) {
requestFromDownstream(exploration.downstreamManager().nextDownstream(), fromUpstream, iteration);
} else {
// TODO: The cache should not be set as complete during recursion
requestState.answerCache().setComplete();
failToUpstream(fromUpstream, iteration);
}
} else {
failToUpstream(fromUpstream, iteration);
}
}
}
use of com.vaticle.typedb.core.reasoner.resolution.answer.AnswerState.Partial in project grakn by graknlabs.
the class AnswerStateTest method test_root_with_unmapped_elements.
@Test
public void test_root_with_unmapped_elements() {
Map<Identifier.Variable.Retrievable, Identifier.Variable.Retrievable> mapping = new HashMap<>();
mapping.put(Identifier.Variable.name("a"), Identifier.Variable.name("x"));
mapping.put(Identifier.Variable.name("b"), Identifier.Variable.name("y"));
Map<Identifier.Variable.Retrievable, Concept> concepts = new HashMap<>();
concepts.put(Identifier.Variable.name("a"), new MockConcept(0));
concepts.put(Identifier.Variable.name("c"), new MockConcept(2));
Set<Identifier.Variable.Retrievable> filter = set(Identifier.Variable.name("a"), Identifier.Variable.name("b"));
Concludable.Match<?> mapped = InitialImpl.create(filter, new ConceptMap(), null, false).toDownstream().with(new ConceptMap(concepts)).toDownstream(Mapping.of(mapping), null);
Map<Identifier.Variable.Retrievable, Concept> expectedMapped = new HashMap<>();
expectedMapped.put(Identifier.Variable.name("x"), new MockConcept(0));
assertEquals(new ConceptMap(expectedMapped), mapped.conceptMap());
Map<Identifier.Variable.Retrievable, Concept> downstreamConcepts = new HashMap<>();
downstreamConcepts.put(Identifier.Variable.name("x"), new MockConcept(0));
downstreamConcepts.put(Identifier.Variable.name("y"), new MockConcept(1));
Partial.Compound<?, ?> partial = mapped.toUpstreamLookup(new ConceptMap(downstreamConcepts), false);
Map<Identifier.Variable.Retrievable, Concept> expectedWithInitial = new HashMap<>();
expectedWithInitial.put(Identifier.Variable.name("a"), new MockConcept(0));
expectedWithInitial.put(Identifier.Variable.name("b"), new MockConcept(1));
expectedWithInitial.put(Identifier.Variable.name("c"), new MockConcept(2));
assertEquals(new ConceptMap(expectedWithInitial), partial.conceptMap());
}
use of com.vaticle.typedb.core.reasoner.resolution.answer.AnswerState.Partial in project grakn by graknlabs.
the class AnswerStateTest method test_root_empty_mapped_to_downstream_and_back.
@Test
public void test_root_empty_mapped_to_downstream_and_back() {
Map<Identifier.Variable.Retrievable, Identifier.Variable.Retrievable> mapping = new HashMap<>();
mapping.put(Identifier.Variable.name("a"), Identifier.Variable.name("x"));
mapping.put(Identifier.Variable.name("b"), Identifier.Variable.name("y"));
Set<Identifier.Variable.Retrievable> filter = set(Identifier.Variable.name("a"), Identifier.Variable.name("b"));
Concludable.Match<?> mapped = InitialImpl.create(filter, new ConceptMap(), null, false).toDownstream().toDownstream(Mapping.of(mapping), null);
assertTrue(mapped.conceptMap().concepts().isEmpty());
Map<Identifier.Variable.Retrievable, Concept> concepts = new HashMap<>();
concepts.put(Identifier.Variable.name("x"), new MockConcept(0));
concepts.put(Identifier.Variable.name("y"), new MockConcept(1));
Partial.Compound<?, ?> partial = mapped.toUpstreamLookup(new ConceptMap(concepts), false);
Map<Identifier.Variable.Retrievable, Concept> expected = new HashMap<>();
expected.put(Identifier.Variable.name("a"), new MockConcept(0));
expected.put(Identifier.Variable.name("b"), new MockConcept(1));
assertEquals(new ConceptMap(expected), partial.conceptMap());
}
Aggregations