ddc
CommonLib/GramInfo.h
Go to the documentation of this file.
1 // DDC originally by Alexey Sokirko
2 // Changes and modifications 2011-2015 by Bryan Jurish
3 //
4 // This file is part of DDC.
5 //
6 // DDC is free software: you can redistribute it and/or modify
7 // it under the terms of the GNU Lesser General Public License as published by
8 // the Free Software Foundation, either version 3 of the License, or
9 // (at your option) any later version.
10 //
11 // DDC is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU Lesser General Public License for more details.
15 //
16 // You should have received a copy of the GNU Lesser General Public License
17 // along with DDC. If not, see <http://www.gnu.org/licenses/>.
18 //
19 #ifndef GramInfo_h
20 #define GramInfo_h
21 
22 
24 struct CGramInfo
25 {
32 
33  CGramInfo () {
34  m_PartOfSpeechMask = 0;
35  m_Grammems = 0;;
36  m_Language = morphUnknown;
37 
38  };
39  CGramInfo (MorphLanguageEnum Language, DWORD PartOfSpeechMask, QWORD Grammems)
40  {
41  m_PartOfSpeechMask = PartOfSpeechMask;
42  m_Grammems = Grammems;
43  m_Language = Language;
44 
45  };
46 
47 
48  bool EqualOrLess (const CGramInfo& X) const
49  {
50  return
51  (X.m_Language == m_Language )
52  && ( (m_PartOfSpeechMask & X.m_PartOfSpeechMask) > 0)
53  && ( (m_Grammems & X.m_Grammems) == X.m_Grammems)
54  ;
55  };
56 
57  bool operator == (const CGramInfo& X) const
58  {
59  return (m_PartOfSpeechMask == X.m_PartOfSpeechMask)
60  && (X.m_Language == m_Language )
61  && (m_Grammems == X.m_Grammems);
62  };
63 
64  bool operator < (const CGramInfo& X) const
65  {
66  if (m_Language != X.m_Language)
67  return m_Language < X.m_Language;
68 
69  if (m_PartOfSpeechMask != X.m_PartOfSpeechMask)
70  return m_PartOfSpeechMask < X.m_PartOfSpeechMask;
71 
72  return m_Grammems < X.m_Grammems;
73  };
74 
75  void AddGramInfo (const CGramInfo& X)
76  {
77  m_PartOfSpeechMask |= X.m_PartOfSpeechMask;
78  m_Grammems |= X.m_Grammems;
79  };
80 
81 };
82 
83 inline size_t get_size_in_bytes (const CGramInfo& i)
84 {
85  return 1/*get_size_in_bytes(i.m_Language)*/
88 
89 };
90 
91 inline size_t save_to_bytes(const CGramInfo& i, BYTE* buf)
92 {
93  BYTE t = i.m_Language;
94  buf += save_to_bytes(t, buf);
95  buf += save_to_bytes(i.m_PartOfSpeechMask, buf);
96  buf += save_to_bytes(i.m_Grammems, buf);
97  return get_size_in_bytes(i);
98 }
99 
100 inline size_t restore_from_bytes(CGramInfo& i, const BYTE* buf)
101 {
102  BYTE t;
103  buf += restore_from_bytes(t, buf);
105  buf += restore_from_bytes(i.m_PartOfSpeechMask, buf);
106  buf += restore_from_bytes(i.m_Grammems, buf);
107  return get_size_in_bytes(i);
108 }
109 
110 
112 {
116  {
117  return m_UnitOffset< X.m_UnitOffset;
118  };
119 };
120 
122 {
124 
125 };
126 
127 inline size_t save_to_bytes(const CGramInfoAndGraphemUnitOffset& i, BYTE* buf)
128 {
129  buf += save_to_bytes(i.m_GramInfo, buf);
130  buf += save_to_bytes(i.m_UnitOffset, buf);
131  return get_size_in_bytes(i);
132 }
133 
135 {
136  buf += restore_from_bytes(i.m_GramInfo, buf);
137  buf += restore_from_bytes(i.m_UnitOffset, buf);
138  return get_size_in_bytes(i);
139 }
140 
141 #endif
142 
143 /*--- emacs style variables ---
144  * Local Variables:
145  * mode: C++
146  * c-file-style: "ellemtel"
147  * c-basic-offset: 4
148  * tab-width: 8
149  * indent-tabs-mode: nil
150  * End:
151  */
const char Grammems[GrammemsCount][10]
Definition: RusGramTab.h:60
bool operator==(const CGramInfo &X) const
Definition: CommonLib/GramInfo.h:57
int m_UnitOffset
Definition: CommonLib/GramInfo.h:114
Definition: CommonLib/GramInfo.h:111
CGramInfo m_GramInfo
Definition: CommonLib/GramInfo.h:113
uint64_t QWORD
Definition: utilit.h:107
size_t get_size_in_bytes(const CGramInfo &i)
Definition: CommonLib/GramInfo.h:83
MorphLanguageEnum m_Language
the language of the pattern
Definition: CommonLib/GramInfo.h:27
DWORD m_PartOfSpeechMask
the part of speech mask (SUB, ART,ADJ...)
Definition: CommonLib/GramInfo.h:29
bool operator<(const CGramInfo &X) const
Definition: CommonLib/GramInfo.h:64
QWORD m_Grammems
morphological features (plu, sig, nom...)
Definition: CommonLib/GramInfo.h:31
void AddGramInfo(const CGramInfo &X)
Definition: CommonLib/GramInfo.h:75
size_t restore_from_bytes(CGramInfo &i, const BYTE *buf)
Definition: CommonLib/GramInfo.h:100
CGramInfo(MorphLanguageEnum Language, DWORD PartOfSpeechMask, QWORD Grammems)
Definition: CommonLib/GramInfo.h:39
CGramInfo represents one morphological pattern, for example "[SUB pl, sg]".
Definition: CommonLib/GramInfo.h:24
size_t save_to_bytes(const CGramInfo &i, BYTE *buf)
Definition: CommonLib/GramInfo.h:91
unsigned char BYTE
Definition: utilit.h:94
MorphLanguageEnum
Definition: utilit.h:162
uint32_t DWORD
Definition: utilit.h:105
CGramInfo()
Definition: CommonLib/GramInfo.h:33
Definition: utilit.h:163
bool EqualOrLess(const CGramInfo &X) const
Definition: CommonLib/GramInfo.h:48