def test_spacy_ner_extractor(spacy_nlp): example = Message( data={ TEXT: "anywhere in the U.K.", "intent": "restaurant_search", "entities": [], "text_spacy_doc": spacy_nlp("anywhere in the west"), }) component = SpacyEntityExtractor(SpacyEntityExtractor.get_default_config()) component.process([example], model=SpacyModel(model=spacy_nlp, model_name="")) assert len(example.get("entities", [])) == 1 assert example.get("entities")[0] == { "start": 16, "extractor": "SpacyEntityExtractor", "end": 20, "value": "U.K.", "entity": "GPE", "confidence": None, } # Test dimension filtering includes only specified dimensions example = Message( data={ TEXT: "anywhere in the West with Sebastian Thrun", "intent": "example_intent", "entities": [], "text_spacy_doc": spacy_nlp("anywhere in the West with Sebastian Thrun"), }) component = SpacyEntityExtractor({"dimensions": ["PERSON"]}) component.process([example], model=SpacyModel(model=spacy_nlp, model_name="")) assert len(example.get("entities", [])) == 1 assert example.get("entities")[0] == { "start": 26, "extractor": "SpacyEntityExtractor", "end": 41, "value": "Sebastian Thrun", "entity": "PERSON", "confidence": None, }
assert os.path.exists( os.path.join(report_folder, "response_selection_histogram.png")) assert not os.path.exists( os.path.join(report_folder, "response_selection_errors.json")) assert os.path.exists( os.path.join(report_folder, "response_selection_successes.json")) @pytest.mark.parametrize( "components, expected_extractors", [ ([DIETClassifier({ENTITY_RECOGNITION: False})], set()), ([DIETClassifier({ENTITY_RECOGNITION: True})], {"DIETClassifier"}), ([CRFEntityExtractor()], {"CRFEntityExtractor"}), ( [SpacyEntityExtractor(), CRFEntityExtractor()], {"SpacyEntityExtractor", "CRFEntityExtractor"}, ), ([ResponseSelector()], set()), ], ) def test_get_entity_extractors(components, expected_extractors): mock_interpreter = Interpreter(components, None) extractors = get_entity_extractors(mock_interpreter) assert extractors == expected_extractors def test_entity_evaluation_report(tmpdir_factory): class EntityExtractorA(EntityExtractor):
assert not os.path.exists( os.path.join(report_folder, "response_selection_errors.json") ) assert os.path.exists( os.path.join(report_folder, "response_selection_successes.json") ) @pytest.mark.parametrize( "components, expected_extractors", [ ([DIETClassifier({ENTITY_RECOGNITION: False})], set()), ([DIETClassifier({ENTITY_RECOGNITION: True})], {"DIETClassifier"}), ([CRFEntityExtractor()], {"CRFEntityExtractor"}), ( [SpacyEntityExtractor(), CRFEntityExtractor()], {"SpacyEntityExtractor", "CRFEntityExtractor"}, ), ([ResponseSelector()], set()), ], ) def test_get_entity_extractors( components: List[Component], expected_extractors: Set[Text] ): mock_interpreter = Interpreter(components, None) extractors = get_entity_extractors(mock_interpreter) assert extractors == expected_extractors def test_entity_evaluation_report(tmp_path: Path):