Esempio n. 1
0
def test_fallback_does_not_trigger_when_intent_is_null():
    disambiguator = Disambiguator(fallback_rule=load_yaml(
        './tests/disambiguator/test_disambiguator7.yaml')['fallback_policy'])

    parse_data = {
        "intent": {
            "name": "",
            "confidence": 0.0
        },
        "entities": [],
        "intent_ranking": []
    }

    assert disambiguator.should_fallback(parse_data) is False
Esempio n. 2
0
def test_fallback_trigger2():
    disambiguator = Disambiguator(fallback_rule=load_yaml(
        './tests/disambiguator/test_disambiguator6.yaml')['fallback_policy'])

    parse_data = {
        "intent_ranking": [{
            "name": "intentA",
            "confidence": 0.6
        }, {
            "name": "intentB",
            "confidence": 0.2
        }]
    }
    result = disambiguator.should_fallback(parse_data)
    assert result is False
Esempio n. 3
0
def test_disamb_and_fallback_trigger_none():
    rules = load_yaml('./tests/disambiguator/test_disambiguator9.yaml')
    disambiguator = Disambiguator(disamb_rule=rules['disambiguation_policy'],
                                  fallback_rule=rules['fallback_policy'])

    parse_data = {
        "intent_ranking": [{
            "name": "intentA",
            "confidence": 0.51
        }, {
            "name": "intentB",
            "confidence": 0.25
        }]
    }
    result = disambiguator.should_fallback(
        parse_data) or disambiguator.should_disambiguate(parse_data)
    assert result is False
Esempio n. 4
0
def test_disamb_and_fallback_trigger_both():
    rules = load_yaml('./tests/disambiguator/test_disambiguator9.yaml')
    disambiguator = Disambiguator(disamb_rule=rules['disambiguation_policy'],
                                  fallback_rule=rules['fallback_policy'])

    parse_data = {
        "intent_ranking": [{
            "name": "intentA",
            "confidence": 0.49
        }, {
            "name": "intentB",
            "confidence": 0.4
        }]
    }
    # fallback has precedence and short-circuits disamb in the actual program flow as per rules.py
    result = disambiguator.should_fallback(
        parse_data) and disambiguator.should_disambiguate(parse_data)
    assert result is True
Esempio n. 5
0
def test_fallback_does_not_trigger_when_data_is_missing_in_parse_data():
    disambiguator = Disambiguator(fallback_rule=load_yaml(
        './tests/disambiguator/test_disambiguator7.yaml')['fallback_policy'])

    parse_data = {}
    assert disambiguator.should_fallback(parse_data) is False