use of ai.grakn.concept.Concept in project grakn by graknlabs.
the class GeoInferenceTest method testTransitiveQuery_Closure_NoRoles_withSubstitution.
@Test
public void testTransitiveQuery_Closure_NoRoles_withSubstitution() {
GraknTx graph = geoKB.tx();
QueryBuilder iqb = geoKB.tx().graql().infer(true);
Concept masovia = getConcept(graph, "name", "Masovia");
String queryString = "match " + "($x, $y) isa is-located-in;" + "$y id '" + masovia.getId().getValue() + "'; get;";
List<Answer> answers = iqb.materialise(false).<GetQuery>parse(queryString).execute();
List<Answer> answers2 = iqb.materialise(true).<GetQuery>parse(queryString).execute();
answers.forEach(ans -> assertEquals(ans.get(var("y")).getId().getValue(), masovia.getId().getValue()));
assertEquals(answers.size(), 5);
answers2.forEach(ans -> assertEquals(ans.get(var("y")).getId().getValue(), masovia.getId().getValue()));
assertCollectionsEqual(answers, answers2);
}
use of ai.grakn.concept.Concept in project grakn by graknlabs.
the class RecursiveInferenceTest method testPathTree.
/**
*test 6.10 from Cao p. 82
*/
@Test
public void testPathTree() {
final int N = 3;
SampleKBContext kb = PathTreeKB.context(N, 3);
GraknTx tx = kb.tx();
QueryBuilder qb = tx.graql().infer(false);
QueryBuilder iqb = tx.graql().infer(true);
Concept a0 = getConcept(tx, "index", "a0");
String queryString = "match (path-from: $x, path-to: $y) isa path;" + "$x has index 'a0';" + "get $y;";
String explicitQuery = "match $y isa vertex; get;";
List<Answer> answers = iqb.materialise(false).<GetQuery>parse(queryString).execute();
List<Answer> explicitAnswers = qb.<GetQuery>parse(explicitQuery).execute();
List<Answer> answers2 = iqb.materialise(true).<GetQuery>parse(queryString).execute();
assertCollectionsEqual(answers, explicitAnswers);
assertCollectionsEqual(answers, answers2);
}
use of ai.grakn.concept.Concept in project grakn by graknlabs.
the class GenealogyTest method genderOfASpecificPerson.
@Test
public void genderOfASpecificPerson() {
Concept concept = Sets.newHashSet(genealogyKB.tx().graql().infer(false).<GetQuery>parse("match $x isa person; get;")).iterator().next().entrySet().iterator().next().getValue();
String queryString = "match $x id '" + concept.getId() + "' has gender $g; get;";
GetQuery query = iqb.parse(queryString);
List<Answer> answers = query.execute();
assertEquals(answers.size(), 1);
}
use of ai.grakn.concept.Concept in project grakn by graknlabs.
the class QueryOperationExecutor method insertAll.
private Answer insertAll(Answer results) {
concepts.putAll(results.map());
sortProperties().forEach(property -> property.executor().execute(this));
conceptBuilders.forEach(this::buildConcept);
ImmutableMap.Builder<Var, Concept> allConcepts = ImmutableMap.<Var, Concept>builder().putAll(concepts);
// Make sure to include all equivalent vars in the result
for (Var var : equivalentVars.getNodes()) {
allConcepts.put(var, concepts.get(equivalentVars.componentOf(var)));
}
Map<Var, Concept> namedConcepts = Maps.filterKeys(allConcepts.build(), Var::isUserDefinedName);
return new QueryAnswer(namedConcepts);
}
use of ai.grakn.concept.Concept in project grakn by graknlabs.
the class QueryOperationExecutor method buildConcept.
private Concept buildConcept(Var var, ConceptBuilder builder) {
Concept concept = builder.build();
assert concept != null : String.format("build() should never return null. var: %s", var);
concepts.put(var, concept);
return concept;
}
Aggregations