How to use the mindmeld.components.dialogue.DialogueStateRule function in mindmeld

To help you get started, we’ve selected a few mindmeld examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github cisco / mindmeld / tests / components / test_dialogue.py View on Github external
def test_dialogue_state_rule_exception():
    with pytest.raises(ValueError):
        DialogueStateRule(dialogue_state="some-state", has_entities=[1, 2])

    rule1 = DialogueStateRule(dialogue_state="some-state", has_entity="entity_1")
    assert rule1.entity_types == frozenset(("entity_1",))

    rule2 = DialogueStateRule(
        dialogue_state="some-state", has_entities=["entity_2", "entity_3"]
    )
    assert rule2.entity_types == frozenset(("entity_2", "entity_3",))

    with pytest.raises(ValueError):
        DialogueStateRule(
            dialogue_state="some-state",
            has_entity="entity_1",
            has_entities=["entity_2", "entity_3"],
        )

    with pytest.raises(NotImplementedError):
        assert rule1 == 1

    with pytest.raises(NotImplementedError):
        assert rule1 != 1

    assert repr(rule1) == ""

    with pytest.raises(NotImplementedError):
        assert DialogueStateRule.compare(rule1, 1)
github cisco / mindmeld / tests / components / test_dialogue.py View on Github external
def test_dialogue_state_rule_not_equal():
    rule1 = DialogueStateRule(dialogue_state="some-state", domain="some-domain")
    rule2 = DialogueStateRule(dialogue_state="some-state-2", domain="some-domain")
    assert rule1 != rule2

    rule2 = DialogueStateRule(dialogue_state="some-state")
    assert rule1 != rule2

    rule2 = DialogueStateRule(
        dialogue_state="some-state", domain="some-domain", intent="some-intent"
    )
    assert rule1 != rule2
github cisco / mindmeld / tests / components / test_dialogue.py View on Github external
def test_dialogue_state_rule_targeted_only():
    request = create_request("some-domain", "some-intent")
    rule1 = DialogueStateRule(dialogue_state="some-state", targeted_only=True)
    assert not rule1.apply(request)

    with pytest.raises(ValueError) as ex:
        DialogueStateRule(
            dialogue_state="some-state", domain="some-domain", targeted_only=True
        )

    msg = (
        "For a dialogue state rule, if targeted_only is True, domain, intent, and has_entity"
        " must be omitted"
    )

    assert msg in str(ex)
github cisco / mindmeld / tests / components / test_dialogue.py View on Github external
def test_dialogue_state_rule_exception():
    with pytest.raises(ValueError):
        DialogueStateRule(dialogue_state="some-state", has_entities=[1, 2])

    rule1 = DialogueStateRule(dialogue_state="some-state", has_entity="entity_1")
    assert rule1.entity_types == frozenset(("entity_1",))

    rule2 = DialogueStateRule(
        dialogue_state="some-state", has_entities=["entity_2", "entity_3"]
    )
    assert rule2.entity_types == frozenset(("entity_2", "entity_3",))

    with pytest.raises(ValueError):
        DialogueStateRule(
            dialogue_state="some-state",
            has_entity="entity_1",
            has_entities=["entity_2", "entity_3"],
        )

    with pytest.raises(NotImplementedError):
        assert rule1 == 1
github cisco / mindmeld / tests / components / test_dialogue.py View on Github external
def test_dialogue_state_rule_equal():
    rule1 = DialogueStateRule(dialogue_state="some-state", domain="some-domain")
    rule2 = DialogueStateRule(dialogue_state="some-state", domain="some-domain")
    assert rule1 == rule2
github cisco / mindmeld / tests / components / test_dialogue.py View on Github external
def test_dialogue_state_rule_targeted_only():
    request = create_request("some-domain", "some-intent")
    rule1 = DialogueStateRule(dialogue_state="some-state", targeted_only=True)
    assert not rule1.apply(request)

    with pytest.raises(ValueError) as ex:
        DialogueStateRule(
            dialogue_state="some-state", domain="some-domain", targeted_only=True
        )

    msg = (
        "For a dialogue state rule, if targeted_only is True, domain, intent, and has_entity"
        " must be omitted"
    )

    assert msg in str(ex)
github cisco / mindmeld / tests / components / test_dialogue.py View on Github external
def test_dialogue_state_rule_not_equal():
    rule1 = DialogueStateRule(dialogue_state="some-state", domain="some-domain")
    rule2 = DialogueStateRule(dialogue_state="some-state-2", domain="some-domain")
    assert rule1 != rule2

    rule2 = DialogueStateRule(dialogue_state="some-state")
    assert rule1 != rule2

    rule2 = DialogueStateRule(
        dialogue_state="some-state", domain="some-domain", intent="some-intent"
    )
    assert rule1 != rule2
github cisco / mindmeld / mindmeld / components / dialogue.py View on Github external
Args:
            name (str): The name of the dialogue state.
            handler (function): The dialogue state handler function.
            kwargs (dict): A list of options to be passed to the DialogueStateRule initializer.
        """
        if name is None:
            name = handler.__name__

        if self.async_mode and not asyncio.iscoroutinefunction(handler):
            msg = (
                "Cannot use dialogue state handler {!r} in async mode. "
                "Handler must be coroutine function in async mode."
            )
            raise TypeError(msg.format(name))

        rule = DialogueStateRule(name, **kwargs)
        self.rules.append(rule)
        self.rules.sort(key=cmp_to_key(DialogueStateRule.compare), reverse=True)
        if handler is not None:
            old_handler = self.handler_map.get(name)
            if old_handler is not None and old_handler != handler:
                msg = (
                    "Handler mapping is overwriting an existing dialogue state: %s"
                    % name
                )
                raise AssertionError(msg)
            self.handler_map[name] = handler

            if rule.default:
                if self.default_rule:
                    raise AssertionError("Only one default rule may be specified")
                self.default_rule = rule