From 5b6dc79427b8f7eeb6a7ff68034ab8548ce670ea Mon Sep 17 00:00:00 2001 From: Alexander Gutkin Date: Thu, 28 Feb 2013 00:24:20 +0000 Subject: Bumped OpenFST implementation to openfst-1.3.3-CL41851770. Updated OpenFST implementation to the most recent version used by Greco3 (corresponds to nlp::fst exported at Perforce CL 41851770). In particular this version has an improved PDT support. Change-Id: I5aadfc962297eef73922c67e7d57866f11ee7d81 --- src/include/fst/state-table.h | 58 ++++++++++++++++++++++++++----------------- 1 file changed, 35 insertions(+), 23 deletions(-) (limited to 'src/include/fst/state-table.h') diff --git a/src/include/fst/state-table.h b/src/include/fst/state-table.h index 7d863a0..d8107a1 100644 --- a/src/include/fst/state-table.h +++ b/src/include/fst/state-table.h @@ -22,6 +22,7 @@ #define FST_LIB_STATE_TABLE_H__ #include +using std::deque; #include using std::vector; @@ -58,14 +59,14 @@ namespace fst { // struct StateTuple { // typedef typename S StateId; // -// // Required constructor. +// // Required constructors. // StateTuple(); +// StateTuple(const StateTuple &); // }; // An implementation using a hash map for the tuple to state ID mapping. -// The state tuple T must have == defined and the default constructor -// must produce a tuple that will never be seen. H is the hash function. +// The state tuple T must have == defined. H is the hash function. template class HashStateTable : public HashBiTable { public: @@ -76,15 +77,18 @@ class HashStateTable : public HashBiTable { using HashBiTable::Size; HashStateTable() : HashBiTable() {} + + // Reserves space for table_size elements. + explicit HashStateTable(size_t table_size) + : HashBiTable(table_size) {} + StateId FindState(const StateTuple &tuple) { return FindId(tuple); } const StateTuple &Tuple(StateId s) const { return FindEntry(s); } }; -// An implementation using a hash set for the tuple to state ID -// mapping. The state tuple T must have == defined and the default -// constructor must produce a tuple that will never be seen. H is the -// hash function. +// An implementation using a hash map for the tuple to state ID mapping. +// The state tuple T must have == defined. H is the hash function. template class CompactHashStateTable : public CompactHashBiTable { @@ -97,7 +101,7 @@ class CompactHashStateTable CompactHashStateTable() : CompactHashBiTable() {} - // Reserves space for table_size elements. + // Reserves space for 'table_size' elements. explicit CompactHashStateTable(size_t table_size) : CompactHashBiTable(table_size) {} @@ -122,7 +126,10 @@ class VectorStateTable using VectorBiTable::Size; using VectorBiTable::Fingerprint; - explicit VectorStateTable(FP *fp = 0) : VectorBiTable(fp) {} + // Reserves space for 'table_size' elements. + explicit VectorStateTable(FP *fp = 0, size_t table_size = 0) + : VectorBiTable(fp, table_size) {} + StateId FindState(const StateTuple &tuple) { return FindId(tuple); } const StateTuple &Tuple(StateId s) const { return FindEntry(s); } }; @@ -268,7 +275,9 @@ class GenericComposeStateTable : public H { GenericComposeStateTable(const Fst &fst1, const Fst &fst2) {} - GenericComposeStateTable(const GenericComposeStateTable &table) {} + // Reserves space for 'table_size' elements. + GenericComposeStateTable(const Fst &fst1, const Fst &fst2, + size_t table_size) : H(table_size) {} bool Error() const { return false; } @@ -342,17 +351,18 @@ VectorStateTable, typedef typename A::StateId StateId; typedef F FilterState; typedef ComposeStateTuple StateTuple; + typedef VectorStateTable > StateTable; - ProductComposeStateTable(const Fst &fst1, const Fst &fst2) - : VectorStateTable, - ComposeFingerprint > - (new ComposeFingerprint(CountStates(fst1), - CountStates(fst2))) { } + // Reserves space for 'table_size' elements. + ProductComposeStateTable(const Fst &fst1, const Fst &fst2, + size_t table_size = 0) + : StateTable(new ComposeFingerprint(CountStates(fst1), + CountStates(fst2)), + table_size) {} ProductComposeStateTable(const ProductComposeStateTable &table) - : VectorStateTable, - ComposeFingerprint > - (new ComposeFingerprint(table.Fingerprint())) {} + : StateTable(new ComposeFingerprint(table.Fingerprint())) {} bool Error() const { return false; } @@ -375,6 +385,8 @@ VectorStateTable, typedef typename A::StateId StateId; typedef F FilterState; typedef ComposeStateTuple StateTuple; + typedef VectorStateTable > StateTable; StringDetComposeStateTable(const Fst &fst1, const Fst &fst2) : error_(false) { @@ -389,7 +401,7 @@ VectorStateTable, } StringDetComposeStateTable(const StringDetComposeStateTable &table) - : error_(table.error_) {} + : StateTable(table), error_(table.error_) {} bool Error() const { return error_; } @@ -409,12 +421,14 @@ VectorStateTable, template class DetStringComposeStateTable : public VectorStateTable, - ComposeState1Fingerprint > { + ComposeState2Fingerprint > { public: typedef A Arc; typedef typename A::StateId StateId; typedef F FilterState; typedef ComposeStateTuple StateTuple; + typedef VectorStateTable > StateTable; DetStringComposeStateTable(const Fst &fst1, const Fst &fst2) :error_(false) { @@ -429,7 +443,7 @@ VectorStateTable, } DetStringComposeStateTable(const DetStringComposeStateTable &table) - : error_(table.error_) {} + : StateTable(table), error_(table.error_) {} bool Error() const { return error_; } @@ -456,8 +470,6 @@ ErasableStateTable, ErasableComposeStateTable(const Fst &fst1, const Fst &fst2) {} - ErasableComposeStateTable(const ErasableComposeStateTable &table) {} - bool Error() const { return false; } private: -- cgit v1.2.3