diff options
Diffstat (limited to 'lib/word.cpp')
-rw-r--r-- | lib/word.cpp | 56 |
1 files changed, 28 insertions, 28 deletions
diff --git a/lib/word.cpp b/lib/word.cpp index d13d0bc..a928659 100644 --- a/lib/word.cpp +++ b/lib/word.cpp | |||
@@ -6,118 +6,118 @@ | |||
6 | #include "query.h" | 6 | #include "query.h" |
7 | 7 | ||
8 | namespace verbly { | 8 | namespace verbly { |
9 | 9 | ||
10 | const object word::objectType = object::word; | 10 | const object word::objectType = object::word; |
11 | 11 | ||
12 | const std::list<std::string> word::select = {"word_id", "notion_id", "lemma_id", "tag_count", "position", "group_id"}; | 12 | const std::list<std::string> word::select = {"word_id", "notion_id", "lemma_id", "tag_count", "position", "group_id"}; |
13 | 13 | ||
14 | const field word::id = field::integerField(object::word, "word_id"); | 14 | const field word::id = field::integerField(object::word, "word_id"); |
15 | const field word::tagCount = field::integerField(object::word, "tag_count", true); | 15 | const field word::tagCount = field::integerField(object::word, "tag_count", true); |
16 | const field word::adjectivePosition = field::integerField(object::word, "position", true); | 16 | const field word::adjectivePosition = field::integerField(object::word, "position", true); |
17 | 17 | ||
18 | const field word::notion = field::joinField(object::word, "notion_id", object::notion); | 18 | const field word::notion = field::joinField(object::word, "notion_id", object::notion); |
19 | const field word::lemma = field::joinField(object::word, "lemma_id", object::lemma); | 19 | const field word::lemma = field::joinField(object::word, "lemma_id", object::lemma); |
20 | const field word::group = field::joinField(object::word, "group_id", object::group, true); | 20 | const field word::group = field::joinField(object::word, "group_id", object::group, true); |
21 | 21 | ||
22 | const field word::antonyms = field::selfJoin(object::word, "word_id", "antonymy", "antonym_2_id", "antonym_1_id"); | 22 | const field word::antonyms = field::selfJoin(object::word, "word_id", "antonymy", "antonym_2_id", "antonym_1_id"); |
23 | 23 | ||
24 | const field word::specifications = field::selfJoin(object::word, "word_id", "specification", "general_id", "specific_id"); | 24 | const field word::specifications = field::selfJoin(object::word, "word_id", "specification", "general_id", "specific_id"); |
25 | const field word::generalizations = field::selfJoin(object::word, "word_id", "specification", "specific_id", "general_id"); | 25 | const field word::generalizations = field::selfJoin(object::word, "word_id", "specification", "specific_id", "general_id"); |
26 | 26 | ||
27 | const field word::pertainyms = field::selfJoin(object::word, "word_id", "pertainymy", "noun_id", "pertainym_id"); | 27 | const field word::pertainyms = field::selfJoin(object::word, "word_id", "pertainymy", "noun_id", "pertainym_id"); |
28 | const field word::antiPertainyms = field::selfJoin(object::word, "word_id", "pertainymy", "pertainym_id", "noun_id"); | 28 | const field word::antiPertainyms = field::selfJoin(object::word, "word_id", "pertainymy", "pertainym_id", "noun_id"); |
29 | 29 | ||
30 | const field word::mannernyms = field::selfJoin(object::word, "word_id", "mannernymy", "adjective_id", "mannernym_id"); | 30 | const field word::mannernyms = field::selfJoin(object::word, "word_id", "mannernymy", "adjective_id", "mannernym_id"); |
31 | const field word::antiMannernyms = field::selfJoin(object::word, "word_id", "mannernymy", "mannernym_id", "adjective_id"); | 31 | const field word::antiMannernyms = field::selfJoin(object::word, "word_id", "mannernymy", "mannernym_id", "adjective_id"); |
32 | 32 | ||
33 | const field word::usageTerms = field::selfJoin(object::word, "word_id", "usage", "domain_id", "term_id"); | 33 | const field word::usageTerms = field::selfJoin(object::word, "word_id", "usage", "domain_id", "term_id"); |
34 | const field word::usageDomains = field::selfJoin(object::word, "word_id", "usage", "term_id", "domain_id"); | 34 | const field word::usageDomains = field::selfJoin(object::word, "word_id", "usage", "term_id", "domain_id"); |
35 | 35 | ||
36 | const field word::topicalTerms = field::selfJoin(object::word, "word_id", "topicality", "domain_id", "term_id"); | 36 | const field word::topicalTerms = field::selfJoin(object::word, "word_id", "topicality", "domain_id", "term_id"); |
37 | const field word::topicalDomains = field::selfJoin(object::word, "word_id", "topicality", "term_id", "domain_id"); | 37 | const field word::topicalDomains = field::selfJoin(object::word, "word_id", "topicality", "term_id", "domain_id"); |
38 | 38 | ||
39 | const field word::regionalTerms = field::selfJoin(object::word, "word_id", "regionality", "domain_id", "term_id"); | 39 | const field word::regionalTerms = field::selfJoin(object::word, "word_id", "regionality", "domain_id", "term_id"); |
40 | const field word::regionalDomains = field::selfJoin(object::word, "word_id", "regionality", "term_id", "domain_id"); | 40 | const field word::regionalDomains = field::selfJoin(object::word, "word_id", "regionality", "term_id", "domain_id"); |
41 | 41 | ||
42 | word::word(const database& db, sqlite3_stmt* row) : db_(&db), valid_(true) | 42 | word::word(const database& db, sqlite3_stmt* row) : db_(&db), valid_(true) |
43 | { | 43 | { |
44 | id_ = sqlite3_column_int(row, 0); | 44 | id_ = sqlite3_column_int(row, 0); |
45 | notionId_ = sqlite3_column_int(row, 1); | 45 | notionId_ = sqlite3_column_int(row, 1); |
46 | lemmaId_ = sqlite3_column_int(row, 2); | 46 | lemmaId_ = sqlite3_column_int(row, 2); |
47 | 47 | ||
48 | if (sqlite3_column_type(row, 3) != SQLITE_NULL) | 48 | if (sqlite3_column_type(row, 3) != SQLITE_NULL) |
49 | { | 49 | { |
50 | hasTagCount_ = true; | 50 | hasTagCount_ = true; |
51 | tagCount_ = sqlite3_column_int(row, 3); | 51 | tagCount_ = sqlite3_column_int(row, 3); |
52 | } | 52 | } |
53 | 53 | ||
54 | if (sqlite3_column_type(row, 4) != SQLITE_NULL) | 54 | if (sqlite3_column_type(row, 4) != SQLITE_NULL) |
55 | { | 55 | { |
56 | adjectivePosition_ = static_cast<positioning>(sqlite3_column_int(row, 4)); | 56 | adjectivePosition_ = static_cast<positioning>(sqlite3_column_int(row, 4)); |
57 | } | 57 | } |
58 | 58 | ||
59 | if (sqlite3_column_type(row, 5) != SQLITE_NULL) | 59 | if (sqlite3_column_type(row, 5) != SQLITE_NULL) |
60 | { | 60 | { |
61 | hasGroup_ = true; | 61 | hasGroup_ = true; |
62 | groupId_ = sqlite3_column_int(row, 5); | 62 | groupId_ = sqlite3_column_int(row, 5); |
63 | } | 63 | } |
64 | } | 64 | } |
65 | 65 | ||
66 | const notion& word::getNotion() const | 66 | const notion& word::getNotion() const |
67 | { | 67 | { |
68 | if (!valid_) | 68 | if (!valid_) |
69 | { | 69 | { |
70 | throw std::domain_error("Bad access to uninitialized word"); | 70 | throw std::domain_error("Bad access to uninitialized word"); |
71 | } | 71 | } |
72 | 72 | ||
73 | if (!notion_) | 73 | if (!notion_) |
74 | { | 74 | { |
75 | notion_ = db_->notions(notion::id == notionId_).first(); | 75 | notion_ = db_->notions(notion::id == notionId_).first(); |
76 | } | 76 | } |
77 | 77 | ||
78 | return notion_; | 78 | return notion_; |
79 | } | 79 | } |
80 | 80 | ||
81 | const lemma& word::getLemma() const | 81 | const lemma& word::getLemma() const |
82 | { | 82 | { |
83 | if (!valid_) | 83 | if (!valid_) |
84 | { | 84 | { |
85 | throw std::domain_error("Bad access to uninitialized word"); | 85 | throw std::domain_error("Bad access to uninitialized word"); |
86 | } | 86 | } |
87 | 87 | ||
88 | if (!lemma_) | 88 | if (!lemma_) |
89 | { | 89 | { |
90 | lemma_ = db_->lemmas(lemma::id == lemmaId_).first(); | 90 | lemma_ = db_->lemmas(lemma::id == lemmaId_).first(); |
91 | } | 91 | } |
92 | 92 | ||
93 | return lemma_; | 93 | return lemma_; |
94 | } | 94 | } |
95 | 95 | ||
96 | const group& word::getGroup() const | 96 | const group& word::getGroup() const |
97 | { | 97 | { |
98 | if (!valid_) | 98 | if (!valid_) |
99 | { | 99 | { |
100 | throw std::domain_error("Bad access to uninitialized word"); | 100 | throw std::domain_error("Bad access to uninitialized word"); |
101 | } | 101 | } |
102 | 102 | ||
103 | if (!hasGroup_) | 103 | if (!hasGroup_) |
104 | { | 104 | { |
105 | throw std::domain_error("Word does not have a group"); | 105 | throw std::domain_error("Word does not have a group"); |
106 | } | 106 | } |
107 | 107 | ||
108 | if (!group_) | 108 | if (!group_) |
109 | { | 109 | { |
110 | group_ = db_->groups(group::id == groupId_).first(); | 110 | group_ = db_->groups(group::id == groupId_).first(); |
111 | } | 111 | } |
112 | 112 | ||
113 | return group_; | 113 | return group_; |
114 | } | 114 | } |
115 | 115 | ||
116 | std::string word::getBaseForm() const | 116 | std::string word::getBaseForm() const |
117 | { | 117 | { |
118 | return getLemma().getBaseForm().getText(); | 118 | return getLemma().getBaseForm().getText(); |
119 | } | 119 | } |
120 | 120 | ||
121 | std::vector<std::string> word::getInflections(inflection category) const | 121 | std::vector<std::string> word::getInflections(inflection category) const |
122 | { | 122 | { |
123 | std::vector<std::string> result; | 123 | std::vector<std::string> result; |
@@ -128,5 +128,5 @@ namespace verbly { | |||
128 | 128 | ||
129 | return result; | 129 | return result; |
130 | } | 130 | } |
131 | 131 | ||
132 | }; | 132 | }; |