Exemplo n.º 1
0
def test_md_format_message_no_text():
    formatted = format_message(
        "",
        intent="location",
        entities=[],
    )
    assert formatted == ""
Exemplo n.º 2
0
def test_md_format_message_using_short_entity_syntax():
    formatted = format_message(
        "I am from Berlin.",
        intent="location",
        entities=[{"start": 10, "end": 16, "entity": "city", "value": "Berlin"}],
    )
    assert formatted == """I am from [Berlin](city)."""
Exemplo n.º 3
0
Arquivo: test.py Projeto: tanbui/rasa
    def inline_comment(self) -> Text:
        """A comment attached to this event. Used during dumping."""
        from rasa.shared.core.events import format_message

        predicted_message = format_message(self.text, self.predicted_intent,
                                           self.predicted_entities)
        return f"predicted: {self.predicted_intent}: {predicted_message}"
Exemplo n.º 4
0
    def as_story_string(self, e2e: bool = True) -> Text:
        """Returns text representation of event."""
        from rasa.shared.core.events import format_message

        correct_message = format_message(self.text, self.intent.get("name"),
                                         self.entities)
        return (f"{self.intent.get('name')}: {correct_message}   "
                f"<!-- {self.inline_comment()} -->")
Exemplo n.º 5
0
def test_md_format_message_using_short_entity_syntax_no_start_end_or_text():
    formatted = format_message("",
                               intent="location",
                               entities=[{
                                   "entity": "city",
                                   "value": "Berlin"
                               }])
    assert formatted == ""
Exemplo n.º 6
0
def test_md_format_message_using_long_entity_syntax_no_start_end():
    formatted = format_message(
        "I am from Berlin.",
        intent="location",
        entities=[
            {"start": 10, "end": 16, "entity": "city", "value": "Berlin"},
            {"entity": "country", "value": "Germany", "role": "destination"},
        ],
    )
    assert formatted == "I am from [Berlin](city)."
Exemplo n.º 7
0
    def inline_comment(self) -> Optional[Text]:
        """A comment attached to this event. Used during dumping."""
        from rasa.shared.core.events import format_message

        if self.predicted_intent != self.intent["name"]:
            predicted_message = format_message(self.text,
                                               self.predicted_intent,
                                               self.predicted_entities)

            return f"predicted: {self.predicted_intent}: {predicted_message}"
        else:
            return None
Exemplo n.º 8
0
def test_md_format_message_using_long_entity_syntax():
    formatted = format_message(
        "I am from Berlin in Germany.",
        intent="location",
        entities=[
            {"start": 10, "end": 16, "entity": "city", "value": "Berlin"},
            {
                "start": 20,
                "end": 27,
                "entity": "country",
                "value": "Germany",
                "role": "destination",
            },
        ],
    )
    assert (
        formatted
        == """I am from [Berlin](city) in [Germany]{"entity": "country", "role": "destination"}."""
    )
Exemplo n.º 9
0
def test_md_format_message_empty():
    assert format_message("", intent=None, entities=[]) == ""
Exemplo n.º 10
0
def test_md_format_message():
    assert format_message("Hello there!", intent="greet", entities=[]) == "Hello there!"