Cambridge SMT System
MertCommon.h
Go to the documentation of this file.
1 //Copyright (c) 2012, University of Cambridge
2 //All rights reserved.
3 //
4 //Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met://
5 //
6 // * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
7 // * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
8 // * Neither the name of the University of Cambridge nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
9 //
10 //THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
11 
12 #ifndef MERTCOMMON_H_
13 #define MERTCOMMON_H_
14 
15 #include <string>
16 #include <iomanip>
17 #include <iostream>
18 #include <fstream>
19 #include <sstream>
20 #include <vector>
21 #include <cstdlib>
22 
25 
26 #define tracer std::cerr << Time()
27 
28 struct MertOpt {
32  double bleuThreshold;
33  bool verbose;
34  std::string writeSurface;
36  bool ignoreGsf;
37  bool useCache;
38  bool noSkip;
39  bool fullLog;
40  bool pointTest;
41 };
42 
43 extern MertOpt opts;
44 
45 typedef unsigned int Sid; // Input sentence id
46 typedef long long Wid; // Word id
47 typedef std::vector<Wid> NGram;
48 typedef std::vector<Wid> Sentence; // Hypothesis
49 
50 std::string Time();
51 
52 const double kDoubleDelta = 1.0F / 4096.0F;
53 
54 void ReplacePattern (std::string& newname, std::string pattern, const char *pat,
55  std::string rep);
56 void ReplacePattern (std::string& newname, std::string pattern, const char *pat,
57  float f);
58 void ReplacePattern (std::string& newname, std::string pattern, const char *pat,
59  int i);
60 
61 std::string ExpandPath (std::string pattern, const int idx);
62 
63 void InitializeFromLimits (std::vector<Sid>& ids, const std::string limits);
64 void InitializeFromScript (std::vector<Sid>& ids, const std::string filename);
65 
66 //string EnvelopeToString(const MertList&, bool);
67 
68 std::vector<PARAMS> InitializeVectorsFromFile (const std::string&);
69 
70 std::vector<PARAMS> InitializeVectorsFromAxes (unsigned int);
71 
72 std::vector<PARAMS> InitializeVectorsFromRandom();
73 
74 std::vector<PARAMS> InitializeVectors (const std::string&);
75 
76 std::string ReadWeight (const std::string&);
77 
78 std::ostream& operator<< (std::ostream& strm, const PARAMS&);
79 
80 std::ostream& operator<< (std::ostream& o, const Sentence& s);
81 
82 PARAMS operator- (const PARAMS&, const PARAMS&);
83 
84 PARAMS operator+ (const PARAMS&, const PARAMS&);
85 
86 std::vector<std::string> InitRefDataFilenames (int, char**);
87 
88 #endif /* MERTCOMMON_H_ */
MertOpt opts
Definition: MertCommon.cpp:14
bool noSkip
Definition: MertCommon.h:38
bool useCache
Definition: MertCommon.h:37
long long Wid
Definition: MertCommon.h:46
unsigned int Sid
Definition: MertCommon.h:45
bool verbose
Definition: MertCommon.h:33
bool pointTest
Definition: MertCommon.h:40
std::vector< std::string > InitRefDataFilenames(int, char **)
Definition: MertCommon.cpp:192
std::string Time()
Definition: MertCommon.cpp:16
void InitializeFromLimits(std::vector< Sid > &ids, const std::string limits)
Definition: MertCommon.cpp:56
std::vector< PARAMS > InitializeVectorsFromRandom()
Definition: MertCommon.cpp:121
std::vector< Wid > Sentence
Definition: MertCommon.h:48
double gammaThreshold
Definition: MertCommon.h:31
bool scaleParams
Definition: MertCommon.h:35
void ReplacePattern(std::string &newname, std::string pattern, const char *pat, std::string rep)
Definition: MertCommon.cpp:26
int32 latticeCutoff
Definition: MertCommon.h:30
const double kDoubleDelta
Definition: MertCommon.h:52
std::string ExpandPath(std::string pattern, const int idx)
Definition: MertCommon.cpp:51
PARAMS operator-(const PARAMS &, const PARAMS &)
Definition: MertCommon.cpp:163
double bleuThreshold
Definition: MertCommon.h:32
bool fullLog
Definition: MertCommon.h:39
std::vector< Wid > NGram
Definition: MertCommon.h:47
std::string ReadWeight(const std::string &)
Definition: MertCommon.cpp:140
int32 printPrecision
Definition: MertCommon.h:29
std::vector< PARAMS > InitializeVectorsFromFile(const std::string &)
std::string writeSurface
Definition: MertCommon.h:34
bool ignoreGsf
Definition: MertCommon.h:36
PARAMS operator+(const PARAMS &, const PARAMS &)
Definition: MertCommon.cpp:176
std::vector< PARAMS > InitializeVectorsFromAxes(unsigned int)
Definition: MertCommon.cpp:108
std::ostream & operator<<(std::ostream &strm, const PARAMS &)
Definition: MertCommon.cpp:152
void InitializeFromScript(std::vector< Sid > &ids, const std::string filename)
Definition: MertCommon.cpp:65
std::vector< PARAMS > InitializeVectors(const std::string &)
Definition: MertCommon.cpp:126