Nuspell
spellchecker
aff_data.hxx
Go to the documentation of this file.
1 /* Copyright 2016-2018 Dimitrij Mijoski
2  *
3  * This file is part of Nuspell.
4  *
5  * Nuspell is free software: you can redistribute it and/or modify
6  * it under the terms of the GNU Lesser General Public License as published by
7  * the Free Software Foundation, either version 3 of the License, or
8  * (at your option) any later version.
9  *
10  * Nuspell is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public License
16  * along with Nuspell. If not, see <http://www.gnu.org/licenses/>.
17  */
18 
24 #ifndef NUSPELL_AFF_DATA_HXX
25 #define NUSPELL_AFF_DATA_HXX
26 
27 #include "locale_utils.hxx"
28 #include "structures.hxx"
29 
30 #include <iosfwd>
31 
32 namespace nuspell {
33 
34 enum Flag_Type {
39 };
40 
41 template <class CharT>
43  Substr_Replacer<CharT> input_substr_replacer;
44  Substr_Replacer<CharT> output_substr_replacer;
45  Break_Table<CharT> break_table;
46  std::basic_string<CharT> ignored_chars;
47  Prefix_Table<CharT> prefixes;
48  Suffix_Table<CharT> suffixes;
49  std::vector<Compound_Pattern<CharT>> compound_patterns;
50  Replacement_Table<CharT> replacements;
51  std::vector<Similarity_Group<CharT>> similarities;
52  std::basic_string<CharT> keyboard_closeness;
53  std::basic_string<CharT> try_chars;
54  Phonetic_Table<CharT> phonetic_table;
55 };
56 
57 struct Affix {
58  char16_t flag;
59  bool cross_product;
60  std::string stripping;
61  std::string appending;
62  Flag_Set new_flags;
63  std::string condition;
64  std::vector<std::string> morphological_fields;
65 };
66 
68  std::string first_word_end;
69  std::string second_word_begin;
70  std::string replacement;
71  char16_t first_word_flag;
72  char16_t second_word_flag;
73 };
74 
75 using Word_List_Base =
77  member<std::pair<std::string, Flag_Set>, std::string,
78  &std::pair<std::string, Flag_Set>::first>>;
88 class Word_List : public Word_List_Base {
89  public:
90  using Word_List_Base::equal_range;
91  auto equal_range(const std::wstring& word) const
92  -> std::pair<Word_List_Base::local_const_iterator,
93  Word_List_Base::local_const_iterator>;
94 };
95 
96 struct Aff_Data {
97  // data members
98  // word list
99  Word_List words;
100 
101  Aff_Structures<char> structures;
102  Aff_Structures<wchar_t> wide_structures;
103 
104  // general options
105  std::locale internal_locale;
106  Flag_Type flag_type;
107  bool complex_prefixes;
108  bool fullstrip;
109  bool checksharps;
110  bool forbid_warn;
111  char16_t circumfix_flag;
112  char16_t forbiddenword_flag;
113  char16_t keepcase_flag;
114  char16_t need_affix_flag;
115  char16_t substandard_flag;
116  char16_t warn_flag;
117 
118  std::vector<Flag_Set> flag_aliases;
119  std::string wordchars; // deprecated?
120 
121  // suggestion options
122  char16_t nosuggest_flag;
123  unsigned short max_compound_suggestions;
124  unsigned short max_ngram_suggestions;
125  unsigned short max_diff_factor;
126  bool only_max_diff;
127  bool no_split_suggestions;
128  bool suggest_with_dots;
129 
130  // compounding options
131  unsigned short compound_min_length;
132  unsigned short compound_max_word_count;
133  char16_t compound_flag;
134  char16_t compound_begin_flag;
135  char16_t compound_last_flag;
136  char16_t compound_middle_flag;
137  char16_t compound_onlyin_flag;
138  char16_t compound_permit_flag;
139  char16_t compound_forbid_flag;
140  char16_t compound_root_flag;
141  char16_t compound_force_uppercase;
142  bool compound_more_suffixes;
143  bool compound_check_duplicate;
144  bool compound_check_rep;
145  bool compound_check_case;
146  bool compound_check_triple;
147  bool compound_simplified_triple;
148 
149  Compound_Rule_Table compound_rules;
150 
151  unsigned short compound_syllable_max;
152  std::string compound_syllable_vowels;
153  Flag_Set compound_syllable_num;
154 
155  // methods
156  auto set_encoding_and_language(const std::string& enc,
157  const std::string& lang = "") -> void;
158  auto parse_aff(std::istream& in) -> bool;
159  auto parse_dic(std::istream& in) -> bool;
160  auto parse_aff_dic(std::istream& aff, std::istream& dic)
161  {
162  if (parse_aff(aff))
163  return parse_dic(dic);
164  return false;
165  }
166  template <class CharT>
167  auto get_structures() const -> const Aff_Structures<CharT>&;
168 };
169 
170 template <>
171 auto inline Aff_Data::get_structures<char>() const
172  -> const Aff_Structures<char>&
173 {
174  return structures;
175 }
176 template <>
177 auto inline Aff_Data::get_structures<wchar_t>() const
178  -> const Aff_Structures<wchar_t>&
179 {
180  return wide_structures;
181 }
182 } // namespace nuspell
183 
184 #endif // NUSPELL_AFF_DATA_HXX
Definition: structures.hxx:313
numerical flag, e.g.
Definition: aff_data.hxx:37
Definition: structures.hxx:869
Definition: structures.hxx:1353
Definition: structures.hxx:1268
Definition: structures.hxx:428
Data structures, private header.
Encoding transformations, private header.
Library main namespace.
Definition: aff_data.cxx:74
Definition: aff_data.hxx:57
Definition: structures.hxx:359
Definition: aff_data.hxx:67
single-character flag, e.g.
Definition: aff_data.hxx:35
double-character flag, e.g for "aa"
Definition: aff_data.hxx:36
Definition: aff_data.hxx:96
UTF-8 flag, e.g.
Definition: aff_data.hxx:38
Map between words and word_flags.
Definition: aff_data.hxx:88
Flag_Type
Definition: aff_data.hxx:34
Definition: structures.hxx:771
Definition: aff_data.hxx:42