PLearn 0.1
|
#include <ShellProgressBar.h>
Public Member Functions | |
ShellProgressBar () | |
ShellProgressBar (int min, int max, string caption="", int width=10) | |
void | init () |
void | draw (bool simple_mode=false) |
bool | update (int value) |
void | reset () |
void | set (int min, int max, string caption="", int w=10) |
void | setCaption (string caption) |
void | setMin (int min) |
void | setMax (int max) |
void | done () |
Static Public Member Functions | |
static string | getTime () |
static int | getAsciiFileLineCount (string file) |
static int | getWcAsciiFileLineCount (string file) |
Private Attributes | |
int | min |
int | max |
real | blockwidth |
int | pos |
string | caption |
int | width |
bool | max_reached |
Definition at line 74 of file ShellProgressBar.h.
PLearn::ShellProgressBar::ShellProgressBar | ( | ) | [inline] |
void PLearn::ShellProgressBar::done | ( | ) |
Definition at line 127 of file ShellProgressBar.cc.
References PLearn::endl(), getTime(), max, max_reached, and update().
Referenced by PLearn::WordNetOntology::extract(), PLearn::GraphicalBiText::init(), PLearn::WordNetOntology::load(), PLearn::GraphicalBiText::loadBitext(), main(), PLearn::GraphicalBiText::print(), and PLearn::GraphicalBiText::test_WSD().
{ if (!max_reached) update(max); cout << "\033[2C" << getTime() << endl; }
void PLearn::ShellProgressBar::draw | ( | bool | simple_mode = false | ) |
Definition at line 60 of file ShellProgressBar.cc.
References caption, getTime(), i, PLearn::tostring(), and width.
Referenced by PLearn::WordNetOntology::extract(), PLearn::WordNetOntology::extractTaggedWordFrequencies(), PLearn::GraphicalBiText::init(), PLearn::WordNetOntology::load(), PLearn::GraphicalBiText::loadBitext(), PLearn::loadToVMat(), main(), PLearn::GraphicalBiText::print(), and PLearn::GraphicalBiText::test_WSD().
{ if (simple_mode) { cout << caption << " " << getTime() << " "; cout.flush(); } else { cout << caption << " " << getTime() << " |"; for (int i = 0;i < width; i++) cout << " "; cout <<"|"; string move_cursor_left = "\033[" + tostring(width + 1) + "D"; cout << move_cursor_left; cout.flush(); } }
int PLearn::ShellProgressBar::getAsciiFileLineCount | ( | string | file | ) | [static] |
Definition at line 134 of file ShellProgressBar.cc.
References in, and PLearn::pgetline().
Referenced by PLearn::WordNetOntology::extract(), PLearn::WordNetOntology::load(), and PLearn::GraphicalBiText::loadBitext().
{ // not terribly efficient, I fear, but I don't // have the time for a better solution (the one // with Popen crashes with a MPI program...) ifstream in(file.c_str()); int n_lines = 0; while (in) { pgetline(in); n_lines++; } in.close(); return n_lines; }
string PLearn::ShellProgressBar::getTime | ( | ) | [static] |
Definition at line 157 of file ShellProgressBar.cc.
References PLearn::split().
Referenced by done(), and draw().
{ time_t tt; time(&tt); string time_str(ctime(&tt)); vector<string> tokens = split(time_str); return "[" + tokens[3] + "]"; }
int PLearn::ShellProgressBar::getWcAsciiFileLineCount | ( | string | file | ) | [static] |
Definition at line 150 of file ShellProgressBar.cc.
References PLearn::execute(), and PLearn::toint().
Referenced by extractFiles(), and main().
void PLearn::ShellProgressBar::init | ( | ) |
Definition at line 53 of file ShellProgressBar.cc.
References blockwidth, max, max_reached, min, pos, and width.
Referenced by PLearn::GraphicalBiText::compute_likelihood(), PLearn::GraphicalBiText::init(), PLearn::GraphicalBiText::loadBitext(), main(), PLearn::GraphicalBiText::print(), PLearn::WordNetOntology::reducePolysemy(), PLearn::GraphicalBiText::sensetag_valid_bitext(), PLearn::GraphicalBiText::senseTagBitext(), ShellProgressBar(), PLearn::GraphicalBiText::test_WSD(), and PLearn::GraphicalBiText::update_WSD_model().
{ blockwidth = (real)(max - min) / width; pos = 0; max_reached = false; }
void PLearn::ShellProgressBar::reset | ( | ) |
Definition at line 106 of file ShellProgressBar.cc.
References max_reached, and pos.
Referenced by main().
{ max_reached = false; pos = 0; }
Definition at line 89 of file ShellProgressBar.h.
References PLearn::max(), PLearn::min(), and w.
Referenced by PLearn::GraphicalBiText::init(), PLearn::GraphicalBiText::loadBitext(), main(), and PLearn::GraphicalBiText::test_WSD().
void PLearn::ShellProgressBar::setCaption | ( | string | caption | ) |
void PLearn::ShellProgressBar::setMax | ( | int | max | ) |
void PLearn::ShellProgressBar::setMin | ( | int | min | ) |
Definition at line 77 of file ShellProgressBar.cc.
References blockwidth, i, max, max_reached, min, pos, and width.
Referenced by done(), PLearn::WordNetOntology::extract(), PLearn::GraphicalBiText::init(), PLearn::WordNetOntology::load(), PLearn::GraphicalBiText::loadBitext(), main(), PLearn::GraphicalBiText::print(), and PLearn::GraphicalBiText::test_WSD().
{ if (value < min || max_reached) { return false; } else if (value >= max) { for (int i = pos; i < width; i++) { cout << "="; cout.flush(); } max_reached = true; return true; } int inc = (int)((value - min) / blockwidth); int i; for (i = pos; i < inc; i++) { cout << "="; cout.flush(); } pos = i; return true; }
real PLearn::ShellProgressBar::blockwidth [private] |
Definition at line 102 of file ShellProgressBar.h.
string PLearn::ShellProgressBar::caption [private] |
Definition at line 104 of file ShellProgressBar.h.
Referenced by draw(), and setCaption().
int PLearn::ShellProgressBar::max [private] |
bool PLearn::ShellProgressBar::max_reached [private] |
int PLearn::ShellProgressBar::min [private] |
Definition at line 100 of file ShellProgressBar.h.
int PLearn::ShellProgressBar::pos [private] |
Definition at line 103 of file ShellProgressBar.h.
int PLearn::ShellProgressBar::width [private] |
Definition at line 105 of file ShellProgressBar.h.