Created
February 18, 2019 11:54
-
-
Save Witty-Kitty/08d0a79177d004a379a16ea14a05c146 to your computer and use it in GitHub Desktop.
Text pre-processing
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.tokenize import word_tokenize | |
from nltk.text import Text | |
# read in text data | |
file = open("crawl-for-parallel-corpora/DataSet/luganda.txt", "r") | |
raw = file.read() | |
# tokenize | |
tokens = word_tokenize(raw) | |
# remove punctuation, numbers and make everything lowercase | |
tokens = [word.lower() for word in tokens if word.isalpha()] | |
# write output to file | |
f = open("luganda", "w") | |
f.write(' '.join(tokens)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment