-
Notifications
You must be signed in to change notification settings - Fork 0
/
FullBackoffStrategy.h
49 lines (33 loc) · 1.14 KB
/
FullBackoffStrategy.h
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
/*
* FullBackoffStrategy.h
*
* Created on: Dec 13, 2016
* Author: onrust
*/
#ifndef FULLBACKOFFSTRATEGY_H_
#define FULLBACKOFFSTRATEGY_H_
#include "BackoffStrategy.h"
#include <unordered_map>
namespace SLM {
class InterpolationStrategy;
const std::string cacheExtension = "cache";
class FullBackoffStrategy: public BackoffStrategy
{
public:
FullBackoffStrategy(SLM::LanguageModel& languageModel, const std::string& baseFileName, SLM::InterpolationStrategy* interpolationStrategy);
virtual ~FullBackoffStrategy();
virtual void init(SLM::LanguageModel& languageModel, const std::string& baseFileName);
virtual std::string name() const;
double prob(const Pattern& context, const Pattern& focus, bool isOOV);
bool addToCache(const Pattern& pattern, double val);
std::experimental::optional<double> getFromCache(const Pattern& pattern);
bool setIgnoreCache(bool setting);
protected:
void writeCache();
SLM::InterpolationStrategy* interpolationStrategy;
std::ofstream cacheOutputFile;
std::unordered_map<Pattern, double> cache;
bool ignoreCache = false;
};
} /* namespace SLM */
#endif /* FULLBACKOFFSTRATEGY_H_ */