Newer
Older
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
#include "mweparser.h"
#include <libpwrutils/foreach.h>
#include <libxml++/libxml++.h>
#include <libxml2/libxml/parser.h>
#include <boost/make_shared.hpp>
#include <fstream>
namespace Corpus2 {
MWEParser::MWEParser()
: BasicSaxParser(), state_(NONE)
{
}
std::string MWEParser::get_tagset_from_attributes(const AttributeList& attributes) const
{
std::string tagset;
foreach (const Attribute& a, attributes) {
if (a.name == "tagset") {
tagset = a.value;
}
}
return tagset;
}
void MWEParser::on_start_element(const Glib::ustring &name,
const AttributeList& attributes)
{
std::cout << state_ << ": " << name << std::endl;
if(state_ == NONE && name == "units_description"){
state_ = UNITSDESC;
tagset_ = get_tagset_from_attributes(attributes);
} else if (state_ == UNITSDESC && name == "macros"){
state_ = MACROS;
}
}
void MWEParser::on_end_element(const Glib::ustring &name)
{
std::cout << "/" << state_ << ": " << name << std::endl;
if(name == "units_description"){
state_ = NONE;
} else if(state_ == MACROS, name == "macros"){
state_ = UNITSDESC;
}
}
} // ns Corpus2