-
Notifications
You must be signed in to change notification settings - Fork 0
/
adjective.cc
146 lines (128 loc) · 4.17 KB
/
adjective.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
// 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 "adjective.hh"
#include "forms.hh"
#include "format.hh"
#include <sstream>
adjective_handler::adjective_handler (id_allocator &parent)
: pos_handler (parent, "adjective")
{}
std::string
adjective_handler::format_form_key (gram_code_t degree, gram_code_t gcase,
gram_code_t number, gram_code_t gender,
bool animate, bool inanimate,
bool secondary)
{
/*
std::cerr << (boost::format ("degree=%s, case=%s, number=%s, gender=%s, "
"animate=%d, inanimate=%d, secondary=%d\n")
% (degree != gm__invalid ? format_rus (degree) : "?")
% (gcase != gm__invalid ? format_rus (gcase) : "?")
% (number != gm__invalid ? format_rus (number) : "?")
% (gender != gm__invalid ? format_rus (gender) : "?")
% animate % inanimate % secondary);
*/
if (degree == gm__invalid)
degree = gm_positive;
bool is_short = gcase == gm__invalid && degree == gm_positive;
std::ostringstream os;
os << format_rus (degree);
if (degree == gm_comparative)
{
if (secondary)
os << '.' << format_rus (gm_secondary);
else
os << ".primary";
}
if (is_short)
os << ".short";
if (gcase == gm_vocative)
{
// Indeclinable adjectives are marked with vocative case.
// Pronominal adjectives have neuter gender, adjectives
// undefined gender.
assert (gender == gm__invalid || gender == gm_neuter);
assert (number == gm_singular);
os << ".indeclinable";
}
else
{
if (number != gm__invalid)
{
if (gender != gm__invalid)
{
assert (number == gm_singular);
os << '.' << format_rus (gender);
}
else
{
assert (number == gm_plural);
os << '.' << format_rus (number);
}
}
if (gcase != gm__invalid)
os << '.' << format_rus (gcase);
}
if ((animate || inanimate) && !(animate && inanimate))
os << '.' << format_rus (animate ? gm_animate : gm_inanimate);
return os.str ();
}
void
adjective_handler::fill_hdf (CAgramtab *agramtab,
lemmatize::const_iterator const &it,
hdf_data_map &data) const
{
lemmatize::forms forms = it.forms ();
for (lemmatize::forms::const_iterator ft = forms.begin ();
ft != forms.end (); ++ft)
{
gramcodes ac = ft.ancode ();
gram_code_t gnumber = gm__invalid;
gram_code_t gcase = gm__invalid;
gram_code_t gender = gm__invalid;
bool animate = false;
bool inanimate = false;
gram_code_t degree = gm__invalid;
bool secondary = false;
std::vector<grammeme> grammemes = ac.grammemes ();
for (std::vector<grammeme>::const_iterator gt = grammemes.begin ();
gt != grammemes.end (); ++gt)
{
gram_code_t code = gt->value_as<gram_code_t> ();
if (!extract_rus_number (gnumber, code)
&& !extract_rus_case (gcase, code)
&& !extract_rus_gender (gender, code)
&& !extract_rus_adj_degree (degree, code))
{
if (code == gm_animate)
animate = true;
else if (code == gm_inanimate)
inanimate = true;
else if (code == gm_secondary)
secondary = true;
}
}
if (gnumber == gm__invalid && degree == gm__invalid)
throw std::runtime_error
("If number is undefined, then degree must be defined.");
if (degree == gm__invalid && secondary)
throw std::runtime_error
("Don't know what 'secondary' means without degree.");
std::string key = format_form_key (degree, gcase, gnumber, gender,
animate, inanimate, secondary);
data[key].push_back (std::make_pair (*ft, ft.accent ()));
}
}