2012-11-03 03:30:51 +04:00
|
|
|
/***********************************************************************
|
|
|
|
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
|
|
|
|
***********************************************************************/
|
|
|
|
|
2014-01-29 22:37:42 +04:00
|
|
|
#include "DomainFeature.h"
|
2012-11-03 03:30:51 +04:00
|
|
|
#include "ScoreFeature.h"
|
|
|
|
#include "tables-core.h"
|
|
|
|
|
|
|
|
#define BOOST_TEST_MODULE MosesTrainingScoreFeature
|
|
|
|
#include <boost/test/test_tools.hpp>
|
|
|
|
#include <boost/test/unit_test.hpp>
|
|
|
|
|
2015-06-17 10:42:46 +03:00
|
|
|
#include <unordered_set>
|
2012-11-03 03:30:51 +04:00
|
|
|
|
|
|
|
using namespace MosesTraining;
|
|
|
|
using namespace std;
|
|
|
|
|
|
|
|
//pesky global variables
|
2013-05-29 21:16:15 +04:00
|
|
|
namespace MosesTraining
|
|
|
|
{
|
|
|
|
bool hierarchicalFlag = false;
|
|
|
|
Vocabulary vcbT;
|
|
|
|
Vocabulary vcbS;
|
2012-11-03 03:30:51 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-05-29 21:16:15 +04:00
|
|
|
const char *DomainFileLocation()
|
|
|
|
{
|
2012-11-03 03:30:51 +04:00
|
|
|
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;
|
2014-10-09 01:07:19 +04:00
|
|
|
BOOST_CHECK_THROW(
|
2015-06-17 10:25:27 +03:00
|
|
|
manager.configure( {"--DomainRatio","/dev/null","--DomainIndicator","/dev/null"}),
|
2015-01-14 14:07:42 +03:00
|
|
|
ScoreFeatureArgumentException);
|
2014-10-09 01:07:19 +04:00
|
|
|
BOOST_CHECK_THROW(
|
2015-06-17 10:25:27 +03:00
|
|
|
manager.configure( {"--SparseDomainSubset","/dev/null","--SparseDomainRatio","/dev/null"}),
|
2015-01-14 14:07:42 +03:00
|
|
|
ScoreFeatureArgumentException);
|
2014-10-09 01:07:19 +04:00
|
|
|
BOOST_CHECK_THROW(
|
2015-06-17 10:25:27 +03:00
|
|
|
manager.configure( {"--SparseDomainBlah","/dev/null"}),
|
2015-01-14 14:07:42 +03:00
|
|
|
ScoreFeatureArgumentException);
|
2014-10-09 01:07:19 +04:00
|
|
|
BOOST_CHECK_THROW(
|
2015-06-17 10:25:27 +03:00
|
|
|
manager.configure( {"--DomainSubset"}),
|
2015-01-14 14:07:42 +03:00
|
|
|
ScoreFeatureArgumentException);
|
2012-11-03 03:30:51 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
template <class Expected>
|
|
|
|
static void checkDomainConfigured(
|
2013-05-29 21:16:15 +04:00
|
|
|
const vector<string>& args)
|
2012-11-03 03:30:51 +04:00
|
|
|
{
|
|
|
|
ScoreFeatureManager manager;
|
|
|
|
manager.configure(args);
|
|
|
|
const std::vector<ScoreFeaturePtr>& features = manager.getFeatures();
|
2013-09-13 14:45:46 +04:00
|
|
|
//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?
|
2012-11-03 03:30:51 +04:00
|
|
|
Expected* feature = dynamic_cast<Expected*>(features[0].get());
|
|
|
|
BOOST_REQUIRE(feature);
|
|
|
|
BOOST_CHECK(manager.includeSentenceId());
|
|
|
|
}
|
|
|
|
|
|
|
|
BOOST_AUTO_TEST_CASE(manager_config_domain)
|
|
|
|
{
|
|
|
|
checkDomainConfigured<RatioDomainFeature>
|
2015-06-17 10:25:27 +03:00
|
|
|
( {"--DomainRatio","/dev/null"});
|
2012-11-03 03:30:51 +04:00
|
|
|
checkDomainConfigured<IndicatorDomainFeature>
|
2015-06-17 10:25:27 +03:00
|
|
|
( {"--DomainIndicator","/dev/null"});
|
2012-11-03 03:30:51 +04:00
|
|
|
checkDomainConfigured<SubsetDomainFeature>
|
2015-06-17 10:25:27 +03:00
|
|
|
( {"--DomainSubset","/dev/null"});
|
2012-11-03 03:30:51 +04:00
|
|
|
checkDomainConfigured<SparseRatioDomainFeature>
|
2015-06-17 10:25:27 +03:00
|
|
|
( {"--SparseDomainRatio","/dev/null"});
|
2012-11-03 03:30:51 +04:00
|
|
|
checkDomainConfigured<SparseIndicatorDomainFeature>
|
2015-06-17 10:25:27 +03:00
|
|
|
( {"--SparseDomainIndicator","/dev/null"});
|
2012-11-03 03:30:51 +04:00
|
|
|
checkDomainConfigured<SparseSubsetDomainFeature>
|
2015-06-17 10:25:27 +03:00
|
|
|
( {"--SparseDomainSubset","/dev/null"});
|
2015-06-17 10:42:46 +03:00
|
|
|
|
|
|
|
unordered_set<int> s;
|
|
|
|
s.insert(4);
|
|
|
|
s.insert(7);
|
|
|
|
s.insert(4);
|
|
|
|
s.insert(1);
|
|
|
|
|
|
|
|
for (auto i: s) {
|
|
|
|
cerr << i << " ";
|
|
|
|
}
|
2012-11-03 03:30:51 +04:00
|
|
|
}
|
|
|
|
|