weixin_39672396
weixin_39672396
2021-01-12 03:40

bugfix/utterance remainder, only replace complete words

Description

“Turn the room light on in 30 seconds” will return a remainder of “Turn in 30 secds”

utterance remainder now is parsed word by word instead of just replacing the keywords in the string

bug originally reported here

How to test

make an intent with following required keywords

state.voc -> on / off action.voc -> turn / switch object.voc -> light / bulb / plug

say “Turn the room light on in 30 seconds”

check utterance remainder, notice "on" will no longer be wrongly replaced in "seconds"

Contributor license agreement signed?

CLA [yes ] (Whether you have signed a CLA - Contributor Licensing Agreement

该提问来源于开源项目:MycroftAI/mycroft-core

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享
  • 邀请回答

5条回答

  • weixin_39821874 weixin_39821874 4月前

    Hello ! Thanks for submitting the PR.

    点赞 评论 复制链接分享
  • weixin_39562998 weixin_39562998 4月前

    Can we do something slightly simpler:

    python
            utt = normalize(self.data.get("utterance", ""))
            if utt and "__tags__" in self.data:
                for token in self.data["__tags__"]:
                    if utt == token.get("key", ""):
                        utt = ""
                        break
                    utt = utt.replace(token.get("key", "") + " ", "")
                    utt = utt.replace(" " + token.get("key", ""), "")
            return normalize(utt)
    

    or using a simple regex:

    python
            utt = normalize(self.data.get("utterance", ""))
            if utt and "__tags__" in self.data:
                for token in self.data["__tags__"]:
                    # Substitute only whole words matching the token
                    utt = re.sub(r'\b' + token.get("key", "") + r"\b", "", utt)
            return normalize(utt)
    
    点赞 评论 复制链接分享
  • weixin_39672396 weixin_39672396 4月前

    regex could work, the "simple" way would not account for words that end or start with the substring, "ongoing" would become "going" etc

    点赞 评论 复制链接分享
  • weixin_39562998 weixin_39562998 4月前

    True true. the regex is my favorite anyways :)

    点赞 评论 复制链接分享
  • weixin_39562998 weixin_39562998 4月前

    Looks excellent! I took the liberty of rebasing and squashing your commits.

    点赞 评论 复制链接分享