-
Notifications
You must be signed in to change notification settings - Fork 167
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
Open
AlexanderSchicktanz
wants to merge
10
commits into
e-valuation:main
Choose a base branch
from
AlexanderSchicktanz:main
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
4c1623f
fix: word limit
e6g3 84854ba
added newline at end of file
e6g3 920ea84
fixed formatting for test-answer-warnings.ts
e6g3 c5ff7ea
removed console.log
e6g3 d83569a
fixed line ending
e6g3 e07971b
fixed false negatives
e6g3 9bc2237
fixed test
e6g3 9a12841
feat: make array comparison generic
e6g3 be965e8
ignore punctuation
e6g3 fa8fdc2
fix: type error
e6g3 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6,8 +6,29 @@ function isTextMeaningless(text: string): boolean { | |
| return text.length > 0 && ["", "ka", "na", "none", "keine", "keines", "keiner"].includes(text.replace(/\W/g, "")); | ||
| } | ||
|
|
||
| function containsPhrase(arr: string[], sub: string[]): boolean { | ||
| for (let i = 0; i <= arr.length - sub.length; i++) { | ||
| let j; | ||
| for (j = 0; j < sub.length; j++) { | ||
| if (j == sub.length - 1 && arr[i + j].length > sub[j].length) { | ||
| if (!arr[i + j].startsWith(sub[j])) break; | ||
| if (null !== RegExp("^[!?.]*$", "").exec(arr[i + j].substring(sub[j].length))) return true; | ||
| } | ||
| if (arr[i + j] !== sub[j]) break; | ||
| } | ||
| if (j >= sub.length) return true; | ||
| } | ||
| return false; | ||
| } | ||
|
|
||
| function matchesTriggerString(text: string, triggerString: string): boolean { | ||
| const words = text.split(" "); | ||
| const triggerWords = triggerString.split(" "); | ||
|
Comment on lines
+25
to
+26
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
| return containsPhrase(words, triggerWords); | ||
| } | ||
|
|
||
| function doesTextContainTriggerString(text: string, triggerStrings: string[]): boolean { | ||
| return triggerStrings.some(triggerString => text.includes(triggerString)); | ||
| return triggerStrings.some(triggerString => matchesTriggerString(text, triggerString)); | ||
| } | ||
|
|
||
| function updateTextareaWarning(textarea: HTMLTextAreaElement, textAnswerWarnings: string[][]) { | ||
|
|
@@ -35,7 +56,7 @@ function updateTextareaWarning(textarea: HTMLTextAreaElement, textAnswerWarnings | |
|
|
||
| export function initTextAnswerWarnings(textareas: NodeListOf<HTMLTextAreaElement>, textAnswerWarnings: string[][]) { | ||
| textAnswerWarnings = textAnswerWarnings.map(triggerStrings => triggerStrings.map(normalize)); | ||
|
|
||
| console.log(textAnswerWarnings); | ||
| textareas.forEach(textarea => { | ||
| let warningDelayTimer: ReturnType<typeof setTimeout>; | ||
| textarea.addEventListener("input", () => { | ||
|
|
@@ -53,4 +74,5 @@ export const testable = { | |
| normalize, | ||
| isTextMeaningless, | ||
| doesTextContainTriggerString, | ||
| matchesTriggerString, | ||
| }; | ||
|
AlexanderSchicktanz marked this conversation as resolved.
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 function is very difficult to read, it does too many things at once. We should probably have something like
Then the isSubArray should also not be this complicated, it should use another function areArraysEqual, as I previously suggested
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.
note that this also means that all of our custom "how do we handle weird text things" is separated from the entire "do the arrays match" logic