Permalink
Browse files

Merge pull request #30 from aleksandrpanteleymonov/master

Fix analyze_classifier_coverage when using --ngrams parameter
  • Loading branch information...
2 parents 85f42eb + 3b60292 commit e245bd5bb1a7c4cb9a7327b6f8b35b29c0fba74e @japerk committed Aug 5, 2015
Showing with 6 additions and 2 deletions.
  1. +6 −2 analyze_classifier_coverage.py
@@ -1,5 +1,5 @@
#!/usr/bin/env python
-import argparse, collections, itertools, operator, re, string, time
+import argparse, collections, functools, itertools, operator, re, string, time
import nltk.data
from nltk.classify.util import accuracy
from nltk.corpus import stopwords
@@ -106,8 +106,12 @@ def norm_words(words):
if stopset:
words = [w for w in words if w.lower() not in stopset]
+ # in case we modified words in a generator, ensure it's a list so we can add together
+ if not isinstance(words, list):
+ words = list(words)
+
if args.ngrams:
- return reduce(operator.add, [words if n == 1 else ngrams(words, n) for n in args.ngrams])
+ return functools.reduce(operator.add, [words if n == 1 else list(ngrams(words, n)) for n in args.ngrams])
else:
return words

0 comments on commit e245bd5

Please sign in to comment.