Skip to content

Commit 0e8fbb2

Browse files
authored
UPDATE flutter-hms-mltext 3.7.0+300
1 parent d1687da commit 0e8fbb2

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

66 files changed

+1664
-1474
lines changed

flutter-hms-mltext/CHANGELOG.md

+17
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,20 @@
1+
## 3.7.0+300
2+
3+
- Added `setUserRegion` and `getCountryCode` methods to MLTextApplication.
4+
5+
- **Breaking Changes:**
6+
7+
- With this release, `MLTextPermissions` has been removed. You are expected to handle required permissions on your own. You can learn more about the required permissions from our [official documentations](https://developer.huawei.com/consumer/en/doc/development/HMS-Plugin-Guides/assigning-permissions-0000001052789343?ha_source=hms1).
8+
- Modified the internal structure of the plugin. Please use import **package:huawei_ml_text/huawei_ml_text.dart** not to get any errors.
9+
10+
**Updated API List**
11+
12+
- MLTextEmbeddingAnalyzer:
13+
- Return type of `analyzeSentenceVector` changed to `List<double>` from `List<dynamic>`.
14+
- Return type of `analyseWordVector` changed to `List<double>` from `List<dynamic>`.
15+
- Return type of `analyseSimilarWords` changed to `List<String>` from `List<dynamic>`.
16+
- Return type of `analyseWordVectorBatch` changed to `Map<String, List<double>>` from `dynamic`.
17+
118
## 3.2.0+301
219

320
- Deleted the capability of prompting users to install HMS Core (APK).

flutter-hms-mltext/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ If you have questions about how to use HMS samples, try the following options:
3636
**huawei-mobile-services**.
3737
- [Github](https://github.com/HMS-Core/hms-flutter-plugin) is the official repository for these plugins, You can open an issue or submit your ideas.
3838
- [Huawei Developer Forum](https://forums.developer.huawei.com/forumPortal/en/home?fid=0101187876626530001) HMS Core Module is great for general questions, or seeking recommendations and opinions.
39-
- [Huawei Developer Docs](https://developer.huawei.com/consumer/en/doc/overview/HMS-Core-Plugin) is place to official documentation for all HMS Core Kits, you can find detailed documentations in there.
39+
- [Huawei Developer Docs](https://developer.huawei.com/consumer/en/doc/overview/HMS-Core-Plugin?ha_source=hms1) is place to official documentation for all HMS Core Kits, you can find detailed documentations in there.
4040

4141
If you run into a bug in our samples, please submit an issue to the [GitHub repository](https://github.com/HMS-Core/hms-flutter-plugin).
4242

flutter-hms-mltext/android/.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,4 @@
66
.DS_Store
77
/build
88
/captures
9+
.cxx

flutter-hms-mltext/android/build.gradle

+28-19
Original file line numberDiff line numberDiff line change
@@ -26,36 +26,45 @@ apply plugin: 'com.android.library'
2626
android {
2727
compileSdkVersion 30
2828
buildToolsVersion "30.0.3"
29+
2930
defaultConfig {
3031
minSdkVersion 19
3132
targetSdkVersion 30
3233
}
34+
3335
lintOptions {
3436
disable 'InvalidPackage'
3537
}
38+
3639
compileOptions {
3740
sourceCompatibility JavaVersion.VERSION_1_8
3841
targetCompatibility JavaVersion.VERSION_1_8
3942
}
4043
}
4144

4245
dependencies{
43-
// text recognition
44-
implementation 'com.huawei.hms:ml-computer-vision-ocr:3.5.0.302'
45-
implementation 'com.huawei.hms:ml-computer-vision-ocr-latin-model:3.5.0.302'
46-
implementation 'com.huawei.hms:ml-computer-vision-ocr-jk-model:3.5.0.302'
47-
implementation 'com.huawei.hms:ml-computer-vision-ocr-cn-model:3.5.0.302'
48-
// vision cloud
49-
implementation 'com.huawei.hms:ml-computer-vision-cloud:3.5.0.300'
50-
// card recognition
51-
implementation 'com.huawei.hms:ml-computer-card-icr-vn:3.5.0.300'
52-
// bankcard recognition
53-
implementation 'com.huawei.hms:ml-computer-card-bcr:3.5.0.300'
54-
// general card recognition
55-
implementation 'com.huawei.hms:ml-computer-card-gcr-plugin:3.5.0.303'
56-
// form recognition
57-
implementation 'com.huawei.hms:ml-computer-vision-formrecognition:3.5.0.300'
58-
implementation 'com.huawei.hms:ml-computer-vision-formrecognition-model:3.5.0.300'
59-
// text embedding
60-
implementation 'com.huawei.hms:ml-nlp-textembedding:3.5.0.300'
61-
}
46+
// Text Recognition
47+
implementation 'com.huawei.hms:ml-computer-vision-ocr:3.7.0.302'
48+
implementation 'com.huawei.hms:ml-computer-vision-ocr-latin-model:3.7.0.302'
49+
implementation 'com.huawei.hms:ml-computer-vision-ocr-jk-model:3.7.0.302'
50+
implementation 'com.huawei.hms:ml-computer-vision-ocr-cn-model:3.7.0.302'
51+
52+
// Document Recognition
53+
implementation 'com.huawei.hms:ml-computer-vision-cloud:3.7.0.302'
54+
55+
// ID Card Recognition
56+
implementation 'com.huawei.hms:ml-computer-card-icr-vn:3.7.0.303'
57+
58+
// Bank Card Recognition
59+
implementation 'com.huawei.hms:ml-computer-card-bcr:3.7.0.302'
60+
61+
// General Card Recognition
62+
implementation 'com.huawei.hms:ml-computer-card-gcr-plugin:3.7.0.303'
63+
64+
// Form Recognition
65+
implementation 'com.huawei.hms:ml-computer-vision-formrecognition:3.7.0.301'
66+
implementation 'com.huawei.hms:ml-computer-vision-formrecognition-model:3.7.0.301'
67+
68+
// Text Embedding
69+
implementation 'com.huawei.hms:ml-nlp-textembedding:3.7.0.303'
70+
}

flutter-hms-mltext/android/src/main/java/com/huawei/hms/flutter/mltext/HuaweiMlTextPlugin.java

+1-7
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@
3030
import com.huawei.hms.flutter.mltext.handlers.TextAnalyzerMethodHandler;
3131
import com.huawei.hms.flutter.mltext.handlers.TextEmbeddingMethodHandler;
3232
import com.huawei.hms.flutter.mltext.mlapplication.MlApplicationMethodHandler;
33-
import com.huawei.hms.flutter.mltext.permissions.PermissionHandler;
3433

3534
import io.flutter.embedding.engine.plugins.FlutterPlugin;
3635
import io.flutter.embedding.engine.plugins.activity.ActivityAware;
@@ -50,7 +49,6 @@ public class HuaweiMlTextPlugin implements FlutterPlugin, ActivityAware {
5049
private MethodChannel textEmbeddingMethodChannel;
5150
private MethodChannel mlApplicationMethodChannel;
5251
private MethodChannel lensMethodChannel;
53-
private MethodChannel permissionChannel;
5452

5553
private void onAttachedToEngine(@NonNull final BinaryMessenger messenger, @NonNull final Activity activity, final TextureRegistry textureRegistry) {
5654
initializeChannels(messenger);
@@ -67,7 +65,6 @@ private void initializeChannels(final BinaryMessenger messenger) {
6765
textEmbeddingMethodChannel = new MethodChannel(messenger, Channel.TEXT_EMBEDDING_CHANNEL);
6866
mlApplicationMethodChannel = new MethodChannel(messenger, Channel.APPLICATION_CHANNEL);
6967
lensMethodChannel = new MethodChannel(messenger, Channel.LENS_CHANNEL);
70-
permissionChannel = new MethodChannel(messenger, Channel.PERMISSION_CHANNEL);
7168
}
7269

7370
private void setHandlers(final Activity activity, TextureRegistry textureRegistry) {
@@ -80,7 +77,6 @@ private void setHandlers(final Activity activity, TextureRegistry textureRegistr
8077
textEmbeddingMethodChannel.setMethodCallHandler(new TextEmbeddingMethodHandler(activity));
8178
mlApplicationMethodChannel.setMethodCallHandler(new MlApplicationMethodHandler(activity));
8279
lensMethodChannel.setMethodCallHandler(new LensHandler(activity, lensMethodChannel, textureRegistry));
83-
permissionChannel.setMethodCallHandler(new PermissionHandler(activity));
8480
}
8581

8682
@Override
@@ -122,7 +118,6 @@ private void removeChannels() {
122118
idCardChannel = null;
123119
mlApplicationMethodChannel = null;
124120
lensMethodChannel = null;
125-
permissionChannel = null;
126121
}
127122

128123
@Override
@@ -135,6 +130,5 @@ public void onDetachedFromActivity() {
135130
idCardChannel.setMethodCallHandler(null);
136131
mlApplicationMethodChannel.setMethodCallHandler(null);
137132
lensMethodChannel.setMethodCallHandler(null);
138-
permissionChannel.setMethodCallHandler(null);
139133
}
140-
}
134+
}

flutter-hms-mltext/android/src/main/java/com/huawei/hms/flutter/mltext/constant/Channel.java

-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ public interface Channel {
2424
String GCR_CHANNEL = BASE_CHANNEL + ".gcr";
2525
String FORM_CHANNEL = BASE_CHANNEL + ".form";
2626
String ICR_CHANNEL = BASE_CHANNEL + ".icr";
27-
String PERMISSION_CHANNEL = BASE_CHANNEL + ".permission";
2827
String TEXT_EMBEDDING_CHANNEL = BASE_CHANNEL + ".text_embedding";
2928
String APPLICATION_CHANNEL = BASE_CHANNEL + ".application";
3029
String LENS_CHANNEL = BASE_CHANNEL + ".lens";

flutter-hms-mltext/android/src/main/java/com/huawei/hms/flutter/mltext/constant/Method.java

+2-7
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,6 @@ public interface Method {
2626
String BANKCARD_IS_AVAILABLE = "bankcard#isAvailable";
2727
String BANKCARD_STOP = "bankcard#stop";
2828

29-
/**
30-
* Permission methods
31-
*/
32-
String REQUEST_PERMISSION = "requestPermission";
33-
String HAS_CAMERA_PERMISSION = "hasCameraPermission";
34-
String HAS_STORAGE_PERMISSION = "hasStoragePermission";
35-
3629
/**
3730
* Form methods
3831
*/
@@ -104,6 +97,8 @@ public interface Method {
10497
*/
10598
String SET_API_KEY = "setApiKey";
10699
String SET_ACCESS_TOKEN = "setAccessToken";
100+
String SET_USER_REGION = "setUserRegion";
101+
String GET_COUNTRY_CODE = "getCountryCode";
107102
String ENABLE_LOGGER = "enableLogger";
108103
String DISABLE_LOGGER = "disableLogger";
109104
}

flutter-hms-mltext/android/src/main/java/com/huawei/hms/flutter/mltext/handlers/TextEmbeddingMethodHandler.java

+13-25
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@
3232

3333
import org.json.JSONObject;
3434

35-
import java.util.ArrayList;
3635
import java.util.Arrays;
3736
import java.util.HashMap;
3837
import java.util.List;
@@ -43,9 +42,7 @@
4342

4443
public class TextEmbeddingMethodHandler implements MethodChannel.MethodCallHandler {
4544
private final static String TAG = TextEmbeddingMethodHandler.class.getSimpleName();
46-
4745
private final TextResponseHandler responseHandler;
48-
4946
private MLTextEmbeddingAnalyzer analyzer;
5047

5148
public TextEmbeddingMethodHandler(final Activity activity) {
@@ -88,9 +85,8 @@ public void onMethodCall(@NonNull MethodCall call, @NonNull MethodChannel.Result
8885
}
8986

9087
private void createTextEmbeddingAnalyzer(MethodCall call) {
91-
String language = FromMap.toString(Param.LANGUAGE, call.argument(Param.LANGUAGE), false);
92-
93-
MLTextEmbeddingSetting setting = new MLTextEmbeddingSetting.Factory().setLanguage(language).create();
88+
final String language = FromMap.toString(Param.LANGUAGE, call.argument(Param.LANGUAGE), false);
89+
final MLTextEmbeddingSetting setting = new MLTextEmbeddingSetting.Factory().setLanguage(language).create();
9490
analyzer = MLTextEmbeddingAnalyzerFactory.getInstance().getMLTextEmbeddingAnalyzer(setting);
9591
responseHandler.success(true);
9692
}
@@ -100,11 +96,9 @@ private void analyseSentenceVector(MethodCall call) {
10096
responseHandler.noService();
10197
return;
10298
}
103-
104-
String sentence = FromMap.toString(Param.SENTENCE, call.argument(Param.SENTENCE), false);
105-
99+
final String sentence = FromMap.toString(Param.SENTENCE, call.argument(Param.SENTENCE), false);
106100
analyzer.analyseSentenceVector(sentence)
107-
.addOnSuccessListener(floats -> responseHandler.success(new ArrayList<>(Arrays.asList(floats))))
101+
.addOnSuccessListener(floats -> responseHandler.success(Arrays.asList(floats)))
108102
.addOnFailureListener(responseHandler::exception);
109103
}
110104

@@ -113,9 +107,8 @@ private void analyseSentencesSimilarity(MethodCall call) {
113107
responseHandler.noService();
114108
return;
115109
}
116-
String sentence1 = FromMap.toString(Param.SENTENCE1, call.argument(Param.SENTENCE1), true);
117-
String sentence2 = FromMap.toString(Param.SENTENCE2, call.argument(Param.SENTENCE2), true);
118-
110+
final String sentence1 = FromMap.toString(Param.SENTENCE1, call.argument(Param.SENTENCE1), true);
111+
final String sentence2 = FromMap.toString(Param.SENTENCE2, call.argument(Param.SENTENCE2), true);
119112
analyzer.analyseSentencesSimilarity(sentence1, sentence2)
120113
.addOnSuccessListener(responseHandler::success)
121114
.addOnFailureListener(responseHandler::exception);
@@ -126,10 +119,9 @@ private void analyseWordVector(MethodCall call) {
126119
responseHandler.noService();
127120
return;
128121
}
129-
String word = FromMap.toString(Param.WORD, call.argument(Param.WORD), false);
130-
122+
final String word = FromMap.toString(Param.WORD, call.argument(Param.WORD), false);
131123
analyzer.analyseWordVector(word)
132-
.addOnSuccessListener(floats -> responseHandler.success(new ArrayList<>(Arrays.asList(floats))))
124+
.addOnSuccessListener(floats -> responseHandler.success(Arrays.asList(floats)))
133125
.addOnFailureListener(responseHandler::exception);
134126
}
135127

@@ -138,9 +130,8 @@ private void analyseWordsSimilarity(MethodCall call) {
138130
responseHandler.noService();
139131
return;
140132
}
141-
String word1 = FromMap.toString(Param.WORD1, call.argument(Param.WORD1), true);
142-
String word2 = FromMap.toString(Param.WORD2, call.argument(Param.WORD2), true);
143-
133+
final String word1 = FromMap.toString(Param.WORD1, call.argument(Param.WORD1), true);
134+
final String word2 = FromMap.toString(Param.WORD2, call.argument(Param.WORD2), true);
144135
analyzer.analyseWordsSimilarity(word1, word2)
145136
.addOnSuccessListener(responseHandler::success)
146137
.addOnFailureListener(responseHandler::exception);
@@ -151,9 +142,8 @@ private void analyseSimilarWords(MethodCall call) {
151142
responseHandler.noService();
152143
return;
153144
}
154-
String word = FromMap.toString(Param.WORD, call.argument(Param.WORD), false);
155-
Integer number = FromMap.toInteger(Param.NUMBER, call.argument(Param.NUMBER));
156-
145+
final String word = FromMap.toString(Param.WORD, call.argument(Param.WORD), false);
146+
final Integer number = FromMap.toInteger(Param.NUMBER, call.argument(Param.NUMBER));
157147
analyzer.analyseSimilarWords(word, number != null ? number : 1)
158148
.addOnSuccessListener(responseHandler::success)
159149
.addOnFailureListener(responseHandler::exception);
@@ -164,7 +154,6 @@ private void getVocabularyVersion() {
164154
responseHandler.noService();
165155
return;
166156
}
167-
168157
analyzer.getVocabularyVersion()
169158
.addOnSuccessListener(mlVocabularyVersion -> responseHandler.success(vocabularyVersionToMap(mlVocabularyVersion).toString()))
170159
.addOnFailureListener(responseHandler::exception);
@@ -175,8 +164,7 @@ private void analyseWordVectorBatch(@NonNull MethodCall call) {
175164
responseHandler.noService();
176165
return;
177166
}
178-
List<String> words = FromMap.toStringArrayList(Param.WORDS, call.argument(Param.WORDS));
179-
167+
final List<String> words = FromMap.toStringArrayList(Param.WORDS, call.argument(Param.WORDS));
180168
analyzer.analyseWordVectorBatch(Commons.getStringSet(words))
181169
.addOnSuccessListener(stringMap -> {
182170
Map<String, Object> map = new HashMap<>();

flutter-hms-mltext/android/src/main/java/com/huawei/hms/flutter/mltext/logger/HMSLogger.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public final class HMSLogger {
4040

4141
private static final String PLATFORM = "Flutter";
4242

43-
private static final String VERSION = "3.2.0.301";
43+
private static final String VERSION = "3.7.0.300";
4444

4545
private static final String SERVICE = "Cross-Platform";
4646

flutter-hms-mltext/android/src/main/java/com/huawei/hms/flutter/mltext/mlapplication/MlApplicationMethodHandler.java

+21-2
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@
2828
import com.huawei.hms.flutter.mltext.utils.TextResponseHandler;
2929
import com.huawei.hms.mlsdk.common.MLApplication;
3030

31+
import java.util.Objects;
32+
3133
import io.flutter.plugin.common.MethodCall;
3234
import io.flutter.plugin.common.MethodChannel;
3335

@@ -52,6 +54,12 @@ public void onMethodCall(@NonNull MethodCall call, @NonNull MethodChannel.Result
5254
case Method.SET_ACCESS_TOKEN:
5355
setAccessToken(call);
5456
break;
57+
case Method.SET_USER_REGION:
58+
setUserRegion(call);
59+
break;
60+
case Method.GET_COUNTRY_CODE:
61+
getCountryCode();
62+
break;
5563
case Method.ENABLE_LOGGER:
5664
enableLogger();
5765
break;
@@ -64,17 +72,28 @@ public void onMethodCall(@NonNull MethodCall call, @NonNull MethodChannel.Result
6472
}
6573

6674
private void setApiKey(@NonNull MethodCall call) {
67-
String key = FromMap.toString(Param.KEY, call.argument(Param.KEY), false);
75+
final String key = FromMap.toString(Param.KEY, call.argument(Param.KEY), false);
6876
MLApplication.getInstance().setApiKey(key);
6977
responseHandler.success(true);
7078
}
7179

7280
private void setAccessToken(@NonNull MethodCall call) {
73-
String key = FromMap.toString(Param.TOKEN, call.argument(Param.TOKEN), false);
81+
final String key = FromMap.toString(Param.TOKEN, call.argument(Param.TOKEN), false);
7482
MLApplication.getInstance().setAccessToken(key);
7583
responseHandler.success(true);
7684
}
7785

86+
private void setUserRegion(@NonNull MethodCall call) {
87+
final Integer region = FromMap.toInteger("region", call.argument("region"));
88+
MLApplication.getInstance().setUserRegion(Objects.requireNonNull(region));
89+
responseHandler.success(true);
90+
}
91+
92+
private void getCountryCode() {
93+
final String countryCode = MLApplication.getInstance().getCountryCode();
94+
responseHandler.success(countryCode);
95+
}
96+
7897
private void enableLogger() {
7998
HMSLogger.getInstance(activity).enableLogger();
8099
responseHandler.success(null);

0 commit comments

Comments
 (0)