def test_get_ents_returns_dictionary_given_empty_string_causes_empty_spacy_doc_ents( self): model = NerModelTestDouble('eng') model.returns_doc_ents([]) ner = NamedEntityClient(model) ents = ner.get_ents("") self.assertIsInstance(ents, dict)
def test_get_ents_returns_list_given_nonempty_string_causes_empty_spacy_doc_ents( self): model = NerModelTestDouble('eng') model.returns_doc_ents([]) ner = NamedEntityClient(model) ents = ner.get_ents("Madison is a city in Wisconin") self.assertIsInstance(ents, dict)
def test_get_ents_given_multiple_ents_serializes_all(self): model = NerModelTestDouble('eng') doc_ents = [{'text': 'Denmark', 'label_': 'GPE'},{'text': 'Jerry Springer', 'label_': 'PERSON'}] model.returns_doc_ents(doc_ents) ner = NamedEntityClient(model) result = ner.get_ents('xxxxxxx') expected_result = {'ents': [{'ent': 'Denmark', 'label': 'Location'},{'ent': 'Jerry Springer', 'label': 'Person'}], 'html': ""} self.assertListEqual(result['ents'], expected_result['ents'])
def test_get_ents_given_spacy_GPE_is_returned_serializes_to_Location(self): model = NerModelTestDouble('eng') doc_ents = [{'text': 'Denmark', 'label_': 'GPE'}] model.returns_doc_ents(doc_ents) ner = NamedEntityClient(model) result = ner.get_ents('xxxxxxx') expected_result = {'ents': [{'ent': 'Denmark', 'label': 'Location'}], 'html': ""} self.assertListEqual(result['ents'], expected_result['ents'])
def test_get_ents_given_spacy_NORP_is_returned_serializes_to_Group(self): model = NerModelTestDouble('eng') doc_ents = [{'text': 'Iceland', 'label_': 'NORP'}] model.returns_doc_ents(doc_ents) ner = NamedEntityClient(model) result = ner.get_ents('xxxxxxx') expected_result = {'ents': [{'ent': 'Iceland', 'label': 'Group'}], 'html': ""} self.assertListEqual(result['ents'], expected_result['ents'])
def test_get_ents_given_spacy_PERSON_is_returned_serializes_to_Person(self): model = NerModelTestDouble('eng') doc_ents = [{'text': 'Paul Graham', 'label_': 'PERSON'}] model.returns_doc_ents(doc_ents) ner = NamedEntityClient(model) result = ner.get_ents('xxxxxxx') expected_result = {'ents': [{'ent': 'Paul Graham', 'label': 'Person'}], 'html': ""} self.assertListEqual(result['ents'], expected_result['ents'])
def test_get_ents_given_spacy_LANGUAGE_is_returned_serializes_to_Language(self): model = NerModelTestDouble('eng') doc_ents = [{'text': 'ASL', 'label_': 'LANGUAGE'}] model.returns_doc_ents(doc_ents) ner = NamedEntityClient(model) ents = ner.get_ents('...') expected_result = {'ents': [{'ent': 'ASL', 'label': 'Language'}], 'html': ""} self.assertListEqual(ents['ents'], expected_result['ents'])
def test_get_ents_given_spacy_LOC_is_returned_serializes_to_Location(self): model = NerModelTestDouble('eng') doc_ents = [{'text': 'the ocean', 'label_': 'LOC'}] model.returns_doc_ents(doc_ents) ner = NamedEntityClient(model) ents = ner.get_ents('...') expected_result = {'ents': [{'ent': 'the ocean', 'label': 'Location'}], 'html': ""} self.assertListEqual(ents['ents'], expected_result['ents'])
def test_get_ents_given_multiple_ents_serializes_all(self): model = NerModelTestDouble('eng') doc_ents = [{'text': 'Australia', 'label_': 'GPE'}, {'text': 'Judith Polgar', 'label_': 'PERSON'}] model.returns_doc_ents(doc_ents) ner = NamedEntityClient(model) ents = ner.get_ents('...') expected_result = {'ents': [{'ent': 'Australia', 'label': 'Location'}, {'ent': 'Judith Polgar', 'label': 'Person'}], 'html': ""} self.assertListEqual(ents['ents'], expected_result['ents'])
def test_get_ents_given_multiple_ents_serializes_all(self): model = NerModelTestDouble('eng') doc_ents = [{ 'text': 'Australia', 'label_': 'GPE' }, { 'text': 'ASL', 'label_': 'LANGUAGE' }] model.return_doc_ents(doc_ents) ner = NamedEntityClient(model) result = ner.get_ents('...') expected_result = { 'ents': [{ 'ent': 'Australia', 'label': 'Location' }, { 'ent': 'ASL', 'label': 'Language' }], 'html': "" } self.assertEqual(result['ents'], expected_result['ents'])