diff options
author | graehl <graehl@ec762483-ff6d-05da-a07a-a48fb63a330f> | 2010-07-19 23:40:30 +0000 |
---|---|---|
committer | graehl <graehl@ec762483-ff6d-05da-a07a-a48fb63a330f> | 2010-07-19 23:40:30 +0000 |
commit | 190ad8ae1e131ac0e29ff975b0d6502f3cc57af6 (patch) | |
tree | 7016b7671bfa385a1b3e4a8ab4c2a2544e5208df /decoder/sentences.h | |
parent | 7d31056d098694b85847d9f75d3870913661e73b (diff) |
fixed oracle generate, detailed score info with --verbose
git-svn-id: https://ws10smt.googlecode.com/svn/trunk@329 ec762483-ff6d-05da-a07a-a48fb63a330f
Diffstat (limited to 'decoder/sentences.h')
-rwxr-xr-x | decoder/sentences.h | 32 |
1 files changed, 28 insertions, 4 deletions
diff --git a/decoder/sentences.h b/decoder/sentences.h index 842072b9..622a6f43 100755 --- a/decoder/sentences.h +++ b/decoder/sentences.h @@ -9,6 +9,10 @@ #include "stringlib.h" typedef std::vector<WordID> Sentence; +inline std::ostream & operator<<(std::ostream &out,Sentence const& s) { + return out<<TD::GetString(s); +} + inline void StringToSentence(std::string const& str,Sentence &s) { using namespace std; vector<string> ss=SplitOnWhitespace(str); @@ -38,15 +42,35 @@ public: Sentences() { } Sentences(unsigned n,Sentence const& sentence) : VS(n,sentence) { } Sentences(unsigned n,std::string const& sentence) : VS(n,StringToSentence(sentence)) { } + std::string filename; void Load(std::string file) { ReadFile r(file); - Load(*r.stream()); + Load(r.get(),file); } - void Load(std::istream &in) { - this->push_back(Sentence()); - while(in>>this->back()) ; + void Load(std::istream &in,std::string filen="-") { + filename=filen; + do { + this->push_back(Sentence()); + } while(in>>this->back()); this->pop_back(); } + void Print(std::ostream &out,int headn=0) const { + out << "[" << size()<< " sentences from "<<filename<<"]"; + if (headn!=0) { + int i=0,e=this->size(); + if (headn>0&&headn<e) { + e=headn; + out << " (first "<<headn<<")"; + } + out << " :\n"; + for (;i<e;++i) + out<<(*this)[i] << "\n"; + } + } + friend inline std::ostream& operator<<(std::ostream &out,Sentences const& s) { + s.Print(out); + return out; + } }; |