Newer
Older
#include <libwccl/lexicon/lexicon.h>
#include <libpwrutils/util.h>
#include <libwccl/exception.h>
#include <libpwrutils/foreach.h>
#include <boost/make_shared.hpp>
const UnicodeString& Lexicon::translate(const UnicodeString &key) const
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
{
static UnicodeString empty;
map_t::const_iterator i = map_.find(key);
if (i == map_.end()) {
return empty;
}
return i->second;
}
boost::shared_ptr<StrSet> Lexicon::translate(const StrSet& set) const
{
boost::shared_ptr<StrSet> ret_set = boost::make_shared<StrSet>();
foreach(const UnicodeString& s, set.get_value()) {
const UnicodeString& v = translate(s);
if (!v.isEmpty()) {
ret_set->insert(v);
}
}
return ret_set;
}
void Lexicon::insert(const UnicodeString& key, const UnicodeString& value)
{
if (has_key(key)) {
throw InvalidArgument("key", PwrNlp::to_utf8(key) + " - entry already added.");
}
if (key.isEmpty()) {
throw InvalidArgument("key", "Cannot add an empty string.");
}
if (value.isEmpty()) {
throw InvalidArgument("value", "Cannot add an empty string.");
}
map_[key] = value;
}
} /* end ns Wccl */