-
Notifications
You must be signed in to change notification settings - Fork 0
/
ictclas.cc
57 lines (46 loc) · 1.46 KB
/
ictclas.cc
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
#include <node.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "NLPIR.h"
namespace demo {
using v8::Exception;
using v8::Function;
using v8::FunctionCallbackInfo;
using v8::FunctionTemplate;
using v8::Isolate;
using v8::Local;
using v8::Object;
using v8::String;
using v8::Value;
void init(const FunctionCallbackInfo<Value>& args) {
Isolate* isolate = args.GetIsolate();
// 此处硬编码,与目录Data的相对目录
// 1表示使用uft8编码
NLPIR_Init("./", 1);
args.GetReturnValue().Set(String::NewFromUtf8(isolate, "ok"));
}
void wordFreqStat(const FunctionCallbackInfo<Value>& args) {
Isolate* isolate = args.GetIsolate();
// Check the number of arguments passed.
if (args.Length() != 1) {
// Throw an Error that is passed back to JavaScript
isolate->ThrowException(Exception::TypeError(
String::NewFromUtf8(isolate, "Wrong number of arguments")));
return;
}
// Check the argument types
if (!args[0]->IsString()) {
isolate->ThrowException(Exception::TypeError(
String::NewFromUtf8(isolate, "String type needed !")));
return;
}
String::Utf8Value txt(args[0]);
args.GetReturnValue().Set(String::NewFromUtf8(isolate, NLPIR_WordFreqStat(*txt)));
}
void Init(Local<Object> exports) {
NODE_SET_METHOD(exports, "init", init);
NODE_SET_METHOD(exports, "wordFreqStat", wordFreqStat);
}
NODE_MODULE(ictclas, Init)
} // namespace demo