Search in sources :

Example 6 with GraknTx

use of ai.grakn.GraknTx in project grakn by graknlabs.

the class ReasonerTest method testReasoningWithQueryContainingSub.

@Test
public void testReasoningWithQueryContainingSub() {
    GraknTx graph = nonMaterialisedGeoKB.tx();
    String queryString = "match " + "$x isa $type;$type sub geoObject;" + "(geo-entity: $x, entity-location: $y) isa is-located-in; $y isa country;" + "$y has name 'Poland';" + "$x has name $name; get;";
    String queryString2 = "match " + "$x isa $type;{$type label 'region';} or {$type label 'city';} or {$type label 'geoObject';};" + "(geo-entity: $x, entity-location: $y) isa is-located-in;$y isa country;" + "$y has name 'Poland';" + "$x has name $name; get;";
    QueryBuilder iqb = graph.graql().infer(true);
    GetQuery query = iqb.parse(queryString);
    GetQuery query2 = iqb.parse(queryString2);
    assertQueriesEqual(query, query2);
}
Also used : GraknTx(ai.grakn.GraknTx) EmbeddedGraknTx(ai.grakn.kb.internal.EmbeddedGraknTx) GetQuery(ai.grakn.graql.GetQuery) QueryBuilder(ai.grakn.graql.QueryBuilder) Test(org.junit.Test)

Example 7 with GraknTx

use of ai.grakn.GraknTx in project grakn by graknlabs.

the class ReasonerTest method testReasoningWithQueryContainingTautology.

@Test
public void testReasoningWithQueryContainingTautology() {
    GraknTx graph = nonMaterialisedGeoKB.tx();
    String queryString = "match ($x, $y) isa is-located-in;city sub geoObject; get;";
    String queryString2 = "match ($x, $y) isa is-located-in; get;";
    QueryBuilder iqb = graph.graql().infer(true);
    GetQuery query = iqb.parse(queryString);
    GetQuery query2 = iqb.parse(queryString2);
    assertQueriesEqual(query, query2);
}
Also used : GraknTx(ai.grakn.GraknTx) EmbeddedGraknTx(ai.grakn.kb.internal.EmbeddedGraknTx) GetQuery(ai.grakn.graql.GetQuery) QueryBuilder(ai.grakn.graql.QueryBuilder) Test(org.junit.Test)

Example 8 with GraknTx

use of ai.grakn.GraknTx in project grakn by graknlabs.

the class ReasonerTest method testReasoningWithQueryContainingTypeHas.

@Test
public void testReasoningWithQueryContainingTypeHas() {
    GraknTx graph = nonMaterialisedGeoKB.tx();
    String queryString = "match $x isa $type;$type has name;$y isa country;$y has name 'Poland';" + "($x, $y) isa is-located-in;get $x, $y;";
    String queryString2 = "match $y isa country;$y has name 'Poland';" + "($x, $y) isa is-located-in; get;";
    QueryBuilder iqb = graph.graql().infer(true);
    GetQuery query = iqb.parse(queryString);
    GetQuery query2 = iqb.parse(queryString2);
    assertQueriesEqual(query, query2);
}
Also used : GraknTx(ai.grakn.GraknTx) EmbeddedGraknTx(ai.grakn.kb.internal.EmbeddedGraknTx) GetQuery(ai.grakn.graql.GetQuery) QueryBuilder(ai.grakn.graql.QueryBuilder) Test(org.junit.Test)

Example 9 with GraknTx

use of ai.grakn.GraknTx in project grakn by graknlabs.

the class ReasonerTest method testReasoningWithQueryContainingContradiction.

@Test
public void testReasoningWithQueryContainingContradiction() {
    GraknTx graph = nonMaterialisedGeoKB.tx();
    // geoObject sub city always returns an empty set
    String queryString = "match ($x, $y) isa is-located-in;geoObject sub city; get;";
    QueryBuilder iqb = graph.graql().infer(true);
    List<Answer> answers = iqb.<GetQuery>parse(queryString).execute();
    assertThat(answers, empty());
}
Also used : GraknTx(ai.grakn.GraknTx) EmbeddedGraknTx(ai.grakn.kb.internal.EmbeddedGraknTx) Answer(ai.grakn.graql.admin.Answer) QueryBuilder(ai.grakn.graql.QueryBuilder) Test(org.junit.Test)

Example 10 with GraknTx

use of ai.grakn.GraknTx in project grakn by graknlabs.

the class OntologicalQueryTest method allInstancesOfTypesThatCanHaveAGivenResourceType.

/**
 * HasAtom *
 */
@Test
public void allInstancesOfTypesThatCanHaveAGivenResourceType() {
    GraknTx tx = testContext.tx();
    QueryBuilder qb = tx.graql().infer(true);
    String queryString = "match $x isa $type; $type has name; get;";
    List<Answer> answers = qb.<GetQuery>parse(queryString).execute();
    // 1 x noRoleEntity + 3 x 3 (hierarchy) anotherTwoRoleEntities
    assertEquals(answers.size(), 10);
    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)

Aggregations

GraknTx (ai.grakn.GraknTx)243 Test (org.junit.Test)189 EntityType (ai.grakn.concept.EntityType)54 GetQuery (ai.grakn.graql.GetQuery)52 Entity (ai.grakn.concept.Entity)51 QueryBuilder (ai.grakn.graql.QueryBuilder)49 Role (ai.grakn.concept.Role)48 RelationshipType (ai.grakn.concept.RelationshipType)46 Answer (ai.grakn.graql.admin.Answer)44 Set (java.util.Set)44 EmbeddedGraknTx (ai.grakn.kb.internal.EmbeddedGraknTx)33 Label (ai.grakn.concept.Label)28 Attribute (ai.grakn.concept.Attribute)27 Concept (ai.grakn.concept.Concept)27 HashSet (java.util.HashSet)26 GraknSession (ai.grakn.GraknSession)22 AttributeType (ai.grakn.concept.AttributeType)22 ConceptId (ai.grakn.concept.ConceptId)22 List (java.util.List)19 GraknTxType (ai.grakn.GraknTxType)17