final class PredictiveService
This is the main class of the library and the class that should be instantiated to make use of the functionalities of autocorrect, next word prediction or swipe typing.
Initializers | |
---|---|
PredictiveService(languageFileURL: URL, configuration: LibraryConfiguration) |
Methods | |
---|---|
Void |
addPhrasesToDictionary([String]) Adds phrases to the dictionary. |
Void |
addWordsToDictionary([String]) Adds words to the dictionary. |
Result<[Candidate], PredictiveService.Error> |
currentWordPrediction(String) Given a specific typing context, predicts the words and emojis the user is trying to type. |
Result<[Candidate], PredictiveService.Error> |
currentWordPrediction(TypingContext) Given a specific text and a set of points where the user tapped, predicts the words and emojis the user is trying to type. |
Void |
currentWordPrediction( String, completion: (Result<[Candidate], PredictiveService.Error>) -> Void ) Given a specific typing context, predicts the words and emojis the user is trying to type. |
Void |
currentWordPrediction( TypingContext, completion: (Result<[Candidate], PredictiveService.Error>) -> Void ) Given a specific text and a set of points where the user tapped, predicts the words and emojis the user is trying to type. |
Result<[Candidate], PredictiveService.Error> |
currentWordPrediction( TypingContext, currentWordTaps: [LayoutPoint] ) Given a specific text and a set of points where the user tapped, predicts the words and emojis the user is trying to type. |
Void |
currentWordPrediction( TypingContext, currentWordTaps: [LayoutPoint], completion: (Result<[Candidate], PredictiveService.Error>) -> Void ) Given a specific text and a set of points where the user tapped, predicts the words and emojis the user is trying to type. |
Result<[Candidate], PredictiveService.Error> |
nextWordPrediction(TypingContext) Given a specific text context, suggests the next possible words and emojis the user is likely to type. |
Result<[Candidate], PredictiveService.Error> |
nextWordPrediction(String) Given a specific text context, suggests the next possible words and emojis the user is likely to type. |
Void |
nextWordPrediction( TypingContext, completion: (Result<[Candidate], PredictiveService.Error>) -> Void ) Given a specific text context, suggests the next possible words and emojis the user is likely to type. |
Void |
nextWordPrediction( String, completion: (Result<[Candidate], PredictiveService.Error>) -> Void ) Given a specific text context, suggests the next possible words and emojis the user is likely to type. |
Void |
reloadLanguageFile(URL) Reloads the language file. Dictionary and configuration are kept during this process. |
Void |
removePhrasesFromDictionary([String]) Removes phrases from the dictionary. |
Void |
removeWordsFromDictionary([String]) Removes words from the dictionary. |
Result<[Candidate], PredictiveService.Error> |
swipePrediction( TypingContext, swipePoints: [LayoutPoint] ) Given a text context and an array of swipe positions, predicts the words the user likely swiped. |
Void |
swipePrediction( TypingContext, swipePoints: [LayoutPoint], completion: (Result<[Candidate], PredictiveService.Error>) -> Void ) Given a text context and an array of swipe positions, predicts the words the user likely swiped. |
Enumerations | |
---|---|
Error | The error type used by the methods in LanguagesHelper. |
init(languageFileURL: URL, configuration: LibraryConfiguration)
Initializes the PredictiveService instance with a languange file and configuration.
Parameters | |
---|---|
languageFileURL: URL | The URL of the language file to use by the instance. |
configuration: LibraryConfiguration | The configuration for the instance, such as the keyboard layout to use or the license credentials. |
func addPhrasesToDictionary(_ phrases: [String])
Adds phrases to the dictionary.
Parameters | |
---|---|
phrases: [String] | The array of phrases to add to the dictionary. |
func addWordsToDictionary(_ words: [String])
Adds words to the dictionary.
Parameters | |
---|---|
words: [String] | The array of words to add to the dictionary. |
func currentWordPrediction(_ text: String) async -> Result<[Candidate], PredictiveService.Error>
Given a specific typing context, predicts the words and emojis the user is trying to type.
Parameters | |
---|---|
text: String | The text whose last word wants to be corrected. |
Returns | |
---|---|
Result<[Candidate], PredictiveService.Error> | The array of Candidates for the autocorrection in case of success. |
func currentWordPrediction(_ context: TypingContext) async -> Result<[Candidate], PredictiveService.Error>
Given a specific text and a set of points where the user tapped, predicts the words and emojis the user is trying to type.
Parameters | |
---|---|
context: TypingContext | The text context to be corrected. |
Returns | |
---|---|
Result<[Candidate], PredictiveService.Error> | The array of Candidates for the autocorrection in case of success. |
func currentWordPrediction(_ text: String, completion: @escaping (Result<[Candidate], PredictiveService.Error>) -> Void)
Given a specific typing context, predicts the words and emojis the user is trying to type.
Parameters | |
---|---|
text: String | The text whose last word wants to be corrected. |
completion: (Result<[Candidate], PredictiveService.Error>) -> Void | A closure that gets executed when the operation finishes and contains the array of Candidates for the autocorrection in case of success. |
func currentWordPrediction(_ context: TypingContext, completion: @escaping (Result<[Candidate], PredictiveService.Error>) -> Void)
Given a specific text and a set of points where the user tapped, predicts the words and emojis the user is trying to type.
Parameters | |
---|---|
context: TypingContext | The text context to be corrected. |
completion: (Result<[Candidate], PredictiveService.Error>) -> Void | A closure that gets executed when the operation finishes and contains the array of Candidates for the autocorrection in case of success. |
func currentWordPrediction(_ context: TypingContext, currentWordTaps: [LayoutPoint]) async -> Result<[Candidate], PredictiveService.Error>
Given a specific text and a set of points where the user tapped, predicts the words and emojis the user is trying to type.
Parameters | |
---|---|
context: TypingContext | The text context to be corrected. |
currentWordTaps: [LayoutPoint] |
Returns | |
---|---|
Result<[Candidate], PredictiveService.Error> | The array of Candidates for the autocorrection in case of success. |
func currentWordPrediction(_ context: TypingContext, currentWordTaps: [LayoutPoint], completion: @escaping (Result<[Candidate], PredictiveService.Error>) -> Void)
Given a specific text and a set of points where the user tapped, predicts the words and emojis the user is trying to type.
Parameters | |
---|---|
context: TypingContext | The text context to be corrected. |
currentWordTaps: [LayoutPoint] | |
completion: (Result<[Candidate], PredictiveService.Error>) -> Void | A closure that gets executed when the operation finishes and contains the array of Candidates for the autocorrection in case of success. |
func nextWordPrediction(_ context: TypingContext) async -> Result<[Candidate], PredictiveService.Error>
Given a specific text context, suggests the next possible words and emojis the user is likely to type.
Parameters | |
---|---|
context: TypingContext | The text context used for the next word prediction. |
Returns | |
---|---|
Result<[Candidate], PredictiveService.Error> | The array of Candidates for the autocorrection in case of success. |
func nextWordPrediction(_ text: String) async -> Result<[Candidate], PredictiveService.Error>
Given a specific text context, suggests the next possible words and emojis the user is likely to type.
Parameters | |
---|---|
text: String | The text used for the next word prediction. |
Returns | |
---|---|
Result<[Candidate], PredictiveService.Error> | The array of Candidates for the autocorrection in case of success. |
func nextWordPrediction(_ context: TypingContext, completion: @escaping (Result<[Candidate], PredictiveService.Error>) -> Void)
Given a specific text context, suggests the next possible words and emojis the user is likely to type.
Parameters | |
---|---|
context: TypingContext | The text context used for the next word prediction. |
completion: (Result<[Candidate], PredictiveService.Error>) -> Void | A closure that gets executed when the operation finishes and contains the array of Candidates for the next word prediction in case of success. |
func nextWordPrediction(_ text: String, completion: @escaping (Result<[Candidate], PredictiveService.Error>) -> Void)
Given a specific text context, suggests the next possible words and emojis the user is likely to type.
Parameters | |
---|---|
text: String | The text used for the next word prediction. |
completion: (Result<[Candidate], PredictiveService.Error>) -> Void | A closure that gets executed when the operation finishes and contains the array of Candidates for the next word prediction in case of success. |
func reloadLanguageFile(_ languageFileURL: URL)
Reloads the language file. Dictionary and configuration are kept during this process.
Parameters | |
---|---|
languageFileURL: URL | The URL of the new language file. |
func removePhrasesFromDictionary(_ phrases: [String])
Removes phrases from the dictionary.
Parameters | |
---|---|
phrases: [String] | The array of phrases to remove from the dictionary. |
func removeWordsFromDictionary(_ words: [String])
Removes words from the dictionary.
Parameters | |
---|---|
words: [String] | The array of words to remove from the dictionary. |
func swipePrediction(_ context: TypingContext, swipePoints: [LayoutPoint]) async -> Result<[Candidate], PredictiveService.Error>
Given a text context and an array of swipe positions, predicts the words the user likely swiped.
Parameters | |
---|---|
context: TypingContext | The text context used for the swipe prediction. |
swipePoints: [LayoutPoint] | An array of LayoutPoint containing the information of the swipe. |
Returns | |
---|---|
Result<[Candidate], PredictiveService.Error> | The array of Candidates for the autocorrection in case of success. |
func swipePrediction(_ context: TypingContext, swipePoints: [LayoutPoint], completion: @escaping (Result<[Candidate], PredictiveService.Error>) -> Void)
Given a text context and an array of swipe positions, predicts the words the user likely swiped.
Parameters | |
---|---|
context: TypingContext | The text context used for the swipe prediction. |
swipePoints: [LayoutPoint] | An array of LayoutPoint containing the information of the swipe. |
completion: (Result<[Candidate], PredictiveService.Error>) -> Void | A closure that gets executed when the operation finishes and contains the array of Candidates for the swipe prediction in case of success. |
enum Error
The error type used by the methods in PredictiveService.
Enumeration Cases | |
---|---|
invalidFileURL |
Error thrown when initializing the PredictiveService instance if the specified file is not a valid language file or if there’s no file in the URL. |
licenseNotValid |
Error returned when the license credentials used are invalid or do not include the use of PredictiveSDK. |