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"
35 
36 namespace uf = ucam::fsttools;
37 namespace uh = ucam::hifst;
38 
41  public:
43  sidx (0),
44  stats (new uf::StatsData) {
45  };
46 
47  unsigned sidx;
48  std::string sentence;
50 
51  unordered_map<std::string, std::vector< pair <unsigned, unsigned> > >
53  boost::shared_ptr<uf::StatsData> stats;
54 };
55 
57 TEST ( HifstPatternsToInstances, basic_test ) {
58  uh::GrammarData gd;
60  d.grammar = &gd;
62  unordered_map<std::string, boost::any> v;
65  v[HifstConstants::kPatternstoinstancesStore] = std::string ( "" );
66  const uu::RegistryPO rg ( v );
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
Handles simple wildcard expansion for strings.
Relative to Stats across the pipeline.
Contains patterns to instance-patterns implementation.
Contains structures and classes for GrammarData.
Public Data class with variables required by PatternsToInstancestask to compile and run...
Converts patterns to instanced patterns.
const std::string kPatternstoinstancesStore
TEST(HifstPatternsToInstances, basic_test)
Basic test for PatternsToInstancesTask class.
Interfaces with basic methods for iteration.
unordered_set< std::string > patterns
Patterns in these rules.
Struct containing grammar rules.
unordered_map< std::string, std::vector< pair< unsigned, unsigned > > > hpinstances
Static variables for logger. Include only once from main file.
int main(int argc, char **argv)
Contains definitions for cykparser data and task.
const std::string kPatternstoinstancesGapmaxspan
Unit testing: google testing common header.
const std::string kPatternstoinstancesMaxspan
Static variable for custom_assert. Include only once from main file.