All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
trie.h
Go to the documentation of this file.
1 /* -*-C-*-
2  ********************************************************************************
3  *
4  * File: trie.h (Formerly trie.h)
5  * Description: Functions to build a trie data structure.
6  * Author: Mark Seaman, SW Productivity
7  * Created: Fri Oct 16 14:37:00 1987
8  * Modified: Fri Jul 26 11:26:34 1991 (Mark Seaman) marks@hpgrlt
9  * Language: C
10  * Package: N/A
11  * Status: Reusable Software Component
12  *
13  * (c) Copyright 1987, Hewlett-Packard Company.
14  ** Licensed under the Apache License, Version 2.0 (the "License");
15  ** you may not use this file except in compliance with the License.
16  ** You may obtain a copy of the License at
17  ** http://www.apache.org/licenses/LICENSE-2.0
18  ** Unless required by applicable law or agreed to in writing, software
19  ** distributed under the License is distributed on an "AS IS" BASIS,
20  ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
21  ** See the License for the specific language governing permissions and
22  ** limitations under the License.
23  *
24  *********************************************************************************/
25 #ifndef TRIE_H
26 #define TRIE_H
27 
28 #include "dawg.h"
29 #include "cutil.h"
30 #include "genericvector.h"
31 
32 class UNICHARSET;
33 
34 // Note: if we consider either NODE_REF or EDGE_INDEX to ever exceed
35 // max int32, we will need to change GenericVector to use int64 for size
36 // and address indices. This does not seem to be needed immediately,
37 // since currently the largest number of edges limit used by tesseract
38 // (kMaxNumEdges in wordlist2dawg.cpp) is far less than max int32.
39 // There are also int casts below to satisfy the WIN32 compiler that would
40 // need to be changed.
41 // It might be cleanest to change the types of most of the Trie/Dawg related
42 // typedefs to int and restrict the casts to extracting these values from
43 // the 64 bit EDGE_RECORD.
44 typedef inT64 EDGE_INDEX; // index of an edge in a given node
45 typedef bool *NODE_MARKER;
47 
51 };
53 
54 namespace tesseract {
55 
62 class Trie : public Dawg {
63  public:
68  };
69 
70  // Minimum number of concrete characters at the beginning of user patterns.
71  static const int kSaneNumConcreteChars = 0;
72  // Various unicode whitespace characters are used to denote unichar patterns,
73  // (character classifier would never produce these whitespace characters as a
74  // valid classification).
75  static const char kAlphaPatternUnicode[];
76  static const char kDigitPatternUnicode[];
77  static const char kAlphanumPatternUnicode[];
78  static const char kPuncPatternUnicode[];
79  static const char kLowerPatternUnicode[];
80  static const char kUpperPatternUnicode[];
81 
82  static const char *get_reverse_policy_name(
83  RTLReversePolicy reverse_policy);
84 
85  // max_num_edges argument allows limiting the amount of memory this
86  // Trie can consume (if a new word insert would cause the Trie to
87  // contain more edges than max_num_edges, all the edges are cleared
88  // so that new inserts can proceed).
90  int unicharset_size, int debug_level) {
91  init(type, lang, perm, unicharset_size, debug_level);
92  num_edges_ = 0;
94  new_dawg_node(); // need to allocate node 0
95  initialized_patterns_ = false;
96  }
98 
99  // Reset the Trie to empty.
100  void clear();
101 
103  EDGE_REF edge_char_of(NODE_REF node_ref, UNICHAR_ID unichar_id,
104  bool word_end) const {
105  EDGE_RECORD *edge_ptr;
106  EDGE_INDEX edge_index;
107  if (!edge_char_of(node_ref, NO_EDGE, FORWARD_EDGE, word_end, unichar_id,
108  &edge_ptr, &edge_index)) return NO_EDGE;
109  return make_edge_ref(node_ref, edge_index);
110  }
111 
117  bool word_end) const {
118  const EDGE_VECTOR &forward_edges =
119  nodes_[static_cast<int>(node)]->forward_edges;
120  for (int i = 0; i < forward_edges.size(); ++i) {
121  if (!word_end || end_of_word_from_edge_rec(forward_edges[i])) {
122  vec->push_back(NodeChild(unichar_id_from_edge_rec(forward_edges[i]),
123  make_edge_ref(node, i)));
124  }
125  }
126  }
127 
132  NODE_REF next_node(EDGE_REF edge_ref) const {
133  if (edge_ref == NO_EDGE || num_edges_ == 0) return NO_EDGE;
134  return next_node_from_edge_rec(*deref_edge_ref(edge_ref));
135  }
136 
141  bool end_of_word(EDGE_REF edge_ref) const {
142  if (edge_ref == NO_EDGE || num_edges_ == 0) return false;
143  return end_of_word_from_edge_rec(*deref_edge_ref(edge_ref));
144  }
145 
147  UNICHAR_ID edge_letter(EDGE_REF edge_ref) const {
148  if (edge_ref == NO_EDGE || num_edges_ == 0) return INVALID_UNICHAR_ID;
149  return unichar_id_from_edge_rec(*deref_edge_ref(edge_ref));
150  }
151  // Sets the UNICHAR_ID in the given edge_rec to unicharset_size_, marking
152  // the edge dead.
153  void KillEdge(EDGE_RECORD* edge_rec) const {
154  *edge_rec &= ~letter_mask_;
155  *edge_rec |= (unicharset_size_ << LETTER_START_BIT);
156  }
157  bool DeadEdge(const EDGE_RECORD& edge_rec) const {
158  return unichar_id_from_edge_rec(edge_rec) == unicharset_size_;
159  }
160 
161  // Prints the contents of the node indicated by the given NODE_REF.
162  // At most max_num_edges will be printed.
163  void print_node(NODE_REF node, int max_num_edges) const;
164 
165  // Writes edges from nodes_ to an EDGE_ARRAY and creates a SquishedDawg.
166  // Eliminates redundant edges and returns the pointer to the SquishedDawg.
167  // Note: the caller is responsible for deallocating memory associated
168  // with the returned SquishedDawg pointer.
170 
171  // Reads a list of words from the given file and adds into the Trie.
172  // Calls WERD_CHOICE::reverse_unichar_ids_if_rtl() according to the reverse
173  // policy and information in the unicharset.
174  // Returns false on error.
175  bool read_and_add_word_list(const char *filename,
176  const UNICHARSET &unicharset,
178 
179  // Reads a list of words from the given file, applying the reverse_policy,
180  // according to information in the unicharset.
181  // Returns false on error.
182  bool read_word_list(const char *filename,
183  const UNICHARSET &unicharset,
184  Trie::RTLReversePolicy reverse_policy,
185  GenericVector<STRING>* words);
186  // Adds a list of words previously read using read_word_list to the trie
187  // using the given unicharset to convert to unichar-ids.
188  // Returns false on error.
189  bool add_word_list(const GenericVector<STRING>& words,
190  const UNICHARSET &unicharset);
191 
192  // Inserts the list of patterns from the given file into the Trie.
193  // The pattern list file should contain one pattern per line in UTF-8 format.
194  //
195  // Each pattern can contain any non-whitespace characters, however only the
196  // patterns that contain characters from the unicharset of the corresponding
197  // language will be useful.
198  // The only meta character is '\'. To be used in a pattern as an ordinary
199  // string it should be escaped with '\' (e.g. string "C:\Documents" should
200  // be written in the patterns file as "C:\\Documents").
201  // This function supports a very limited regular expression syntax. One can
202  // express a character, a certain character class and a number of times the
203  // entity should be repeated in the pattern.
204  //
205  // To denote a character class use one of:
206  // \c - unichar for which UNICHARSET::get_isalpha() is true (character)
207  // \d - unichar for which UNICHARSET::get_isdigit() is true
208  // \n - unichar for which UNICHARSET::get_isdigit() and
209  // UNICHARSET::isalpha() are true
210  // \p - unichar for which UNICHARSET::get_ispunct() is true
211  // \a - unichar for which UNICHARSET::get_islower() is true
212  // \A - unichar for which UNICHARSET::get_isupper() is true
213  //
214  // \* could be specified after each character or pattern to indicate that
215  // the character/pattern can be repeated any number of times before the next
216  // character/pattern occurs.
217  //
218  // Examples:
219  // 1-8\d\d-GOOG-411 will be expanded to strings:
220  // 1-800-GOOG-411, 1-801-GOOG-411, ... 1-899-GOOG-411.
221  //
222  // http://www.\n\*.com will be expanded to strings like:
223  // http://www.a.com http://www.a123.com ... http://www.ABCDefgHIJKLMNop.com
224  //
225  // Note: In choosing which patterns to include please be aware of the fact
226  // providing very generic patterns will make tesseract run slower.
227  // For example \n\* at the beginning of the pattern will make Tesseract
228  // consider all the combinations of proposed character choices for each
229  // of the segmentations, which will be unacceptably slow.
230  // Because of potential problems with speed that could be difficult to
231  // identify, each user pattern has to have at least kSaneNumConcreteChars
232  // concrete characters from the unicharset at the beginning.
233  bool read_pattern_list(const char *filename, const UNICHARSET &unicharset);
234 
235  // Initializes the values of *_pattern_ unichar ids.
236  // This function should be called before calling read_pattern_list().
237  void initialize_patterns(UNICHARSET *unicharset);
238 
239  // Fills in the given unichar id vector with the unichar ids that represent
240  // the patterns of the character classes of the given unichar_id.
241  void unichar_id_to_patterns(UNICHAR_ID unichar_id,
242  const UNICHARSET &unicharset,
243  GenericVector<UNICHAR_ID> *vec) const;
244 
245  // Returns the given EDGE_REF if the EDGE_RECORD that it points to has
246  // a self loop and the given unichar_id matches the unichar_id stored in the
247  // EDGE_RECORD, returns NO_EDGE otherwise.
249  UNICHAR_ID unichar_id,
250  bool word_end) const {
251  if (edge_ref == NO_EDGE) return NO_EDGE;
252  EDGE_RECORD *edge_rec = deref_edge_ref(edge_ref);
253  return (marker_flag_from_edge_rec(*edge_rec) &&
254  unichar_id == unichar_id_from_edge_rec(*edge_rec) &&
255  word_end == end_of_word_from_edge_rec(*edge_rec)) ?
256  edge_ref : NO_EDGE;
257  }
258 
259  // Adds a word to the Trie (creates the necessary nodes and edges).
260  //
261  // If repetitions vector is not NULL, each entry in the vector indicates
262  // whether the unichar id with the corresponding index in the word is allowed
263  // to repeat an unlimited number of times. For each entry that is true, MARKER
264  // flag of the corresponding edge created for this unichar id is set to true).
265  //
266  // Return true if add succeeded, false otherwise (e.g. when a word contained
267  // an invalid unichar id or the trie was getting too large and was cleared).
268  bool add_word_to_dawg(const WERD_CHOICE &word,
269  const GenericVector<bool> *repetitions);
270  bool add_word_to_dawg(const WERD_CHOICE &word) {
271  return add_word_to_dawg(word, NULL);
272  }
273 
274  protected:
275  // The structure of an EDGE_REF for Trie edges is as follows:
276  // [LETTER_START_BIT, flag_start_bit_):
277  // edge index in *_edges in a TRIE_NODE_RECORD
278  // [flag_start_bit, 30th bit]: node index in nodes (TRIE_NODES vector)
279  //
280  // With this arrangement there are enough bits to represent edge indices
281  // (each node can have at most unicharset_size_ forward edges and
282  // the position of flag_start_bit is set to be log2(unicharset_size_)).
283  // It is also possible to accommodate a maximum number of nodes that is at
284  // least as large as that of the SquishedDawg representation (in SquishedDawg
285  // each EDGE_RECORD has 32-(flag_start_bit+NUM_FLAG_BITS) bits to represent
286  // the next node index).
287  //
288 
289  // Returns the pointer to EDGE_RECORD after decoding the location
290  // of the edge from the information in the given EDGE_REF.
291  // This function assumes that EDGE_REF holds valid node/edge indices.
292  inline EDGE_RECORD *deref_edge_ref(EDGE_REF edge_ref) const {
293  int edge_index = static_cast<int>(
294  (edge_ref & letter_mask_) >> LETTER_START_BIT);
295  int node_index = static_cast<int>(
296  (edge_ref & deref_node_index_mask_) >> flag_start_bit_);
297  TRIE_NODE_RECORD *node_rec = nodes_[node_index];
298  return &(node_rec->forward_edges[edge_index]);
299  }
301  inline EDGE_REF make_edge_ref(NODE_REF node_index,
302  EDGE_INDEX edge_index) const {
303  return ((node_index << flag_start_bit_) |
304  (edge_index << LETTER_START_BIT));
305  }
307  inline void link_edge(EDGE_RECORD *edge, NODE_REF nxt, bool repeats,
308  int direction, bool word_end, UNICHAR_ID unichar_id) {
309  EDGE_RECORD flags = 0;
310  if (repeats) flags |= MARKER_FLAG;
311  if (word_end) flags |= WERD_END_FLAG;
312  if (direction == BACKWARD_EDGE) flags |= DIRECTION_FLAG;
313  *edge = ((nxt << next_node_start_bit_) |
314  (static_cast<EDGE_RECORD>(flags) << flag_start_bit_) |
315  (static_cast<EDGE_RECORD>(unichar_id) << LETTER_START_BIT));
316  }
318  inline void print_edge_rec(const EDGE_RECORD &edge_rec) const {
319  tprintf("|" REFFORMAT "|%s%s%s|%d|", next_node_from_edge_rec(edge_rec),
320  marker_flag_from_edge_rec(edge_rec) ? "R," : "",
321  (direction_from_edge_rec(edge_rec) == FORWARD_EDGE) ? "F" : "B",
322  end_of_word_from_edge_rec(edge_rec) ? ",E" : "",
323  unichar_id_from_edge_rec(edge_rec));
324  }
325  // Returns true if the next node in recorded the given EDGE_RECORD
326  // has exactly one forward edge.
327  inline bool can_be_eliminated(const EDGE_RECORD &edge_rec) {
328  NODE_REF node_ref = next_node_from_edge_rec(edge_rec);
329  return (node_ref != NO_EDGE &&
330  nodes_[static_cast<int>(node_ref)]->forward_edges.size() == 1);
331  }
332 
333  // Prints the contents of the Trie.
334  // At most max_num_edges will be printed for each node.
335  void print_all(const char* msg, int max_num_edges) {
336  tprintf("\n__________________________\n%s\n", msg);
337  for (int i = 0; i < nodes_.size(); ++i) print_node(i, max_num_edges);
338  tprintf("__________________________\n");
339  }
340 
341  // Finds the edge with the given direction, word_end and unichar_id
342  // in the node indicated by node_ref. Fills in the pointer to the
343  // EDGE_RECORD and the index of the edge with the the values
344  // corresponding to the edge found. Returns true if an edge was found.
345  bool edge_char_of(NODE_REF node_ref, NODE_REF next_node,
346  int direction, bool word_end, UNICHAR_ID unichar_id,
347  EDGE_RECORD **edge_ptr, EDGE_INDEX *edge_index) const;
348 
349  // Adds an single edge linkage between node1 and node2 in the direction
350  // indicated by direction argument.
351  bool add_edge_linkage(NODE_REF node1, NODE_REF node2, bool repeats,
352  int direction, bool word_end,
353  UNICHAR_ID unichar_id);
354 
355  // Adds forward edge linkage from node1 to node2 and the corresponding
356  // backward edge linkage in the other direction.
357  bool add_new_edge(NODE_REF node1, NODE_REF node2,
358  bool repeats, bool word_end, UNICHAR_ID unichar_id) {
359  return (add_edge_linkage(node1, node2, repeats, FORWARD_EDGE,
360  word_end, unichar_id) &&
361  add_edge_linkage(node2, node1, repeats, BACKWARD_EDGE,
362  word_end, unichar_id));
363  }
364 
365  // Sets the word ending flags in an already existing edge pair.
366  // Returns true on success.
367  void add_word_ending(EDGE_RECORD *edge,
368  NODE_REF the_next_node,
369  bool repeats,
370  UNICHAR_ID unichar_id);
371 
372  // Allocates space for a new node in the Trie.
374 
375  // Removes a single edge linkage to between node1 and node2 in the
376  // direction indicated by direction argument.
377  void remove_edge_linkage(NODE_REF node1, NODE_REF node2, int direction,
378  bool word_end, UNICHAR_ID unichar_id);
379 
380  // Removes forward edge linkage from node1 to node2 and the corresponding
381  // backward edge linkage in the other direction.
382  void remove_edge(NODE_REF node1, NODE_REF node2,
383  bool word_end, UNICHAR_ID unichar_id) {
384  remove_edge_linkage(node1, node2, FORWARD_EDGE, word_end, unichar_id);
385  remove_edge_linkage(node2, node1, BACKWARD_EDGE, word_end, unichar_id);
386  }
387 
388  // Compares edge1 and edge2 in the given node to see if they point to two
389  // next nodes that could be collapsed. If they do, performs the reduction
390  // and returns true.
391  bool eliminate_redundant_edges(NODE_REF node, const EDGE_RECORD &edge1,
392  const EDGE_RECORD &edge2);
393 
394  // Assuming that edge_index indicates the first edge in a group of edges
395  // in this node with a particular letter value, looks through these edges
396  // to see if any of them can be collapsed. If so does it. Returns to the
397  // caller when all edges with this letter have been reduced.
398  // Returns true if further reduction is possible with this same letter.
399  bool reduce_lettered_edges(EDGE_INDEX edge_index,
400  UNICHAR_ID unichar_id,
401  NODE_REF node,
402  EDGE_VECTOR* backward_edges,
403  NODE_MARKER reduced_nodes);
404 
411  void sort_edges(EDGE_VECTOR *edges);
412 
414  void reduce_node_input(NODE_REF node, NODE_MARKER reduced_nodes);
415 
416  // Returns the pattern unichar id for the given character class code.
418 
419  // Member variables
420  TRIE_NODES nodes_; // vector of nodes in the Trie
421  uinT64 num_edges_; // sum of all edges (forward and backward)
422  uinT64 deref_direction_mask_; // mask for EDGE_REF to extract direction
423  uinT64 deref_node_index_mask_; // mask for EDGE_REF to extract node index
424  // Freelist of edges in the root backwards node that were previously zeroed.
426  // Variables for translating character class codes denoted in user patterns
427  // file to the unichar ids used to represent them in a Trie.
435 };
436 } // namespace tesseract
437 
438 #endif
virtual EDGE_REF pattern_loop_edge(EDGE_REF edge_ref, UNICHAR_ID unichar_id, bool word_end) const
Definition: trie.h:248
GenericVector< EDGE_RECORD > EDGE_VECTOR
Definition: trie.h:46
bool reduce_lettered_edges(EDGE_INDEX edge_index, UNICHAR_ID unichar_id, NODE_REF node, EDGE_VECTOR *backward_edges, NODE_MARKER reduced_nodes)
Definition: trie.cpp:621
int next_node_start_bit_
Definition: dawg.h:299
const STRING & lang() const
Definition: dawg.h:128
int size() const
Definition: genericvector.h:72
static const char kAlphaPatternUnicode[]
Definition: trie.h:75
bool end_of_word_from_edge_rec(const EDGE_RECORD &edge_rec) const
Returns true if this edge marks the end of a word.
Definition: dawg.h:213
void unichar_ids_of(NODE_REF node, NodeChildVector *vec, bool word_end) const
Definition: trie.h:116
EDGE_VECTOR backward_edges
Definition: trie.h:50
uinT64 num_edges_
Definition: trie.h:421
static const char kDigitPatternUnicode[]
Definition: trie.h:76
bool eliminate_redundant_edges(NODE_REF node, const EDGE_RECORD &edge1, const EDGE_RECORD &edge2)
Definition: trie.cpp:574
UNICHAR_ID alphanum_pattern_
Definition: trie.h:431
bool DeadEdge(const EDGE_RECORD &edge_rec) const
Definition: trie.h:157
static const char kPuncPatternUnicode[]
Definition: trie.h:78
void print_node(NODE_REF node, int max_num_edges) const
Definition: trie.cpp:713
#define LETTER_START_BIT
Definition: dawg.h:90
int push_back(T object)
bool * NODE_MARKER
Definition: trie.h:45
UNICHAR_ID digit_pattern_
Definition: trie.h:430
#define tprintf(...)
Definition: tprintf.h:31
#define DIRECTION_FLAG
Definition: dawg.h:88
int direction(EDGEPT *point)
Definition: vecfuncs.cpp:43
void print_edge_rec(const EDGE_RECORD &edge_rec) const
Definition: trie.h:318
static const char kUpperPatternUnicode[]
Definition: trie.h:80
uinT64 deref_direction_mask_
Definition: trie.h:422
PermuterType
Definition: ratngs.h:240
NODE_REF new_dawg_node()
Definition: trie.cpp:277
void unichar_id_to_patterns(UNICHAR_ID unichar_id, const UNICHARSET &unicharset, GenericVector< UNICHAR_ID > *vec) const
Definition: trie.cpp:369
uinT64 deref_node_index_mask_
Definition: trie.h:423
void sort_edges(EDGE_VECTOR *edges)
Definition: trie.cpp:662
NODE_REF next_node_from_edge_rec(const EDGE_RECORD &edge_rec) const
Returns the next node visited by following this edge.
Definition: dawg.h:200
EDGE_RECORD * deref_edge_ref(EDGE_REF edge_ref) const
Definition: trie.h:292
EDGE_REF make_edge_ref(NODE_REF node_index, EDGE_INDEX edge_index) const
Definition: trie.h:301
void clear()
Definition: trie.cpp:66
bool add_new_edge(NODE_REF node1, NODE_REF node2, bool repeats, bool word_end, UNICHAR_ID unichar_id)
Definition: trie.h:357
UNICHAR_ID lower_pattern_
Definition: trie.h:433
EDGE_REF edge_char_of(NODE_REF node_ref, UNICHAR_ID unichar_id, bool word_end) const
Definition: trie.h:103
TRIE_NODES nodes_
Definition: trie.h:420
SquishedDawg * trie_to_dawg()
Definition: trie.cpp:526
bool initialized_patterns_
Definition: trie.h:428
UNICHAR_ID upper_pattern_
Definition: trie.h:434
static const char kLowerPatternUnicode[]
Definition: trie.h:79
bool add_word_to_dawg(const WERD_CHOICE &word, const GenericVector< bool > *repetitions)
Definition: trie.cpp:178
UNICHAR_ID punc_pattern_
Definition: trie.h:432
bool end_of_word(EDGE_REF edge_ref) const
Definition: trie.h:141
bool add_edge_linkage(NODE_REF node1, NODE_REF node2, bool repeats, int direction, bool word_end, UNICHAR_ID unichar_id)
Definition: trie.cpp:125
void print_all(const char *msg, int max_num_edges)
Definition: trie.h:335
UNICHAR_ID alpha_pattern_
Definition: trie.h:429
#define WERD_END_FLAG
Definition: dawg.h:89
#define FORWARD_EDGE
Definition: dawg.h:84
void remove_edge_linkage(NODE_REF node1, NODE_REF node2, int direction, bool word_end, UNICHAR_ID unichar_id)
Definition: trie.cpp:491
uinT64 letter_mask_
Definition: dawg.h:302
void reduce_node_input(NODE_REF node, NODE_MARKER reduced_nodes)
Definition: trie.cpp:676
LIST reverse(LIST list)
Definition: oldlist.cpp:357
int unicharset_size_
Definition: dawg.h:297
void initialize_patterns(UNICHARSET *unicharset)
Definition: trie.cpp:352
uinT64 EDGE_RECORD
Definition: dawg.h:50
void KillEdge(EDGE_RECORD *edge_rec) const
Definition: trie.h:153
void delete_data_pointers()
#define BACKWARD_EDGE
Definition: dawg.h:85
UNICHAR_ID character_class_to_pattern(char ch)
Definition: trie.cpp:391
bool can_be_eliminated(const EDGE_RECORD &edge_rec)
Definition: trie.h:327
UNICHAR_ID unichar_id_from_edge_rec(const EDGE_RECORD &edge_rec) const
Returns UNICHAR_ID recorded in this edge.
Definition: dawg.h:217
static const char * get_reverse_policy_name(RTLReversePolicy reverse_policy)
Definition: trie.cpp:61
int direction_from_edge_rec(const EDGE_RECORD &edge_rec) const
Returns the direction flag of this edge.
Definition: dawg.h:208
int UNICHAR_ID
Definition: unichar.h:33
bool read_word_list(const char *filename, const UNICHARSET &unicharset, Trie::RTLReversePolicy reverse_policy, GenericVector< STRING > *words)
Definition: trie.cpp:301
unsigned long long int uinT64
Definition: host.h:109
int flag_start_bit_
Definition: dawg.h:298
bool add_word_to_dawg(const WERD_CHOICE &word)
Definition: trie.h:270
NODE_REF next_node(EDGE_REF edge_ref) const
Definition: trie.h:132
#define REFFORMAT
Definition: dawg.h:92
bool read_and_add_word_list(const char *filename, const UNICHARSET &unicharset, Trie::RTLReversePolicy reverse)
Definition: trie.cpp:291
DawgType type() const
Definition: dawg.h:127
RTLReversePolicy
Definition: trie.h:64
#define MARKER_FLAG
Definition: dawg.h:87
DawgType
Definition: dawg.h:71
EDGE_VECTOR forward_edges
Definition: trie.h:49
bool marker_flag_from_edge_rec(const EDGE_RECORD &edge_rec) const
Returns the marker flag of this edge.
Definition: dawg.h:204
bool add_word_list(const GenericVector< STRING > &words, const UNICHARSET &unicharset)
Definition: trie.cpp:336
GenericVector< TRIE_NODE_RECORD * > TRIE_NODES
Definition: trie.h:52
inT64 EDGE_REF
Definition: dawg.h:54
Definition: strngs.h:44
void add_word_ending(EDGE_RECORD *edge, NODE_REF the_next_node, bool repeats, UNICHAR_ID unichar_id)
Definition: trie.cpp:161
#define NULL
Definition: host.h:144
GenericVector< EDGE_INDEX > root_back_freelist_
Definition: trie.h:425
void link_edge(EDGE_RECORD *edge, NODE_REF nxt, bool repeats, int direction, bool word_end, UNICHAR_ID unichar_id)
Definition: trie.h:307
inT64 NODE_REF
Definition: dawg.h:55
static const char kAlphanumPatternUnicode[]
Definition: trie.h:77
void init(DawgType type, const STRING &lang, PermuterType perm, int unicharset_size, int debug_level)
Definition: dawg.cpp:177
virtual ~Trie()
Definition: trie.h:97
Trie(DawgType type, const STRING &lang, PermuterType perm, int unicharset_size, int debug_level)
Definition: trie.h:89
static const int kSaneNumConcreteChars
Definition: trie.h:71
UNICHAR_ID edge_letter(EDGE_REF edge_ref) const
Definition: trie.h:147
bool read_pattern_list(const char *filename, const UNICHARSET &unicharset)
Definition: trie.cpp:409
inT64 EDGE_INDEX
Definition: trie.h:32
void remove_edge(NODE_REF node1, NODE_REF node2, bool word_end, UNICHAR_ID unichar_id)
Definition: trie.h:382
long long int inT64
Definition: host.h:108