Example #1
0
def test_buttons_without_fallback():
    disambiguator = Disambiguator(
        disamb_rule=load_yaml('./tests/disambiguator/test_disambiguator4.yaml')
        ['disambiguation_policy'])

    parse_data = {
        "intent_ranking": [{
            "name": "intentA",
            "confidence": 0.6
        }, {
            "name": "intentB",
            "confidence": 0.2
        }]
    }

    expected = {
        "text":
        "utter_disamb_text",
        "buttons": [{
            "title": "utter_disamb_intentA",
            "payload": "/intentA"
        }, {
            "title": "utter_disamb_intentB",
            "payload": "/intentB"
        }]
    }

    dispatcher = StubDispatcher()
    intents = disambiguator.get_intent_names(parse_data)
    assert ActionDisambiguate.get_disambiguation_message(
        dispatcher, disambiguator.disamb_rule,
        disambiguator.get_payloads(parse_data, intents), intents,
        tracker) == expected
Example #2
0
def test_disamb_exclude_regex():
    disambiguator = Disambiguator(
        disamb_rule=load_yaml('./tests/disambiguator/test_disambiguator11.yaml'
                              )['disambiguation_policy'])

    parse_data = {
        "intent_ranking": [{
            "name": "chitchat.insults",
            "confidence": 0.3
        }, {
            "name": "intentA",
            "confidence": 0.2
        }, {
            "name": "chitchat.this_is_bad",
            "confidence": 0.2
        }, {
            "name": "basics.yes",
            "confidence": 0.15
        }, {
            "name": "intentB",
            "confidence": 0.15
        }],
        "entities": [{
            "entity": "entity1",
            "value": "value1"
        }]
    }

    expected = {
        "text":
        "utter_disamb_text",
        "buttons": [{
            "title": "utter_disamb_intentA",
            "payload": "/intentA{\"entity1\": \"value1\"}"
        }, {
            "title": "utter_disamb_intentB",
            "payload": "/intentB{\"entity1\": \"value1\"}"
        }, {
            "title": "utter_fallback",
            "payload": "/fallback"
        }]
    }

    dispatcher = StubDispatcher()
    intents = disambiguator.get_intent_names(parse_data)
    assert ActionDisambiguate.get_disambiguation_message(
        dispatcher, disambiguator.disamb_rule,
        disambiguator.get_payloads(parse_data, intents), intents,
        tracker) == expected