mirror of
				https://github.com/explosion/spaCy.git
				synced 2025-10-30 23:47:31 +03:00 
			
		
		
		
	Fix setting empty entities in Example.from_dict (#8426)
This commit is contained in:
		
							parent
							
								
									81515b4690
								
							
						
					
					
						commit
						e3f1d4a7d0
					
				|  | @ -182,6 +182,27 @@ def test_Example_from_dict_with_entities(annots): | |||
|     assert example.reference[5].ent_type_ == "LOC" | ||||
| 
 | ||||
| 
 | ||||
| def test_Example_from_dict_with_empty_entities(): | ||||
|     annots = { | ||||
|         "words": ["I", "like", "New", "York", "and", "Berlin", "."], | ||||
|         "entities": [], | ||||
|     } | ||||
|     vocab = Vocab() | ||||
|     predicted = Doc(vocab, words=annots["words"]) | ||||
|     example = Example.from_dict(predicted, annots) | ||||
|     # entities as empty list sets everything to O | ||||
|     assert example.reference.has_annotation("ENT_IOB") | ||||
|     assert len(list(example.reference.ents)) == 0 | ||||
|     assert all(token.ent_iob_ == "O" for token in example.reference) | ||||
|     # various unset/missing entities leaves entities unset | ||||
|     annots["entities"] = None | ||||
|     example = Example.from_dict(predicted, annots) | ||||
|     assert not example.reference.has_annotation("ENT_IOB") | ||||
|     annots.pop("entities", None) | ||||
|     example = Example.from_dict(predicted, annots) | ||||
|     assert not example.reference.has_annotation("ENT_IOB") | ||||
| 
 | ||||
| 
 | ||||
| @pytest.mark.parametrize( | ||||
|     "annots", | ||||
|     [ | ||||
|  |  | |||
|  | @ -416,7 +416,7 @@ def _fix_legacy_dict_data(example_dict): | |||
|     token_dict = example_dict.get("token_annotation", {}) | ||||
|     doc_dict = example_dict.get("doc_annotation", {}) | ||||
|     for key, value in example_dict.items(): | ||||
|         if value: | ||||
|         if value is not None: | ||||
|             if key in ("token_annotation", "doc_annotation"): | ||||
|                 pass | ||||
|             elif key == "ids": | ||||
|  |  | |||
		Loading…
	
		Reference in New Issue
	
	Block a user