00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #include <vector>
00023 #include <string>
00024 #include <sstream>
00025 #include <boost/algorithm/string.hpp>
00026
00027 #include "TabbedSentence.h"
00028
00029 namespace Moses
00030 {
00031
00032 void TabbedSentence::CreateFromString(const std::vector<FactorType> &factorOrder
00033 , const std::string &tabbedString)
00034 {
00035 TabbedColumns allColumns;
00036
00037 boost::split(allColumns, tabbedString, boost::is_any_of("\t"));
00038
00039 if(allColumns.size() < 2) {
00040 Sentence::CreateFromString(factorOrder, tabbedString);
00041 } else {
00042 m_columns.resize(allColumns.size() - 1);
00043 std::copy(allColumns.begin() + 1, allColumns.end(), m_columns.begin());
00044 Sentence::CreateFromString(factorOrder, allColumns[0]);
00045 }
00046 }
00047
00048 int
00049 TabbedSentence::
00050 Read(std::istream& in)
00051 {
00052 TabbedColumns allColumns;
00053
00054 std::string line;
00055 if (getline(in, line, '\n').eof())
00056 return 0;
00057
00058 boost::split(allColumns, line, boost::is_any_of("\t"));
00059
00060 if(allColumns.size() < 2) {
00061 Sentence::init(line);
00062 } else {
00063 m_columns.resize(allColumns.size() - 1);
00064 std::copy(allColumns.begin() + 1, allColumns.end(), m_columns.begin());
00065 Sentence::init(allColumns[0]);
00066 }
00067 return 1;
00068
00069 }
00070
00071 }