Search in sources :

Example 71 with GetQuery

use of ai.grakn.graql.GetQuery in project grakn by graknlabs.

the class GenealogyTest method matchAllRelationsWithDocumentPlayingARole.

/*
    test for first rule file:
    match $x isa person has first-name $name;
    match (child: $x, parent: $y) isa parentship;
    match (spouse: $x, spouse: $y) isa marriage;
    */
@Test
public void matchAllRelationsWithDocumentPlayingARole() {
    String queryString = "match $x isa document; ($x, $y); get;";
    GetQuery query = iqb.parse(queryString);
    List<Answer> answers = query.execute();
    assertTrue(answers.isEmpty());
}
Also used : Answer(ai.grakn.graql.admin.Answer) GetQuery(ai.grakn.graql.GetQuery) Test(org.junit.Test)

Example 72 with GetQuery

use of ai.grakn.graql.GetQuery in project grakn by graknlabs.

the class GenealogyTest method testParentship.

@Test
public void testParentship() {
    String queryString = "match (child: $c, parent: $p) isa parentship; get;";
    GetQuery query = iqb.parse(queryString);
    List<Answer> answers = query.execute();
    assertEquals(answers.size(), 76);
    assertTrue(!hasDuplicates(answers));
    answers.forEach(answer -> assertEquals(answer.size(), 2));
}
Also used : Answer(ai.grakn.graql.admin.Answer) GetQuery(ai.grakn.graql.GetQuery) Test(org.junit.Test)

Example 73 with GetQuery

use of ai.grakn.graql.GetQuery in project grakn by graknlabs.

the class ExplanationTest method testExplainingConjunctions.

@Test
public void testExplainingConjunctions() {
    GraknTx expGraph = explanationKB.tx();
    QueryBuilder eiqb = expGraph.graql().infer(true);
    String queryString = "match " + "(role1: $x, role2: $w) isa inferredRelation;" + "$x has name $xName;" + "$w has name $wName; get;";
    GetQuery query = eiqb.parse(queryString);
    List<Answer> answers = query.execute();
    testExplanation(answers);
}
Also used : GraknTx(ai.grakn.GraknTx) Answer(ai.grakn.graql.admin.Answer) QueryAnswer(ai.grakn.graql.internal.query.QueryAnswer) GetQuery(ai.grakn.graql.GetQuery) QueryBuilder(ai.grakn.graql.QueryBuilder) Test(org.junit.Test)

Example 74 with GetQuery

use of ai.grakn.graql.GetQuery in project grakn by graknlabs.

the class ExplanationTest method testExplainingNonRuleResolvableQuery.

@Test
public void testExplainingNonRuleResolvableQuery() {
    String queryString = "match $x isa city, has name $n; get;";
    GetQuery query = iqb.parse(queryString);
    List<Answer> answers = query.execute();
    answers.forEach(ans -> assertEquals(ans.getExplanation().isEmpty(), true));
}
Also used : Answer(ai.grakn.graql.admin.Answer) QueryAnswer(ai.grakn.graql.internal.query.QueryAnswer) GetQuery(ai.grakn.graql.GetQuery) Test(org.junit.Test)

Example 75 with GetQuery

use of ai.grakn.graql.GetQuery in project grakn by graknlabs.

the class ExplanationTest method testExplainingQueryContainingContradiction2.

@Test
public void testExplainingQueryContainingContradiction2() {
    GraknTx expGraph = explanationKB.tx();
    QueryBuilder eiqb = expGraph.graql().infer(true);
    Concept a1 = getConcept(expGraph, "name", "a1");
    Concept a2 = getConcept(expGraph, "name", "a2");
    String queryString = "match " + "(role1: $x, role2: $y) isa relation1;" + "$x id '" + a1.getId() + "';" + "$y id '" + a2.getId() + "'; get;";
    GetQuery query = eiqb.parse(queryString);
    List<Answer> answers = query.execute();
    assertEquals(answers.size(), 0);
}
Also used : Concept(ai.grakn.concept.Concept) GraknTx(ai.grakn.GraknTx) Answer(ai.grakn.graql.admin.Answer) QueryAnswer(ai.grakn.graql.internal.query.QueryAnswer) GetQuery(ai.grakn.graql.GetQuery) QueryBuilder(ai.grakn.graql.QueryBuilder) Test(org.junit.Test)

Aggregations

GetQuery (ai.grakn.graql.GetQuery)163 Test (org.junit.Test)161 Answer (ai.grakn.graql.admin.Answer)65 QueryBuilder (ai.grakn.graql.QueryBuilder)61 GraknTx (ai.grakn.GraknTx)51 EmbeddedGraknTx (ai.grakn.kb.internal.EmbeddedGraknTx)23 QueryAnswer (ai.grakn.graql.internal.query.QueryAnswer)14 SampleKBContext (ai.grakn.test.rule.SampleKBContext)12 Concept (ai.grakn.concept.Concept)9 List (java.util.List)8 Assert.assertEquals (org.junit.Assert.assertEquals)7 Assert.assertTrue (org.junit.Assert.assertTrue)7 Set (java.util.Set)6 Label (ai.grakn.concept.Label)5 RelationshipType (ai.grakn.concept.RelationshipType)5 VarPatternAdmin (ai.grakn.graql.admin.VarPatternAdmin)5 ReasonerAtomicQuery (ai.grakn.graql.internal.reasoner.query.ReasonerAtomicQuery)5 Sets (com.google.common.collect.Sets)5 Collectors (java.util.stream.Collectors)5 Collectors.toSet (java.util.stream.Collectors.toSet)5