mirror of
				https://github.com/explosion/spaCy.git
				synced 2025-10-30 23:47:31 +03:00 
			
		
		
		
	Improve Morphology errors (#4314)
* Improve Morphology errors * Also clean up some other errors * Update errors.py
This commit is contained in:
		
							parent
							
								
									9bf69bfbb2
								
							
						
					
					
						commit
						16aa092fb5
					
				|  | @ -469,6 +469,13 @@ class Errors(object): | ||||||
|             "that case.") |             "that case.") | ||||||
|     E166 = ("Can only merge DocBins with the same pre-defined attributes.\n" |     E166 = ("Can only merge DocBins with the same pre-defined attributes.\n" | ||||||
|             "Current DocBin: {current}\nOther DocBin: {other}") |             "Current DocBin: {current}\nOther DocBin: {other}") | ||||||
|  |     E167 = ("Unknown morphological feature: '{feat}' ({feat_id}). This can " | ||||||
|  |             "happen if the tagger was trained with a different set of " | ||||||
|  |             "morphological features. If you're using a pre-trained model, make " | ||||||
|  |             "sure that your models are up to date:\npython -m spacy validate") | ||||||
|  |     E168 = ("Unknown field: {field}") | ||||||
|  |     E169 = ("Can't find module: {module}") | ||||||
|  |     E170 = ("Cannot apply transition {name}: invalid for the current state.") | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| @add_codes | @add_codes | ||||||
|  |  | ||||||
|  | @ -197,7 +197,7 @@ cdef class Morphology: | ||||||
|         cdef attr_t feature |         cdef attr_t feature | ||||||
|         for feature in features: |         for feature in features: | ||||||
|             if feature != 0 and feature not in self._feat_map.id2feat: |             if feature != 0 and feature not in self._feat_map.id2feat: | ||||||
|                 raise KeyError("Unknown feature: %s" % self.strings[feature]) |                 raise ValueError(Errors.E167.format(feat=self.strings[feature], feat_id=feature)) | ||||||
|         cdef MorphAnalysisC tag |         cdef MorphAnalysisC tag | ||||||
|         tag = create_rich_tag(features) |         tag = create_rich_tag(features) | ||||||
|         cdef hash_t key = self.insert(tag) |         cdef hash_t key = self.insert(tag) | ||||||
|  | @ -531,7 +531,7 @@ cdef attr_t get_field(const MorphAnalysisC* tag, int field_id) nogil: | ||||||
|     elif field == Field_VerbType: |     elif field == Field_VerbType: | ||||||
|         return tag.verb_type |         return tag.verb_type | ||||||
|     else: |     else: | ||||||
|         raise ValueError("Unknown field: (%d)" % field_id) |         raise ValueError(Errors.E168.format(field=field_id)) | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| cdef int check_feature(const MorphAnalysisC* tag, attr_t feature) nogil: | cdef int check_feature(const MorphAnalysisC* tag, attr_t feature) nogil: | ||||||
|  | @ -726,7 +726,7 @@ cdef int set_feature(MorphAnalysisC* tag, | ||||||
|     elif field == Field_VerbType: |     elif field == Field_VerbType: | ||||||
|         tag.verb_type = value_ |         tag.verb_type = value_ | ||||||
|     else: |     else: | ||||||
|         raise ValueError("Unknown feature: %s (%d)" % (FEATURE_NAMES.get(feature), feature)) |         raise ValueError(Errors.E167.format(field=FEATURE_NAMES.get(feature), field_id=feature)) | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| FIELDS = { | FIELDS = { | ||||||
|  |  | ||||||
|  | @ -96,8 +96,7 @@ cdef class TransitionSystem: | ||||||
| 
 | 
 | ||||||
|     def apply_transition(self, StateClass state, name): |     def apply_transition(self, StateClass state, name): | ||||||
|         if not self.is_valid(state, name): |         if not self.is_valid(state, name): | ||||||
|             raise ValueError( |             raise ValueError(Errors.E170.format(name=name)) | ||||||
|                 "Cannot apply transition {name}: invalid for the current state.".format(name=name)) |  | ||||||
|         action = self.lookup_transition(name) |         action = self.lookup_transition(name) | ||||||
|         action.do(state.c, action.label) |         action.do(state.c, action.label) | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -136,7 +136,7 @@ def load_language_data(path): | ||||||
| 
 | 
 | ||||||
| def get_module_path(module): | def get_module_path(module): | ||||||
|     if not hasattr(module, "__module__"): |     if not hasattr(module, "__module__"): | ||||||
|         raise ValueError("Can't find module {}".format(repr(module))) |         raise ValueError(Errors.E169.format(module=repr(module))) | ||||||
|     return Path(sys.modules[module.__module__].__file__).parent |     return Path(sys.modules[module.__module__].__file__).parent | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue
	
	Block a user