58 unordered_map<std::string, std::vector< pair <unsigned, unsigned> > >
61 std::auto_ptr<uf::StatsData>
stats;
62 unordered_set<std::string>
tvcb;
66 TEST ( HifstSentenceSpecificGrammarTask, basic_test ) {
68 unordered_map<std::string, boost::any> v;
78 boost::scoped_ptr< uh::GrammarTask<DataForSentenceSpecificGrammarTask> > gt (
81 ss <<
"X 3 3 0" << endl <<
"S S_X S_X 0" << endl;
82 ss <<
"X 4 4 0" << endl <<
"X 5 5 0" << endl;
83 ss <<
"X 2 2 0" << endl;
84 ss <<
"X 3_4 3_4 0" << endl <<
"X 3_X1_5 3_X1_5 0" << endl;
87 ss <<
"S X1 X1 0" << endl;
88 ss <<
"S M1 M1 0" << endl;
90 boost::scoped_ptr< DataForSentenceSpecificGrammarTask> dor (
93 d.
grammar = gt->getGrammarData();
94 ASSERT_TRUE ( d.
grammar != NULL );
101 d.
hpinstances[
"1"].push_back ( pair<unsigned, unsigned> ( 0, 0 ) );
102 d.
hpinstances[
"3"].push_back ( pair<unsigned, unsigned> ( 1, 0 ) );
103 d.
hpinstances[
"4"].push_back ( pair<unsigned, unsigned> ( 2, 0 ) );
104 d.
hpinstances[
"5"].push_back ( pair<unsigned, unsigned> ( 3, 0 ) );
105 d.
hpinstances[
"2"].push_back ( pair<unsigned, unsigned> ( 4, 0 ) );
108 d.
hpinstances[
"3_4"].push_back ( pair<unsigned, unsigned> ( 1, 1 ) );
109 d.
hpinstances[
"3_X_5"].push_back ( pair<unsigned, unsigned> ( 1, 2 ) );
110 d.
hpinstances[
"X_X"].push_back ( pair<unsigned, unsigned> ( 1, 1 ) );
112 d.
hpinstances[
"X_X"].push_back ( pair<unsigned, unsigned> ( 1, 1 ) );
113 d.
hpinstances[
"X"].push_back ( pair<unsigned, unsigned> ( 0, 0 ) );
114 boost::scoped_ptr< uh::SentenceSpecificGrammarTask<DataForSentenceSpecificGrammarTask> >
118 ASSERT_TRUE ( d.
ssgd != NULL );
120 std::vector<std::string> testrhs1, testrhs1X, testrhs1M;
121 testrhs1.push_back (
"X 1 <oov> 0" );
122 testrhs1.push_back (
"X 3 3 0" );
123 testrhs1.push_back (
"X 4 4 0" );
124 testrhs1.push_back (
"X 5 5 0" );
125 testrhs1.push_back (
"X 2 2 0" );
128 testrhs1M.push_back (
"S M1 M1 0" );
129 testrhs1X.push_back (
"S X1 X1 0" );
130 for ( uh::ssgrammar_rulesmap_t::iterator itx =
134 ASSERT_TRUE ( itx->second.size() >= 1 );
135 for ( uh::ssgrammar_firstelementmap_t::iterator itx2 = itx->second.begin();
136 itx2 != itx->second.end(); ++itx2 ) {
137 ASSERT_EQ ( itx->second[itx2->first].size(), 1 );
138 std::string element = itx2->first;
140 EXPECT_EQ ( element, itx2->first );
142 if ( itx2->first ==
"M" ) {
143 EXPECT_EQ ( d.
ssgd->
getRule ( itx->second[itx2->first][0] ),
144 testrhs1M[itx->first] );
145 }
else if ( itx2->first ==
"X" ) {
146 EXPECT_EQ ( d.
ssgd->
getRule ( itx->second[itx2->first][0] ),
147 testrhs1X[itx->first] );
150 EXPECT_EQ ( d.
ssgd->
getRule ( itx->second[itx2->first][0] ),
151 testrhs1[itx->first] );
155 std::vector<std::string> testrhs2;
156 testrhs2.push_back (
"X 3_4 3_4 0" );
157 for ( uh::ssgrammar_rulesmap_t::iterator itx =
161 if ( itx->first != 1 ) ASSERT_TRUE ( !itx->second.size() );
163 ASSERT_TRUE ( itx->second.size() == 2 );
169 unordered_set<std::string> aux;
173 EXPECT_TRUE ( aux.find (
"S S_X S_X 0" ) != aux.end() );
174 EXPECT_TRUE ( aux.find (
"X 3_X1_5 3_X1_5 0" ) != aux.end() );
175 EXPECT_TRUE ( aux.find (
"X 3_4 3_4 0" ) != aux.end() );
178 TEST ( HifstSentenceSpecificGrammarTask, data ) {
181 std::stringstream ss;
182 ss <<
"XT 35_47_T T_43_55_58 0.450" << endl <<
"ST ST_XT ST_XT 0.370" << endl;
187 EXPECT_EQ ( gd.
getRule ( 1 ),
"X 35_47 43_55_58 0.45" );
188 EXPECT_EQ ( gd.
getLHS ( 1 ),
"X" );
199 EXPECT_EQ ( gd.
getIdx ( 1 ), 1 );
200 EXPECT_EQ ( gd.
getRule ( 0 ),
"S S_X S_X 0.37" );
201 EXPECT_EQ ( gd.
getLHS ( 0 ),
"S" );
209 EXPECT_EQ ( gd.
getIdx ( 0 ), 0 );
210 EXPECT_EQ ( gd.
isPhrase ( 1 ), true );
211 EXPECT_EQ ( gd.
isPhrase ( 0 ), false );
214 unordered_map<unsigned, unsigned> mappings;
216 EXPECT_EQ ( mappings.size(), 2 );
219 EXPECT_EQ ( mappings.size(), 0 );
224 int main (
int argc,
char **argv ) {
225 ::testing::InitGoogleTest ( &argc, argv );
226 return RUN_ALL_TESTS();
Handles simple wildcard expansion for strings.
const std::string getRHSTranslation(std::size_t idx)
Returns RHS translation of a rule with index idx.
Relative to Stats across the pipeline.
const float getWeight(std::size_t idx)
Returns the weight of a rule. This weight is the dot product of all the features with its scales...
Public Data class with variables required by SentenceSpecificGrammarTask.
ssgrammar_rulesmap_t rulesWithRhsSpan1
std::string toString(const T &x, uint pr=2)
Converts an arbitrary type to string Converts to string integers, floats, doubles Quits execution if ...
Contains structures and classes for GrammarData.
void getMappings(std::size_t idx, unordered_map< uint, uint > *mappings)
Returns the non-terminal mappings for a rule. For more details see getRuleMappings function...
const std::string kGrammarFeatureweights
const std::string getRule(std::size_t idx)
Returns rule corresponding to index idx.
int main(int argc, char **argv)
Interfaces with basic methods for iteration.
unordered_set< std::string > patterns
Patterns in these rules.
Struct containing grammar rules.
uh::SentenceSpecificGrammarData * ssgd
Describes class GrammarTask.
const bool isPhrase(std::size_t idx)
Task class that loads a grammar into memory.
const std::string getRHSSource(std::size_t idx)
Returns Right-hand-side (source) of the rule with index=idx.
TEST(HifstSentenceSpecificGrammarTask, basic_test)
Basic test for TextTask class.
const std::string getLHS(std::size_t idx)
Returns Left-hand-side of a rule corresponding to index idx.
Static variables for logger. Include only once from main file.
const std::string kSsgrammarAddoovsSourcedeletions
std::auto_ptr< uf::StatsData > stats
const std::string kSsgrammarAddoovsEnable
Convenience functions to parse parameters from a string.
DataForSentenceSpecificGrammarTask()
void load(const std::string &file)
Loads rules from a grammar file.
This class uses instantiated patterns to analyze the grammar and deliver two hashes providing candida...
Contains implementation for sentence-specific grammar task.
ssgrammar_rulesmap_t rulesWithRhsSpan2OrMore
cells containing potentially applicable rules with two or more elements
const uint getRHSSourceSize(std::size_t idx)
Returns size of RHS source of a rule.
Contains definitions for cykparser data and task.
const std::size_t getIdx(std::size_t idx)
Returns the true idx of a rule (i.e. line in the grammar file). If it is sentence specific...
unordered_map< std::string, std::vector< pair< unsigned, unsigned > > > hpinstances
Contains definitions for sentence-specific grammar data and task.
unordered_map< std::size_t, std::string > extrarules
const GrammarData * grammar
Pointer to the original grammar data (no ownership)
unordered_set< std::string > tvcb
GrammarData * getGrammarData()
Returns GrammarData.
const std::string kSsgrammarStore
const std::string kGrammarStorepatterns
Contains sentence-specific grammar data.
Structure for sentence-specific grammar Rules will be queried by cyk per position and number of eleme...
uh::GrammarData * grammar
const std::string kGrammarStorentorder
const uint getRHSTranslationSize(std::size_t idx)
Returns size of RHS (translation) of a rule.
Unit testing: google testing common header.
const std::string kGrammarLoad
const std::vector< std::string > getRHSSplitTranslation(std::size_t idx)
Returns translation as a vector of elements.
Static variable for custom_assert. Include only once from main file.
void getFilteredNonTerminal(std::string &word)
Return the filtered non-terminal name. For example, for the rule Z 3_XT2_5 XT2, getFilteredNonTermina...