Cambridge SMT System
RefsData.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 REFSDATA_H_
13 #define REFSDATA_H_
14 
15 #include <iostream>
16 #include <sstream>
17 #include <vector>
18 #include <string>
19 #include <limits>
20 #include <cstdlib>
21 #include <tr1/unordered_map>
22 
23 #include "BleuStats.h"
24 #include "MertHashVec.h"
25 #include "MertCommon.h"
26 
27 using std::min;
28 using std::max;
29 using std::vector;
30 using std::string;
31 using std::ostream;
32 using std::ostringstream;
33 using std::numeric_limits;
34 
35 typedef unordered_map<NGram, unsigned int, hashfvecint64,
37 
38 class RefsData {
39  RefsData();
40  NGram SubStr (const Sentence& s, const unsigned int n,
41  const unsigned int l) const;
42  unsigned int ClosestReferenceLength (const unsigned int hypLength) const;
43  NGramToCountMap refCounts; // Counts of ngrams in the reference translations
44  vector<unsigned int> refLengths; // Lengths of the reference translations
45  public:
47  RefsData (const vector<Sentence>& refs);
48  BleuStats ComputeBleuStats (const Sentence& hyp) const;
49  string ToString (const char separator) const;
50  static RefsData dummy;
51 };
52 
53 typedef vector<RefsData> RefsDataIndex;
54 
56  RefsDataIndex refsData; // Map from sentence ID to reference ngrams
57 
58  public:
60  void LoadRefData (vector<string>);
61  ErrorStats ComputeErrorStats (Sid, Sentence) const;
62 
63 };
64 
65 ostream& operator<< (ostream& o, const Sentence& s);
66 
67 #endif /* REFSDATA_H_ */
unordered_map< NGram, unsigned int, hashfvecint64, hasheqvecint64 > NGramToCountMap
Definition: RefsData.h:36
HashFVec< std::vector< long long > > hashfvecint64
BleuStats ErrorStats
Definition: RefsData.h:46
unsigned int Sid
Definition: MertCommon.h:45
static RefsData dummy
Definition: RefsData.h:50
std::vector< Wid > Sentence
Definition: MertCommon.h:48
BleuStats ComputeBleuStats(const Sentence &hyp) const
Definition: RefsData.cpp:43
vector< RefsData > RefsDataIndex
Definition: RefsData.h:53
std::vector< Wid > NGram
Definition: MertCommon.h:47
BleuStats ErrorStats
Definition: RefsData.h:59
ostream & operator<<(ostream &o, const Sentence &s)
string ToString(const char separator) const
Definition: RefsData.cpp:84