summary refs log tree commit diff stats
path: root/lib/word.h
blob: ddcabe45b50208473c42a4789b82c09517e2471e (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
#ifndef WORD_H_DF91B1B4
#define WORD_H_DF91B1B4

#include <stdexcept>
#include <map>
#include "field.h"
#include "filter.h"
#include "notion.h"
#include "lemma.h"
#include "group.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

    operator bool() 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;

    const lemma& getLemma() const;

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

      return hasGroup_;
    }

    const group& getGroup() const;

    // Convenience accessors

    std::string getBaseForm() const;

    std::vector<std::string> getInflections(inflection infl) 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
    {
      return (id == id_);
    }

    // Relationships with other objects

    static const field notion;
    static const field lemma;
    static const field group;

    // 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;

  private:
    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 class notion notion_;
    mutable class lemma lemma_;
    mutable class group group_;

  };

};

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