use of com.vaticle.typeql.lang.query.TypeQLQuery in project grakn by graknlabs.
the class StatisticsTest method updateAges.
private void updateAges(CoreDatabaseManager databaseMgr, Set<Long> ages) {
try (CoreSession session = databaseMgr.session(database, Arguments.Session.Type.DATA)) {
try (CoreTransaction tx = session.transaction(Arguments.Transaction.Type.WRITE)) {
TypeQLQuery query = TypeQL.parseQuery("match $x isa person, has age $y;");
List<ConceptMap> conceptMaps = tx.query().match(query.asMatch()).toList();
conceptMaps.forEach(cm -> {
Attribute.Long attribute = cm.get("y").asAttribute().asLong();
cm.get("x").asEntity().unsetHas(attribute);
long newAge = attribute.getValue() + 1;
Attribute.Long newAttribute = attribute.getType().asLong().put(newAge);
cm.get("x").asEntity().setHas(newAttribute);
cm.get("x").asEntity().setHas(newAttribute);
ages.add(newAge);
});
tx.commit();
}
}
}
use of com.vaticle.typeql.lang.query.TypeQLQuery in project grakn by graknlabs.
the class StatisticsTest method insertPersonAndAges.
private void insertPersonAndAges(CoreDatabaseManager databaseMgr, int personCount, Set<Long> ages, Random random) {
try (CoreSession session = databaseMgr.session(database, Arguments.Session.Type.DATA)) {
try (CoreTransaction tx = session.transaction(Arguments.Transaction.Type.WRITE)) {
for (int i = 0; i < personCount; i++) {
long age = random.nextInt(personCount);
ages.add(age);
TypeQLQuery query = TypeQL.parseQuery("insert $x isa person, has age " + age + ";").asInsert();
tx.query().insert(query.asInsert());
}
tx.commit();
}
}
}
use of com.vaticle.typeql.lang.query.TypeQLQuery in project typeql-lang-java by vaticle.
the class ParserTest method testParseListOneInsertWithWhitespacePrefix.
@Test
public void testParseListOneInsertWithWhitespacePrefix() {
final String insertString = " insert $x isa movie;";
List<TypeQLQuery> queries = TypeQL.parseQueries(insertString).collect(toList());
assertEquals(list(insert(var("x").isa("movie"))), queries);
}
use of com.vaticle.typeql.lang.query.TypeQLQuery in project typeql-lang-java by vaticle.
the class TypeQLSteps method typeql_match.
@Given("for typeql query")
@Given("reasoning query")
@Given("get answers of typeql match")
@Given("get answers of typeql match group")
@Given("get answer of typeql match aggregate")
@Given("get answers of typeql match group aggregate")
@Given("verify answer set is equivalent for query")
public void typeql_match(String query) {
TypeQLQuery parsed = TypeQL.parseQuery(query);
assertEquals(parsed, TypeQL.parseQuery(parsed.toString()));
if (parsed instanceof TypeQLMatch) {
parsed.asMatch().conjunction().normalise();
}
}
use of com.vaticle.typeql.lang.query.TypeQLQuery in project typeql-lang-java by vaticle.
the class ParserTest method testParseListOneMatch.
@Test
public void testParseListOneMatch() {
final String getString = "match\n$y isa movie;";
List<TypeQLQuery> queries = TypeQL.parseQueries(getString).collect(toList());
assertEquals(list(match(var("y").isa("movie"))), queries);
}
Aggregations