Ejemplo n.º 1
0
def test_validator_intent_none():
    validator = InputValidator(
        InputValidator._load_yaml(VALIDATOR_RULES_YAML)['input_validation'])
    previous = "utter_garantie_type_bien"
    parse_data = {'intent': {'name': None}, 'entities': []}
    assert validator._get_error(parse_data,
                                previous) == 'utter_general_validation_options'
Ejemplo n.º 2
0
def test_validator_dummy_valid():

    validator = InputValidator(
        InputValidator._load_yaml(VALIDATOR_RULES_YAML)['input_validation'])
    previous = "not_in_file"
    parse_data = {'intent': {'name': 'affirm'}, 'entities': []}
    assert validator._get_error(parse_data, previous) is None
Ejemplo n.º 3
0
def test_swap_intent_with2():
    swap_rules = InputValidator(
        InputValidator._load_yaml(VALIDATOR_RULES_YAML)['intent_substitution'])
    # make sure intent not swapped after another action than the one specified in the rule
    parse_data = {"intent": {"name": "whatever", "confidence": 1.0}}
    Rules._swap_intent(parse_data, None, swap_rules.rules[1])
    assert parse_data["intent"]["name"] == "whatever"
Ejemplo n.º 4
0
def test_swap_intent_with1():
    swap_rules = InputValidator(
        InputValidator._load_yaml(VALIDATOR_RULES_YAML)['intent_substitution'])
    # make sure intent swapped
    parse_data = {"intent": {"name": "chitchat.i_am_angry", "confidence": 1.0}}
    Rules._swap_intent(parse_data, None, swap_rules.rules[1])
    assert parse_data["intent"]["name"] == "request.handover"
Ejemplo n.º 5
0
def test_swap_intent_after1():
    swap_rules = InputValidator(
        InputValidator._load_yaml(VALIDATOR_RULES_YAML)['intent_substitution'])
    # make sure intent swapped
    parse_data = {"intent": {"name": "whatever", "confidence": 1.0}}
    Rules._swap_intent(parse_data, "utter_something", swap_rules.rules[0])
    assert parse_data["intent"]["name"] == "intent_something"
Ejemplo n.º 6
0
 def __init__(self, rules_file):
     data = self._load_yaml(rules_file)
     self.actions_to_ignore = ['action_listen', 'action_invalid_utterance']
     self.allowed_entities = data["allowed_entities"] if data and "allowed_entities" in data else {}
     self.intent_substitutions = data["intent_substitutions"] if data and "intent_substitutions" in data else []
     self.input_validation = InputValidator(data["input_validation"]) if data and "input_validation" in data else []
     self.disambiguation_policy = Disambiguator(data["disambiguation_policy"]) if data and "disambiguation_policy" in data else []
Ejemplo n.º 7
0
def test_swap_intent_with3():
    swap_rules = InputValidator(
        InputValidator._load_yaml(VALIDATOR_RULES_YAML)['intent_substitution'])
    # make sure intent is swapped and entity is added
    parse_data = {"intent": {"name": "chitchat.bye", "confidence": 1.0}}
    Rules._swap_intent(parse_data, None, swap_rules.rules[2])
    assert parse_data["intent"]["name"] == "chitchat"
    assert parse_data["entities"][0]["entity"] == "intent"
    assert parse_data["entities"][0]["value"] == "chitchat.bye"
Ejemplo n.º 8
0
def test_swap_intent_with4():
    swap_rules = InputValidator(
        InputValidator._load_yaml(VALIDATOR_RULES_YAML)['intent_substitution'])
    # just checking regex is ok
    parse_data = {
        "intent": {
            "name": "chitchat.this_is_frustrating",
            "confidence": 1.0
        }
    }
    Rules._swap_intent(parse_data, None, swap_rules.rules[2])
    assert parse_data["intent"]["name"] == "chitchat.this_is_frustrating"
Ejemplo n.º 9
0
def test_swap_intent_after2():
    swap_rules = InputValidator(
        InputValidator._load_yaml(VALIDATOR_RULES_YAML)['intent_substitution'])
    # make sure intent is not swapped when in unless list
    parse_data = {
        "intent": {
            "name": "chitchat.this_is_frustrating",
            "confidence": 1.0
        }
    }
    Rules._swap_intent(parse_data, "utter_something", swap_rules.rules[0])
    assert parse_data["intent"]["name"] == "chitchat.this_is_frustrating"
Ejemplo n.º 10
0
def test_validator_intent_and_entity_ok():
    validator = InputValidator(
        InputValidator._load_yaml(VALIDATOR_RULES_YAML)['input_validation'])
    previous = "utter_garantie_type_bien"
    parse_data = {
        'intent': {
            'name': 'garantie'
        },
        'entities': [{
            'entity': 'product_type'
        }]
    }
    assert validator._get_error(parse_data, previous) is None
Ejemplo n.º 11
0
def test_validator_regex():
    validator = InputValidator(
        InputValidator._load_yaml(VALIDATOR_RULES_YAML)['input_validation'])

    previous = "utter_garantie_confirm_particulier"
    parse_data = {
        'intent': {
            'name': 'cancel'
        },
        'entities': [{
            'entity': 'product_type'
        }]
    }
    # having an entity in parse_data that is not expected is ok
    assert validator._get_error(parse_data, previous) is None

    previous = "utter_garantie_confirm_particulier"
    parse_data = {'intent': {'name': 'cancel'}, 'entities': []}
    assert validator._get_error(parse_data, previous) is None

    previous = "utter_garantie_confirm_particulier"
    parse_data = {'intent': {'name': 'lakjshdflkjashdf'}, 'entities': []}
    assert validator._get_error(
        parse_data, previous) == 'utter_general_validation_affirm_deny'
Ejemplo n.º 12
0
def test_validator_intent_no_entity():
    validator = InputValidator(
        InputValidator._load_yaml(VALIDATOR_RULES_YAML)['input_validation'])
    previous = "utter_garantie_type_bien"
    parse_data = {'intent': {'name': 'cancel'}, 'entities': []}
    assert validator._get_error(parse_data, previous) is None