| class info |
| com.huawei.hms.mlsdk.langdetect.cloud.MLRemoteLangDetector |
| Language detector, which is used to perform language detection on supplied text. The on-cloud API is called, and the detection model runs on the cloud. You can create a language detector in two ways based on the site requirements. |
- // Obtain the language detector.
- // Method 1: Use default parameter settings.
- MLRemoteLangDetector mlRemoteLangDetector = MLLangDetectorFactory.getInstance()
- .getRemoteLangDetector();
- // Method 2: Use customized parameter settings.
- // setTrustedThreshold: Set the minimum confidence threshold for language detection.
- MLRemoteLangDetectorSetting mlRemoteLangDetectorSetting = new MLRemoteLangDetectorSetting.Factory()
- .setTrustedThreshold(0.01f)
- .create();
- MLRemoteLangDetector mlRemoteLangDetector = MLLangDetectorFactory.getInstance()
- .getRemoteLangDetector(mlRemoteLangDetectorSetting);
- // Return the detection results of multiple languages, including language codes and confidences, sourceText: text to be detected.
- Task<List<MLDetectedLang>> probabilityDetectTask = mlRemoteLangDetector.probabilityDetect(sourceText);
- probabilityDetectTask.addOnSuccessListener(new OnSuccessListener<List<MLDetectedLang>>() {
- public void onSuccess(List<MLDetectedLang> result) {
- // Processing logic for success.
- }
- }).addOnFailureListener(new OnFailureListener() {
- public void onFailure(Exception e) {
- // Processing logic for failure.
- }
- });
- // Return the language code with the highest confidence, sourceText: text to be detected.
- Task<String> firstBestDetectTask = mlRemoteLangDetector.firstBestDetect(sourceText);
- firstBestDetectTask.addOnSuccessListener(new OnSuccessListener<String>() {
- public void onSuccess(String s) {
- // Processing logic for success.
- }
- }).addOnFailureListener(new OnFailureListener() {
- public void onFailure(Exception e) {
- // Processing logic for failure.
- }
- });
- // Release the resources.
- mlRemoteLangDetector.stop();
| Type | Name | Desc |
| float | FIRST_BEST_DETECTION_LANGUAGE_TRUSTED_THRESHOLD | Confidence threshold in the scenario where the language detection result with the highest confidence is returned. |
| float | PROBABILITY_DETECTION_LANGUAGE_TRUSTED_THRESHOLD | Confidence threshold in the scenario where detection results of multiple languages are returned. |
| String | UNDETECTION_LANGUAGE_TRUSTED_THRESHOLD | Undetected language code. |
| Return type | Method name |
| MLRemoteLangDetector | create(MLApplication app, MLRemoteLangDetectorSetting setting) |
| com.huawei.hmf.tasks.Task | firstBestDetect(String text) |
| com.huawei.hmf.tasks.Task | probabilityDetect(String text) |
| void | stop() |
| Constant |
| public static final float PROBABILITY_DETECTION_LANGUAGE_TRUSTED_THRESHOLD |
| Confidence threshold in the scenario where detection results of multiple languages are returned. Constant value: 0.01f |
| Constant |
| public static final String UNDETECTION_LANGUAGE_TRUSTED_THRESHOLD |
| Undetected language code. Constant value: unknown |
| Method |
| public static synchronized MLRemoteLangDetector create(MLApplication app, MLRemoteLangDetectorSetting setting) |
| Creates a language detector object. |
Parameters
| Parameter name | Parameter desc |
| app | MLApplication instance. |
| setting | Instance of the language detection configurator. |
Return
| Type | desc |
| MLRemoteLangDetector | Returns a language detector object. |
| Method |
| public com.huawei.hmf.tasks.TaskfirstBestDetect(String text) |
| Returns the language detection result with the highest confidence based on the supplied text. |
Parameters
| Parameter name | Parameter desc |
| text | Text. |
Return
| Type | desc |
| com.huawei.hmf.tasks.Task | Language detection result with the highest confidence. |
| Method |
| public com.huawei.hmf.tasks.Task<list> probabilityDetect(String text) |
| Returns multi-language detection results based on the supplied text. |
Parameters
| Parameter name | Parameter desc |
| text | Text. |
Return
| Type | desc |
| com.huawei.hmf.tasks.Task<list> | Task object of the multi-language detection results. |
| Method |
| public void stop() |
| Releases resources, including input and output streams. |