Search in sources :

Example 11 with Answer

use of ai.grakn.graql.admin.Answer in project grakn by graknlabs.

the class OntologicalQueryTest method allInstancesOfMetaRelation.

@Test
public void allInstancesOfMetaRelation() {
    GraknTx tx = testContext.tx();
    QueryBuilder qb = tx.graql().infer(true);
    String queryString = "match $x isa relationship;get;";
    List<Answer> answers = qb.<GetQuery>parse(queryString).execute();
    assertEquals(answers.size(), 13);
}
Also used : GraknTx(ai.grakn.GraknTx) Answer(ai.grakn.graql.admin.Answer) QueryBuilder(ai.grakn.graql.QueryBuilder) Test(org.junit.Test)

Example 12 with Answer

use of ai.grakn.graql.admin.Answer in project grakn by graknlabs.

the class OntologicalQueryTest method allInstancesOfTypesThatPlayGivenRole.

/**
 * PlaysAtom *
 */
@Test
public void allInstancesOfTypesThatPlayGivenRole() {
    GraknTx tx = testContext.tx();
    QueryBuilder qb = tx.graql().infer(true);
    String queryString = "match $x isa $type; $type plays role1; get;";
    List<Answer> answers = qb.<GetQuery>parse(queryString).execute();
    List<Answer> reifiableRelations = qb.<GetQuery>parse("match $x isa reifiable-relation;get;").execute();
    assertEquals(answers.size(), tx.getEntityType("noRoleEntity").subs().flatMap(EntityType::instances).count() + reifiableRelations.size());
    assertCollectionsEqual(answers, qb.infer(false).<GetQuery>parse(queryString).execute());
}
Also used : GraknTx(ai.grakn.GraknTx) Answer(ai.grakn.graql.admin.Answer) GetQuery(ai.grakn.graql.GetQuery) QueryBuilder(ai.grakn.graql.QueryBuilder) Test(org.junit.Test)

Example 13 with Answer

use of ai.grakn.graql.admin.Answer in project grakn by graknlabs.

the class OntologicalQueryTest method allTypesOfRolePlayerInASpecificRelationWithUnspecifiedRoles.

@Test
public void allTypesOfRolePlayerInASpecificRelationWithUnspecifiedRoles() {
    GraknTx tx = testContext.tx();
    QueryBuilder qb = tx.graql().infer(true);
    String queryString = "match ($x, $y) isa reifiable-relation;$x isa $type; get;";
    // 3 instances * {anotherTwoRoleEntity, anotherSingleRoleEntity, noRoleEntity, entity, Thing} * arity
    List<Answer> answers = qb.<GetQuery>parse(queryString).execute();
    assertEquals(answers.size(), qb.<GetQuery>parse("match $x isa reifiable-relation; get;").stream().count() * 5 * 2);
}
Also used : GraknTx(ai.grakn.GraknTx) Answer(ai.grakn.graql.admin.Answer) QueryBuilder(ai.grakn.graql.QueryBuilder) Test(org.junit.Test)

Example 14 with Answer

use of ai.grakn.graql.admin.Answer in project grakn by graknlabs.

the class OntologicalQueryTest method allInstancesOfRelationsThatRelateGivenRole.

/**
 * RelatesAtom *
 */
@Test
public void allInstancesOfRelationsThatRelateGivenRole() {
    GraknTx tx = testContext.tx();
    QueryBuilder qb = tx.graql().infer(true);
    String queryString = "match $x isa $type; $type relates role1; get;";
    List<Answer> answers = qb.<GetQuery>parse(queryString).execute();
    assertCollectionsEqual(answers, qb.infer(false).<GetQuery>parse(queryString).execute());
    List<Answer> relations = qb.<GetQuery>parse("match $x isa relationship;get;").execute();
    // plus extra 3 cause there are 3 binary relations which are not extra counted as reifiable-relations
    assertEquals(answers.size(), relations.stream().filter(ans -> !ans.get("x").asRelationship().type().isImplicit()).count() + 3);
}
Also used : QueryBuilder(ai.grakn.graql.QueryBuilder) GraqlTestUtil.assertCollectionsEqual(ai.grakn.util.GraqlTestUtil.assertCollectionsEqual) Test(org.junit.Test) Answer(ai.grakn.graql.admin.Answer) Collectors(java.util.stream.Collectors) GetQuery(ai.grakn.graql.GetQuery) Sets(com.google.common.collect.Sets) EntityType(ai.grakn.concept.EntityType) List(java.util.List) Rule(org.junit.Rule) Label(ai.grakn.concept.Label) Ignore(org.junit.Ignore) RelationshipType(ai.grakn.concept.RelationshipType) GraknTx(ai.grakn.GraknTx) SampleKBContext(ai.grakn.test.rule.SampleKBContext) ExpectedException(org.junit.rules.ExpectedException) Assert.assertEquals(org.junit.Assert.assertEquals) GraknTx(ai.grakn.GraknTx) Answer(ai.grakn.graql.admin.Answer) GetQuery(ai.grakn.graql.GetQuery) QueryBuilder(ai.grakn.graql.QueryBuilder) Test(org.junit.Test)

Example 15 with Answer

use of ai.grakn.graql.admin.Answer in project grakn by graknlabs.

the class OntologicalQueryTest method allInstancesAndTheirType.

// TODO need to correctly return THING and RELATIONSHIP mapping for %type
@Ignore
@Test
public void allInstancesAndTheirType() {
    GraknTx tx = testContext.tx();
    QueryBuilder qb = tx.graql().infer(true);
    String queryString = "match $x isa $type; get;";
    List<Answer> answers = qb.<GetQuery>parse(queryString).execute();
    assertCollectionsEqual(answers, qb.infer(false).<GetQuery>parse(queryString).execute());
}
Also used : GraknTx(ai.grakn.GraknTx) Answer(ai.grakn.graql.admin.Answer) GetQuery(ai.grakn.graql.GetQuery) QueryBuilder(ai.grakn.graql.QueryBuilder) Ignore(org.junit.Ignore) Test(org.junit.Test)

Aggregations

Answer (ai.grakn.graql.admin.Answer)193 Test (org.junit.Test)164 QueryBuilder (ai.grakn.graql.QueryBuilder)104 GetQuery (ai.grakn.graql.GetQuery)69 GraknTx (ai.grakn.GraknTx)47 QueryAnswer (ai.grakn.graql.internal.query.QueryAnswer)37 Concept (ai.grakn.concept.Concept)32 Var (ai.grakn.graql.Var)21 Set (java.util.Set)21 Unifier (ai.grakn.graql.admin.Unifier)19 MultiUnifier (ai.grakn.graql.admin.MultiUnifier)18 Collectors (java.util.stream.Collectors)18 ReasonerAtomicQuery (ai.grakn.graql.internal.reasoner.query.ReasonerAtomicQuery)17 Sets (com.google.common.collect.Sets)16 List (java.util.List)16 EmbeddedGraknTx (ai.grakn.kb.internal.EmbeddedGraknTx)15 Stream (java.util.stream.Stream)15 VarPatternAdmin (ai.grakn.graql.admin.VarPatternAdmin)14 SampleKBContext (ai.grakn.test.rule.SampleKBContext)14 Pair (ai.grakn.graql.internal.reasoner.utils.Pair)12