1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
|
#include <gtest/gtest.h>
#include <memory>
#include <string>
#include <vector>
#include "grammar.h"
#include "grammar_extractor.h"
#include "mocks/mock_rule_factory.h"
#include "mocks/mock_vocabulary.h"
#include "rule.h"
using namespace std;
using namespace ::testing;
namespace extractor {
namespace {
TEST(GrammarExtractorTest, TestAnnotatingWords) {
shared_ptr<MockVocabulary> vocabulary = make_shared<MockVocabulary>();
EXPECT_CALL(*vocabulary, GetTerminalIndex("<s>"))
.WillRepeatedly(Return(0));
EXPECT_CALL(*vocabulary, GetTerminalIndex("Anna"))
.WillRepeatedly(Return(1));
EXPECT_CALL(*vocabulary, GetTerminalIndex("has"))
.WillRepeatedly(Return(2));
EXPECT_CALL(*vocabulary, GetTerminalIndex("many"))
.WillRepeatedly(Return(3));
EXPECT_CALL(*vocabulary, GetTerminalIndex("apples"))
.WillRepeatedly(Return(4));
EXPECT_CALL(*vocabulary, GetTerminalIndex("."))
.WillRepeatedly(Return(5));
EXPECT_CALL(*vocabulary, GetTerminalIndex("</s>"))
.WillRepeatedly(Return(6));
shared_ptr<MockHieroCachingRuleFactory> factory =
make_shared<MockHieroCachingRuleFactory>();
vector<int> word_ids = {0, 1, 2, 3, 3, 4, 5, 6};
vector<Rule> rules;
vector<string> feature_names;
Grammar grammar(rules, feature_names);
EXPECT_CALL(*factory, GetGrammar(word_ids))
.WillOnce(Return(grammar));
GrammarExtractor extractor(vocabulary, factory);
string sentence = "Anna has many many apples .";
extractor.GetGrammar(sentence);
}
} // namespace
} // namespace extractor
|