sergi-s / spelling-practice-2

Spelling practice, because I think I am dyslexic (Next + Mongo + Prisma + Ollma gemma:2b)
https://dyslexicon.vercel.app
Apache License 2.0
1 stars 0 forks source link

Better String Comparison #8

Open Stezzly opened 3 months ago

Stezzly commented 3 months ago

String comparison of words needs updating - Dependent on issue #6

For example words with ' can cause for unexpected results Ex: "The company's revenue increased this year" gets converted to "The company s revenue increased this year" which is not correct and will highlight every word after company to be incorrect.

sergi-s commented 3 months ago

Also BUG: "Enter" adds a white space

Stezzly commented 3 months ago

Sometimes blank spaces will cause other correct words to be marked wrong. commas "," are properly handled

User input examples: Ex1) The dog went to the store -> everything after The will be marked wrong even if spelt correct Ex2) The brown dog, went to the store. -> , and . removed by parsing sentences. This currently works properly

Stezzly commented 2 months ago

String comparison update in free model (SpellChecker.tsx):

1) Dynamic Input Replacement: Adjusted the logic to replace [missing] placeholders directly with user input as it's typed, ensuring that the input appears in the correct position within the sentence instead of being appended at the end.

2) Improved Color Coding: Implemented a color-coding system that responds more accurately to the correctness of the input: Red: Incorrect input that does not match the beginning of the correct word. Blue: Partially correct input that matches the beginning of the correct word. Green: Fully correct input that matches the correct word entirely.

3) Handling of Extra Words: Added logic to handle and display any extra words that the user inputs beyond the length of the correct sentence. These extra words are marked in red and displayed at the end of the entered sentence to indicate that they are superfluous.

4) Use of Optional Chaining: Utilized optional chaining (?.) to safely access indices of the userWords array, which prevents runtime errors if the user has entered fewer words than there are in the correct sentence.

5) Efficient Word Comparison: The comparison function (compareSentences) was optimized to loop through the correct words and compare each one with the corresponding user input, applying the appropriate style based on the comparison results.

6) Keypress Event Handling: Modified the handleKeyPress function to activate spell checking and update the state when the Enter key is pressed. This function also calculates which words are wrong based on the latest user input and updates the misspelled words list accordingly.

7) State and Event Management: Enhanced state management within the component to handle user input changes (handleChange), toggle spell checking state (setIsSpellChecking), and update the list of misspelled words (onWrongWordsChange) based on dynamic evaluations.

8) UI Feedback Improvements: Refined the user interface feedback to ensure that the textarea and result display are responsive and provide immediate visual cues to the user, enhancing the usability and interactive experience of the spell checker.