Welcome to mirror list, hosted at ThFree Co, Russian Federation.

TargetPhrase.h « OnDiskPt - github.com/moses-smt/mosesdecoder.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 85b8ceeef447670e084e7c851bcd1cb74e7a53eb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
#pragma once
// $Id$
/***********************************************************************
 Moses - factored phrase-based, hierarchical and syntactic language decoder
 Copyright (C) 2009 Hieu Hoang

 This library is free software; you can redistribute it and/or
 modify it under the terms of the GNU Lesser General Public
 License as published by the Free Software Foundation; either
 version 2.1 of the License, or (at your option) any later version.

 This library is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 Lesser General Public License for more details.

 You should have received a copy of the GNU Lesser General Public
 License along with this library; if not, write to the Free Software
 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 ***********************************************************************/

#include <fstream>
#include <string>
#include <vector>
#include "Word.h"
#include "Phrase.h"
#include "SourcePhrase.h"

namespace Moses
{
class PhraseDictionary;
class TargetPhrase;
class LMList;
class Phrase;
class WordPenaltyProducer;
}

namespace OnDiskPt
{

typedef std::pair<UINT64, UINT64>  AlignPair;
typedef std::vector<AlignPair> AlignType;

class TargetPhrase: public Phrase
{
  friend std::ostream& operator<<(std::ostream&, const TargetPhrase&);
protected:
  AlignType m_align;
  Phrase* m_sourcePhrase; 

  std::vector<float>	m_scores;
  UINT64 m_filePos;

  size_t WriteAlignToMemory(char *mem) const;
  size_t WriteScoresToMemory(char *mem) const;

  UINT64 ReadAlignFromFile(std::fstream &fileTPColl);
  UINT64 ReadScoresFromFile(std::fstream &fileTPColl);

public:
  TargetPhrase(size_t numScores);
  TargetPhrase(const 	TargetPhrase &copy);
  virtual ~TargetPhrase();

  void SetSourcePhrase(Phrase *p) {
	Phrase *copy = new Phrase(*p);
    m_sourcePhrase = copy;
  }
  const Phrase* GetSourcePhrase() const {
	return m_sourcePhrase;
  }
  
  void SetLHS(Word *lhs);

  void Create1AlignFromString(const std::string &align1Str);
  void CreateAlignFromString(const std::string &align1Str);
  void SetScore(float score, size_t ind);

  const AlignType &GetAlign() const {
    return m_align;
  }
  void SortAlign();

  char *WriteToMemory(OnDiskWrapper &onDiskWrapper, size_t &memUsed) const;
  char *WriteOtherInfoToMemory(OnDiskWrapper &onDiskWrapper, size_t &memUsed) const;
  void Save(OnDiskWrapper &onDiskWrapper);

  UINT64 GetFilePos() const {
    return m_filePos;
  }
  float GetScore(size_t ind) const {
    return m_scores[ind];
  }

  Moses::TargetPhrase *ConvertToMoses(const std::vector<Moses::FactorType> &inputFactors
                                      , const std::vector<Moses::FactorType> &outputFactors
                                      , const Vocab &vocab
                                      , const Moses::PhraseDictionary &phraseDict
                                      , const std::vector<float> &weightT
                                      , const Moses::WordPenaltyProducer* wpProducer
                                      , const Moses::LMList &lmList) const;
  UINT64 ReadOtherInfoFromFile(UINT64 filePos, std::fstream &fileTPColl);
  UINT64 ReadFromFile(std::fstream &fileTP, size_t numFactors, size_t numSourceFactors);

};

}