-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCountInterpolationStrategy.cpp
61 lines (50 loc) · 1.25 KB
/
CountInterpolationStrategy.cpp
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
52
53
54
55
56
57
58
59
60
61
/*
* CountInterpolationStrategy.cpp
*
* Created on: Feb 14, 2017
* Author: louis
*/
#include "CountInterpolationStrategy.h"
namespace SLM {
CountInterpolationStrategy::CountInterpolationStrategy(SLM::LanguageModel& lm) : lm(&lm) {
// TODO Auto-generated constructor stub
}
CountInterpolationStrategy::~CountInterpolationStrategy() {
// TODO Auto-generated destructor stub
}
double CountInterpolationStrategy::get(const Pattern& context)
{
Pattern contextContext;
Pattern contextFocus;
int contextSize = context.size();
if(contextSize == 1)
{
contextFocus = context;
} else if(contextSize == 2)
{
contextContext = Pattern(context, 0, 1);
contextFocus = Pattern(context, 1, 1);
} else if(contextSize == 3)
{
contextContext = Pattern(context, 0, 2);
contextFocus = Pattern(context, 2, 1);
} else if(contextSize == 4)
{
contextContext = Pattern(context, 0, 3);
contextFocus = Pattern(context, 3, 1);
}
// std::map<Pattern, double>::const_iterator i = weights.find(context);
// if(i == weights.end())
// {
// weights[context] = mle;
return 1.0 + lm->getCount(contextFocus, contextContext);
// } else
// {
// return i->second;
// }
}
std::string CountInterpolationStrategy::name() const
{
return "count";
}
} /* namespace SLM */