-
Notifications
You must be signed in to change notification settings - Fork 0
/
pos_handler.cc
103 lines (89 loc) · 2.67 KB
/
pos_handler.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
// 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 "default.hh"
#include "noun.hh"
#include "number.hh"
#include "pos_handler.hh"
#include "simple.hh"
#include "verb.hh"
pos_handler::pos_handler (id_allocator &parent, char const *name)
: _m_name (name)
, _m_id (parent.get_id ())
{}
char const *
pos_handler::template_name () const
{
return _m_name;
}
void
pos_handler_map::insert (int pos, pos_handler const *handler)
{
assert (pos >= 0);
size_t idx = (size_t)pos;
if (idx >= size ())
resize (idx + 1, NULL);
(*this)[idx] = handler;
}
pos_handler_map::pos_handler_map (id_allocator &id_a)
: _m_default (new default_handler (id_a))
{
pos_handler const *noun = new noun_handler (id_a);
insert (pos_noun, noun);
insert (pos_pronoun, noun);
pos_handler const *verb = new verb_handler (id_a);
insert (pos_verb, verb);
insert (pos_infinitive, verb);
insert (pos_adj_participle, verb);
insert (pos_adv_participle, verb);
insert (pos_short_participle, verb);
pos_handler const *adj = new adjective_handler (id_a);
insert (pos_adjective, adj);
insert (pos_short_adjective, adj);
insert (pos_pronominal_adjective, adj);
insert (pos_ordinal_number, adj);
pos_handler const *simple = new simple_handler (id_a);
insert (pos_adverb, simple);
insert (pos_interjection, simple);
insert (pos_transition_word, simple);
insert (pos_particle, simple);
insert (pos_conjunction, simple);
pos_handler const *number = new number_handler (id_a);
insert (pos_number, number);
}
pos_handler_map::~pos_handler_map ()
{
// Take care not to delete twice, we share handlers.
std::sort (begin (), end ());
pos_handler const *last = NULL;
for (iterator it = begin (); it != end (); ++it)
{
if (*it != last)
delete *it;
last = *it;
}
delete _m_default;
}
pos_handler const *
pos_handler_map::get_handler (int pos)
{
if (pos < 0 || (size_t)pos >= size ())
return NULL;
if (pos_handler const *ret = operator[] (pos))
return ret;
else
return _m_default;
}