Skip to content

Commit

Permalink
Remove warning on gensim import "pattern not installed". Fix #1009 (#…
Browse files Browse the repository at this point in the history
…1018)

* has_pattern removed from utils, pattern check moved to utils.lemmatize

* default value for lemmatize in corpora/wikicorpus.__init__ changed to True

* duplicate check for pattern removed from corpora/wikicorpus

* exception handling added in lematize if pattern not found

* wikicorpus lemmatize call giving error issue fixed

* syntax error fix in lematize

* multiple import checks for pattern in utils removed, single import added

* pattern check statement changed in has_pattern method
  • Loading branch information
shashankg7 authored and tmylk committed Nov 16, 2016
1 parent 284a9f7 commit 80e9c98
Showing 1 changed file with 4 additions and 8 deletions.
12 changes: 4 additions & 8 deletions gensim/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,6 @@ def smart_open(fname, mode='rb'):
RE_HTML_ENTITY = re.compile(r'&(#?)([xX]?)(\w{1,8});', re.UNICODE)



def synchronous(tlockname):
"""
A decorator to place an instance-based lock around a method.
Expand Down Expand Up @@ -1005,15 +1004,13 @@ def pyro_daemon(name, obj, random_suffix=False, ip=None, port=None, ns_conf={}):

def has_pattern():
"""
Function to check if there is installed pattern library
Function which returns a flag indicating whether pattern is installed or not
"""
pattern = False
try:
from pattern.en import parse
pattern = True
return True
except ImportError:
warnings.warn("Pattern library is not installed, lemmatization won't be available.")
return pattern
return False


def lemmatize(content, allowed_tags=re.compile('(NN|VB|JJ|RB)'), light=False,
Expand All @@ -1038,8 +1035,7 @@ def lemmatize(content, allowed_tags=re.compile('(NN|VB|JJ|RB)'), light=False,
"""
if not has_pattern():
raise ImportError("Pattern library is not installed. Pattern library is needed in order \
to use lemmatize function")
raise ImportError("Pattern library is not installed. Pattern library is needed in order to use lemmatize function")
from pattern.en import parse

if light:
Expand Down

0 comments on commit 80e9c98

Please sign in to comment.