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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
|
/***********************************************************************
Moses - factored phrase-based language decoder
Copyright (C) 2012- University of Edinburgh
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 "moses/Util.h"
#include "domain.h"
#include "ScoreFeature.h"
#include "tables-core.h"
#define BOOST_TEST_MODULE MosesTrainingScoreFeature
#include <boost/test/test_tools.hpp>
#include <boost/test/unit_test.hpp>
#include <boost/assign/list_of.hpp>
using namespace MosesTraining;
using namespace Moses;
using namespace std;
//pesky global variables
namespace MosesTraining
{
bool hierarchicalFlag = false;
Vocabulary vcbT;
Vocabulary vcbS;
}
const char *DomainFileLocation()
{
if (boost::unit_test::framework::master_test_suite().argc < 2) {
return "test.domain";
}
return boost::unit_test::framework::master_test_suite().argv[1];
}
BOOST_AUTO_TEST_CASE(manager_configure_domain_except)
{
//Check that configure rejects illegal domain arg combinations
ScoreFeatureManager manager;
vector<string> args = Tokenize("--DomainRatio /dev/null --DomainIndicator /dev/null"," ");
std::cerr << "args.size():" << args.size() << std::endl;
BOOST_CHECK_THROW(manager.configure(args), ScoreFeatureArgumentException);
args.clear();
args = Tokenize("--SparseDomainSubset /dev/null --SparseDomainRatio /dev/null"," ");
BOOST_CHECK_THROW(manager.configure(args), ScoreFeatureArgumentException);
args.clear();
args = Tokenize("--SparseDomainBlah /dev/null"," ");
BOOST_CHECK_THROW(manager.configure(args), ScoreFeatureArgumentException);
args.clear();
args = Tokenize("--DomainSubset"," ");
BOOST_CHECK_THROW(manager.configure(args), ScoreFeatureArgumentException);
}
template <class Expected>
static void checkDomainConfigured(
const vector<string>& args)
{
ScoreFeatureManager manager;
manager.configure(args);
const std::vector<ScoreFeaturePtr>& features = manager.getFeatures();
//BOOST_REQUIRE_EQUAL(features.size(), 2);
//if I add to features this check will fail?
BOOST_REQUIRE_EQUAL(features.size(), 1); //MARIA -> what is this check and why does it fail when I add my feature?
Expected* feature = dynamic_cast<Expected*>(features[0].get());
// BOOST_REQUIRE(feature);
BOOST_CHECK(manager.includeSentenceId());
}
BOOST_AUTO_TEST_CASE(manager_config_domain)
{
std::vector<std::string> args = Tokenize("--DomainRatio /dev/null"," ");
checkDomainConfigured<RatioDomainFeature>(args);
args.clear();
args = Tokenize("--DomainIndicator /dev/null"," ");
checkDomainConfigured<RatioDomainFeature>(args);
args.clear();
args = Tokenize("--DomainSubset /dev/null"," ");
checkDomainConfigured<RatioDomainFeature>(args);
args.clear();
args = Tokenize("--SparseDomainRatio /dev/null"," ");
checkDomainConfigured<RatioDomainFeature>(args);
args.clear();
args = Tokenize("--SparseDomainIndicator /dev/null"," ");
checkDomainConfigured<RatioDomainFeature>(args);
args.clear();
args = Tokenize("--SparseDomainSubset /dev/null"," ");
checkDomainConfigured<RatioDomainFeature>(args);
}
BOOST_AUTO_TEST_CASE(domain_equals)
{
SubsetDomainFeature feature(DomainFileLocation());
PhraseAlignment a1,a2,a3;
char buf1[] = "a ||| b ||| 0-0 ||| 1";
char buf2[] = "a ||| b ||| 0-0 ||| 2";
char buf3[] = "a ||| b ||| 0-0 ||| 3";
a1.create(buf1, 0, true); //domain a
a2.create(buf2, 1, true); //domain c
a3.create(buf3, 2, true); //domain c
BOOST_CHECK(feature.equals(a2,a3));
BOOST_CHECK(!feature.equals(a1,a3));
BOOST_CHECK(!feature.equals(a1,a3));
}
|