|
PLearn 0.1
|
The first sentence should be a BRIEF DESCRIPTION of what the class does. More...
#include <StatsCommand.h>


Public Member Functions | |
| StatsCommand () | |
| virtual void | run (const std::vector< std::string > &args) |
| The actual implementation of the 'StatsCommand' command. | |
Static Protected Attributes | |
| static PLearnCommandRegistry | reg_ |
| This allows to register the 'StatsCommand' command in the command registry. | |
Private Types | |
| typedef PLearnCommand | inherited |
The first sentence should be a BRIEF DESCRIPTION of what the class does.
Place the rest of the class programmer documentation here. Doxygen supports Javadoc-style comments. See http://www.doxygen.org/manual.html
Definition at line 58 of file StatsCommand.h.
typedef PLearnCommand PLearn::StatsCommand::inherited [private] |
Definition at line 60 of file StatsCommand.h.
| PLearn::StatsCommand::StatsCommand | ( | ) |
Definition at line 54 of file StatsCommand.cc.
: PLearnCommand( "stats", "allow to extract some stats from stats file", "plearn stats sum_sort <statsfile> --filter=boost_regex --replace=boost_regex=new_value\n" "FULL DETAILED HELP HERE \n" ) {}
| void PLearn::StatsCommand::run | ( | const std::vector< std::string > & | args | ) | [virtual] |
The actual implementation of the 'StatsCommand' command.
Implements PLearn::PLearnCommand.
Definition at line 64 of file StatsCommand.cc.
References PLearn::endl(), PLearn::filter(), PLearn::VecStatsCollector::getFieldNames(), PLearn::VecStatsCollector::getStats(), i, PLearn::load(), m, PLERROR, PLearn::pout, PLearn::VecStatsCollector::size(), PLearn::sortRows(), PLearn::split_on_first(), and PLearn::StatsCollector::sum().
{
if(args[0]=="sum_sort"){
//plearn Stats sum_sort <statsfile> --filter=boost_regex --replace=boost_regex=new_value
if(args.size()<2)
PLERROR("plearn stats sum_sort <statsfile> --filter=boost_regex --replace=boost_regex=new_value");
//default regex that match all non new line caracter
boost::regex filter(".*");
boost::regex replace_re;
string replace_new = "";
string statsfile = args[1];
string test_re;
try{
for(uint i=2;i<args.size();i++){
if(args[i].substr(0,9)=="--filter="){
test_re=args[i].substr(9);
filter.assign(test_re);
}else if(args[i].substr(0,10)=="--replace="){
split_on_first(args[i].substr(10), "=",
test_re, replace_new);
replace_re.assign(test_re);
}else
PLERROR("In StatsCommand::run() - unknow parameter '%s'",
args[i].c_str());
}
}catch (boost::regex_error& e){
PLERROR("invalid regular expression: \"%s\"\n %s",
test_re.c_str(),
e.what());
}
TVec<StatsCollector> stats1;
VecStatsCollector stats;
PLearn::load(statsfile, stats);
Mat m(stats.size(),2);
for(int i = 0;i<stats.size();i++){
m(i,0)=i;
m(i,1)=stats.getStats(i).sum();
}
pout<<"NAME "<<"SUM"<<endl;
sortRows(m,1,false);
for(int i=0;i<m.length();i++){
string f = stats.getFieldNames()[int(m(i,0))];
if(boost::regex_match(f, filter)){
if(replace_re.size()>0)
f = boost::regex_replace(f,replace_re,"");
pout<<f<<" "<<m(i,1)<<endl;
}
}
}else
PLERROR("Currently only the sub commands sum_sort is supported!");
}

PLearnCommandRegistry PLearn::StatsCommand::reg_ [static, protected] |
This allows to register the 'StatsCommand' command in the command registry.
Definition at line 67 of file StatsCommand.h.
1.7.4