Created
September 12, 2013 04:02
-
-
Save menzenski/6532911 to your computer and use it in GitHub Desktop.
tokenizes Russian text
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
#! /usr/bin/env python | |
# -*- coding: utf-8 -*- | |
import nltk | |
import codecs | |
from urllib import urlopen | |
def print_list(mylist): | |
'''Print a list containing unicode characters.''' | |
print '[' + ', '.join( | |
"" + word.encode('utf8') + "" for word in mylist) + ']' | |
data = codecs.open("masterandmargarita.txt", encoding="utf8") | |
text = data.read() | |
tokens = nltk.word_tokenize(text) | |
print len(tokens) | |
print len(set(tokens)) | |
print_list(tokens[:200]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment