Search in sources :

Example 1 with TypeQLMatch

use of com.vaticle.typeql.lang.query.TypeQLMatch in project grakn by graknlabs.

the class CorrectnessVerifierTest method testSoundnessThrowsWhenRuleTriggersTooOftenEmployableExample.

@Test
public void testSoundnessThrowsWhenRuleTriggersTooOftenEmployableExample() {
    TypeQLMatch inferenceQuery = parseQuery("match $x has employable true;").asMatch();
    CorrectnessVerifier correctnessVerifier;
    try (CoreSession session = databaseMgr.session(database, Arguments.Session.Type.DATA)) {
        correctnessVerifier = CorrectnessVerifier.initialise(session);
        try (CoreTransaction tx = session.transaction(Arguments.Transaction.Type.WRITE)) {
            tx.query().insert(parseQuery("insert $p isa person;"));
            tx.commit();
        }
        assertThrows(() -> correctnessVerifier.verifySoundness(inferenceQuery), SoundnessException.class);
        assertNotThrows(() -> correctnessVerifier.verifyCompleteness(inferenceQuery));
    }
}
Also used : CorrectnessVerifier(com.vaticle.typedb.core.test.behaviour.reasoner.verification.CorrectnessVerifier) CoreSession(com.vaticle.typedb.core.database.CoreSession) TypeQLMatch(com.vaticle.typeql.lang.query.TypeQLMatch) CoreTransaction(com.vaticle.typedb.core.database.CoreTransaction) Test(org.junit.Test)

Example 2 with TypeQLMatch

use of com.vaticle.typeql.lang.query.TypeQLMatch in project grakn by graknlabs.

the class CorrectnessVerifierTest method testCompletenessThrowsWhenRuleIsNotTriggeredEmployableExample.

@Test
public void testCompletenessThrowsWhenRuleIsNotTriggeredEmployableExample() {
    TypeQLMatch inferenceQuery = parseQuery("match $x has employable true;").asMatch();
    CorrectnessVerifier correctnessVerifier;
    try (CoreSession session = databaseMgr.session(database, Arguments.Session.Type.DATA)) {
        correctnessVerifier = CorrectnessVerifier.initialise(session);
        try (CoreTransaction tx = session.transaction(Arguments.Transaction.Type.WRITE)) {
            tx.query().delete(parseQuery("match $p isa person; delete $p isa person;"));
            tx.commit();
        }
        assertThrows(() -> correctnessVerifier.verifyCompleteness(inferenceQuery), CompletenessException.class);
        assertNotThrows(() -> correctnessVerifier.verifySoundness(inferenceQuery));
    }
}
Also used : CorrectnessVerifier(com.vaticle.typedb.core.test.behaviour.reasoner.verification.CorrectnessVerifier) CoreSession(com.vaticle.typedb.core.database.CoreSession) TypeQLMatch(com.vaticle.typeql.lang.query.TypeQLMatch) CoreTransaction(com.vaticle.typedb.core.database.CoreTransaction) Test(org.junit.Test)

Example 3 with TypeQLMatch

use of com.vaticle.typeql.lang.query.TypeQLMatch in project grakn by graknlabs.

the class CorrectnessVerifierTest method testCorrectnessPassesForEmployableExample.

@Test
public void testCorrectnessPassesForEmployableExample() {
    TypeQLMatch inferenceQuery = parseQuery("match $x has employable true;").asMatch();
    try (CoreSession session = databaseMgr.session(database, Arguments.Session.Type.DATA)) {
        CorrectnessVerifier correctnessVerifier = CorrectnessVerifier.initialise(session);
        correctnessVerifier.verifyCorrectness(inferenceQuery);
        correctnessVerifier.close();
    }
}
Also used : CoreSession(com.vaticle.typedb.core.database.CoreSession) CorrectnessVerifier(com.vaticle.typedb.core.test.behaviour.reasoner.verification.CorrectnessVerifier) TypeQLMatch(com.vaticle.typeql.lang.query.TypeQLMatch) Test(org.junit.Test)

Example 4 with TypeQLMatch

use of com.vaticle.typeql.lang.query.TypeQLMatch in project grakn by graknlabs.

the class MaterialiserTest method testDeduplicationOfInferredConcepts.

@Test
public void testDeduplicationOfInferredConcepts() {
    loadTransitivityExample(databaseMgr);
    try (CoreSession session = databaseMgr.session(database, Arguments.Session.Type.DATA)) {
        Materialiser materialiser = Materialiser.materialise(session);
        TypeQLMatch inferredAnswersQuery = TypeQL.match(TypeQL.var("lh").isa("location-hierarchy"));
        List<ConceptMap> inferredAnswers = iterate(materialiser.query(inferredAnswersQuery).entrySet()).flatMap(Map.Entry::getValue).toList();
        assertEquals(6, inferredAnswers.size());
    }
}
Also used : Materialiser(com.vaticle.typedb.core.test.behaviour.reasoner.verification.Materialiser) CoreSession(com.vaticle.typedb.core.database.CoreSession) TypeQLMatch(com.vaticle.typeql.lang.query.TypeQLMatch) ConceptMap(com.vaticle.typedb.core.concept.answer.ConceptMap) Map(java.util.Map) ConceptMap(com.vaticle.typedb.core.concept.answer.ConceptMap) Test(org.junit.Test)

Example 5 with TypeQLMatch

use of com.vaticle.typeql.lang.query.TypeQLMatch in project grakn by graknlabs.

the class TypeQLSteps method each_answer_does_not_satisfy.

@Then("each answer does not satisfy")
public void each_answer_does_not_satisfy(String templatedTypeQLQuery) {
    String templatedQuery = String.join("\n", templatedTypeQLQuery);
    for (ConceptMap answer : answers) {
        String queryString = applyQueryTemplate(templatedQuery, answer);
        TypeQLMatch query = TypeQL.parseQuery(queryString).asMatch();
        long answerSize = tx().query().match(query).toList().size();
        assertEquals(0, answerSize);
    }
}
Also used : ConceptMap(com.vaticle.typedb.core.concept.answer.ConceptMap) TypeQLMatch(com.vaticle.typeql.lang.query.TypeQLMatch) Then(io.cucumber.java.en.Then)

Aggregations

TypeQLMatch (com.vaticle.typeql.lang.query.TypeQLMatch)10 ConceptMap (com.vaticle.typedb.core.concept.answer.ConceptMap)6 Test (org.junit.Test)5 CoreSession (com.vaticle.typedb.core.database.CoreSession)4 CorrectnessVerifier (com.vaticle.typedb.core.test.behaviour.reasoner.verification.CorrectnessVerifier)3 Then (io.cucumber.java.en.Then)3 CoreTransaction (com.vaticle.typedb.core.database.CoreTransaction)2 TypeDB (com.vaticle.typedb.core.TypeDB)1 Context (com.vaticle.typedb.core.common.parameters.Context)1 Materialiser (com.vaticle.typedb.core.test.behaviour.reasoner.verification.Materialiser)1 TypeQLException (com.vaticle.typeql.lang.common.exception.TypeQLException)1 TypeQLDefine (com.vaticle.typeql.lang.query.TypeQLDefine)1 TypeQLDelete (com.vaticle.typeql.lang.query.TypeQLDelete)1 TypeQLInsert (com.vaticle.typeql.lang.query.TypeQLInsert)1 When (io.cucumber.java.en.When)1 Map (java.util.Map)1