I have a two-class inheritance hierarchy:
class TfIdfSimilarity(SimilarityModel):
@property
def corpus(self):
return self.model[self._corpus]
@property
def model(self):
return TfidfModel(self._corpus, dictionary=self._dict)
class LsiSimilarity(TfIdfSimilarity):
@property
def corpus(self):
tfidf_corpus = super().corpus
return self.model[tfidf_corpus]
@property
def model(self):
tfidf_corpus = super().corpus
return LsiModel(tfidf_corpus)
However, this is causing an infinite recursion error, because whenever I try to get the LsiSimilarity#model
, it calls TfIdfSimilarity#corpus
, which then tries to access the model, and thus calls LsiSimilarity#model
again.
What I actually want is for TfIdfSimilarity#corpus
to only ever call TfIdfSimilarity#model
, and never consider the child class's version of it.
Is this possible in Python? (Python 3) If not, how can I better structure my inheritance hierarchy, while still providing the same API via the corpus
and model
functions (which are used by my main logic).