Cambridge SMT System
hifst.task.patternstoinstances.gtest.cpp
Go to the documentation of this file.
1
// Licensed under the Apache License, Version 2.0 (the "License");
2
// you may not use these files except in compliance with the License.
3
// You may obtain a copy of the License at
4
//
5
// http://www.apache.org/licenses/LICENSE-2.0
6
//
7
// Unless required by applicable law or agreed to in writing, software
8
// distributed under the License is distributed on an "AS IS" BASIS,
9
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10
// See the License for the specific language governing permissions and
11
// limitations under the License.
12
13
// Copyright 2012 - Gonzalo Iglesias, AdriĆ de Gispert, William Byrne
14
21
#include <
googletesting.h
>
22
23
#ifndef GMAINTEST
24
#include "
main.custom_assert.hpp
"
25
#include "
main.logger.hpp
"
26
#endif
27
28
#include "
addresshandler.hpp
"
29
#include "
taskinterface.hpp
"
30
31
#include "
data.stats.hpp
"
32
#include "
defs.grammar.hpp
"
33
#include "
data.grammar.hpp
"
34
#include "
task.patternstoinstances.hpp
"
35
36
namespace
uf
=
ucam::fsttools
;
37
namespace
uh
=
ucam::hifst
;
38
40
class
DataForPatternsToInstancesTask
{
41
public
:
42
DataForPatternsToInstancesTask
() :
43
sidx
(0),
44
stats
(new
uf
::StatsData) {
45
};
46
47
unsigned
sidx
;
48
std::string
sentence
;
49
uh::GrammarData
*
grammar
;
50
51
unordered_map<std::string, std::vector< pair <unsigned, unsigned> > >
52
hpinstances
;
53
boost::shared_ptr<uf::StatsData>
stats
;
54
};
55
57
TEST
( HifstPatternsToInstances, basic_test ) {
58
uh::GrammarData
gd;
59
DataForPatternsToInstancesTask
d;
60
d.
grammar
= &gd;
62
unordered_map<std::string, boost::any> v;
63
v[
HifstConstants::kPatternstoinstancesMaxspan
] = unsigned ( 5 );
64
v[
HifstConstants::kPatternstoinstancesGapmaxspan
] = unsigned ( 2 );
65
v[
HifstConstants::kPatternstoinstancesStore
] = std::string (
""
);
66
const
uu::RegistryPO
rg ( v );
67
uh::PatternsToInstancesTask<DataForPatternsToInstancesTask>
ptask ( rg );
68
gd.
patterns
.insert (
"w_X_w"
);
69
d.
sentence
=
"1 3 4 5 2"
;
70
ptask.instantiatePatternsHash ( d );
71
EXPECT_EQ ( d.
hpinstances
.size(), 5 );
72
EXPECT_FALSE ( d.
hpinstances
.find (
"1_X_2"
) != d.
hpinstances
.end() );
73
EXPECT_TRUE ( d.
hpinstances
.find (
"1_X_4"
) != d.
hpinstances
.end() );
74
EXPECT_TRUE ( d.
hpinstances
.find (
"1_X_5"
) != d.
hpinstances
.end() );
75
EXPECT_TRUE ( d.
hpinstances
.find (
"3_X_2"
) != d.
hpinstances
.end() );
76
EXPECT_TRUE ( d.
hpinstances
.find (
"3_X_5"
) != d.
hpinstances
.end() );
77
EXPECT_TRUE ( d.
hpinstances
.find (
"4_X_2"
) != d.
hpinstances
.end() );
78
}
79
80
#ifndef GMAINTEST
81
82
int
main
(
int
argc,
char
**argv ) {
83
::testing::InitGoogleTest ( &argc, argv );
84
return
RUN_ALL_TESTS();
85
}
86
#endif
addresshandler.hpp
Handles simple wildcard expansion for strings.
DataForPatternsToInstancesTask::sentence
std::string sentence
Definition:
hifst.task.patternstoinstances.gtest.cpp:48
data.stats.hpp
Relative to Stats across the pipeline.
task.patternstoinstances.hpp
Contains patterns to instance-patterns implementation.
DataForPatternsToInstancesTask::stats
boost::shared_ptr< uf::StatsData > stats
Definition:
hifst.task.patternstoinstances.gtest.cpp:53
ucam::util::RegistryPO
Definition:
registrypo.hpp:95
data.grammar.hpp
Contains structures and classes for GrammarData.
DataForPatternsToInstancesTask
Public Data class with variables required by PatternsToInstancestask to compile and run...
Definition:
hifst.task.patternstoinstances.gtest.cpp:40
ucam::hifst::PatternsToInstancesTask
Converts patterns to instanced patterns.
Definition:
task.patternstoinstances.hpp:36
HifstConstants::kPatternstoinstancesStore
const std::string kPatternstoinstancesStore
Definition:
constants-hifst.hpp:30
TEST
TEST(HifstPatternsToInstances, basic_test)
Basic test for PatternsToInstancesTask class.
Definition:
hifst.task.patternstoinstances.gtest.cpp:57
taskinterface.hpp
Interfaces with basic methods for iteration.
ucam::hifst::GrammarData::patterns
unordered_set< std::string > patterns
Patterns in these rules.
Definition:
data.grammar.hpp:63
ucam::hifst::GrammarData
Struct containing grammar rules.
Definition:
data.grammar.hpp:42
ucam::hifst
Definition:
data-main.alilats2splats.hpp:25
DataForPatternsToInstancesTask::hpinstances
unordered_map< std::string, std::vector< pair< unsigned, unsigned > > > hpinstances
Definition:
hifst.task.patternstoinstances.gtest.cpp:52
main.logger.hpp
Static variables for logger. Include only once from main file.
DataForPatternsToInstancesTask::grammar
uh::GrammarData * grammar
Definition:
hifst.task.patternstoinstances.gtest.cpp:49
main
int main(int argc, char **argv)
Definition:
hifst.task.patternstoinstances.gtest.cpp:82
defs.grammar.hpp
Contains definitions for cykparser data and task.
DataForPatternsToInstancesTask::DataForPatternsToInstancesTask
DataForPatternsToInstancesTask()
Definition:
hifst.task.patternstoinstances.gtest.cpp:42
DataForPatternsToInstancesTask::sidx
unsigned sidx
Definition:
hifst.task.patternstoinstances.gtest.cpp:45
HifstConstants::kPatternstoinstancesGapmaxspan
const std::string kPatternstoinstancesGapmaxspan
Definition:
constants-hifst.hpp:28
ucam::fsttools
Definition:
bleu.hpp:15
googletesting.h
Unit testing: google testing common header.
HifstConstants::kPatternstoinstancesMaxspan
const std::string kPatternstoinstancesMaxspan
Definition:
constants-hifst.hpp:27
main.custom_assert.hpp
Static variable for custom_assert. Include only once from main file.
ucam-smt
cpp
tests
hifst.task.patternstoinstances.gtest.cpp
Generated on Wed May 25 2016 10:26:01 for Cambridge SMT System by
1.8.11