forked from HIT-SCIR/ltp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsegmentwriter.h
84 lines (70 loc) · 2.25 KB
/
segmentwriter.h
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
#ifndef __LTP_SEGMENTOR_WRITER_H__
#define __LTP_SEGMENTOR_WRITER_H__
#include <iostream>
#include "instance.h"
namespace ltp {
namespace segmentor {
class SegmentWriter {
public:
SegmentWriter(std::ostream & _ofs) : ofs(_ofs) {}
void write(const Instance * inst) {
int len = inst->predicted_words.size();
for (int i = 0; i < len; ++ i) {
ofs << inst->predicted_words[i];
if (i+1==len) ofs << std::endl;
else ofs << "\t";
}
}
void debug(const Instance * inst, bool show_feat = false) {
int len = inst->size();
ofs << "_instance_debug_" << std::endl;
ofs << "FORMS: ";
for (int i = 0; i < len; ++ i) {
ofs << inst->forms[i] << "|";
}
ofs << std::endl;
ofs << "TAGS: ";
for (int i = 0; i < inst->tags.size(); ++ i) {
ofs << inst->tags[i] << "|";
}
ofs << std::endl;
ofs << "TAGS(index): ";
for (int i = 0; i < inst->tagsidx.size(); ++ i) {
ofs << inst->tagsidx[i] << "|";
}
ofs << std::endl;
ofs << "PREDICTED TAGS: ";
for (int i = 0; i < inst->predicted_tags.size(); ++ i) {
ofs << inst->predicted_tags[i] << "|";
}
ofs << std::endl;
ofs << "PREDICTED TAGS(index): ";
for (int i = 0; i < inst->predicted_tagsidx.size(); ++ i) {
ofs << inst->predicted_tagsidx[i] << "|";
}
ofs << std::endl;
ofs << "WORDS: ";
for (int i = 0; i < inst->words.size(); ++ i) {
ofs << inst->words[i] << "|";
}
ofs << std::endl;
ofs << "PREDICTED WORDS: ";
for (int i = 0; i < inst->predicted_words.size(); ++ i) {
ofs << inst->predicted_words[i] << "|";
}
ofs << std::endl;
if (show_feat) {
ofs << "GOLD FEATURES: ";
inst->features.str(ofs);
ofs << std::endl;
ofs << "PREDICTED FEATURES: ";
inst->predicted_features.str(ofs);
ofs << std::endl;
}
}
private:
std::ostream & ofs;
};
} // end for namespace segmentor
} // end for namespace ltp
#endif // end for __LTP_SEGMENTOR_WRITER_H__