utils
pymusas.spacy_api.utils
Helper functions for anything spaCy related in the code base.
set_custom_token_extension
def set_custom_token_extension(extension_name: str) -> None
Defines a custom attribute of the spaCy Token which becomes avaliable
via Token._.{extension_name}. The difference between this and using the
spaCy Token.set_extension method
is this method will check if the extension exists already and if so will force it
through and output an UserWarning message that it has had to force this through.
Parameters¶
- extension_name :
str
Name of the custom attribute that will become avaliable throughToken._.{extension_name}.
update_factory_attributes
def update_factory_attributes(
meta_information_to_update: str,
factory_name: str,
new_attribute_name: str,
old_attribute_name: str
) -> None
Updates the
spaCy Language meta information
for either assigns or requires for the given component, find through
it's factory name, by replacing the old_attribute_name with the
new_attribute_name.
Parameters¶
- meta_information_to_update :
str
Eitherassignsorrequires, raises a ValueError if it is any other value. - factory_name :
str
The name of the component factory, e.g.pymusas_rule_based_tagger - new_attribute_name :
str
The name of the new attribute that is required for this component. An example,token.pos. - old_attribute_name :
str
The name of the old attribute that is to be replaced with thenew_attribute_name. An example,token.tag.