dispatchanalyser.h
2.53 KB
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
/*
Copyright (C) 2010 Tomasz Śniatowski, Adam Radziszewski
Part of the libmaca project
This program is free software; you can redistribute it and/or modify it
under the terms of the GNU Lesser 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 LICENSE.MACA, LICENSE.SFST, LICENSE.GUESSER, COPYING.LESSER and COPYING files for more details.
*/
#ifndef LIBMACA_DISPATCHANALYSER_H
#define LIBMACA_DISPATCHANALYSER_H
#include <libmaca/morph/morphanalyser.h>
#include <map>
#include <set>
namespace Maca {
/**
* An analyser that delegates analysis to other analysers based on the
* Toki token type.
*/
class DispatchAnalyser : public MorphAnalyser
{
public:
/// Constructor for a DispatchAnalyser working with a tagset
DispatchAnalyser(const Corpus2::Tagset* tagset);
/// Constructor for a DispatchAnalyser from config
DispatchAnalyser(const Config::Node& cfg);
/**
* Convenience creation function from a config name
*/
static boost::shared_ptr<DispatchAnalyser> create_from_named_config(
const std::string& config_name);
/// Destructor
~DispatchAnalyser();
/// Cloning
DispatchAnalyser* clone() const;
/// MorphAnalyser override
bool process_functional(const Toki::Token &t,
boost::function<void (Corpus2::Token*)> sink);
/**
* Handler adding function. The passed analyser should have the same
* output tagset as the DispatchAnalyser's tagset. The DispatchAnalyser
* takes ownership of the passed analyser.
*/
void add_type_handler(const std::string& type, MorphAnalyser* a);
/// adder for the default analyser list, used when no analyser matches
/// the Toki token type
void add_default_handler(MorphAnalyser* a);
/// getter for the default handlers size
size_t default_handlers_count() const;
/// getter for the number of handlers
size_t handler_count() const;
private:
typedef std::vector<MorphAnalyser*> analyser_vector_t;
typedef std::map<std::string, analyser_vector_t > analyser_map_t;
/// the toki type -> analyser map
analyser_map_t type_handlers_;
/// the set of analysers this DispatchAnalyser owns
std::set<MorphAnalyser*> analysers_;
/// the default analysers
analyser_vector_t default_;
/// the fallback analyser
MorphAnalyser* fallback_;
};
} /* end ns Maca */
#endif // LIBMACA_DISPATCHANALYSER_H