B4A Library ML Kit Language Identification

Original library: https://developers.google.com/ml-kit/language/identification
Usage: https://developers.google.com/ml-kit/language/identification/android
Supported languages: https://developers.google.com/ml-kit/language/identification/langid-support

With ML Kit's on-device language identification API, you can determine the language of a string of text.
Language identification can be useful when working with user-provided text, which often doesn't come with any language information.

Screenshot_1620123352.png Screenshot_1620123356.png

MlKitLanguageId

Author:
Author: Google - B4a Wrapper: Pendrush
Version: 1.0
  • MlKitLanguageId
    • Events:
      • OnError (Error As String)
      • OnSuccess (Language As String)
      • OnSuccessAll (Languages As Map)
    • Functions:
      • IdentifyLanguage (InputText As String, SetConfidenceThreshold As Float)
        If the call succeeds, a BCP-47 language code is passed to the OnSuccess event, indicating the language of the text.
        If no language is confidently detected, the code 'und' (undetermined) is passed.
        SetConfidenceThreshold - From 0.01 to 1
        MlKitLanguageId1.IdentifyLanguage("Hello", 0.01)
      • IdentifyPossibleLanguages (InputText As String, SetConfidenceThreshold As Float)
        To get the confidence values of a string's most likely languages, pass the string to the IdentifyPossibleLanguages() method.
        From each object, you can get the language's BCP-47 code and the confidence that the string is in that language.
        Note that these values indicate the confidence that the entire string is in the given language.
        ML Kit doesn't identify multiple languages in a single string.
        SetConfidenceThreshold - From 0.01 to 1
        MlKitLanguageId1.IdentifyPossibleLanguages("Hello", 0.01)
      • Initialize (EventName As String)
        Initialize MlKitLanguageId
        MlKitLanguageId1.Initialize("MlKitLanguageId1")
      • IsInitialized As Boolean


Install with SDK Manager:
B4X:
com.google.mlkit:language-id
com.google.mlkit:common
androidx.lifecycle:lifecycle-common
com.google.android.gms:play-services-tasks
com.google.firebase:firebase-encoders
com.google.firebase:firebase-encoders-json


Add this to manifest:
B4X:
AddApplicationText(<provider
            android:name="com.google.mlkit.common.internal.MlKitInitProvider"
            android:authorities="${applicationId}.mlkitinitprovider"
            android:exported="false"
            android:initOrder="99" />      
           <service
            android:name="com.google.mlkit.common.internal.MlKitComponentDiscoveryService"
            android:exported="false" >
            <meta-data
                android:name="com.google.firebase.components:com.google.mlkit.nl.languageid.LanguageIdRegistrar"
                android:value="com.google.firebase.components.ComponentRegistrar" />
                <meta-data
                android:name="com.google.firebase.components:com.google.mlkit.common.internal.CommonComponentRegistrar"
                android:value="com.google.firebase.components.ComponentRegistrar" />
        </service>)
 

Attachments

  • MlKitLanguageIdLibrary.zip
    6.2 KB · Views: 245
  • MlKitLanguageIdExample.zip
    9.7 KB · Views: 270
Last edited:

Jerryk

Member
Licensed User
Longtime User
B4A Version: 12.20
Parsing code. (0.00s)
Java Version: 11
Building folders structure. (0.09s)
Compiling code. (0.02s)
Compiling layouts code. (0.00s)
Organizing libraries. Error
Maven artifact not found: com.google.auto/auto-common
Source: MlKitLanguageId

on SDK not found to install com.google.auto/auto-common

how to resolve this?
 

Jerryk

Member
Licensed User
Longtime User
I deleted SDK and resources files and copied new one from www.b4x.com. Installed SDK writen on post#1. When compiled error showed:

B4A Version: 12.20
Parsing code. (0.01s)
Java Version: 11
Building folders structure. (0.08s)
Compiling code. (0.06s)
Compiling layouts code. (0.01s)
Organizing libraries. Error
Maven artifact not found: androidx.lifecycle/lifecycle-livedata-core-ktx-lint
Source: MlKitLanguageId

any idea?
 
Top