i have a some problems understanding the following Code.
I have a class inside a class (it was given that way and we should use it like this) and i want to use the Fitter class to change the vocabulary attribute of the Tokenizer class.
The problem is i dont understand how i can access the Parent Objekt.
Here is the code of my classes:
class Tokenizer(TokenizerABC):
def __init__(
self,
vocabulary,
pre_tokenizer
):
self._vocabulary = vocabulary
self._pre_tokenizer = pre_tokenizer
class Fitter(TokenizerABC.Fitter["Tokenizer"]):
"""A builder-style object for fitting a tokenizer to a corpus."""
def __init__(self, lowercase=False, limit=None):
...
def fit(self, corpus: list[str]) -> TokenizerABC:
"""Fit a tokenizer to the given corpus.
Args:
corpus (list[str]): The corpus to fit the tokenizer to.
Returns:
Parent (Generic[TokenizerABC]): The fitted tokenizer.
"""
# some code
vocabulary = # some code
return ...
@classmethod
def fitter(cls) -> 'Tokenizer.Fitter':# -> Fitter[Self]:
"""Create a new Fitter object for this tokenizer.
Returns:
Fitter[Self]: The Fitter object for this tokenizer.
"""
return ...
And in the test code he initializes the Objekts with:
abcd = ["a a a b", "c c c d d"]
tokenizer = Tokenizer.fitter().fit(abcd)
I use Python 3.12