summary refs log tree commit diff stats
path: root/lib/notion.h
blob: 69f5cef3f2cb8aee2f7fc0b8a4ac5d033b16c8c3 (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
#ifndef NOTION_H_FD1C7646
#define NOTION_H_FD1C7646

#include <stdexcept>
#include <string>
#include "field.h"
#include "filter.h"

struct sqlite3_stmt;

namespace verbly {
  
  class database;
  
  class notion {
  public:
    
    // Default constructor
    
    notion() = default;
    
    // Construct from database
    
    notion(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 notion");
      }
      
      return id_;
    }
    
    part_of_speech getPartOfSpeech() const
    {
      if (!valid_)
      {
        throw std::domain_error("Bad access to uninitialized notion");
      }
      
      return partOfSpeech_;
    }
    
    bool hasWnid() const
    {
      if (!valid_)
      {
        throw std::domain_error("Bad access to uninitialized notion");
      }
      
      return hasWnid_;
    }
    
    int getWnid() const
    {
      if (!valid_)
      {
        throw std::domain_error("Bad access to uninitialized notion");
      }
      
      if (!hasWnid_)
      {
        throw std::domain_error("Notion has no wnid");
      }
      
      return wnid_;
    }
    
    bool hasNumOfImages() const
    {
      if (!valid_)
      {
        throw std::domain_error("Bad access to uninitialized notion");
      }
      
      return hasNumOfImages_;
    }
    
    int getNumOfImages() const
    {
      if (!valid_)
      {
        throw std::domain_error("Bad access to uninitialized notion");
      }
      
      if (!hasNumOfImages_)
      {
        throw std::domain_error("Notion does not have a number of images");
      }
      
      return numOfImages_;
    }
    
    // Convenience
    
    std::string getImageNetUrl() const;
    
    // Type info
    
    static const object objectType;
    
    static const std::list<std::string> select;
    
    // Query fields
    
    static const field id;
    static const field partOfSpeech;
    static const field wnid;
    static const field numOfImages;
    
    operator filter() const
    {
      return (id == id_);
    }
    
    // Relationships with other objects
    
    static const field words;
    
    // Relationships with self
    
    static const field hypernyms;
    static const field hyponyms;
    
    static const field fullHypernyms;
    static const field fullHyponyms;
    
    static const field instances;
    static const field classes;
    
    static const field memberMeronyms;
    static const field memberHolonyms;
    
    static const field fullMemberMeronyms;
    static const field fullMemberHolonyms;
    
    static const field partMeronyms;
    static const field partHolonyms;
    
    static const field fullPartMeronyms;
    static const field fullPartHolonyms;
    
    static const field substanceMeronyms;
    static const field substanceHolonyms;
    
    static const field fullSubstanceMeronyms;
    static const field fullSubstanceHolonyms;
    
    static const field variants;
    static const field attributes;
    
    static const field similarAdjectives;
    
    static const field entails;
    static const field entailedBy;
    
    static const field causes;
    static const field effects;
    
    // Preposition group relationship
    
    class preposition_group_field {
    public:
      
      filter operator==(std::string groupName) const;
      
    private:
      
      static const field isA;
      static const field groupNameField;
    };
    
    static const preposition_group_field prepositionGroups;
    
  private:
    bool valid_ = false;
    
    int id_;
    part_of_speech partOfSpeech_;
    bool hasWnid_ = false;
    int wnid_;
    bool hasNumOfImages_ = false;
    int numOfImages_;
    
    const database* db_;
    
  };
  
};

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