use of ai.grakn.graql.GetQuery in project grakn by graknlabs.
the class QueryParserTest method testParseBooleanType.
@Test
public void testParseBooleanType() {
GetQuery query = parse("match $x datatype boolean; get;");
VarPatternAdmin var = query.match().admin().getPattern().varPatterns().iterator().next();
// noinspection OptionalGetWithoutIsPresent
DataTypeProperty property = var.getProperty(DataTypeProperty.class).get();
Assert.assertEquals(AttributeType.DataType.BOOLEAN, property.dataType());
}
use of ai.grakn.graql.GetQuery in project grakn by graknlabs.
the class TypeInferenceQueryTest method typedAnswers.
private List<Answer> typedAnswers(List<RelationshipType> possibleTypes, String pattern, EmbeddedGraknTx<?> graph) {
List<Answer> answers = new ArrayList<>();
ReasonerAtomicQuery query = ReasonerQueries.atomic(conjunction(pattern, graph), graph);
for (Type type : possibleTypes) {
GetQuery typedQuery = graph.graql().match(ReasonerQueries.atomic(query.getAtom().addType(type)).getPattern()).get();
typedQuery.stream().filter(ans -> !answers.contains(ans)).forEach(answers::add);
}
return answers;
}
use of ai.grakn.graql.GetQuery in project grakn by graknlabs.
the class SNBInferenceTest method testRecommendation.
@Test
public void testRecommendation() {
QueryBuilder qb = snbGraph.tx().graql().infer(false);
QueryBuilder iqb = snbGraph.tx().graql().infer(true);
String queryString = "match $x isa person;($x, $y) isa recommendation; get;";
String limitedQueryString = "match $x isa person;($x, $y) isa recommendation; limit 1; get;";
GetQuery query = iqb.parse(queryString);
GetQuery limitedQuery = iqb.parse(limitedQueryString);
String explicitQuery = "match $x isa person;" + "{$x has name 'Alice';$y has name 'War of the Worlds';} or" + "{$x has name 'Bob';{$y has name 'Ducatti 1299';} or {$y has name 'The Good the Bad the Ugly';};} or" + "{$x has name 'Charlie';{$y has name 'Blizzard of Ozz';} or {$y has name 'Stratocaster';};} or " + "{$x has name 'Denis';{$y has name 'Colour of Magic';} or {$y has name 'Dorian Gray';};} or" + "{$x has name 'Frank';$y has name 'Nocturnes';} or" + "{$x has name 'Karl Fischer';{$y has name 'Faust';} or {$y has name 'Nocturnes';};} or " + "{$x has name 'Gary';$y has name 'The Wall';} or" + "{$x has name 'Charlie';" + "{$y has name 'Yngwie Malmsteen';} or {$y has name 'Cacophony';} or {$y has name 'Steve Vai';} or {$y has name 'Black Sabbath';};} or " + "{$x has name 'Gary';$y has name 'Pink Floyd';}; get;";
long startTime = System.nanoTime();
List<Answer> limitedAnswers = limitedQuery.execute();
System.out.println("limited time: " + (System.nanoTime() - startTime) / 1e6);
startTime = System.nanoTime();
List<Answer> answers = query.execute();
System.out.println("full time: " + (System.nanoTime() - startTime) / 1e6);
assertCollectionsEqual(answers, qb.<GetQuery>parse(explicitQuery).execute());
assertTrue(answers.containsAll(limitedAnswers));
}
use of ai.grakn.graql.GetQuery in project grakn by graknlabs.
the class ReasoningTests method relationTypesAreCorrectlyInferredInConjunction_TypeArePresent.
// Expected result: no answers (if types were incorrectly inferred the query would yield answers)
@Test
public void relationTypesAreCorrectlyInferredInConjunction_TypeArePresent() {
QueryBuilder qb = testSet28.tx().graql().infer(true);
String queryString = "match " + "(role1: $x, role2: $y) isa relation1;" + "(role1: $y, role2: $z) isa relation1;" + "(role3: $z, role4: $w) isa relation3; get;";
assertThat(qb.<GetQuery>parse(queryString).execute(), empty());
}
use of ai.grakn.graql.GetQuery in project grakn by graknlabs.
the class GetQueryTest method whenGettingResultsString_StringHasExpectedContents.
@Test
public void whenGettingResultsString_StringHasExpectedContents() {
GetQuery query = qb.match(x.isa("movie")).get();
List<String> resultsString = query.resultsString(Printers.graql(false)).collect(toList());
assertThat(resultsString, everyItem(allOf(containsString("$x"), containsString("movie"), containsString(";"))));
}
Aggregations