主题
导入txt文本字库 - ImportTxtDict
函数简介
从指定的txt文本文件导入字库数据到内存,便于后续文字识别使用。该接口不会将数据保存到数据库。
接口名称
ImportTxtDictDLL调用
int ImportTxtDict(long instance, string dictName, string dictPath);参数说明
| 参数名 | 类型 | 说明 |
|---|---|---|
| instance | 长整数型 | OLAPlug对象的指针,由 CreateCOLAPlugInterFace 接口生成。 |
| dictName | 字符串 | 字库名称,用于标识当前导入的字库。 |
| dictPath | 字符串 | txt文本字库文件路径,例如 C:\\dicts\\mydict.txt。 |
示例
SDK 调用
cpp
#include "OLAPlugServer.h"
OLAPlugServer ola;
int ret = ola.ImportTxtDict("value", "C:\\test.txt");csharp
using OLAPlug;
var ola = new OLAPlugServer();
int ret = ola.ImportTxtDict("value", "C:\\test.txt");python
from OLAPlugServer import OLAPlugServer
ola = OLAPlugServer()
ret = ola.ImportTxtDict("value", "C:\\test.txt")java
import com.olaplug.OLAPlugServer;
OLAPlugServer ola = new OLAPlugServer();
int ret = ola.ImportTxtDict("value", "C:\\test.txt");cpp
var ola = com("OlaPlug.OlaSoft")
var ret = ola.ImportTxtDict("value", "C:\\test.txt")vbscript
Set ola = CreateObject("OlaPlug.OlaSoft")
ret = ola.ImportTxtDict("value", "C:\\test.txt")text
.局部变量 ola, OLAPlug
ola.创建 ()
ret = ola.ImportTxtDict(“value”, “C:\\test.txt”)aardio
import OLAPlugServer;
var ola = OLAPlugServer();
var ret = ola.ImportTxtDict("value", "C:\\test.txt");text
变量 ola <类型 = OLAPlugServer>
ola = 新建 OLAPlugServer
整数 ret = ola.ImportTxtDict("value", "C:\\test.txt")cpp
#include "OLAPlugServer.h"
OLAPlugServer ola;
int32_t ret = ola.ImportTxtDict("value", "C:\\test.txt");原生 DLL 调用
cpp
long instance = CreateCOLAPlugInterFace();
ImportTxtDict(instance, "value", "C:\\test.txt");csharp
using System.Runtime.InteropServices;
using System.Text;
[DllImport("OLAPlug_x64.dll", CallingConvention = CallingConvention.StdCall)]
static extern long CreateCOLAPlugInterFace();
[DllImport("OLAPlug_x64.dll", CallingConvention = CallingConvention.StdCall)]
static extern int ImportTxtDict(long ola, string dictName, string dictPath);
long instance = CreateCOLAPlugInterFace();
ImportTxtDict(instance, "value", "C:\\test.txt");python
from ctypes import CDLL, c_int, c_int64, create_string_buffer
ola = CDLL("OLAPlug_x64.dll")
ola.CreateCOLAPlugInterFace.restype = c_int64
instance = ola.CreateCOLAPlugInterFace()
ola.ImportTxtDict(instance, "value", "C:\\test.txt")返回值
| 返回值 | 说明 |
|---|---|
1 | 成功。 |
0 | 失败。 |
注意事项
| 项目 | 说明 |
|---|---|
| 该接口仅将字库数据导入内存 | 该接口仅将字库数据导入内存,不会保存到数据库,如需持久化请使用 InitDictFromTxt 接口。 |
| 在开发调试阶段使用该接口导入/调试字库 | 建议在开发调试阶段使用该接口导入/调试字库,正式发布时可将字库存入数据库。 |
| 格式 | 请确保 dictPath 对应的txt文件存在且格式正确。 |
| 若字库中已存在同名条目 | 若字库中已存在同名条目,则返回失败。 |
