summaryrefslogtreecommitdiff
path: root/extractor/vocabulary.cc
diff options
context:
space:
mode:
authorPaul Baltescu <pauldb89@gmail.com>2013-03-07 22:49:46 +0000
committerPaul Baltescu <pauldb89@gmail.com>2013-03-07 22:49:46 +0000
commite362788ec318f0d9a349eeb2459cf72747502919 (patch)
tree474f8bccf1f88a0a358094fd4d855ebc6278a2b2 /extractor/vocabulary.cc
parentb34c347cd7f4f8965e4d943543a31f9a4e886f54 (diff)
Parallelized grammar extraction.
Diffstat (limited to 'extractor/vocabulary.cc')
-rw-r--r--extractor/vocabulary.cc27
1 files changed, 15 insertions, 12 deletions
diff --git a/extractor/vocabulary.cc b/extractor/vocabulary.cc
index 57f564d9..15795d1e 100644
--- a/extractor/vocabulary.cc
+++ b/extractor/vocabulary.cc
@@ -5,14 +5,18 @@ namespace extractor {
Vocabulary::~Vocabulary() {}
int Vocabulary::GetTerminalIndex(const string& word) {
- if (!dictionary.count(word)) {
- int word_id = words.size();
- dictionary[word] = word_id;
- words.push_back(word);
- return word_id;
+ int word_id = -1;
+ #pragma omp critical (vocabulary)
+ {
+ if (!dictionary.count(word)) {
+ word_id = words.size();
+ dictionary[word] = word_id;
+ words.push_back(word);
+ } else {
+ word_id = dictionary[word];
+ }
}
-
- return dictionary[word];
+ return word_id;
}
int Vocabulary::GetNonterminalIndex(int position) {
@@ -24,11 +28,10 @@ bool Vocabulary::IsTerminal(int symbol) {
}
string Vocabulary::GetTerminalValue(int symbol) {
- return words[symbol];
-}
-
-int Vocabulary::Size() {
- return words.size();
+ string word;
+ #pragma omp critical (vocabulary)
+ word = words[symbol];
+ return word;
}
} // namespace extractor