diff options
Diffstat (limited to 'extractor/phrase_builder.cc')
-rw-r--r-- | extractor/phrase_builder.cc | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/extractor/phrase_builder.cc b/extractor/phrase_builder.cc index 7f3447e5..c4e0c2ed 100644 --- a/extractor/phrase_builder.cc +++ b/extractor/phrase_builder.cc @@ -19,3 +19,27 @@ Phrase PhraseBuilder::Build(const vector<int>& symbols) { } return phrase; } + +Phrase PhraseBuilder::Extend(const Phrase& phrase, bool start_x, bool end_x) { + vector<int> symbols = phrase.Get(); + int num_nonterminals = 0; + if (start_x) { + num_nonterminals = 1; + symbols.insert(symbols.begin(), + vocabulary->GetNonterminalIndex(num_nonterminals)); + } + + for (size_t i = start_x; i < symbols.size(); ++i) { + if (vocabulary->IsTerminal(symbols[i])) { + ++num_nonterminals; + symbols[i] = vocabulary->GetNonterminalIndex(num_nonterminals); + } + } + + if (end_x) { + ++num_nonterminals; + symbols.push_back(vocabulary->GetNonterminalIndex(num_nonterminals)); + } + + return Build(symbols); +} |