Test that running an entity_ruler after ner gives consistent results
()
| 177 | |
| 178 | @pytest.mark.issue(4267) |
| 179 | def test_issue4267(): |
| 180 | """Test that running an entity_ruler after ner gives consistent results""" |
| 181 | nlp = English() |
| 182 | ner = nlp.add_pipe("ner") |
| 183 | ner.add_label("PEOPLE") |
| 184 | nlp.initialize() |
| 185 | assert "ner" in nlp.pipe_names |
| 186 | # assert that we have correct IOB annotations |
| 187 | doc1 = nlp("hi") |
| 188 | assert doc1.has_annotation("ENT_IOB") |
| 189 | for token in doc1: |
| 190 | assert token.ent_iob == 2 |
| 191 | # add entity ruler and run again |
| 192 | patterns = [{"label": "SOFTWARE", "pattern": "spacy"}] |
| 193 | ruler = nlp.add_pipe("entity_ruler") |
| 194 | ruler.add_patterns(patterns) |
| 195 | assert "entity_ruler" in nlp.pipe_names |
| 196 | assert "ner" in nlp.pipe_names |
| 197 | # assert that we still have correct IOB annotations |
| 198 | doc2 = nlp("hi") |
| 199 | assert doc2.has_annotation("ENT_IOB") |
| 200 | for token in doc2: |
| 201 | assert token.ent_iob == 2 |
| 202 | |
| 203 | |
| 204 | @pytest.mark.issue(4313) |
nothing calls this directly
no test coverage detected
searching dependent graphs…