15 #ifndef TASK_HIFST_STATS_HPP 16 #define TASK_HIFST_STATS_HPP 61 bool run ( Data& d ) {
62 if ( statsoutput_() ==
"" )
return false;
64 FORCELINFO (
"Writing stats to " << statsoutput_ ( d.sidx ) );
68 o <<
"=================================================================" <<
70 o <<
"Local pruning during lattice construction" << endl;
71 writePruneStats ( o );
84 void writeCYKStats ( oszfstream& o ) {
85 std::vector<std::string> ws;
86 boost::algorithm::split ( ws, d_->sentence,
87 boost::algorithm::is_any_of (
" " ) );
88 std::stringstream line;
89 for (
unsigned z = 0; z < width_; ++z ) line <<
"-";
90 o <<
"Source sentence:" << d_->sentence << endl;
91 o <<
"Word count:" << ws.size() << endl;
94 o <<
"Number of rules (R), states (NS) and states after pruning (NSP) for each cell of the CYK grid:" 96 o <<
"=================================================================" <<
98 o << std::setw ( width_ + 5 ) << std::setiosflags ( std::ios::left ) <<
"x\\y";
99 for (
unsigned x = 0; x < ws.size(); x++ ) {
100 o << std::setw ( width_ ) << std::setiosflags ( std::ios::left ) << x + 1;
103 o << std::setw ( 4 ) << std::setiosflags ( std::ios::left ) <<
"----";
104 for (
unsigned x = 0; x < ws.size() + 1; x++ ) {
105 o << std::setw ( width_ ) << line.str();
108 for (
unsigned x = 0; x < ws.size(); x++ ) {
109 o << std::setw ( 4 ) << std::setiosflags ( std::ios::left ) <<
110 std::resetiosflags ( std::ios::right ) << ( ucam::util::toString<unsigned>
112 o << std::setw ( width_ - 4 ) << std::setiosflags ( std::ios::left ) <<
113 std::resetiosflags ( std::ios::right ) << ws[x];
114 o << std::setw ( 4 ) << std::setiosflags ( std::ios::right ) <<
"R:";
115 for (
unsigned int y = 0; y < ws.size() - x; y++ ) {
116 std::stringstream a1;
118 for (
unsigned int cc = 1; cc <= d_->stats->numcats; cc++ ) {
119 if ( d_->stats->rulecounts[cc * 1000000 + y * 1000 + x] ) {
121 a1 << d_->vcat[cc] <<
"=" << d_->stats->rulecounts[cc * 1000000 + y * 1000 + x]
125 o << std::setw ( width_ ) << std::setiosflags ( std::ios::left ) <<
126 std::resetiosflags ( std::ios::right ) << a1.str() ;
128 o << std::setiosflags ( std::ios::left ) <<
"|" << endl;
129 o << std::setw ( width_ ) <<
" ";
130 o << std::setw ( 4 ) << std::setiosflags ( std::ios::right ) <<
"NS:";
131 for (
unsigned int y = 0; y < ws.size() - x; y++ ) {
132 std::stringstream a2;
134 for (
unsigned int cc = 1; cc <= d_->stats->numcats; cc++ ) {
135 if ( d_->stats->numstates[cc * 1000000 + y * 1000 + x] ) {
137 a2 << d_->vcat[cc] <<
"=" << d_->stats->numstates[cc * 1000000 + y * 1000 + x]
141 o << std::setw ( width_ ) << std::setiosflags ( std::ios::left ) <<
142 std::resetiosflags ( std::ios::right ) << a2.str();
144 o << std::setiosflags ( std::ios::left ) <<
"|" << endl;
145 o << std::setw ( width_ ) <<
" ";
146 o << std::setw ( 4 ) << std::setiosflags ( std::ios::right ) <<
"NSP:";
147 for (
unsigned int y = 0; y < ws.size() - x; y++ ) {
148 std::stringstream a3;
150 for (
unsigned int cc = 1; cc <= d_->stats->numcats; cc++ ) {
151 if ( d_->stats->numprunedstates[cc * 1000000 + y * 1000 + x] ) {
153 a3 << d_->vcat[cc] <<
"=" << d_->stats->numprunedstates[cc * 1000000 + y * 1000
157 o << std::setw ( width_ ) << std::setiosflags ( std::ios::left ) <<
158 std::resetiosflags ( std::ios::right ) << a3.str();
160 o << std::setiosflags ( std::ios::left ) <<
"|" << endl;
161 o << std::setw ( 4 ) <<
"----";
162 for (
unsigned int y = 0; y < ws.size() - x + 1; y++ ) {
163 o << std::setw ( width_ ) << line.str();
174 void writePruneStats ( oszfstream& o ) {
175 o <<
"Number of times=" << d_->stats->lpcount << endl;
Wrapper stream class that writes to pipes, text files or gzipped files.
class that expands a wildcard into its actual value. This is useful e.g. for filenames ranging severa...
Task that dumps statistics stored by any previous task in the pipeline.
const std::string kStatsHifstCykgridCellwidth
HifstStatsTask(const ucam::util::RegistryPO &rg)
Constructor with RegistryPO object.
const std::string kStatsHifstCykgridEnable
Templated (hybrid) Interface for Task classes.
TaskInterface & appendTask(TaskInterface *t)
Appends a task class. If there is no task, append here, otherwise delegate in next task...
const std::string kStatsHifstWrite
Reads StatsData and dumps all stats to (sentence-specific) file. Provides a special method for cyk da...
bool run(Data &d)
General run method from TaskInterface. Dumps all stats to a file.
void close()
Closes the file.