iink SDK on Device

Android sdk 中是否支持动态生成子集知识

在android sdk中是否提供预制的配置文件*.conf中不存在的配置,

在程序运行过程中调用sdk代码生成“自定义子集知识”或“自定义词典”使用。

实现动态配置识别,来提高识别精准度。


Dear Li Perry,


Than you for contacting us.

You can customise the configuration file according to your neeeds. For instance, to choose the language you should modify the .conf file. You can refer to
https://developer.myscript.com/docs/interactive-ink/1.3/android/fundamentals/interactive-ink-runtime/#language-recognition-configuration

Modifying the configuration to use custom resources is a more advanced use case. You can refer to following page:
https://developer.myscript.com/docs/interactive-ink/1.3/android/advanced/custom-recognition/
to learn how to build your custom resources and use them.

If you want to modify the configuration dynamically, please check following topics that describes how to proceed:
https://developer-support.myscript.com/support/discussions/topics/16000026598

Best regards,

Gwenaëlle

感谢你给我的链接资料;这些资料我都阅读过;没能帮助到我;

我需要的是在配置文件*.conf中不存在的;在程序运行过程中需要动态加载“自定义子集知识”;这个过程中可以不生成.res文件;

例如:我在代码中直接传入: “0123456789”,他就可以直接只识别这些数字。

而不是先生成.res;再修改.conf,然后再打包apk安装运行。

Dear Li Perry,

Thank you for your update.

If I come back to your question and example: "I directly pass in the code: "0123456789", he can directly recognize these numbers only. Instead of geneating .res first; then modify .conf, then package and install apk to run."

You can't directly pass the "0123456789": you must generate the corresponding the .res file and set a configuration file that refers to this resource file.
But you can do this AFTER the apk installation, dynamically in your application code thanks to the RecognitionAssetsBuilder API:
https://developer.myscript.com/refguides/interactive-ink/android/1.3/com/myscript/iink/RecognitionAssetsBuilder.html

This section describes step by step how to use the RecognitionAssetsBuilder inside your code to generate and use the .res file on device:
https://developer.myscript.com/docs/interactive-ink/1.3/android/advanced/build-custom-resources/#on-device

Best regards,

Gwenaëlle

hi,Gwenaelle,

感谢你的答复;这些文档我都认真的阅读过了;但我现在需要的是Android app 配置文件*.conf中不存在的配置,是否可以加载到正在运行的app中?

我现在已经知道如何在app中生成.res了;那如何可以在不更新.conf和重新打包apk的状态下来直接调用之前生成的.res呢?

期待您的回复

Hi,


Thank you for your update.


Let's assume you want to set a lexicon dynamically in your English US recognition.

Here is how you could proceed:


In the en_US.conf file that you package in your apk, you plan your customised resource that will be generated dynamically by adding the dir resource path with the line AddResDir /data/user/0/com.myscript.iink.getstarted/files

and by adding the customisedLexicon that your application will use dynamically. Depending whether you want to replace the English US lexicon to only recognize your custom lexicon or you want to enrich the English US lexicon with your custom lexicon, in which case you would also keep the

 AddResource en_US/en_US-lk-text.res in your  customisedLexicon, this would look like:



Bundle-Version: 1.0
Bundle-Name: en_US
Configuration-Script:
 AddResDir ../resources/
 AddResDir /data/user/0/com.myscript.iink.getstarted/files

Name: text
Type: Text
Configuration-Script:
 AddResource en_US/en_US-ak-cur.res
 AddResource en_US/en_US-lk-text.res
 EnableAlienCharacters
 SetTextListSize 1
 SetWordListSize 5
 SetCharListSize 1

Name: customisedLexicon
Type: Text
Configuration-Script:
 AddResource en_US/en_US-ak-cur.res
 AddResource customised-lexicon.res
 EnableAlienCharacters
 SetTextListSize 1
 SetWordListSize 5
 SetCharListSize 1



Then the method in your app to generate and use the customised Lexicon, could be:



private void updateLexicon()
  {
    Editor editor = editorView.getEditor();

    String internalStoragePath = getBaseContext().getFilesDir().getPath();

// 1. Create a recognition assets builder
RecognitionAssetsBuilder assetsBuilder = engine.createRecognitionAssetsBuilder();

// 2. Define and compile the lexicon: here it contains two words Johnson and Meyer
String lexicon = "Johnson" + "\n" + "Meyer" + "\n" +  "Lopez" ;

    assetsBuilder.compile("Text Lexicon", lexicon);

// 3. Save it to the disc
File file = new File(internalStoragePath, File.separator + "customised-lexicon.res");
    Log.d(TAG, "creating resource file  \""  + file.getPath());
try {
      assetsBuilder.store(file.getPath());
    }
catch(IOException e){
      Log.e(TAG, "Failed to save custom lexicon  \""  + e.getMessage());
    }

// 4. Update editor conf to take this resource into account. NB the conf shall be updated before setting the part of the editor.

if (contentPart != null)
    {
      contentPart.close();
      contentPart = null;
    }
    contentPart = contentPackage.getPart(0);
if (contentPart != null)
    {
      contentPart.close();
      contentPart = null;
    }
    editor.setPart(null);
    editor.clear();

    Configuration conf = editor.getConfiguration();
    conf.setString("text.configuration.name", "customisedLexicon");

    contentPart = contentPackage.createPart("Text");

    editor.setPart(contentPart);


  }


Just and additional warning, if you plan to re-use several times the res file with same name;


When building a dynamic lexicon, resource happens to be loaded in  memory. It shall then be released before re-compiling it. To proceed,  one solution can be to set the default "text" configuration: https://developer-support.myscript.com/support/discussions/topics/16000026598

  • set Default Text configuration =>this releases the resource from memory
  • add word to the lexicon and compile the resource
  • load the configuration


Best regards


Gwenaëlle