Skip to content

Commit

Permalink
Merge pull request #135 from forslund/bugfix/remove-regexp
Browse files Browse the repository at this point in the history
Fix storing regex as string when cleaned
  • Loading branch information
forslund authored Jun 24, 2021
2 parents 4a8fe8a + a190983 commit 4e9f9b2
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 5 deletions.
11 changes: 7 additions & 4 deletions adapt/engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -232,12 +232,15 @@ def default_match_func(regexp):
if match_func(r)]
matching_patterns = [r.pattern for r in matches]

self.regular_expressions_entities = [
r for r in self.regular_expressions_entities if r not in matches
matches = [
r for r in self.regular_expressions_entities if r in matches
]
self._regex_strings = [
for match in matches:
self.regular_expressions_entities.remove(match)

self._regex_strings = {
r for r in self._regex_strings if r not in matching_patterns
]
}

return len(matches) != 0

Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def required(requirements_file):

setup(
name="adapt-parser",
version="0.4.1",
version="0.4.2",
author="Sean Fitzgerald",
author_email="sean@fitzgeralds.me",
description=("A text-to-intent parsing framework."),
Expand Down
31 changes: 31 additions & 0 deletions test/IntentEngineTest.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,37 @@ def matcher(regexp):
self.engine.drop_regex_entity(match_func=matcher)
assert len(self.engine._regex_strings) == 2
assert len(self.engine.regular_expressions_entities) == 2

def testAddingOfRemovedRegexp(self):
self.engine.register_regex_entity(r"the cool (?P<thing>.*)")

def matcher(regexp):
"""Matcher for all match groups defined for SkillB"""
match_groups = regexp.groupindex.keys()
return any([k.startswith('thing') for k in match_groups])

self.engine.drop_regex_entity(match_func=matcher)
assert len(self.engine.regular_expressions_entities) == 0
self.engine.register_regex_entity(r"the cool (?P<thing>.*)")
assert len(self.engine.regular_expressions_entities) == 1

def testUsingOfRemovedRegexp(self):
self.engine.register_regex_entity(r"the cool (?P<thing>.*)")
parser = IntentBuilder("Intent").require("thing").build()
self.engine.register_intent_parser(parser)

def matcher(regexp):
"""Matcher for all match groups defined for SkillB"""
match_groups = regexp.groupindex.keys()
return any([k.startswith('thing') for k in match_groups])

self.engine.drop_regex_entity(match_func=matcher)
assert len(self.engine.regular_expressions_entities) == 0

utterance = "the cool cat"
intents = [match for match in self.engine.determine_intent(utterance)]
assert len(intents) == 0

def testEmptyTags(self):
# Validates https://github.com/MycroftAI/adapt/issues/114
engine = IntentDeterminationEngine()
Expand Down

0 comments on commit 4e9f9b2

Please sign in to comment.