summary refs log tree commit diff stats
path: root/lib/word.h
blob: 8c8de51d9ef33a362df5d1696ff9b288c8de2502 (plain) (blame)
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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
#ifndef WORD_H_DF91B1B4
#define WORD_H_DF91B1B4

#include <stdexcept>
#include <map>
#include "field.h"
#include "filter.h"
#include "notion.h"
#include "frame.h"
#include "form.h"

struct sqlite3_stmt;

namespace verbly {

  class database;

  class word {
  public:

    // Default constructor

    word() = default;

    // Construct from database

    word(const database& db, sqlite3_stmt* row);

    // Accessors

    bool isValid() const
    {
      return valid_;
    }

    int getId() const
    {
      if (!valid_)
      {
        throw std::domain_error("Bad access to uninitialized word");
      }

      return id_;
    }

    bool hasTagCount() const
    {
      if (!valid_)
      {
        throw std::domain_error("Bad access to uninitialized word");
      }

      return hasTagCount_;
    }

    int getTagCount() const
    {
      if (!valid_)
      {
        throw std::domain_error("Bad access to uninitialized word");
      }

      if (!hasTagCount_)
      {
        throw std::domain_error("Word has no tag count");
      }

      return tagCount_;
    }

    bool hasAdjectivePositioning() const
    {
      if (!valid_)
      {
        throw std::domain_error("Bad access to uninitialized word");
      }

      return (adjectivePosition_ != positioning::undefined);
    }

    positioning getAdjectivePosition() const
    {
      if (!valid_)
      {
        throw std::domain_error("Bad access to uninitialized word");
      }

      if (adjectivePosition_ == positioning::undefined)
      {
        throw std::domain_error("Word has no adjective position");
      }

      return adjectivePosition_;
    }

    const notion& getNotion() const;

    bool hasFrames() const;

    const std::vector<frame>& getFrames() const;

    const form& getBaseForm() const;

    bool hasInflection(inflection category) const;

    const std::vector<form>& getInflections(inflection category) const;

    // Type info

    static const object objectType;

    static const std::list<std::string> select;

    // Query fields

    static const field id;
    static const field tagCount;
    static const field adjectivePosition;

    operator filter() const
    {
      if (!valid_)
      {
        throw std::domain_error("Bad access to uninitialized word");
      }

      return (id == id_);
    }

    filter operator!() const
    {
      if (!valid_)
      {
        throw std::domain_error("Bad access to uninitialized word");
      }

      return (id != id_);
    }

    // Relationships with other objects

    static const field notions;
    static const field frames;

    static field forms(inflection category);

    // Relationships with self

    static const field antonyms;

    static const field specifications;
    static const field generalizations;

    static const field pertainyms;
    static const field antiPertainyms;

    static const field mannernyms;
    static const field antiMannernyms;

    static const field usageTerms;
    static const field usageDomains;

    static const field topicalTerms;
    static const field topicalDomains;

    static const field regionalTerms;
    static const field regionalDomains;

    // Synonymy relationship

    class synonyms_field {
    public:

      filter operator%=(filter joinCondition) const;

      operator filter() const;
    };

    static const synonyms_field synonyms;

  private:

    void initializeForm(inflection category) const;
    void initializeFrames() const;

    bool valid_ = false;

    int id_;
    bool hasTagCount_ = false;
    int tagCount_;
    positioning adjectivePosition_ = positioning::undefined;
    int notionId_;
    int lemmaId_;
    bool hasGroup_ = false;
    int groupId_;

    const database* db_;

    mutable notion notion_;
    mutable bool initializedFrames_ = false;
    mutable std::vector<frame> frames_;
    mutable std::map<inflection, std::vector<form>> forms_;

  };

};

#endif /* end of include guard: WORD_H_DF91B1B4 */