This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import nltk | |
from nltk import * | |
import random | |
from nltk.corpus.reader import CategorizedPlaintextCorpusReader | |
file = "dataset" | |
collCategorized= CategorizedPlaintextCorpusReader(file, r'.*\.txt', cat_pattern=r'(\w+)/*',encoding="utf8") | |
documents=[(list(collCategorized.words(fileid)), category) for category in collCategorized.categories() | |
for fileid in collCategorized.fileids(category)] | |
random.shuffle(documents) |