Newer
Older
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
62
#ifndef LIBWCCL_LEXICON_LEXICON_H
#define LIBWCCL_LEXICON_LEXICON_H
#include <boost/unordered_map.hpp>
#include <boost/noncopyable.hpp>
#include <libcorpus2/lexeme.h> // for unicodestring hash
#include <libwccl/values/strset.h>
namespace Wccl {
class Lexicon : boost::noncopyable
{
public:
typedef boost::unordered_map<UnicodeString, UnicodeString> map_t;
Lexicon(const std::string& name)
: name_(name)
{
BOOST_ASSERT(!name_.empty());
}
/**
* Translate given key to a value held in this lexicon.
* @returns Value assigned to the given key, if present.
* Empty UnicodeString if the key was not present.
*/
const UnicodeString& translate(const UnicodeString& key) const;
/**
* Translate given set of strings to corresponding values
* from the lexicon.
* Nonexisting keys will translate to nothing (will be removed
* from output).
*/
boost::shared_ptr<StrSet> translate(const StrSet& set) const;
std::string name() const {
return name_;
}
bool has_key(const UnicodeString& key) const {
return map_.find(key) != map_.end();
}
void insert(const UnicodeString& key, const UnicodeString& value);
void insert(const UnicodeString& key) {
insert(key, key);
}
const map_t& map() const {
return map_;
}
private:
map_t map_;
const std::string name_;
};
} /* end ns Wccl */
#endif // LIBWCCL_LEXICON_LEXICON_H