This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| private val pipeline: StanfordCoreNLP | |
| ... | |
| fun extractRootNoun(text: CharSequence): String? { | |
| val input = text.toString() | |
| val document = Annotation(input) | |
| pipeline.annotate(document) | |
| // Get split sentences | |
| val sentences: List<CoreMap> = document.get(CoreAnnotations.SentencesAnnotation::class.java) | |
| // Get the tokens for the sentences |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| val props = Properties() | |
| props.setProperty("annotators", "tokenize, ssplit, pos, lemma") | |
| instance = NLPClient(StanfordCoreNLP(props)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| private val scope = CoroutineScope(Dispatchers.IO) | |
| override fun onCreate(savedInstanceState: Bundle?) { | |
| ... | |
| scope.launch { viewModel.requestInitializeNLP() } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| private fun requestExtractQuery(bundle: Bundle?) { | |
| val data = bundle?.getStringArrayList(SpeechRecognizer.RESULTS_RECOGNITION) | |
| data?.let { results -> | |
| val resultedText = results[0] // First we set the text result to a TextView | |
| txtSpeechInput.text = resultedText | |
| // Secondly, we send a processing command downstream to the viewModel | |
| // In return, we get a colorized text result with the noun highlighted and we set it again | |
| val result: Spannable = viewModel.requestQuery(resultedText) | |
| txtSpeechInput.text = result |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| private var speechRecognizer: SpeechRecognizer? = null | |
| ... | |
| private fun listenToSpeechInput() { | |
| speechRecognizer = SpeechRecognizer.createSpeechRecognizer(context) | |
| speechRecognizer?.setRecognitionListener(object: RecognitionListener { | |
| ... | |
| override fun onResults(p0: Bundle?) { | |
| speechRecognizer?.stopListening() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| private fun promptSpeechInput() { | |
| val intent = Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH) | |
| intent.putExtra( | |
| RecognizerIntent.EXTRA_LANGUAGE_MODEL, | |
| RecognizerIntent.LANGUAGE_MODEL_FREE_FORM | |
| ) | |
| intent.putExtra(RecognizerIntent.EXTRA_CALLING_PACKAGE, activity?.application?.packageName?: "") | |
| speechRecognizer?.startListening(intent) | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| @AppScoped | |
| public class MessageRepository { | |
| @Inject | |
| public MessageRepository() { | |
| } | |
| @NonNull | |
| public String getData(){ | |
| return "Hello Medium!"; | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public class MessageUiModel { | |
| private final String mMessageText; | |
| public MessageUiModel(String messageText) { | |
| this.mMessageText = messageText; | |
| } | |
| public String getMessageText() { | |
| return mMessageText; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| @Module | |
| public abstract class ViewModelModule { | |
| @Binds | |
| @IntoMap | |
| @ViewModelKey(MessageViewModel.class) | |
| abstract ViewModel bindMessageViewModel(MessageViewModel messageViewModel); | |
| @Binds | |
| @AppScoped | |
| abstract ViewModelProvider.Factory bindViewModelFactory(MessageViewModelFactory factory); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| @AppScoped | |
| public class MessageViewModelFactory implements ViewModelProvider.Factory { | |
| private final Map<Class<? extends ViewModel>, Provider<ViewModel>> creators; | |
| @Inject | |
| public MessageViewModelFactory(Map<Class<? extends ViewModel>, Provider<ViewModel>> creators) { | |
| this.creators = creators; | |
| } | |
| @SuppressWarnings("unchecked") |