-
Notifications
You must be signed in to change notification settings - Fork 0
/
gramcodes.cc
184 lines (154 loc) · 3.74 KB
/
gramcodes.cc
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
// Copyright (C) 2011 Petr Machata
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as
// published by the Free Software Foundation, either version 3 of the
// License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful, but
// WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public
// License along with this program. If not, see
// <http://www.gnu.org/licenses/>.
#include <iostream>
#include <iterator>
#include <AgramtabLib/RusGramTab.h>
#include "gramcodes.hh"
#include "part_of_speech.hh"
gramcodes::gramcodes (CAgramtab *agramtab, std::string const &gramcodes)
: _m_agramtab (agramtab)
, _m_gramcodes (gramcodes)
{}
gramcodes::~gramcodes ()
{
}
part_of_speech
gramcodes::get_part_of_speech () const
{
return part_of_speech (_m_agramtab,
_m_agramtab->GetPartOfSpeech (_m_gramcodes.c_str ()));
}
gramcodes::const_iterator
gramcodes::begin () const
{
return const_iterator (*this, 0);
}
gramcodes::const_iterator
gramcodes::end () const
{
return const_iterator (*this, _m_gramcodes.length ());
}
std::vector<grammeme>
gramcodes::grammemes () const
{
std::vector<grammeme> ret;
for (const_iterator it = begin (); it != end (); ++it)
{
std::vector<grammeme> const &sub = it.grammemes ();
std::copy (sub.begin (), sub.end(), std::back_inserter (ret));
}
return ret;
}
grammeme::grammeme (CAgramtab *agramtab, size_t idx)
: _m_agramtab (agramtab)
, _m_idx (idx)
{
}
grammeme::grammeme (grammeme const ©)
: _m_agramtab (copy._m_agramtab)
, _m_idx (copy._m_idx)
{
}
grammeme &
grammeme::operator= (grammeme ©)
{
_m_agramtab = copy._m_agramtab;
_m_idx = copy._m_idx;
return *this;
}
char const *
grammeme::c_str () const
{
return _m_agramtab->GetGrammemStr (_m_idx);
}
size_t
grammeme::value () const
{
return _m_idx;
}
gramcodes::const_iterator::const_iterator (gramcodes const &gc, size_t idx)
: _m_gc (gc)
, _m_idx (idx)
{
}
gramcodes::const_iterator::const_iterator (const_iterator const ©)
: _m_gc (copy._m_gc)
, _m_idx (copy._m_idx)
{}
gramcodes::const_iterator &
gramcodes::const_iterator::operator= (const_iterator ©)
{
_m_idx = copy._m_idx;
return *this;
}
bool
gramcodes::const_iterator::operator== (const_iterator const &other) const
{
return _m_idx == other._m_idx;
}
bool
gramcodes::const_iterator::operator!= (const_iterator const &other) const
{
return !(*this == other);
}
bool
gramcodes::const_iterator::operator< (const_iterator const &other) const
{
return _m_idx < other._m_idx;
}
gramcodes::const_iterator &
gramcodes::const_iterator::operator++ () //prefix
{
_m_idx += 2;
return *this;
}
gramcodes::const_iterator
gramcodes::const_iterator::operator++ (int) //suffix
{
const_iterator copy = *this;
++*this;
return copy;
}
gramcodes::const_iterator &
gramcodes::const_iterator::operator-- () //prefix
{
_m_idx -= 2;
return *this;
}
gramcodes::const_iterator
gramcodes::const_iterator::operator-- (int) //suffix
{
const_iterator copy = *this;
--*this;
return copy;
}
char const *
gramcodes::const_iterator::operator* () const
{
return _m_gc._m_gramcodes.c_str () + _m_idx;
}
#define _QM(X) (((QWORD)1)<<X)
std::vector<grammeme>
gramcodes::const_iterator::grammemes () const
{
std::vector<grammeme> ret;
QWORD g = 0;
_m_gc._m_agramtab->GetGrammems (**this, g);
for (size_t i = 0; i < _m_gc._m_agramtab->GetGrammemsCount (); ++i)
if (_QM(i) & g)
ret.push_back (grammeme (_m_gc._m_agramtab, i));
return ret;
}