Newer
Older
#ifndef LIBWCCL_WCCLFILE_H
#define LIBWCCL_WCCLFILE_H
#include <libwccl/values/bool.h>
#include <libwccl/values/match.h>
#include <libwccl/values/position.h>
#include <libwccl/values/strset.h>
#include <libwccl/values/tset.h>
#include <libwccl/wcclfileopsections.h>
#include <libwccl/ops/tagrulesequence.h>
namespace Wccl {
class WcclFile
: WcclFileOpSections<UntypedOpSequence>,
WcclFileOpSections<OpSequence<StrSet> >,
WcclFileOpSections<OpSequence<TSet> >,
WcclFileOpSections<OpSequence<Bool> >,
WcclFileOpSections<OpSequence<Position> >,
WcclFileOpSections<OpSequence<Match> >
{
public:
explicit WcclFile(const Corpus2::Tagset& tagset);
const std::vector<boost::shared_ptr<UntypedOpSequence> >& untyped_sections();
template<class T>
const typename std::vector<boost::shared_ptr<OpSequence<T> > >& sections();
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
bool has_untyped_section(const std::string& name) const;
template<class T>
bool has_section(const std::string& name) const;
std::vector<std::string> untyped_section_names() const;
template<class T>
std::vector<std::string> section_names() const;
UntypedOpSequence& get_untyped_section(const std::string& name);
const UntypedOpSequence& get_untyped_section(const std::string& name) const;
template<class T>
OpSequence<T>& get_section(const std::string& name);
template<class T>
const OpSequence<T>& get_section(const std::string& name) const;
boost::shared_ptr<UntypedOpSequence> get_untyped_section_ptr(const std::string& name);
boost::shared_ptr<const UntypedOpSequence> get_untyped_section_ptr(const std::string& name) const;
template<class T>
boost::shared_ptr<OpSequence<T> > get_section_ptr(const std::string& name);
template<class T>
boost::shared_ptr<const OpSequence<T> > get_section_ptr(const std::string& name) const;
FunctionalOperator& get_untyped_op(const std::string& name, size_t idx = 0);
const FunctionalOperator& get_untyped_op(const std::string& name, size_t idx = 0) const;
template<class T>
Operator<T>& get_op(const std::string& name, size_t idx = 0);
template<class T>
const Operator<T>& get_op(const std::string& name, size_t idx = 0) const;
boost::shared_ptr<FunctionalOperator> get_untyped_op_ptr(const std::string& name, size_t idx = 0);
boost::shared_ptr<const FunctionalOperator> get_untyped_op_ptr(const std::string& name, size_t idx = 0) const;
template<class T>
boost::shared_ptr<Operator<T> > get_op_ptr(const std::string& name, size_t idx = 0);
template<class T>
boost::shared_ptr<const Operator<T> > get_op_ptr(const std::string& name, size_t idx = 0) const;
UntypedOpSequence::name_op_v_t gen_name_untyped_op_pairs();
UntypedOpSequence::name_op_v_c_t gen_name_untyped_op_pairs() const;
template<class T>
typename OpSequence<T>::name_op_v_t gen_name_op_pairs();
template<class T>
typename OpSequence<T>::name_op_v_c_t gen_name_op_pairs() const;
FunctionalOpSequence::name_op_v_t gen_all_op_pairs();
FunctionalOpSequence::name_op_v_c_t gen_all_op_pairs() const;
void import_lexicon(const boost::shared_ptr<Lexicon>& lexicon);
bool has_lexicon(const std::string& name) const;
boost::shared_ptr<const Lexicon> get_lexicon_ptr(const std::string& name) const;
const Lexicon& get_lexicon(const std::string& name) const;
boost::shared_ptr<const Lexicons> get_lexicons_ptr() const;
const Lexicons& get_lexicons() const;
void add_untyped_section(const boost::shared_ptr<UntypedOpSequence>& section);
void add_untyped_section(const boost::shared_ptr<const UntypedOpSequence>& section);
void add_untyped_section(const UntypedOpSequence& section);
template<class T>
void add_section(const boost::shared_ptr<OpSequence<T> >& section);
template<class T>
void add_section(const boost::shared_ptr<const OpSequence<T> >& section);
template<class T>
void add_section(const OpSequence<T>& section);
bool has_tag_rules() const;
void set_tag_rules(const boost::shared_ptr<TagRuleSequence>& tag_rules);
const TagRuleSequence& get_tag_rules() const;
boost::shared_ptr<TagRuleSequence> get_tag_rules_ptr();
boost::shared_ptr<const TagRuleSequence> get_tag_rules_ptr() const;
friend std::ostream& operator<<(std::ostream& ostream, const WcclFile& wccl_file);
std::string to_string() const;
const Corpus2::Tagset& tagset() const;
private:
std::ostream& write_to(std::ostream& ostream) const;
std::vector<boost::shared_ptr<FunctionalOpSequence> > all_sections_;
boost::shared_ptr<TagRuleSequence> tag_rules_;
const Corpus2::Tagset& tagset_;
};
} /* end ns Wccl */
//
// Implementation
//
namespace Wccl {
inline
WcclFile::WcclFile(const Corpus2::Tagset& tagset)
: tagset_(tagset)
{
}
inline
const std::vector<boost::shared_ptr<UntypedOpSequence> >& WcclFile::untyped_sections()
{
return WcclFileOpSections<UntypedOpSequence>::sections();
}
template<class T> inline
const typename std::vector<boost::shared_ptr<OpSequence<T> > >& WcclFile::sections()
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
{
return WcclFileOpSections<OpSequence<T> >::sections();
}
inline
bool WcclFile::has_untyped_section(const std::string& name) const
{
return WcclFileOpSections<UntypedOpSequence>::has_section(name);
}
template<class T> inline
bool WcclFile::has_section(const std::string &name) const
{
return WcclFileOpSections<OpSequence<T> >::has_section(name);
}
inline
std::vector<std::string> WcclFile::untyped_section_names() const
{
return WcclFileOpSections<UntypedOpSequence>::section_names();
}
template<class T> inline
std::vector<std::string> WcclFile::section_names() const
{
return WcclFileOpSections<OpSequence<T> >::section_names();
}
inline
UntypedOpSequence& WcclFile::get_untyped_section(const std::string& name)
{
return WcclFileOpSections<UntypedOpSequence>::get_section(name);
}
inline
const UntypedOpSequence& WcclFile::get_untyped_section(const std::string& name) const
{
return WcclFileOpSections<UntypedOpSequence>::get_section(name);
}
template<class T> inline
OpSequence<T>& WcclFile::get_section(const std::string& name)
{
return WcclFileOpSections<OpSequence<T> >::get_section(name);
}
template<class T> inline
const OpSequence<T>& WcclFile::get_section(const std::string& name) const
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
{
return WcclFileOpSections<OpSequence<T> >::get_section(name);
}
inline
boost::shared_ptr<UntypedOpSequence> WcclFile::get_untyped_section_ptr(const std::string& name)
{
return WcclFileOpSections<UntypedOpSequence>::get_section_ptr(name);
}
inline
boost::shared_ptr<const UntypedOpSequence> WcclFile::get_untyped_section_ptr(const std::string& name) const
{
return WcclFileOpSections<UntypedOpSequence>::get_section_ptr(name);
}
template<class T> inline
typename boost::shared_ptr<OpSequence<T> > WcclFile::get_section_ptr(const std::string& name)
{
return WcclFileOpSections<OpSequence<T> >::get_section_ptr(name);
}
template<class T> inline
typename boost::shared_ptr<const OpSequence<T> > WcclFile::get_section_ptr(const std::string& name) const
{
return WcclFileOpSections<OpSequence<T> >::get_section_ptr(name);
}
inline
FunctionalOperator& WcclFile::get_untyped_op(const std::string &name, size_t idx)
{
return WcclFileOpSections<UntypedOpSequence>::get_op(name, idx);
}
inline
const FunctionalOperator& WcclFile::get_untyped_op(const std::string& name, size_t idx) const
{
return WcclFileOpSections<UntypedOpSequence>::get_op(name, idx);
}
template<class T> inline
Operator<T>& WcclFile::get_op(const std::string& name, size_t idx)
{
return WcclFileOpSections<Operator<T> >::get_op(name, idx);
}
template<class T> inline
const Operator<T>& WcclFile::get_op(const std::string& name, size_t idx) const
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
{
return WcclFileOpSections<Operator<T> >::get_op(name, idx);
}
inline
boost::shared_ptr<FunctionalOperator> WcclFile::get_untyped_op_ptr(
const std::string& name,
size_t idx)
{
return WcclFileOpSections<UntypedOpSequence>::get_op_ptr(name, idx);
}
inline
boost::shared_ptr<const FunctionalOperator> WcclFile::get_untyped_op_ptr(
const std::string& name,
size_t idx) const
{
return WcclFileOpSections<UntypedOpSequence>::get_op_ptr(name, idx);
}
template<class T> inline
boost::shared_ptr<Operator<T> > WcclFile::get_op_ptr(
const std::string& name,
size_t idx)
{
return WcclFileOpSections<OpSequence<T> >::get_op_ptr(name, idx);
}
template<class T> inline
boost::shared_ptr<const Operator<T> > WcclFile::get_op_ptr(
const std::string& name,
size_t idx) const
{
return WcclFileOpSections<OpSequence<T> >::get_op_ptr(name, idx);
}
inline
UntypedOpSequence::name_op_v_t WcclFile::gen_name_untyped_op_pairs()
{
return WcclFileOpSections<UntypedOpSequence>::gen_name_op_pairs();
}
inline
UntypedOpSequence::name_op_v_c_t WcclFile::gen_name_untyped_op_pairs() const
{
return WcclFileOpSections<UntypedOpSequence>::gen_name_op_pairs();
}
template<class T> inline
typename OpSequence<T>::name_op_v_t WcclFile::gen_name_op_pairs()
{
return WcclFileOpSections<OpSequence<T> >::gen_name_op_pairs();
}
template<class T> inline
typename OpSequence<T>::name_op_v_c_t WcclFile::gen_name_op_pairs() const
{
return WcclFileOpSections<OpSequence<T> >::gen_name_op_pairs();
}
inline
void WcclFile::import_lexicon(const boost::shared_ptr<Lexicon>& lexicon)
{
lexicons_->insert(lexicon);
}
inline
bool WcclFile::has_lexicon(const std::string& name) const
{
return lexicons_->has_lexicon(name);
}
inline
boost::shared_ptr<const Lexicon> WcclFile::get_lexicon_ptr(const std::string& name) const
{
return lexicons_->get_ptr(name);
}
inline
const Lexicon& WcclFile::get_lexicon(const std::string &name) const
{
return lexicons_->get(name);
}
inline
boost::shared_ptr<const Lexicons> WcclFile::get_lexicons_ptr() const
{
return lexicons_;
}
inline
const Lexicons& WcclFile::get_lexicons() const
{
return *lexicons_;
}
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
inline
void WcclFile::add_untyped_section(const boost::shared_ptr<UntypedOpSequence>& section)
{
WcclFileOpSections<UntypedOpSequence>::append(section);
all_sections_.push_back(section);
}
inline
void WcclFile::add_untyped_section(const boost::shared_ptr<const UntypedOpSequence>& section)
{
boost::shared_ptr<UntypedOpSequence> s = section->clone();
add_untyped_section(s);
}
inline
void WcclFile::add_untyped_section(const UntypedOpSequence& section)
{
boost::shared_ptr<UntypedOpSequence> s = section.clone();
add_untyped_section(s);
}
template<class T> inline
void WcclFile::add_section(const boost::shared_ptr<OpSequence<T> >& section)
{
WcclFileOpSections<OpSequence<T> >::append(section);
all_sections_.push_back(section);
}
template<class T> inline
void WcclFile::add_section(const boost::shared_ptr<const OpSequence<T> >& section)
{
boost::shared_ptr<OpSequence<T> > s = section->clone();
add_section(s);
}
template<class T> inline
void WcclFile::add_section(const OpSequence<T>& section)
{
boost::shared_ptr<OpSequence<T> > s = section.clone();
add_section(s);
}
inline
bool WcclFile::has_tag_rules() const
{
return tag_rules_;
}
inline
const TagRuleSequence& WcclFile::get_tag_rules() const
{
return *get_tag_rules_ptr();
}
inline
void WcclFile::set_tag_rules(const boost::shared_ptr<TagRuleSequence>& tag_rules)
{
if (has_tag_rules()) {
throw WcclError("Tag rules already added.");
}
tag_rules_ = tag_rules;
}
inline
std::ostream& operator <<(std::ostream& ostream, const WcclFile& wccl_file) {
return wccl_file.write_to(ostream);
}
inline
const Corpus2::Tagset& WcclFile::tagset() const {
return tagset_;
}
} /* end ns Wccl */
#endif // LIBWCCL_WCCLFILE_H