From a7daae145f2c26138c0751eac8a3122c1e051e11 Mon Sep 17 00:00:00 2001 From: Nisaba Authors Date: Fri, 31 Jan 2025 00:32:03 -0800 Subject: [PATCH] [translit] Add using fst:: directives Fully qualify ::fst where needed. PiperOrigin-RevId: 721667942 --- nisaba/translit/fst/pairlm_decoder.cc | 12 +++++++----- nisaba/translit/fst/pairlm_decoder.h | 12 ++++++------ nisaba/translit/fst/wordpiece-segmenter.cc | 5 +++-- 3 files changed, 16 insertions(+), 13 deletions(-) diff --git a/nisaba/translit/fst/pairlm_decoder.cc b/nisaba/translit/fst/pairlm_decoder.cc index 49d46159..2e4cdf86 100644 --- a/nisaba/translit/fst/pairlm_decoder.cc +++ b/nisaba/translit/fst/pairlm_decoder.cc @@ -88,6 +88,7 @@ using ::fst::MutableArcIterator; using ::fst::OLabelCompare; using ::fst::PhiMatcher; using ::fst::Project; +using ::fst::ProjectType; using ::fst::Prune; using ::fst::Push; using ::fst::REWEIGHT_TO_INITIAL; @@ -103,6 +104,7 @@ using ::fst::SymbolTable; using ::fst::TopSort; using ::fst::Union; using ::fst::VectorFst; +using ::fst::kNoSymbol; namespace nisaba { namespace translit { @@ -578,7 +580,7 @@ StdVectorFst PairLMDecoder::GetWordTransliterations( } else { StdVectorFst pair_lattice; Compose(string_fst, *unicode_to_pair_fst_, &pair_lattice); - Project(&pair_lattice, ::fst::ProjectType::OUTPUT); + Project(&pair_lattice, ProjectType::OUTPUT); ArcSort(&pair_lattice, OLabelCompare()); // Composes lattice of pair strings with pair language model. @@ -600,7 +602,7 @@ StdVectorFst PairLMDecoder::GetWordTransliterations( if (prune_lattice) { Prune(&pair_lm_composed_output, /*weight_threshold=*/word_cand_thresh_); } - Project(&pair_lm_composed_output, ::fst::ProjectType::OUTPUT); + Project(&pair_lm_composed_output, ProjectType::OUTPUT); return pair_lm_composed_output; } @@ -702,7 +704,7 @@ void PairLMDecoder::AddCandSymArc(absl::string_view new_symbol, double cost, StdVectorFst *word_transliterations) { // Look for candidate symbol in the symbol list, add if not there. int cand_sym = fst_params.cand_syms.Find(new_symbol); - if (cand_sym == ::fst::kNoSymbol) { + if (cand_sym == kNoSymbol) { cand_sym = fst_params.cand_syms.AddSymbol(new_symbol); AddToCandsToLMFst(new_symbol, cand_sym, fst_params); } @@ -805,7 +807,7 @@ StdVectorFst PairLMDecoder::TransliterateSegmentedWord( void PairLMDecoder::ExtractCachedWordTransliterations( absl::string_view input_word, TranslitContext &fst_params, - ::fst::StdVectorFst &cached) { + StdVectorFst &cached) { mutex_.ReaderLock(); const auto cached_pairs = global_word_transliteration_cache_.at(input_word); mutex_.ReaderUnlock(); @@ -1045,7 +1047,7 @@ StdVectorFst PairLMDecoder::ComposeLatticeWithLM( new PhiMatcher>(transliteration_fst, MATCH_NONE, -1), new PhiMatcher>(*lm_fst_, MATCH_INPUT, kPhiSymbol, true, MATCHER_REWRITE_NEVER)))); - Project(&string_lm_composed_fst, ::fst::ProjectType::INPUT); + Project(&string_lm_composed_fst, ProjectType::INPUT); Connect(&string_lm_composed_fst); impl::PushInLogSemiring(&string_lm_composed_fst); TopSort(&string_lm_composed_fst); diff --git a/nisaba/translit/fst/pairlm_decoder.h b/nisaba/translit/fst/pairlm_decoder.h index a3367936..ed2a6df7 100644 --- a/nisaba/translit/fst/pairlm_decoder.h +++ b/nisaba/translit/fst/pairlm_decoder.h @@ -49,7 +49,7 @@ class PairLMDecoder { // Transliterates a full string, returning an Fst of results. ::fst::StdVectorFst TransliterateString(absl::string_view input_line, - int k_best); + int k_best); // Prints output from transliteration along with user provided line prefix. std::string PrintTransliterations( @@ -95,8 +95,8 @@ class PairLMDecoder { // Transliterates a single word, returning an Fst of results. ::fst::StdVectorFst TransliterateWord(absl::string_view input_word, - int k_best, - TranslitContext &fst_params) + int k_best, + TranslitContext &fst_params) ABSL_LOCKS_EXCLUDED(mutex_); // Initializes full class for transliteration. @@ -130,7 +130,7 @@ class PairLMDecoder { // Returns a lattice of possible single word transliterations. ::fst::StdVectorFst GetWordTransliterations(absl::string_view input_word, - bool prune_lattice) const; + bool prune_lattice) const; // Puts arc in Fst that maps from candidate to lm_fst_ symbols. void AddToCandsToLMFst(absl::string_view new_symbol, int cand_sym, @@ -187,8 +187,8 @@ class PairLMDecoder { ::fst::StdVectorFst *transliteration_fst) const; // Performs a final pruning of transliterations per word position. - void ApplyFinalKBestFilter(int k_best, - ::fst::StdVectorFst *transliteration_fst) const; + void ApplyFinalKBestFilter( + int k_best, ::fst::StdVectorFst *transliteration_fst) const; std::unique_ptr<::fst::StdVectorFst> translit_fst_; // PairLM model. bool translit_fst_is_transducer_; // Whether PairLM model is transducer. diff --git a/nisaba/translit/fst/wordpiece-segmenter.cc b/nisaba/translit/fst/wordpiece-segmenter.cc index 4a2390f0..c93b0b91 100644 --- a/nisaba/translit/fst/wordpiece-segmenter.cc +++ b/nisaba/translit/fst/wordpiece-segmenter.cc @@ -41,6 +41,7 @@ namespace fst { using ::fst::StdArc; using ::fst::StdVectorFst; using ::fst::SymbolTable; +using ::fst::kNoSymbol; namespace impl { namespace { @@ -228,9 +229,9 @@ absl::StatusOr WordpieceSegmenter::GetWordpieceTransducer( int curr_state = fst.Start(); for (const auto &wordpiece : wordpieces) { int wordpiece_idx = wordpiece_syms.Find(wordpiece); - if (wordpiece_idx == ::fst::kNoSymbol) { + if (wordpiece_idx == kNoSymbol) { // Wordpiece is not in vocabulary, hence replaced with . - if (unk_label == ::fst::kNoSymbol) { + if (unk_label == kNoSymbol) { return absl::InternalError("Need OOV in wordpiece syms."); } wordpiece_idx = unk_label;