seed = random.randrange(n-1, size) for i in range(seed - (n-1), seed): context.append(wordlist[i]) return context, wordlist[seed][0] # corpus, trainCorpus, testCorpus, testSents = corpus.loadCorpus() corpus, trainCorpus, testCorpus, testSents = corpus.loadCorpus("POP") # corpus, trainCorpus, testCorpus, testSents = corpus.loadCorpus("ROCK") # print (testCorpus) nTag = 2 nWord = 4 n = max(nTag, nWord) tm = NgramTagModel(nTag,nWord,trainCorpus,0.5) # testTag = tm.tagTestCorpus(testCorpus) totalTest = 0 correctTest = 0 for sent in testSents: tagSent = tm.tagTestCorpus(sent) if(len(list(sent)) >= n): print (sent) context, correctWord = getWordContext(tagSent, n) print (context, correctWord) predictWord = tm.nextWord(context) print (predictWord) totalTest += 1 if(totalTest >= 100): break
__author__ = 'Salma' #from nGram import NgramTagModel,nGramModel import corpus.lyric_corpus.corpus_access as corpus from nGram.NgramTagModel import NgramTagModel trainCorpus, testCorpus, devCorpus = corpus.loadCorpus("POP") # trainCorpus, testCorpus, devCorpus = corpus.loadCorpus("ROCK") # print (testCorpus) tm = NgramTagModel(3,2,trainCorpus) testTag = tm.tagTestCorpus(testCorpus) context = tm.getRandomContext(testTag) print("Context", context) print(tm.nextWord(context)) # print(sents)