0

I am trying to alter user input in real time in an android app (I'm using android studio). When the user is typing and has a spelling error, I want to create my own autocorrect that will automatically correct the error for them.

For example, the user intends to type "Meeting with Rob." By accident, they type "Meetng"

Without the user having to click a suggestion or anything, "Meetng" becomes "Meeting" just as the regular autocorrect on your phone would do.

Note:

Code efficiency doesn't matter in this case and I don't want to use the regular built in autocorrect because this part of the code is part of something else that requires me to have full control over the autocorrection happening. I don't think I can use the regular autocorrect but please correct me if I am wrong.

Code:

void checkWordAndAutocorrectIt(){

            if (dict.contains(VEvent.DESCRIPTION) || newDictionary.contains(VEvent.DESCRIPTION)) {
                //then you don't need to do anything I don't think but
                //this is here in case it starts ignoring words that haven't been autocorrected
                //so I can append them manually onto the string
            } else if (!dict.contains(VEvent.DESCRIPTION) && !newDictionary.contains(VEvent.DESCRIPTION)) {
                VEvent.DESCRIPTION.replace(VEvent.DESCRIPTION, autoCorrector(VEvent.DESCRIPTION));
                //this should hopefully replace the incorrect word with the corrected one returned by autoCorrector
                for (int i = 1; i <= 3; i++) {
                    if (val.get(i).autoCorrection == "") {
                        val.get(i).autoCorrection = autoCorrector(VEvent.DESCRIPTION);
                    } //this should check if there is a word already in the spot
                    //if not, it should save the autocorrected word.
                }
            }
        }

Thank you for any help, suggestions or resources you can provide!

  • Just thinking aloud. You could usea Trie (also known as digital tree, radix tree or prefix tree) as its used when doing autocomplete, example: https://www.geeksforgeeks.org/auto-complete-feature-using-trie/ – acarlstein May 08 '19 at 19:37
  • @acarlstein Hi, I spent some time going over what a Trie is and came upon this: https://www.cs.drexel.edu/~jah473/java/autocorrect/src/Autocorrect.java However, it seems as though this too only generates suggestions for the user to pick from, rather than implementing the autocorrection? I also looked at this where the autocorrect was done in Javascript, is it possible to achieve the same thing in Java? https://stackoverflow.com/questions/12387910/yielding-spellchecker?rq=1 Thank you so much for your response! – contaminate May 09 '19 at 19:31
  • can't you modify it implement one of those suggestions? I mean, the reason they are created to make suggestion is that there is a limit of what you can do to do a proper replacement of the word. You would have to get into the realm of AI to improve the percentage of what word should be pick between the suggestion to force the replacement. – acarlstein May 09 '19 at 20:40
  • I'm not concerned rn about accuracy in correcting misspellings. 'Meetng' becoming 'mouse' or even 'bat' or something way off is fine. I just want to figure out how to actually do the word replacement aspect. This person did it in Javascript (http://jsfiddle.net/mgibsonbr/VkENt/), after the user pressed space, the word became capitalized and they added a number to it but the word is still editable by the user and inside of the textbox, it wasn't a printout or a suggestion. Is this possible in Java? @acarlstein Sorry to bother you again but thanks for your replies, I appreciate it – contaminate May 10 '19 at 17:40

1 Answers1

0

So, according to this (How to convert input char to uppercase automatically in Java), apparently changing user input as it is typed is not possible in java, which is what I feared. Guess I'm going to be changing my project.