Open Chinese Convert: DictGroup.hpp Source File

Open Chinese Convert 1.3.2.dirty A project for conversion between Traditional and Simplified Chinese

Loading...
Searching...
No Matches
DictGroup.hpp
1/*
2 * Open Chinese Convert
3 *
4 * Copyright 2010-2014 Carbo Kuo <byvoid@byvoid.com>
5 *
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
17 */
18
19#pragma once
20
21#include <list>
22
23#include "Common.hpp"
24#include "Dict.hpp"
25
26namespace opencc {
27
44 class OPENCC_EXPORT DictGroup : public Dict {
45public:
46 explicit DictGroup(const std::list<DictPtr>& dicts);
47
48 DictGroup(const std::list<DictPtr>& dicts, DictGroupMatchPolicy matchPolicy);
49
50 static DictGroupPtr NewFromDict(const Dict& dict);
51
52 virtual ~DictGroup();
53
57 virtual size_t KeyMaxLength() const;
58
63 virtual Optional<const DictEntry*> Match(const char* word, size_t len) const;
64
74 virtual Optional<const DictEntry*> MatchPrefix(const char* word,
75 size_t len) const;
76
86 virtual std::vector<const DictEntry*> MatchAllPrefixes(const char* word,
87 size_t len) const;
88
95 virtual LexiconPtr GetLexicon() const;
96
102 virtual const std::list<DictPtr>* GetDictGroupItems() const {
103 return &dicts;
104 }
105
109 const std::list<DictPtr> GetDicts() const { return dicts; }
110
114 virtual DictGroupMatchPolicy GetMatchPolicy() const { return matchPolicy; }
115
116private:
117 const size_t keyMaxLength;
118 const std::list<DictPtr> dicts;
119 const DictGroupMatchPolicy matchPolicy;
120};
121
130 class OPENCC_EXPORT UnionDictGroup : public DictGroup {
131public:
132 explicit UnionDictGroup(const std::list<DictPtr>& dicts);
133
134 virtual Optional<const DictEntry*> MatchPrefix(const char* word,
135 size_t len) const;
136};
137} // namespace opencc
opencc::DictGroup::KeyMaxLength
virtual size_t KeyMaxLength() const
Returns the maximum KeyMaxLength() among all child dictionaries.
Definition DictGroup.cpp:50
opencc::DictGroup::GetLexicon
virtual LexiconPtr GetLexicon() const
Returns a merged lexicon from all child dictionaries.
Definition DictGroup.cpp:96
opencc::DictGroup::MatchPrefix
virtual Optional< const DictEntry * > MatchPrefix(const char *word, size_t len) const
Matches the longest prefix within the first child dictionary that has any prefix match.
Definition DictGroup.cpp:63
opencc::DictGroup::GetMatchPolicy
virtual DictGroupMatchPolicy GetMatchPolicy() const
Returns how this group resolves matches across child dictionaries.
Definition DictGroup.hpp:114
opencc::DictGroup::GetDicts
const std::list< DictPtr > GetDicts() const
Returns the child dictionaries by value.
Definition DictGroup.hpp:109
opencc::DictGroup::Match
virtual Optional< const DictEntry * > Match(const char *word, size_t len) const
Matches the key exactly against child dictionaries in group order.
Definition DictGroup.cpp:52
opencc::DictGroup::GetDictGroupItems
virtual const std::list< DictPtr > * GetDictGroupItems() const
Exposes child dictionaries to callers that need group-aware behavior.
Definition DictGroup.hpp:102
opencc::DictGroup::MatchAllPrefixes
virtual std::vector< const DictEntry * > MatchAllPrefixes(const char *word, size_t len) const
Returns prefix matches from all child dictionaries, sorted by key length descending.
Definition DictGroup.cpp:74
opencc::Dict
Abstract class of dictionary.
Definition Dict.hpp:63
opencc::Optional
A class that wraps type T into a nullable type.
Definition Optional.hpp:26
opencc::UnionDictGroup::MatchPrefix
virtual Optional< const DictEntry * > MatchPrefix(const char *word, size_t len) const
Matches the longest prefix within the first child dictionary that has any prefix match.
Definition DictGroup.cpp:117