Example #1
0
def test_operators_nested_simple():
    events = [
        UserUttered(intent={"name": "1"}),
        UserUttered(intent={"name": "2"}),
        UserUttered(intent={"name": "3"}),
        SlotSet("s1", value="any"),
        UserUttered(intent={"name": "4"}),
        UserUttered(intent={"name": "5"}),
        UserUttered(intent={"name": "6"}),
    ]
    marker = AndMarker(
        markers=[
            SlotSetMarker("s1"),
            OrMarker([
                IntentDetectedMarker("4"),
                IntentDetectedMarker("6"),
            ]),
        ],
        name="marker_name",
    )
    evaluation = marker.evaluate_events(events)

    assert len(evaluation[0]["marker_name"]) == 2
    assert evaluation[0]["marker_name"][0].preceding_user_turns == 3
    assert evaluation[0]["marker_name"][1].preceding_user_turns == 5
Example #2
0
def test_marker_from_config():
    config = {
        AndMarker.positive_tag(): [
            {
                SlotSetMarker.positive_tag(): "s1"
            },
            {
                OrMarker.positive_tag(): [
                    {
                        IntentDetectedMarker.positive_tag(): "4"
                    },
                    {
                        IntentDetectedMarker.negated_tag(): "6"
                    },
                ]
            },
        ]
    }

    marker = Marker.from_config(config)
    assert isinstance(marker, AndMarker)
    assert isinstance(marker.sub_markers[0], SlotSetMarker)
    or_marker = marker.sub_markers[1]
    assert isinstance(or_marker, OrMarker)
    for sub_marker in or_marker.sub_markers:
        assert isinstance(sub_marker, ConditionMarker)
Example #3
0
def test_operator_and(negated: bool):
    events_expected = [
        (UserUttered(intent={INTENT_NAME_KEY: "1"}), False),
        (SlotSet("2", value="bla"), False),
        (UserUttered(intent={INTENT_NAME_KEY: "1"}), True),
        (SlotSet("2", value=None), False),
        (UserUttered(intent={INTENT_NAME_KEY: "1"}), False),
        (SlotSet("2", value="bla"), False),
        (UserUttered(intent={INTENT_NAME_KEY: "2"}), False),
    ]
    events, expected = zip(*events_expected)
    sub_markers = [IntentDetectedMarker("1"), SlotSetMarker("2")]
    marker = AndMarker(sub_markers, name="marker_name", negated=negated)
    for event in events:
        marker.track(event)
    expected = list(expected)
    if negated:
        expected = [not applies for applies in expected]
    assert marker.history == expected
Example #4
0
@pytest.mark.parametrize(
    "config",
    [
        # (1) top level configuration
        # - config is list
        [SlotSetMarker.positive_tag()],
        # - config is list with nested dict
        [{
            SlotSetMarker.positive_tag(): "s1"
        }],
        # - config is just a str
        # (2) sub-markers
        SlotSetMarker.positive_tag(),
        # - sub-marker config is dict not list
        {
            AndMarker.positive_tag(): {
                SlotSetMarker.positive_tag(): "s1"
            }
        },
        # - sub-marker under condition
        {
            SlotSetMarker.positive_tag(): {
                IntentDetectedMarker.positive_tag(): "blah"
            }
        },
        # - no sub-config for operator (see also: "amount_sub_markers" tests)
        {
            AndMarker.positive_tag(): "blah"
        },
        # (3) tags
        # - unknown operator