From 538bc2149631e989e4806165632c5460c3514670 Mon Sep 17 00:00:00 2001 From: graehl Date: Fri, 16 Jul 2010 01:57:08 +0000 Subject: oracle refactor, oracle vest directions, sparse_vector git-svn-id: https://ws10smt.googlecode.com/svn/trunk@280 ec762483-ff6d-05da-a07a-a48fb63a330f --- decoder/sentences.h | 53 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100755 decoder/sentences.h (limited to 'decoder/sentences.h') diff --git a/decoder/sentences.h b/decoder/sentences.h new file mode 100755 index 00000000..842072b9 --- /dev/null +++ b/decoder/sentences.h @@ -0,0 +1,53 @@ +#ifndef CDEC_SENTENCES_H +#define CDEC_SENTENCES_H + +#include +#include +#include +#include "filelib.h" +#include "tdict.h" +#include "stringlib.h" +typedef std::vector Sentence; + +inline void StringToSentence(std::string const& str,Sentence &s) { + using namespace std; + vector ss=SplitOnWhitespace(str); + s.clear(); + transform(ss.begin(),ss.end(),back_inserter(s),ToTD()); +} + +inline Sentence StringToSentence(std::string const& str) { + Sentence s; + StringToSentence(str,s); + return s; +} + +inline std::istream& operator >> (std::istream &in,Sentence &s) { + using namespace std; + string str; + if (getline(in,str)) { + StringToSentence(str,s); + } + return in; +} + + +class Sentences : public std::vector { + typedef std::vector VS; +public: + Sentences() { } + Sentences(unsigned n,Sentence const& sentence) : VS(n,sentence) { } + Sentences(unsigned n,std::string const& sentence) : VS(n,StringToSentence(sentence)) { } + void Load(std::string file) { + ReadFile r(file); + Load(*r.stream()); + } + void Load(std::istream &in) { + this->push_back(Sentence()); + while(in>>this->back()) ; + this->pop_back(); + } +}; + + +#endif -- cgit v1.2.3