本文整理了Java中ai.grakn.graql.QueryBuilder.parser
方法的一些代码示例,展示了QueryBuilder.parser
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。QueryBuilder.parser
方法的具体详情如下:
包路径:ai.grakn.graql.QueryBuilder
类名称:QueryBuilder
方法名:parser
[英]Get a QueryParser for parsing queries from strings
[中]获取用于解析字符串查询的QueryParser
代码示例来源:origin: ai.grakn/grakn-graql
/**
* Get a {@link QueryParser} for parsing queries from strings
*/
public static QueryParser parser() {
return withoutGraph().parser();
}
代码示例来源:origin: ai.grakn/grakn-test-tools
public static void loadFromFile(GraknTx graph, String file) {
File graql = new File(GraknSystemProperty.PROJECT_RELATIVE_DIR.value() + "/grakn-test-tools/src/main/graql/" + file);
List<String> queries;
try {
queries = Files.readLines(graql, StandardCharsets.UTF_8);
} catch (IOException e) {
throw new RuntimeException(e);
}
graph.graql().parser().parseList(queries.stream().collect(Collectors.joining("\n"))).forEach(Query::execute);
}
}
代码示例来源:origin: ai.grakn/grakn-test-tools
@Override
protected void buildRules(GraknTx tx) {
// These rules are totally made up for testing purposes and don't work!
Pattern when = tx.graql().parser().parsePattern("$x has name 'expectation-when'");
Pattern then = tx.graql().parser().parsePattern("$x has name 'expectation-then'");
tx.putRule("expectation-rule", when, then);
when = tx.graql().parser().parsePattern("$x has name 'materialize-when'");
then = tx.graql().parser().parsePattern("$x has name 'materialize-then'");
tx.putRule("materialize-rule", when, then);
}
代码示例来源:origin: ai.grakn/grakn-test-tools
@Override
public void buildRules(GraknTx tx) {
Pattern transitivity_LHS = tx.graql().parser().parsePattern("{(geo-entity: $x, entity-location: $y) isa is-located-in;" +
"(geo-entity: $y, entity-location: $z) isa is-located-in;}");
Pattern transitivity_RHS = tx.graql().parser().parsePattern("{(geo-entity: $x, entity-location: $z) isa is-located-in;}");
tx.putRule("Geo Rule", transitivity_LHS, transitivity_RHS);
}
}
代码示例来源:origin: ai.grakn/grakn-test-tools
@Override
protected Rule newSchemaConcept(Label label) {
// TODO: generate more complicated rules
QueryBuilder graql = this.tx().graql();
return tx().putRule(label, graql.parser().parsePattern("$x"), graql.parser().parsePattern("$x"));
}
代码示例来源:origin: ai.grakn/grakn-test-tools
@Override
protected BiFunction<GraknTx, Label, SchemaConcept> generate() {
return random.choose(ImmutableList.of(
GraknTx::putEntityType,
(graph, label) -> graph.putAttributeType(label, gen(AttributeType.DataType.class)),
GraknTx::putRelationshipType,
GraknTx::putRole,
//TODO: Make smarter rules
(graph, label) -> graph.putRule(label, graph.graql().parser().parsePattern("$x"), graph.graql().parser().parsePattern("$x"))
));
}
}
代码示例来源:origin: ai.grakn/grakn-kb
private Pattern parsePattern(String value){
if(value == null) {
return null;
} else {
return vertex().tx().graql().parser().parsePattern(value);
}
}
代码示例来源:origin: ai.grakn/grakn-test-tools
Pattern R1_LHS = tx.graql().parser().parsePattern("{" +
"$x isa person;$x has nationality 'American';" +
"$y isa weapon;" +
Pattern R1_RHS = tx.graql().parser().parsePattern("{$x isa criminal;}");
tx.putRule("R1: It is a crime for an American to sell weapons to hostile nations" , R1_LHS, R1_RHS);
Pattern R2_LHS = tx.graql().parser().parsePattern("{$x isa missile;}");
Pattern R2_RHS = tx.graql().parser().parsePattern("{$x isa weapon;}");
tx.putRule("R2: Missiles are a kind of a weapon\"" , R2_LHS, R2_RHS);
Pattern R3_LHS = tx.graql().parser().parsePattern("{$x isa country;" +
"($x, $y) isa is-enemy-of;" +
"$y isa country;$y has name 'America';}");
Pattern R3_RHS = tx.graql().parser().parsePattern("{$x has alignment 'hostile';}");
tx.putRule("R3: If a country is an enemy of America then it is hostile" , R3_LHS, R3_RHS);
Pattern R4_LHS = tx.graql().parser().parsePattern("{$x isa rocket;$x has propulsion 'gsp';}");
Pattern R4_RHS = tx.graql().parser().parsePattern("{$x isa missile;}");
tx.putRule("R4: If a rocket is self-propelled and guided, it is a missile" , R4_LHS, R4_RHS);
Pattern R5_LHS = tx.graql().parser().parsePattern("{$x isa person;" +
"$y isa country;" +
"$z isa weapon;" +
Pattern R5_RHS = tx.graql().parser().parsePattern("{(seller: $x, buyer: $y, transaction-item: $z) isa transaction;}");
tx.putRule("R5: If a country pays a person and that country now owns a weapon then the person has sold the country a weapon" , R5_LHS, R5_RHS);
内容来源于网络,如有侵权,请联系作者删除!