How to get spelling corrected words in Android? - android

When you type in any text area OS wide in Android (not only in my app) the user could use auto correct or click the misspelled word to correct it. Is there a way to get a list of all the misspelled words and what they were turned into?.
Alternatively, is this possible with a rooted device or can you even replace autocorrect with your own dictionary to track this?

This functionality present in Android is provided by the Spell Checker Framework. Its documentation here and here shows how you can connect to it and interact with it's suggestions inside an app.
Because this is a service provided by the system, much like something such as Location Services, there isn't a way to hook into it system-wide without being rooted. I don't have any personal experience tinkering with the inner workings of the Android system or its services, but as a starting point, you could take a look into any open source apps that tamper with the input/output of some of these services e.g. GPS spoofing apps.
Worst case scenario would be you'd have to locate where the Spell Checker Framework compiles to and is stored, and overwrite it with a modified version that does what you want.
I was able to find an older version of SpellCheckerService.java here from Android 5.1.1. You might be able to look into this and figure out what you need to do and where.
EDIT: After checking out the entire list of 1149 Android source repos (100+ GB), I found the two most likely candidates for you to scour for an opening.
git clone https://android.googlesource.com/platform/frameworks/base
git clone https://android.googlesource.com/platform/packages/inputmethods/LatinIME
In base, you'll find the SpellChecker sources in base/core/java/android/****/textservice/, where **** is one of service, view, widget, or internal (internal is in com/android). This appears to be the lowest level. Many of the methods and such here are abstract.
In LatinIME, you'll find the higher level SpellChecker sources for the latin character set (there are other repos for other charsets). You will find them in LatinIME/java/src/com/android/inputmethod/latin/spellcheck/. This is where you'll find the implementations.
After tracing through the sources (specifically tracing getSuggestionResults), the calls go down to the Dictionary level. LatinIME/java/src/com/android/inputmethod/latin/Dictionary.java has abstract public ArrayList<SuggestedWordInfo> getSuggestions() which means that it is the Dictionary's responsibility to return the results. Still, I would assume that a user installable dictionary is just a simple database which is used by the Android system's Dictionary handling code, which likely means you are still going to need to modify system code and be rooted to accomplish your goal.
I'm afraid this is as far down the rabbit hole as I go on the subject. I fear I have not completely answered the question, but this should give you some direction on how you want to proceed.
YET ANOTHER EDIT: Maybe I'm wrong about an installable dictionary just being a database. See this example. This example appears to be in the form of an app though, so I am not sure.

To find suggestion of Typed text
Spannable str = myEditText.getText();
SuggestionSpan[] spanned = str.getSpans(startIndex, endIndex, SuggestionSpan.class);
If spanned is not empty, there is an error in the text between startIndex and endIndex. By changing the values of these indices, it will be possible to find which word is erroneous. Each item in the spanned array has a field called mSuggestions, which is an array of strings and provides the suggested words for the erroneous word.
There is other method to check for: here

Related

Modifying an existing Flutter app to make it Multilingual

I have a full-fledged working Flutter app. Now, I want it to support multiple languages, such as Spanish, Hindi, Urdu, etc. (primarily Indian Languages which are available in Google Translate).
I have searched about this, but all of them mention about "arb files" in which I believe, I have to manually write each and every translated string of the whole app.
I would like to build a package with a class (or just a method) which may require 2 parameters, string and the locale in which translation is required.
Kindly suggest me the best way to achieve it and how can I do it. A link to tutorial would be appreciated.
Flutters own step by step walkthrough to i18n is literally the first result that pops up when you put "Flutter localization" into Google.
https://docs.flutter.dev/development/accessibility-and-localization/internationalization
If for some reason you don't want .arb files, you can roll your own. But be prepared that you will find out along the way what is missing and ending up with a home-brewn solution that is worse than Flutters own to achieve the same thing.
There is no magic function to translate text. Even if you could translate on the fly with a translation service, translation services have become really good in recent years, but they (as any human you could hire) are only as good as the context they get. If they get only single words or half sentences, as is common in an app with headlines and buttons, the result will be horrible. As if you just put every single word into a dictionary. That is not translation. It will feel artificial and laughable.
So... give the existing packages a try. Start with Flutters. It might seem complicated, but it's complicated for a reason.

Android - how do I translate my existing app into a different language?

If I wanted to translate an entire app (with button names and labels, and long text), is it better to just make a different app? Or is there a translation api I can use?
The reason I ask is that I tried going to the Goolge Play store and searching it in a different language, and it basically didn't understand what I wanted. So is there a different Goolge Play interface for different languages? Or some setting which I need to turn on?
How does this generally work?
Thank you!
use all your strings from a file instead of hard coded way. the name of the file is strings.xml in values folder, and for another language what u need to do is to crate values-ru values-ch etc. folder and put your strings.xml inside the folder. and change the values. this was a fast approach to explain your solution. for expanded, detailed solution is here : http://developer.android.com/guide/topics/resources/localization.html
You don't want to make multiple versions of the application. In general this is accomplished by using a locale-specific dictionary for each translation you want to use, so instead of hard-coding strings in your application you would reference an element in the appropriate reference database instead, which is basically a list of all the strings you use in your application.
Here's some information I found specifically for Android development: http://developer.android.com/guide/topics/resources/localization.html
As for translating, natural language processing isn't far enough along yet to give good translations automatically, especially without context. You can try Google's translate API (https://developers.google.com/translate/) which uses some statistical methods, but even that will likely give you erroneous translations (I'm sure you've probably used Google or another service to translate something and out came something you could be pretty certain wasn't accurate). You might be able to use that as a first step to converting the application to different languages and, if your application is open source (or even if it isn't) ask for user input as to the accuracy of the various translations.
Hopefully that is helpful.

Implementing voice recognition in android

i have used the code provided in this link for the speech recognition. in emulator it is saying recognizer not present,so i installed it on mobile. when i click on speak button it is working. but when i speak some names "rajesh" it is showing some possible verbs and all but not the name. but i want to use the input to select a contact from the address book in order to make a call . so please tell me how to carry on in this direction. one more thing, every time i need to develop the code in eclipse then install it on mobile and then check for output. is there any alternative to edit and check the app code in the mobile from eclipse.
please provide me any possible links. i want to develop a call app for blind,if the voice recognition does not work, what else could be done to take input from the user.
Names are hard for Speech recognition. There are more possible names in the world than words in any dictionary, so being able to recognise any arbitrary name is hard. Though common names are easier.
Anyway, if you want to recognise a customized list of words/names, You might want to look at Dragon Mobile from Nuance. Here is a copy-and-paste from another similar question I answered:
If you use 3rd party Android recognition from Nuance (The people behind DragonDictate), it supports a "grammar mode" where you can somewhat restrict the phrases that will be recognised during recognition.
Importantly, if you add unusual names into a Custom Vocabulary, they SHOULD become recognizable (Complex pronunciation issues aside).
You can find information if you dig through:
http://dragonmobile.nuancemobiledeveloper.com ,
looking for 'Custom Vocabularies'. Grammar mode is essentially a special mode of custom vocabularies.
At the time of writing, there was a document here that makes some mention of grammar mode:
http://dragonmobile.nuancemobiledeveloper.com/downloads/custom_vocabulary/Guide_to_Custom_Vocabularies_v1.5.pdf - It only really becomes clear when you try to progress in their provisioning web GUI.
You have to set up an account, and jump through other hoops, but there is a free tier. This is the only potential way I have found to constrain a recognition vocabulary.
Well, short of running up PocketSphinx, but that is still described as a 'Research' 'PreAlpha'.
No, I don't work for Nuance. Not sure anyone does. They may have all been eaten by zombies. You would guess as much reading their support forums. They never reply.

"Social" internationalization in Android application - loading resources dynamically

I have an idea to let users translate my application to their own languages.
I imagine this in this way:
If application is not translated to user's system language, English version of UI is displayed and user is asked for help in translation (it's obvious)
Next, user is asked for translate some phrases from English to his mother tongue. And asked to check some others translations. (it's a bit of work, but nothing sophisticated)
Hard part of my idea is:
User presses "update translation" and text resources for this application are update to latest editions.
Of course it's possible to make frequent updates, but this approach has some disadvantages:
1. I have to make all of those updates frequently, and not all of users will be happy with it.
2 Even if updates will be done weekly, time from make effort to get results will be too long form most of users, and probably, response will be not as good as it can be.
Have you any idea how to load translations "on-line"?
Android currently doesn't support this. To accomplish what you want, you'd need to insert your own resource handling code to return strings everywhere they are used in your UI. This means you couldn't let the framework load strings itself (for example no use of android:text="#string/something" in your layouts), and calling your own function to retrieve a string that wraps Resources.getString()/getText().
And you'll also need to deal with the fact that resource IDs are not stable and can change with every build of your app.
So you are looking at something quite non-trivial.
I have done some internationalizations using:
launchpad with android2po
getLocalization
I will first check if they have some kind of api. If there is no API, I would check the gettext's java implementation and handle translations with it.
You could cache any of the current user's translations in a file on the SD/storage, and show it to that specific user. Then, when it gets its weekly update, remove the cached file and start again?

swearing in code

I have an application that uses predefined word lists but I want to extend it to give the option of using their own custom lists.
Unfortunately lists like SOWPODS (the official Scrabble word list) are quite comprehensive and contain words I wouldn't want popping up on the screen.
I can easily get hold of a banned word list and build it into my application as a kind of swear filter. Is this likely to get my app trapped by any application filtering that may be present on Google Marketplace and, if so, is there a way around it? (encryption, compression etc.)
EDIT: Most of the answers so far are missing the point that the user will be supplying the list so I have no control over its content and need to filter it in my app either on import or as it is used. (Though they will still blame me if the app "swears" at them)
Is there a reason you couldn't just filter the words upon import against a "bad words" list that, according to a previous comment you made, it sounds like you already compiled?
You could also add the option into a preferences menu so that it doesn't filter them on import.
Edit: Google's policies don't allow "excessive profanity." If it is rejected, I assume you could just appeal with the argument that it is a filter against profanity and your app would be accepted.
Random thought: why not build a Bloom Filter for disallowed words, and store the bits in the filter in your program's executable instead of the word list? Sure, you might get the odd false positive, but in the space of possible strings your word list is going to filter a lot more bits.
Alternatively, if what you're really worried about is someone doing a string dump on your application, some simple obfuscation like base64 should do the trick.
Many *nix distros include a word list in a plain text file /usr/share/dict/words (used for spell-check, etc.). On my OSX Leopard laptop the list appears to be stripped of the f-words. On my linux server, the f-words are there. Check your *nix distro with grep to see what you have and if it doesn't contain f-words, you could base your program on that word list.
Why not have a list of good-words instead of bad-words.. Much easier to find, and will make sure people can not trick your filter. I do however believe that users do not really like filters.
I would think the banned word list would be relatively small (what, 15-20 words?). I haven't done anything like this in Java yet, but I imagine it would be simple to, when the user imports a list, put that list into a binary search tree, and then check it against the banned word list, deleting any matching entries. Then save this filtered list and use it.
Just to add to this, I would perhaps have a popup dialog, or maybe a preference that allows the user to disable filtering. Always better to give the option. :)
I commented, but this is really more of an answer.
I think you need to learn how "spam" and "content filtering" works.
Neither of those things will prevent your app from containing or emitting any type of word. To be very clear, neither are going to search the binary of your application for those words.
That said, you can absolutely keep a list of words with your installer that you use to filter out what is displayed to the user regardless of what they upload.
BTW, "spam" filters are there to stop spam email from being received and hence block those. Content Filters work two ways. First, by letting the content providers explicitly state what audience their content is good for and second by filtering the data as it comes across. These do NOT work inside of an application; rather, they work on the data a web browser receives.
I would start with a standard word list. A separate program would filter out any bad words and create your own modified standard word list.
Your application would then not need to worry about filtering anything out. No garbage in, no garbage out.

Categories

Resources