I am pretty new to python, and I am trying to inherit a superclass.
The superclass looks like:
class LanguageModel:
# Initialize and train the model (ie, estimate the model's underlying probability
# distribution from the training corpus)
def __init__(self, corpus):
print("""Your task is to implement three kinds of n-gram language models:
#enddef
# Generate a sentence by drawing words according to the
# model's probability distribution
# Note: think about how to set the length of the sentence
# in a principled way
def generateSentence(self):
print("Implement the generateSentence method in each subclass")
return "mary had a little lamb ."
#emddef
And here is the subclass
class UnigramModel(LanguageModel):
def __init__(self, corpus):
print("Subtask: implement the unsmoothed unigram language model")
#endddef
def generateSentence(self):
# Gets the total number of words in the corpus
wordCount = 0
for sentence in self.corpus:
for word in sentence:
wordCount += 1
print(wordCount)
I first tried to get the total wordcount in the corpus by doing the above, but it gives me an error that says "UnigramModel' object has no attribute 'corpus' when I try to call that function.
def __init__(self, corpus):addself.corpus = corpus.