-
Notifications
You must be signed in to change notification settings - Fork 165
fixed wrong word limiter for answer warnings #2540
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can you add test cases where the "trigger word" contains multiple words? because your function actually allows this :)
| let j; | ||
| for (j = 0; j < sub.length; j++) { | ||
| if (arr[i + j] !== sub[j]) break; | ||
| } | ||
| if (j == sub.length) return true; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this could be slightly nicer if you create another helper function arrayEquals(a: string[]. b: string[]): bool :)
Bonus points: Can you remove the string type and make a generic function instead? Take a look at our utils.ts file for examples, or ask if you need some input :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I still think that this change would make a nice improvement to the current implementation
janno42
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
✅ functionality tested
| const words = text.split(" "); | ||
| const triggerWords = triggerString.split(" "); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Splitting by a single space character means that we don't match if users accidentally put two spaces. We should split by any amount of whitespace (like what happens in Python when using str.split without passing any argument)
| function matchesTriggerString(text: string, triggerString: string): boolean { | ||
| const words = text.split(" "); | ||
| const triggerWords = triggerString.split(" "); | ||
| return containsSubArray(words, triggerWords); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This probably means that if users write something like "see above." at the end of a sentence we will not show a warning because the dot is included in the last word.
Doing this completely correct seems tough, unless we at some point change the UI so that staff users can enter arbitrary regexes as trigger words. What do you think we should aim for in this PR @janno42 ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could first preprocess (before splitting) by regex-replacing all non-word characters with a delimiter, then splitting on the delimiter. Then, punctuation, arbitrarily weird (repeated) whitespace and other non-printable characters would not be an issue.
| let j; | ||
| for (j = 0; j < sub.length; j++) { | ||
| if (arr[i + j] !== sub[j]) break; | ||
| } | ||
| if (j == sub.length) return true; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I still think that this change would make a nice improvement to the current implementation
fix #2516