forked from HIT-SCIR/ltp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathltp_test.cpp
68 lines (53 loc) · 1.46 KB
/
ltp_test.cpp
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
// Defines the entry point for the console application.
//
#include <stdlib.h>
#include <iostream>
#include "Xml4nlp.h"
#include "Ltp.h"
using namespace std;
int main(int argc, char *argv[]) {
if (argc != 4) {
cerr << "Usage: ./ltp_test <config_file> <type> <test_file>" << endl;
exit(1);
}
string sentence;
// ofstream log_file("test.log");
LTP ltp(argv[1]);
string type(argv[2]);
ifstream in(argv[3]);
if (!in.is_open()) {
cerr << "Cann't open file!" << endl;
exit(1);
}
while(std::getline(in, sentence)){
int len = sentence.size();
while ( sentence[len-1]=='\n' || sentence[len-1]=='\r' ) {
-- len;
}
if (len == 0) {
continue;
}
sentence = sentence.substr(0, len);
cout << "Input sentence is: " << sentence << endl;
XML4NLP xml4nlp;
xml4nlp.CreateDOMFromString(sentence);
if(type == "ws"){
ltp.wordseg(xml4nlp);
} else if(type == "pos"){
ltp.postag(xml4nlp);
} else if(type == "ner"){
ltp.ner(xml4nlp);
} else if(type == "dp"){
ltp.parser(xml4nlp);
} else if(type == "srl"){
ltp.srl(xml4nlp);
} else {
ltp.srl(xml4nlp);
}
string result;
xml4nlp.SaveDOM(result);
cout << "Result is: " << result << endl;
xml4nlp.ClearDOM();
}
return 0;
}