Skip to content

Commit

Permalink
Merge 7b7375e into 894f333
Browse files Browse the repository at this point in the history
  • Loading branch information
paulaWesselmann committed Mar 6, 2019
2 parents 894f333 + 7b7375e commit 5e9422b
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 9 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ Removed

Fixed
-----
- ``RegexFeaturizer`` detects all regex in user message (not just first)

[0.14.3] - 2019-02-01
^^^^^^^^^^^^^^^^^^^^^
Expand Down
19 changes: 10 additions & 9 deletions rasa_nlu/featurizers/regex_featurizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,18 +72,19 @@ def features_for_patterns(self, message):
relating the name of the regex to whether it was matched."""

matches = []
for i, exp in enumerate(self.known_patterns):
match = re.search(exp["pattern"], message.text)
matches.append(match)
for exp in self.known_patterns:
match = re.finditer(exp["pattern"], message.text)
match_item = [mat for mat in match]
matches.append(None)
for token_index, t in enumerate(message.get("tokens", [])):
patterns = t.get("pattern", default={})
if match is not None:
if t.offset < match.end() and t.end > match.start():
patterns[exp["name"]] = False

for mat in match_item:
if t.offset < mat.end() and t.end > mat.start():
patterns[exp["name"]] = True
else:
patterns[exp["name"]] = False
else:
patterns[exp["name"]] = False
matches[-1] = True

t.set("pattern", patterns)
found = [1.0 if m is not None else 0.0 for m in matches]
return np.array(found)
Expand Down

0 comments on commit 5e9422b

Please sign in to comment.