use of ai.grakn.graql.Pattern in project grakn by graknlabs.
the class ReasonerTest method testTwoRulesOnlyDifferingByVarNamesAreEquivalent.
@Test
public void testTwoRulesOnlyDifferingByVarNamesAreEquivalent() {
EmbeddedGraknTx<?> tx = testGeoKB.tx();
Rule rule1 = tx.getRule("Geo Rule");
Pattern body2 = Graql.and(tx.graql().parser().parsePatterns("(geo-entity: $l1, entity-location: $l2) isa is-located-in;" + "(geo-entity: $l2, entity-location: $l3) isa is-located-in;"));
Pattern head2 = Graql.and(tx.graql().parser().parsePatterns("(geo-entity: $l1, entity-location: $l3) isa is-located-in;"));
Rule rule2 = tx.putRule("Rule 2", body2, head2);
InferenceRule R1 = new InferenceRule(rule1, tx);
InferenceRule R2 = new InferenceRule(rule2, tx);
assertEquals(R1, R2);
}
use of ai.grakn.graql.Pattern in project grakn by graknlabs.
the class PatternTest method testSimpleDisjunction.
@Test
public void testSimpleDisjunction() {
Pattern disjunction = or();
assertFalse(disjunction.admin().isVarPattern());
assertTrue(disjunction.admin().isDisjunction());
assertFalse(disjunction.admin().isConjunction());
// noinspection AssertEqualsBetweenInconvertibleTypes
assertEquals(disjunction.admin(), disjunction.admin().asDisjunction());
}
use of ai.grakn.graql.Pattern in project grakn by graknlabs.
the class CWKB method buildRules.
@Override
protected void buildRules(GraknTx tx) {
// R1: "It is a crime for an American to sell weapons to hostile nations"
Pattern R1_LHS = tx.graql().parser().parsePattern("{" + "$x isa person;$x has nationality 'American';" + "$y isa weapon;" + "$z isa country;$z has alignment 'hostile';" + "(seller: $x, transaction-item: $y, buyer: $z) isa transaction;}");
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);
// R2: "Missiles are a kind of a weapon"
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);
// R3: "If a country is an enemy of America then it is hostile"
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);
// R4: "If a rocket is self-propelled and guided, it is a missile"
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;" + "($x, $y) isa is-paid-by;" + "($y, $z) isa owns;}");
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);
}
use of ai.grakn.graql.Pattern in project grakn by graknlabs.
the class TxObserver method putRule.
private void putRule(PutRule putRule) {
Label label = GrpcUtil.convert(putRule.getLabel());
Pattern when = GrpcUtil.convert(putRule.getWhen());
Pattern then = GrpcUtil.convert(putRule.getThen());
Rule rule = tx().putRule(label, when, then);
responseObserver.onNext(GrpcUtil.conceptResponse(rule));
}
use of ai.grakn.graql.Pattern in project grakn by graknlabs.
the class RemoteGraknTxTest method whenPuttingRule_EnsureCorrectRequestIsSent.
@Test
public void whenPuttingRule_EnsureCorrectRequestIsSent() {
ConceptId id = ConceptId.of(V123.getValue());
Label label = Label.of("foo");
Pattern when = var("x").isa("person");
Pattern then = var("y").isa("person");
try (RemoteGraknTx tx = RemoteGraknTx.create(session, GrpcUtil.openRequest(KEYSPACE, GraknTxType.READ))) {
// The open request
verify(server.requests()).onNext(any());
Concept concept = RemoteConcepts.createRule(tx, id);
server.setResponse(GrpcUtil.putRuleRequest(label, when, then), GrpcUtil.conceptResponse(concept));
assertEquals(concept, tx.putRule(label, when, then));
}
}
Aggregations