File: speller.hpp

package info (click to toggle)
aspell 0.60.8.2-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 15,336 kB
  • sloc: cpp: 24,378; sh: 12,340; perl: 1,924; ansic: 1,661; makefile: 852; sed: 16
file content (147 lines) | stat: -rw-r--r-- 4,325 bytes parent folder | download | duplicates (5)
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
// This file is part of The New Aspell
// Copyright (C) 2001 by Kevin Atkinson under the GNU LGPL license
// version 2.0 or 2.1.  You should have received a copy of the LGPL
// license along with this library if you did not you can find
// it at http://www.gnu.org/.

// Aspell implementation header file.
// Applications that just use the Aspell library should not include 
// these files as they are subject to change.
// Aspell Modules MUST include some of the implementation files and
// spell checkers MAY include some of these files.
// If ANY of the implementation files are included you also link with
// libaspell-impl to protect you from changes in these files.

#ifndef ASPELL_SPELLER__HPP
#define ASPELL_SPELLER__HPP

#include "can_have_error.hpp"
#include "copy_ptr.hpp"
#include "clone_ptr.hpp"
#include "mutable_string.hpp"
#include "posib_err.hpp"
#include "parm_string.hpp"
#include "char_vector.hpp"

namespace acommon {

  typedef void * SpellerLtHandle;

  class Config;
  class WordList;
  class Convert;
  class Tokenizer;
  class Filter;
  class DocumentChecker;

  struct CheckInfo {
    const CheckInfo * next;
    // note: if 'incorrect' then word is a pointer into the string
    // passed into check and is not null terminated;
    // otherwise word is guaranteed to be null termanted
    struct Word {
      const char * str;
      unsigned len;
      ParmString pstr() const {return ParmString(str, len);}
      Word() {}
      Word(const char * str)
        : str(str), len(strlen(str)) {}
      Word(const char * str, unsigned len)
        : str(str), len(len) {}
      Word(ParmStr str)
        : str(str.str()), len(str.size()) {}
    };
    Word word; // generally the root
    short pre_strip_len;
    short pre_add_len;
    const char * pre_add;
    short suf_strip_len;
    short suf_add_len;
    const char * suf_add;
    short pre_flag;
    short suf_flag;
    bool guess;
    bool compound;
    bool incorrect;
  };

  class Speller : public CanHaveError
  {
  private:
    SpellerLtHandle lt_handle_;
    Speller(const Speller &);
    Speller & operator= (const Speller &);
  public:
    String temp_str_0;
    String temp_str_1;
    ClonePtr<Convert> to_internal_;
    ClonePtr<Convert> from_internal_;
  protected:
    CopyPtr<Config> config_;
    Speller(SpellerLtHandle h);
  public:
    SpellerLtHandle lt_handle() const {return lt_handle_;}

    Config * config() {return config_;}
    const Config * config() const {return config_;}

    // utility functions

    virtual char * to_lower(char *) = 0;

    // the setup class will take over for config
    virtual PosibErr<void> setup(Config *) = 0;

    // sets up the tokenizer class
    // should be called only after this class is setup
    virtual void setup_tokenizer(Tokenizer *) = 0;

    ////////////////////////////////////////////////////////////////
    // 
    // Strings from this point on are expected to be in the 
    // encoding specified by encoding()
    //

    virtual PosibErr<bool> check(MutableString) = 0;

    // these functions return information about the last word checked
    virtual const CheckInfo * check_info() = 0;
  
    virtual PosibErr<void> add_to_personal(MutableString) = 0;
    virtual PosibErr<void> add_to_session (MutableString) = 0;
    
    // because the word lists may potently have to convert from one
    // encoding to another the pointer returned by the enumeration is only
    // valid to the next call.

    virtual PosibErr<const WordList *> personal_word_list() const = 0;
    virtual PosibErr<const WordList *> session_word_list () const = 0;
    virtual PosibErr<const WordList *> main_word_list () const = 0;
  
    virtual PosibErr<void> save_all_word_lists() = 0;
  
    virtual PosibErr<void> clear_session() = 0;

    virtual PosibErr<const WordList *> suggest(MutableString) = 0;
    // return null on error
    // the word list returned by suggest is only valid until the next
    // call to suggest
  
    virtual PosibErr<void> store_replacement(MutableString, 
					     MutableString) = 0;

    virtual ~Speller();

  };


  // This function is current a hack to reload the filters in the
  // speller class.  I hope to eventually find a better way.
  PosibErr<void> reload_filters(Speller * m);


  PosibErr<Speller *> new_speller(Config * c);

}

#endif