feat: case insensitive keywords
This commit is contained in:
@@ -107,7 +107,7 @@ class AgentSpeakGenerator:
|
|||||||
check if a keyword is a substring of the user's message.
|
check if a keyword is a substring of the user's message.
|
||||||
|
|
||||||
The generated rule has the form:
|
The generated rule has the form:
|
||||||
keyword_said(Keyword) :- user_said(Message) & .substring(Keyword, Message, Pos) & Pos >= 0
|
keyword_said(Keyword) :- user_said(Message) & .substring_case_insensitive(Keyword, Message, Pos) & Pos >= 0
|
||||||
|
|
||||||
This enables the system to trigger behaviors based on keyword detection.
|
This enables the system to trigger behaviors based on keyword detection.
|
||||||
"""
|
"""
|
||||||
@@ -119,7 +119,7 @@ class AgentSpeakGenerator:
|
|||||||
AstRule(
|
AstRule(
|
||||||
AstLiteral("keyword_said", [keyword]),
|
AstLiteral("keyword_said", [keyword]),
|
||||||
AstLiteral("user_said", [message])
|
AstLiteral("user_said", [message])
|
||||||
& AstLiteral(".substring", [keyword, message, position])
|
& AstLiteral(".substring_case_insensitive", [keyword, message, position])
|
||||||
& (position >= 0),
|
& (position >= 0),
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -342,6 +342,28 @@ class BDICoreAgent(BaseAgent):
|
|||||||
the function expects (which will be located in `term.args`).
|
the function expects (which will be located in `term.args`).
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
@self.actions.add(".substring_case_insensitive", 3)
|
||||||
|
@agentspeak.optimizer.function_like
|
||||||
|
def _substring(agent, term, intention):
|
||||||
|
"""
|
||||||
|
Find out if a string is a substring of another (case insensitive). Copied mostly from
|
||||||
|
the agentspeak library method .substring.
|
||||||
|
"""
|
||||||
|
needle = agentspeak.asl_str(agentspeak.grounded(term.args[0], intention.scope)).lower()
|
||||||
|
haystack = agentspeak.asl_str(agentspeak.grounded(term.args[1], intention.scope)).lower()
|
||||||
|
|
||||||
|
choicepoint = object()
|
||||||
|
|
||||||
|
pos = haystack.find(needle)
|
||||||
|
while pos != -1:
|
||||||
|
intention.stack.append(choicepoint)
|
||||||
|
|
||||||
|
if agentspeak.unify(term.args[2], pos, intention.scope, intention.stack):
|
||||||
|
yield
|
||||||
|
|
||||||
|
agentspeak.reroll(intention.scope, intention.stack, choicepoint)
|
||||||
|
pos = haystack.find(needle, pos + 1)
|
||||||
|
|
||||||
@self.actions.add(".reply", 2)
|
@self.actions.add(".reply", 2)
|
||||||
def _reply(agent, term, intention):
|
def _reply(agent, term, intention):
|
||||||
"""
|
"""
|
||||||
@@ -467,7 +489,6 @@ class BDICoreAgent(BaseAgent):
|
|||||||
body=str(trigger_name),
|
body=str(trigger_name),
|
||||||
)
|
)
|
||||||
|
|
||||||
# TODO: check with Pim
|
|
||||||
self.add_behavior(self.send(msg))
|
self.add_behavior(self.send(msg))
|
||||||
|
|
||||||
yield
|
yield
|
||||||
|
|||||||
Reference in New Issue
Block a user