Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update validator.py warnings #4795

Merged
merged 14 commits into from
Dec 3, 2019
1 change: 1 addition & 0 deletions changelog/4795.feature.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Replaced the warnings about missing templates, intents etc. in validator.py by debug messages.
5 changes: 5 additions & 0 deletions docs/user-guide/validate-files.rst
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@ the script:

.. program-output:: rasa data validate --help

By default the validator searches only for errors in the data (e.g. the same
example being listed as an example for two intents), but does not report other
minor issues (such as unused intents, utterances that are not listed as
actions). To also report the later use the ``-debug`` flag.

You can also run these validations through the Python API by importing the `Validator` class,
which has the following methods:

Expand Down
5 changes: 1 addition & 4 deletions rasa/core/events/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,10 +144,7 @@ def _from_story_string(cls, parameters: Dict[Text, Any]) -> Optional[List["Event
return [cls(parameters.get("timestamp"), parameters.get("metadata"))]

def as_dict(self) -> Dict[Text, Any]:
d = {
"event": self.type_name,
"timestamp": self.timestamp,
}
d = {"event": self.type_name, "timestamp": self.timestamp}

if self.metadata:
d["metadata"] = self.metadata
Expand Down
29 changes: 18 additions & 11 deletions rasa/core/validator.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,17 +43,18 @@ def verify_intents(self, ignore_warnings: bool = True) -> bool:

for intent in self.domain.intents:
if intent not in nlu_data_intents:
warnings.warn(
logger.debug(
f"The intent '{intent}' is listed in the domain file, but "
"is not found in the NLU training data."
f"is not found in the NLU training data."
)
everything_is_alright = ignore_warnings and everything_is_alright

for intent in nlu_data_intents:
if intent not in self.domain.intents:
warnings.warn(
f"The intent '{intent}' is in the NLU training data, but "
f"is not listed in the domain."
f"is not listed in the domain.",
stacklevel=2,
)
everything_is_alright = False

Expand All @@ -77,7 +78,9 @@ def verify_example_repetition_in_intents(
everything_is_alright = ignore_warnings and everything_is_alright
intents_string = ", ".join(sorted(intents))
warnings.warn(
f"The example '{text}' was found in these multiples intents: {intents_string }"
f"The example '{text}' was found in multiple intents: "
f"{intents_string}.",
stacklevel=2,
)
return everything_is_alright

Expand All @@ -100,13 +103,14 @@ def verify_intents_in_stories(self, ignore_warnings: bool = True) -> bool:
if story_intent not in self.domain.intents:
warnings.warn(
f"The intent '{story_intent}' is used in stories, but is not "
f"listed in the domain file."
f"listed in the domain file.",
stacklevel=2,
)
everything_is_alright = False

for intent in self.domain.intents:
if intent not in stories_intents:
warnings.warn(f"The intent '{intent}' is not used in any story.")
logger.debug(f"The intent '{intent}' is not used in any story.")
everything_is_alright = ignore_warnings and everything_is_alright

return everything_is_alright
Expand All @@ -128,16 +132,18 @@ def verify_utterances(self, ignore_warnings: bool = True) -> bool:

for utterance in utterance_templates:
if utterance not in actions:
warnings.warn(
logger.debug(
f"The utterance '{utterance}' is not listed under 'actions' in the "
"domain file. It can only be used as a template."
f"domain file. It can only be used as a template."
)
everything_is_alright = ignore_warnings and everything_is_alright

for action in actions:
if action.startswith(UTTER_PREFIX):
if action not in utterance_templates:
warnings.warn(f"There is no template for utterance '{action}'.")
warnings.warn(
f"There is no template for utterance '{action}'.", stacklevel=2
)
everything_is_alright = False

return everything_is_alright
Expand Down Expand Up @@ -168,14 +174,15 @@ def verify_utterances_in_stories(self, ignore_warnings: bool = True) -> bool:
if event.action_name not in utterance_actions:
warnings.warn(
f"The utterance '{event.action_name}' is used in stories, but is not a "
f"valid utterance."
f"valid utterance.",
stacklevel=2,
)
everything_is_alright = False
stories_utterances.add(event.action_name)

for utterance in utterance_actions:
if utterance not in stories_utterances:
warnings.warn(f"The utterance '{utterance}' is not used in any story.")
logger.debug(f"The utterance '{utterance}' is not used in any story.")
everything_is_alright = ignore_warnings and everything_is_alright

return everything_is_alright
Expand Down
4 changes: 2 additions & 2 deletions tests/core/test_validator.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,8 @@ async def test_verify_logging_message_for_repetition_in_intents(caplog):
validator.verify_example_repetition_in_intents(False)
assert len(record) == 1
assert (
"The example 'good afternoon' was found in these "
"multiples intents: goodbye, greet" in record[0].message.args[0]
"The example 'good afternoon' was found in "
"multiple intents: goodbye, greet" in record[0].message.args[0]
)


Expand Down