Search in sources :

Example 51 with Concept

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);
}
Also used : Concept(ai.grakn.concept.Concept) GraknTx(ai.grakn.GraknTx) Answer(ai.grakn.graql.admin.Answer) QueryBuilder(ai.grakn.graql.QueryBuilder) Test(org.junit.Test)

Example 52 with Concept

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);
}
Also used : Concept(ai.grakn.concept.Concept) GraknTx(ai.grakn.GraknTx) Answer(ai.grakn.graql.admin.Answer) SampleKBContext(ai.grakn.test.rule.SampleKBContext) QueryBuilder(ai.grakn.graql.QueryBuilder) Test(org.junit.Test)

Example 53 with Concept

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);
}
Also used : Concept(ai.grakn.concept.Concept) Answer(ai.grakn.graql.admin.Answer) GetQuery(ai.grakn.graql.GetQuery) Test(org.junit.Test)

Example 54 with Concept

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);
}
Also used : Concept(ai.grakn.concept.Concept) QueryAnswer(ai.grakn.graql.internal.query.QueryAnswer) Var(ai.grakn.graql.Var) ImmutableMap(com.google.common.collect.ImmutableMap)

Example 55 with Concept

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;
}
Also used : Concept(ai.grakn.concept.Concept)

Aggregations

Concept (ai.grakn.concept.Concept)91 Test (org.junit.Test)56 ConceptId (ai.grakn.concept.ConceptId)26 GraknTx (ai.grakn.GraknTx)25 Answer (ai.grakn.graql.admin.Answer)25 SchemaConcept (ai.grakn.concept.SchemaConcept)19 Label (ai.grakn.concept.Label)18 GrpcConcept (ai.grakn.rpc.generated.GrpcConcept)18 QueryBuilder (ai.grakn.graql.QueryBuilder)17 Var (ai.grakn.graql.Var)15 Set (java.util.Set)15 Role (ai.grakn.concept.Role)14 QueryAnswer (ai.grakn.graql.internal.query.QueryAnswer)14 HashSet (java.util.HashSet)13 List (java.util.List)12 AttributeType (ai.grakn.concept.AttributeType)11 EntityType (ai.grakn.concept.EntityType)11 Schema (ai.grakn.util.Schema)10 Collectors (java.util.stream.Collectors)10 Stream (java.util.stream.Stream)10