Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions textblob/en/np_extractors.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,9 @@ def extract(self, sentence):
merge = True
while merge:
merge = False
for x in range(0, len(tags) - 1):

x = 0
while x < len(tags) - 1:
t1 = tags[x]
t2 = tags[x + 1]
key = t1[1], t2[1]
Expand All @@ -154,7 +156,7 @@ def extract(self, sentence):
match = '%s %s' % (t1[0], t2[0])
pos = value
tags.insert(x, (match, pos))
break
x = x + 1

matches = [t[0] for t in tags if t[1] in ['NNP', 'NNI']]
return matches
Expand Down Expand Up @@ -188,7 +190,8 @@ def _is_match(tagged_phrase, cfg):
merge = True
while merge:
merge = False
for i in range(len(copy) - 1):
i = 0
while i < len(copy) - 1:
first, second = copy[i], copy[i + 1]
key = first[1], second[1] # Tuple of tags e.g. ('NN', 'JJ')
value = cfg.get(key, None)
Expand All @@ -199,6 +202,7 @@ def _is_match(tagged_phrase, cfg):
match = '{0} {1}'.format(first[0], second[0])
pos = value
copy.insert(i, (match, pos))
break
i = i + 1

match = any([t[1] in ('NNP', 'NNI') for t in copy])
return match