Skip to content

Instantly share code, notes, and snippets.

@Witty-Kitty
Created February 18, 2019 11:54
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Witty-Kitty/08d0a79177d004a379a16ea14a05c146 to your computer and use it in GitHub Desktop.
Save Witty-Kitty/08d0a79177d004a379a16ea14a05c146 to your computer and use it in GitHub Desktop.
Text pre-processing
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