dc6079821b
Docs Tests / Check for file changes (push) Has been cancelled
Docs Tests / Test Documentation (push) Has been cancelled
Docs Tests / Documentation Linting Checks (push) Has been cancelled
Continuous Integration / Run Tests (ubuntu-24.04, 3.10, test-performance) (push) Has been cancelled
Continuous Integration / Run Tests (ubuntu-24.04, 3.10, test-policies) (push) Has been cancelled
Continuous Integration / Run Tests (ubuntu-24.04, 3.8, test-cli) (push) Has been cancelled
Continuous Integration / Run Tests (ubuntu-24.04, 3.8, test-core-featurizers) (push) Has been cancelled
Continuous Integration / Run Tests (ubuntu-24.04, 3.8, test-full-model-training) (push) Has been cancelled
Continuous Integration / Run Tests (ubuntu-24.04, 3.8, test-nlu-featurizers) (push) Has been cancelled
Continuous Integration / Run Tests (ubuntu-24.04, 3.8, test-nlu-predictors) (push) Has been cancelled
Continuous Integration / Run Tests (ubuntu-24.04, 3.8, test-other-unit-tests) (push) Has been cancelled
Continuous Integration / Run Tests (ubuntu-24.04, 3.8, test-performance) (push) Has been cancelled
Continuous Integration / Run Tests (ubuntu-24.04, 3.8, test-policies) (push) Has been cancelled
Continuous Integration / Run Tests (ubuntu-24.04, 3.9, test-cli) (push) Has been cancelled
Continuous Integration / Run Tests (ubuntu-24.04, 3.9, test-core-featurizers) (push) Has been cancelled
Continuous Integration / Run Tests (ubuntu-24.04, 3.9, test-full-model-training) (push) Has been cancelled
Continuous Integration / Run Tests (ubuntu-24.04, 3.9, test-nlu-featurizers) (push) Has been cancelled
Continuous Integration / Run Tests (ubuntu-24.04, 3.9, test-nlu-predictors) (push) Has been cancelled
Continuous Integration / Run Tests (ubuntu-24.04, 3.9, test-other-unit-tests) (push) Has been cancelled
Continuous Integration / Run Tests (ubuntu-24.04, 3.9, test-performance) (push) Has been cancelled
Continuous Integration / Run Tests (ubuntu-24.04, 3.9, test-policies) (push) Has been cancelled
Continuous Integration / Run Tests (windows-2022, 3.10, test-cli) (push) Has been cancelled
Continuous Integration / Run Tests (windows-2022, 3.10, test-core-featurizers) (push) Has been cancelled
Continuous Integration / Run Tests (windows-2022, 3.10, test-full-model-training) (push) Has been cancelled
Continuous Integration / Run Tests (windows-2022, 3.10, test-nlu-featurizers) (push) Has been cancelled
Continuous Integration / Run Tests (windows-2022, 3.10, test-nlu-predictors) (push) Has been cancelled
Continuous Integration / Run Tests (windows-2022, 3.10, test-other-unit-tests) (push) Has been cancelled
Continuous Integration / Run Tests (windows-2022, 3.10, test-performance) (push) Has been cancelled
Continuous Integration / Run Tests (windows-2022, 3.10, test-policies) (push) Has been cancelled
Continuous Integration / Run Tests (windows-2022, 3.8, test-cli) (push) Has been cancelled
Continuous Integration / Run Tests (windows-2022, 3.8, test-core-featurizers) (push) Has been cancelled
Continuous Integration / Run Tests (windows-2022, 3.8, test-full-model-training) (push) Has been cancelled
Continuous Integration / Run Tests (windows-2022, 3.8, test-nlu-featurizers) (push) Has been cancelled
Continuous Integration / Run Tests (windows-2022, 3.8, test-nlu-predictors) (push) Has been cancelled
Continuous Integration / Run Tests (windows-2022, 3.8, test-other-unit-tests) (push) Has been cancelled
Continuous Integration / Run Tests (windows-2022, 3.8, test-performance) (push) Has been cancelled
Continuous Integration / Run Tests (windows-2022, 3.8, test-policies) (push) Has been cancelled
Continuous Integration / Run Tests (windows-2022, 3.9, test-cli) (push) Has been cancelled
Continuous Integration / Run Tests (windows-2022, 3.9, test-core-featurizers) (push) Has been cancelled
Continuous Integration / Run Tests (windows-2022, 3.9, test-full-model-training) (push) Has been cancelled
Continuous Integration / Run Tests (windows-2022, 3.9, test-nlu-featurizers) (push) Has been cancelled
Continuous Integration / Run Tests (windows-2022, 3.9, test-nlu-predictors) (push) Has been cancelled
Continuous Integration / Run Tests (windows-2022, 3.9, test-other-unit-tests) (push) Has been cancelled
Continuous Integration / Run Tests (windows-2022, 3.9, test-performance) (push) Has been cancelled
Continuous Integration / Run Tests (windows-2022, 3.9, test-policies) (push) Has been cancelled
Continuous Integration / Run Flaky Tests (ubuntu-24.04, 3.10) (push) Has been cancelled
Continuous Integration / Run Flaky Tests (ubuntu-24.04, 3.8) (push) Has been cancelled
Continuous Integration / Run Flaky Tests (ubuntu-24.04, 3.9) (push) Has been cancelled
Continuous Integration / Run Flaky Tests (windows-2022, 3.10) (push) Has been cancelled
Continuous Integration / Run Flaky Tests (windows-2022, 3.8) (push) Has been cancelled
Continuous Integration / Run Flaky Tests (windows-2022, 3.9) (push) Has been cancelled
Continuous Integration / Check for file changes (push) Has been cancelled
Continuous Integration / Wait for docs tests (push) Has been cancelled
Continuous Integration / Code Quality (push) Has been cancelled
Continuous Integration / Check for changelog (push) Has been cancelled
Continuous Integration / Run Tests (ubuntu-24.04, 3.10, test-cli) (push) Has been cancelled
Continuous Integration / Run Tests (ubuntu-24.04, 3.10, test-core-featurizers) (push) Has been cancelled
Continuous Integration / Run Tests (ubuntu-24.04, 3.10, test-full-model-training) (push) Has been cancelled
Continuous Integration / Run Tests (ubuntu-24.04, 3.10, test-nlu-featurizers) (push) Has been cancelled
Continuous Integration / Run Tests (ubuntu-24.04, 3.10, test-nlu-predictors) (push) Has been cancelled
Continuous Integration / Run Tests (ubuntu-24.04, 3.10, test-other-unit-tests) (push) Has been cancelled
Continuous Integration / Upload coverage reports to codeclimate (push) Has been cancelled
Continuous Integration / Run Non-Sequential Integration Tests (push) Has been cancelled
Continuous Integration / Run Broker Integration Tests (push) Has been cancelled
Continuous Integration / Run Sequential Integration Tests (push) Has been cancelled
Continuous Integration / Build Docker base images and setup environment (push) Has been cancelled
Continuous Integration / Build Docker (default) (push) Has been cancelled
Continuous Integration / Build Docker (full) (push) Has been cancelled
Continuous Integration / Build Docker (mitie-en) (push) Has been cancelled
Continuous Integration / Build Docker (spacy-de) (push) Has been cancelled
Continuous Integration / Build Docker (spacy-en) (push) Has been cancelled
Continuous Integration / Build Docker (spacy-it) (push) Has been cancelled
Continuous Integration / Deploy to PyPI (push) Has been cancelled
Continuous Integration / Notify Slack & Publish Release Notes (push) Has been cancelled
Publish Documentation / Evaluate release tag (push) Has been cancelled
Publish Documentation / Prebuild Docs (push) Has been cancelled
Publish Documentation / Preview Docs (push) Has been cancelled
Publish Documentation / Check for file changes (push) Has been cancelled
Publish Documentation / Publish Docs (push) Has been cancelled
Automatic PR Merger / mergepal (push) Has been cancelled
CI Github Actions / Run Tests (push) Has been cancelled
Semgrep / Semgrep Workflow Security Scan (push) Has been cancelled
131 lines
4.1 KiB
Python
131 lines
4.1 KiB
Python
import pytest
|
|
from rasa.shared.nlu.training_data.formats.readerwriter import TrainingDataWriter
|
|
from rasa.shared.nlu.training_data.message import Message
|
|
from rasa.shared.constants import INTENT_MESSAGE_PREFIX
|
|
from typing import Text, List, Dict, Any
|
|
|
|
|
|
@pytest.mark.parametrize(
|
|
"message_text, expected_text, entities",
|
|
[
|
|
(
|
|
"I like chocolate",
|
|
"I like chocolate",
|
|
[],
|
|
),
|
|
(
|
|
"I like chocolate",
|
|
"I like [chocolate](food)",
|
|
[
|
|
{"entity": "food", "value": "chocolate", "start": 7, "end": 16},
|
|
],
|
|
),
|
|
(
|
|
"I like chocolate",
|
|
'I like [chocolate]{"entity": "food", "value": "desert"}',
|
|
[
|
|
{"entity": "food", "value": "desert", "start": 7, "end": 16},
|
|
],
|
|
),
|
|
(
|
|
f"{INTENT_MESSAGE_PREFIX}I like chocolate",
|
|
f"{INTENT_MESSAGE_PREFIX}I like chocolate",
|
|
[
|
|
{"entity": "food", "value": "desert", "start": 7, "end": 16},
|
|
],
|
|
),
|
|
(
|
|
"I like chocolate",
|
|
'I like [chocolate][{"entity": "food"}, {"entity": "desert"}]',
|
|
[
|
|
{"entity": "food", "value": "chocolate", "start": 7, "end": 16},
|
|
{"entity": "desert", "value": "chocolate", "start": 7, "end": 16},
|
|
],
|
|
),
|
|
(
|
|
"I like ice cream",
|
|
"I like [ice cream]"
|
|
'[{"entity": "food", "role": "liked"}, {"entity": "desert"}]',
|
|
[
|
|
{
|
|
"entity": "food",
|
|
"value": "ice cream",
|
|
"start": 7,
|
|
"end": 16,
|
|
"role": "liked",
|
|
},
|
|
{"entity": "desert", "value": "ice cream", "start": 7, "end": 16},
|
|
],
|
|
),
|
|
(
|
|
"I like ice cream with chocolate sprinkes",
|
|
"I like [ice cream]"
|
|
'[{"entity": "food", "role": "liked"}, {"entity": "desert"}] '
|
|
"with chocolate sprinkes",
|
|
[
|
|
{
|
|
"entity": "food",
|
|
"value": "ice cream",
|
|
"start": 7,
|
|
"end": 16,
|
|
"role": "liked",
|
|
},
|
|
{"entity": "desert", "value": "ice cream", "start": 7, "end": 16},
|
|
],
|
|
),
|
|
(
|
|
"I like ice cream with chocolate sprinkes",
|
|
"I like [ice cream]"
|
|
'[{"entity": "food", "role": "liked"}, {"entity": "desert"}] '
|
|
"with [chocolate sprinkes]"
|
|
"(food)",
|
|
[
|
|
{
|
|
"entity": "food",
|
|
"value": "ice cream",
|
|
"start": 7,
|
|
"end": 16,
|
|
"role": "liked",
|
|
},
|
|
{"entity": "desert", "value": "ice cream", "start": 7, "end": 16},
|
|
{
|
|
"entity": "food",
|
|
"value": "chocolate sprinkes",
|
|
"start": 22,
|
|
"end": 40,
|
|
},
|
|
],
|
|
),
|
|
],
|
|
)
|
|
def test_generate_message(
|
|
message_text: Text,
|
|
expected_text: Text,
|
|
entities: List[Dict[Text, Any]],
|
|
):
|
|
message = Message.build(message_text, "dummy_intent", entities=entities)
|
|
message_text = TrainingDataWriter.generate_message(message)
|
|
|
|
assert message_text == expected_text
|
|
|
|
|
|
@pytest.mark.parametrize(
|
|
"message_text, entities",
|
|
[
|
|
(
|
|
"I like chocolate cake",
|
|
[
|
|
{"entity": "food", "value": "chocolate", "start": 7, "end": 16},
|
|
{"entity": "desert", "value": "chocolate cake", "start": 7, "end": 21},
|
|
],
|
|
),
|
|
],
|
|
)
|
|
def test_generate_message_raises_on_overlapping_but_not_identical_spans(
|
|
message_text: Text,
|
|
entities: List[Dict[Text, Any]],
|
|
):
|
|
message = Message.build(message_text, "dummy_intent", entities=entities)
|
|
with pytest.raises(ValueError):
|
|
TrainingDataWriter.generate_message(message)
|