use of ai.grakn.graql.admin.Answer in project grakn by graknlabs.
the class OntologicalQueryTest method allInstancesOfMetaEntity.
/**
* meta concepts *
*/
@Test
public void allInstancesOfMetaEntity() {
GraknTx tx = testContext.tx();
QueryBuilder qb = tx.graql().infer(true);
long noOfEntities = tx.admin().getMetaEntityType().instances().count();
String queryString = "match $x isa entity;get;";
List<Answer> answers = qb.<GetQuery>parse(queryString).execute();
assertEquals(answers.size(), noOfEntities);
}
use of ai.grakn.graql.admin.Answer in project grakn by graknlabs.
the class ReasonerTest method testReasoningWithQueryContainingLimit.
@Test
public void testReasoningWithQueryContainingLimit() {
GraknTx graph = nonMaterialisedGeoKB.tx();
String limitQueryString = "match (geo-entity: $x, entity-location: $y)isa is-located-in;limit 5; get;";
String queryString = "match (geo-entity: $x, entity-location: $y)isa is-located-in; get;";
QueryBuilder iqb = graph.graql().infer(true);
GetQuery limitQuery = iqb.parse(limitQueryString);
GetQuery query = iqb.parse(queryString);
List<Answer> limitedAnswers = limitQuery.execute();
List<Answer> answers = query.execute();
assertEquals(limitedAnswers.size(), 5);
assertTrue(answers.size() > limitedAnswers.size());
assertTrue(answers.containsAll(limitedAnswers));
}
use of ai.grakn.graql.admin.Answer in project grakn by graknlabs.
the class MatchBenchmark method match.
@Benchmark
public void match() {
Match match = graph.graql().match(var("x").isa(BENCHMARK_ENTITY_TYPE).has(BENCHMARK_ATTRIBUTE_TYPE, "0"));
GetQuery answers = match.get();
Optional<Answer> first = answers.stream().findFirst();
first.get();
}
use of ai.grakn.graql.admin.Answer in project grakn by graknlabs.
the class RelationshipAtom method materialise.
@Override
public Stream<Answer> materialise() {
RelationshipType relationType = getSchemaConcept().asRelationshipType();
Multimap<Role, Var> roleVarMap = getRoleVarMap();
Answer substitution = getParentQuery().getSubstitution();
Relationship relationship = RelationshipTypeImpl.from(relationType).addRelationshipInferred();
roleVarMap.asMap().forEach((key, value) -> value.forEach(var -> relationship.addRolePlayer(key, substitution.get(var).asThing())));
Answer relationSub = getRoleSubstitution().merge(getVarName().isUserDefinedName() ? new QueryAnswer(ImmutableMap.of(getVarName(), relationship)) : new QueryAnswer());
return Stream.of(substitution.merge(relationSub));
}
use of ai.grakn.graql.admin.Answer in project grakn by graknlabs.
the class InferenceRule method subGoal.
/**
* @param parentAtom atom to which this rule is applied
* @param ruleUnifier unifier with parent state
* @param parent parent state
* @param visitedSubGoals set of visited sub goals
* @param cache query cache
* @return resolution subGoal formed from this rule
*/
public ResolutionState subGoal(Atom parentAtom, Unifier ruleUnifier, QueryStateBase parent, Set<ReasonerAtomicQuery> visitedSubGoals, QueryCache<ReasonerAtomicQuery> cache) {
Unifier ruleUnifierInverse = ruleUnifier.inverse();
// delta' = theta . thetaP . delta
Answer partialSubPrime = parentAtom.getParentQuery().getSubstitution().unify(ruleUnifierInverse);
return new RuleState(this.propagateConstraints(parentAtom, ruleUnifierInverse), partialSubPrime, ruleUnifier, parent, visitedSubGoals, cache);
}
Aggregations