summaryrefslogtreecommitdiff
path: root/extractor/phrase_builder.cc
diff options
context:
space:
mode:
Diffstat (limited to 'extractor/phrase_builder.cc')
-rw-r--r--extractor/phrase_builder.cc21
1 files changed, 21 insertions, 0 deletions
diff --git a/extractor/phrase_builder.cc b/extractor/phrase_builder.cc
new file mode 100644
index 00000000..7f3447e5
--- /dev/null
+++ b/extractor/phrase_builder.cc
@@ -0,0 +1,21 @@
+#include "phrase_builder.h"
+
+#include "phrase.h"
+#include "vocabulary.h"
+
+PhraseBuilder::PhraseBuilder(shared_ptr<Vocabulary> vocabulary) :
+ vocabulary(vocabulary) {}
+
+Phrase PhraseBuilder::Build(const vector<int>& symbols) {
+ Phrase phrase;
+ phrase.symbols = symbols;
+ phrase.words.resize(symbols.size());
+ for (size_t i = 0; i < symbols.size(); ++i) {
+ if (vocabulary->IsTerminal(symbols[i])) {
+ phrase.words[i] = vocabulary->GetTerminalValue(symbols[i]);
+ } else {
+ phrase.var_pos.push_back(i);
+ }
+ }
+ return phrase;
+}