Merge pull request #310 from gumblex/master

Fix compatibility problem with `with` statememt
This commit is contained in:
Sun Junyi 2015-11-13 14:22:50 +08:00
commit 3d29b0c8e8
2 changed files with 26 additions and 26 deletions

View File

@ -71,7 +71,6 @@ class Tokenizer(object):
lfreq = {}
ltotal = 0
f_name = resolve_filename(f)
with f:
for lineno, line in enumerate(f, 1):
try:
line = line.strip().decode('utf-8')
@ -86,6 +85,7 @@ class Tokenizer(object):
except ValueError:
raise ValueError(
'invalid dictionary entry in %s at Line %s: %s' % (f_name, lineno, line))
f.close()
return lfreq, ltotal
def initialize(self, dictionary=None):

View File

@ -97,7 +97,6 @@ class POSTokenizer(object):
def load_word_tag(self, f):
self.word_tag_tab = {}
f_name = resolve_filename(f)
with f:
for lineno, line in enumerate(f, 1):
try:
line = line.strip().decode("utf-8")
@ -108,6 +107,7 @@ class POSTokenizer(object):
except Exception:
raise ValueError(
'invalid POS dictionary entry in %s at Line %s: %s' % (f_name, lineno, line))
f.close()
def makesure_userdict_loaded(self):
if self.tokenizer.user_word_tag_tab: