forked from HIT-SCIR/ltp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsrl_interface_unittest.cpp
138 lines (120 loc) · 4.43 KB
/
srl_interface_unittest.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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
// Provide some higher-level testcases
// For some unittest on the internal data structure and function,
// please write in the ./srl_internal_unittest.cpp in same
// folder.
#include <iostream>
#include <fstream>
#include <vector>
#include <gtest/gtest.h>
#include "srl/SRL_DLL.h"
TEST(srl_interface_unittest, test_load_model_success) {
int tag = SRL_LoadResource("./ltp_data/srl");
EXPECT_TRUE(0 == tag);
SRL_ReleaseResource();
}
TEST(srl_interface_unittest, test_load_model_fail) {
int tag = SRL_LoadResource("/a/path/that/never/exist");
EXPECT_EQ(-1, tag);
}
const char * kNormalWords[] = {"我", "是", "猫", "。"};
const char * kNormalPostags[] = {"r", "v", "n", "wp"};
const char * kNormalNes[] = {"O", "O", "O", "O"};
const int kNormalHeads[] = {1,-1,1,1};
const char * kNormalDeprels[] = {"SBV", "HED", "VOB", "WP"};
const int kNumNormalWords = 4;
TEST(srl_interface_unittest, test_normal) {
int tag = SRL_LoadResource("./ltp_data/srl");
EXPECT_TRUE(0 == tag);
std::vector<std::string> words;
std::vector<std::string> tags;
std::vector<std::string> nes;
std::vector<std::pair<int,std::string > > parses;
std::vector< std::pair< int, std::vector< std::pair<std::string, std::pair< int, int > > > > > srls;
for (int i = 0; i < kNumNormalWords; ++ i) {
words.push_back(kNormalWords[i]);
tags.push_back(kNormalPostags[i]);
nes.push_back(kNormalNes[i]);
parses.push_back(std::make_pair(kNormalHeads[i], kNormalDeprels[i]));
}
int nr_words = DoSRL(words, tags , nes, parses ,srls);
// tagged words should be greater than 4
EXPECT_GT(nr_words, 0);
SRL_ReleaseResource();
}
TEST(srl_interface_unittest, test_empty_list) {
int tag = SRL_LoadResource("./ltp_data/srl");
EXPECT_TRUE(0 == tag);
std::vector<std::string> words;
std::vector<std::string> tags;
std::vector<std::string> nes;
std::vector<std::pair<int,std::string > > parses;
std::vector< std::pair< int, std::vector< std::pair<std::string, std::pair< int, int > > > > > srls;
int nr_words = DoSRL(words, tags , nes, parses ,srls);
EXPECT_EQ(0, nr_words);
SRL_ReleaseResource();
}
TEST(srl_interface_unittest, test_empty_word) {
int tag = SRL_LoadResource("./ltp_data/srl");
EXPECT_TRUE(0 == tag);
std::vector<std::string> words;
std::vector<std::string> tags;
std::vector<std::string> nes;
std::vector<std::pair<int,std::string > > parses;
std::vector< std::pair< int, std::vector< std::pair<std::string, std::pair< int, int > > > > > srls;
for (int i = 0; i < kNumNormalWords; ++ i) {
if (i == 2) {
words.push_back("");
} else {
words.push_back(kNormalWords[i]);
}
tags.push_back(kNormalPostags[i]);
nes.push_back(kNormalNes[i]);
parses.push_back(std::make_pair(kNormalHeads[i], kNormalDeprels[i]));
}
int nr_words = DoSRL( words, tags, nes, parses, srls);
EXPECT_EQ(-1, nr_words);
SRL_ReleaseResource();
}
TEST(srl_interface_unittest, test_different_size) {
int tag = SRL_LoadResource("./ltp_data/srl");
EXPECT_TRUE(0 == tag);
std::vector<std::string> words;
std::vector<std::string> tags;
std::vector<std::string> nes;
std::vector<std::pair<int,std::string > > parses;
std::vector< std::pair< int, std::vector< std::pair<std::string, std::pair< int, int > > > > > srls;
for (int i = 0; i < kNumNormalWords; ++ i) {
if (i != 2) {
words.push_back(kNormalWords[i]);
}
tags.push_back(kNormalPostags[i]);
tags.push_back(kNormalNes[i]);
parses.push_back(std::make_pair(kNormalHeads[i], kNormalDeprels[i]));
}
int nr_words = DoSRL(words, tags, nes, parses, srls);
EXPECT_EQ(-1, nr_words);
SRL_ReleaseResource();
}
TEST(srl_interface_unittest, test_illeagel_head) {
int tag = SRL_LoadResource("./ltp_data/srl");
EXPECT_TRUE(0 == tag);
std::vector<std::string> words;
std::vector<std::string> tags;
std::vector<std::string> nes;
std::vector<std::pair<int,std::string > > parses;
std::vector< std::pair< int, std::vector< std::pair<std::string, std::pair< int, int > > > > > srls;
for (int i = 0; i < kNumNormalWords; ++ i) {
tags.push_back(kNormalPostags[i]);
words.push_back(kNormalWords[i]);
nes.push_back(kNormalNes[i]);
parses.push_back(std::make_pair(kNormalHeads[i], kNormalDeprels[i]));
}
parses[0].first = -2;
int nr_words = DoSRL(words, tags, nes, parses, srls);
EXPECT_EQ(-1, nr_words);
SRL_ReleaseResource();
}
int main(int argc, char **argv) {
::testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}