00001 #include "LexicalTable.h"
00002
00003 #include "util/tokenize_piece.hh"
00004
00005 #include <cstdlib>
00006 #include <iostream>
00007
00008 namespace MosesTraining
00009 {
00010 namespace Syntax
00011 {
00012 namespace ScoreStsg
00013 {
00014
00015 LexicalTable::LexicalTable(Vocabulary &srcVocab, Vocabulary &tgtVocab)
00016 : m_srcVocab(srcVocab)
00017 , m_tgtVocab(tgtVocab)
00018 {
00019 }
00020
00021 void LexicalTable::Load(std::istream &input)
00022 {
00023 const util::AnyCharacter delimiter(" \t");
00024
00025 std::string line;
00026 std::string tmp;
00027 int i = 0;
00028 while (getline(input, line)) {
00029 ++i;
00030 if (i%100000 == 0) {
00031 std::cerr << ".";
00032 }
00033
00034 util::TokenIter<util::AnyCharacter> it(line, delimiter);
00035
00036
00037 it->CopyToString(&tmp);
00038 Vocabulary::IdType tgtId = m_tgtVocab.Insert(tmp);
00039 ++it;
00040
00041
00042 it->CopyToString(&tmp);
00043 Vocabulary::IdType srcId = m_srcVocab.Insert(tmp);
00044 ++it;
00045
00046
00047 it->CopyToString(&tmp);
00048 double prob = atof(tmp.c_str());
00049 m_table[srcId][tgtId] = prob;
00050 }
00051 std::cerr << std::endl;
00052 }
00053
00054 }
00055 }
00056 }