A simple and efficient autocorrection and autocomplete engine built with Tries for Flutter.
- Autocomplete a given string
- Generate a list of Autocomplete suggestions for the given string
- Autocorrect a given string
- Generate a list of Autocorrect suggestions for the given string
- Sort the given list alphabetically
Add the package to your pubsec.yaml
dependencies:
autocorrect_and_autocomplete_engine:
import the package in a file
import 'package:autocorrect_and_autocomplete_engine/autocorrect_and_autocomplete_engine.dart';
-
TrieEngine
needs a list of string to work with for autocompletion and autocorrection.List<String> testData = ["compete","ability","baker","abilities","able"];
-
Initializing the TrieEngine with
testData
TrieEngine trieEngine = TrieEngine(src : testData);
-
Initialize
TrieEngine
using the list of words in a fileTrieEngine trieEngine = TrieEngine(src : File('PATH_TO_FILE').readAsLinesSync());
trieEngine.insertWord('awesome');
-
Use
autoComplete()
to Autocomplete the given string based on alpabetic orderString result = trieEngine.autoComplete('marv'); print(result); // marvel
-
Use
autoCompleteSuggestions()
to generate a list of suggestions for autocompletionList<String> result = trieEngine.autoCompleteSuggestions('marv'); print(result); // [mar, marathon, marble, marc, march, ...]
-
Use
autoCorrect()
to Autocorrect the given stringString result = trieEngine.autoCorrect('marxvl'); print(result); // marvel
-
Use
autoCorrectSuggestions()
to generate a list of suggestions for autocorrectionList<String> result = trieEngine.autoCorrectSuggestions('marxvl'); print(result); // [marvel, mar, max, ma, mail, male, mali, mall, marble, marc]
use toSortedList()
to generate a alphabetically sorted list for the given testData
List<String> listToSort = ["compete","ability","baker","abilities","able"];
TrieEngine trieEngine = TrieEngine(src : listToSort);
List<String> sortedList = trieEngine.toSortedList();
print(sortedList); // [abilities, ability, able, baker, compete]