Giter Site home page Giter Site logo

shubham0204 / text-predictor-android Goto Github PK

View Code? Open in Web Editor NEW
4.0 1.0 0.0 13.71 MB

Next word prediction and word auto-complete for Android - with the power of Rust ๐Ÿš€

Home Page: https://shubham0204.github.io/text-predictor-android/android

License: GNU General Public License v2.0

Kotlin 100.00%
android android-library autocomplete-suggestions data-structures markov-model rust text-predictions trie-data-structure

text-predictor-android's Introduction

Text Prediction in Android - With Rust ๐Ÿš€

Perform next-word prediction with text-autocompletion, all in Android. The library uses Rust internally, to bring text-suggestions within a few-milliseconds. See the rust branch for more details.

Installation

  1. Download text-predictor.aar from the latest release. (See Releases)
  2. Move the AAR to app/libs.
  3. In module-level build.gradle, add the dependency,
dependencies {
    ...
    implementation files('libs/text-predictor.aar')
    ...
}

Usage

To generate suggestions while text is being entered in a text-widget (could be a EditText or TextField), we use the stream method available in the TextPredictor class. The stream method must be called inside on a onTextChanged or a similar callback that provides a string entered by the user.

For a Compose TextField,

val textPredictor = TextPredictor( this , results )

var inputString by remember{ mutableStateOf("") }
TextField(
    modifier = modifier,
    value = inputString,,
    onValueChange = {
        textPredictor.stream(it)
        inputString = it
    },
    singleLine = true,
)

private val results: ((List<String>) -> Unit) = { suggestions ->
    // Handle UI changes that display `suggestions`
}

For a View-based EditText,

val textPredictor = TextPredictor( this , results )

editText.addTextChangedListener { it ->
    textPredictor.stream( it.toString() )
}

private val results: ((List<String>) -> Unit) = { suggestions ->
    // Handle UI changes that display `suggestions`
} 

text-predictor-android's People

Contributors

shubham0204 avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.