-
Notifications
You must be signed in to change notification settings - Fork 0
/
gse.js
89 lines (74 loc) · 2.08 KB
/
gse.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
// Copyright 2016 The go-vgo Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// https://github.com/go-vgo/robotgo/blob/master/LICENSE
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
var ffi = require('ffi-napi');
// var ffi = require('ffi');
const path = require('path');
var Struct = require("ref-struct");
//
var findS = Struct({
freq: 'double',
pos: 'string',
ok: 'bool'
})
const bin = path.join(__dirname, './gse');
var lib = ffi.Library(bin, {
'GetVersion': ['string', []],
'LoadDict': ['string', ['string']],
'AddToken': ['void', ['string', 'double', 'string']],
'AddTokenForce': ['void', ['string', 'double', 'string']],
'CalcToken': ['void', []],
//
'Find': [findS, ['string']],
'Cut': ['string', ['string', 'bool']],
'CutAll': ['string', ['string']],
'CutSearch': ['string', ['string', 'bool']],
});
function getVersion() {
lib.GetVersion();
}
function loadDict(path = "zh") {
return lib.LoadDict(path);
}
function addToken(text, freq, pos = "") {
lib.AddToken(text, freq, pos);
}
function addTokenForce(text, freq, pos = "") {
lib.AddTokenForce(text, freq, pos);
}
function calcToken() {
lib.CalcToken();
}
function find(text) {
var s = lib.Find(text);
return {
freq: s.freq,
pos: s.pos,
ok: s.ok
};
}
function cut(str, hmm = false) {
return lib.Cut(str, hmm).split(" ");
}
function cutAll(str) {
return lib.CutAll(str).split(" ");
}
function cutSearch(str, hmm = false) {
return lib.CutSearch(str, hmm).split(" ");
}
exports.getVersion = getVersion;
exports.loadDict = loadDict;
exports.addToken = addToken;
exports.addTokenForce = addTokenForce;
exports.calcToken = calcToken;
//
exports.find = find;
exports.cut = cut;
exports.cutAll = cutAll;
exports.cutSearch = cutSearch;