Search in sources :

Example 51 with GetQuery

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

the class QueryParserTest method whenParsingContainsPredicateWithAVariable_ResultMatchesJavaGraql.

@Test
public void whenParsingContainsPredicateWithAVariable_ResultMatchesJavaGraql() {
    GetQuery expected = match(var("x").val(contains(var("y")))).get();
    GetQuery parsed = parse("match $x val contains $y; get;");
    assertEquals(expected, parsed);
}
Also used : GetQuery(ai.grakn.graql.GetQuery) Test(org.junit.Test)

Example 52 with GetQuery

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

the class QueryParserTest method whenParsingAQueryAndDefiningAllVars_AllVarsExceptLabelsAreDefined.

@Test
public void whenParsingAQueryAndDefiningAllVars_AllVarsExceptLabelsAreDefined() {
    QueryParser parser = Graql.parser();
    parser.defineAllVars(true);
    GetQuery query = parser.parseQuery("match ($x, $y) isa foo; get;");
    System.out.println(query);
    Conjunction<PatternAdmin> conjunction = query.match().admin().getPattern();
    Set<PatternAdmin> patterns = conjunction.getPatterns();
    VarPatternAdmin pattern = Iterables.getOnlyElement(patterns).asVarPattern();
    assertTrue(pattern.var().isUserDefinedName());
    IsaProperty property = pattern.getProperty(IsaProperty.class).get();
    assertFalse(property.type().var().isUserDefinedName());
}
Also used : QueryParser(ai.grakn.graql.QueryParser) VarPatternAdmin(ai.grakn.graql.admin.VarPatternAdmin) GetQuery(ai.grakn.graql.GetQuery) PatternAdmin(ai.grakn.graql.admin.PatternAdmin) VarPatternAdmin(ai.grakn.graql.admin.VarPatternAdmin) IsaProperty(ai.grakn.graql.internal.pattern.property.IsaProperty) Test(org.junit.Test)

Example 53 with GetQuery

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

the class QueryParserTest method whenParsingDate_HandleSmallYears.

@Test
public void whenParsingDate_HandleSmallYears() {
    GetQuery expected = match(var("x").has("release-date", LocalDate.of(867, 1, 1).atStartOfDay())).get();
    GetQuery parsed = parse("match $x has release-date 0867-01-01; get;");
    assertEquals(expected, parsed);
}
Also used : GetQuery(ai.grakn.graql.GetQuery) Test(org.junit.Test)

Example 54 with GetQuery

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

the class QueryParserTest method whenParsingAsInMatch_ResultIsSameAsSub.

@Test
public void whenParsingAsInMatch_ResultIsSameAsSub() {
    GetQuery expected = match(label("fatherhood").sub("parenthood").relates(var("x"), label("parent")).relates(label("son"), var("y"))).get();
    GetQuery parsed = parse("match " + "fatherhood sub parenthood, relates $x as parent, relates son as $y; get;");
    assertEquals(expected, parsed);
    assertEquals(expected, parse(expected.toString()));
}
Also used : GetQuery(ai.grakn.graql.GetQuery) Test(org.junit.Test)

Example 55 with GetQuery

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

the class QueryParserTest method testPredicateQuery3.

@Test
public void testPredicateQuery3() {
    GetQuery expected = match(var().rel("x").rel("y"), var("y").isa("person").has("name", var("n")), or(var("n").val(contains("ar")), var("n").val(regex("^M.*$")))).get();
    GetQuery parsed = parse("match ($x, $y); $y isa person, has name $n;" + "$n val contains 'ar' or $n val /^M.*$/; get;");
    assertEquals(expected, parsed);
}
Also used : GetQuery(ai.grakn.graql.GetQuery) 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