Skip to content
Snippets Groups Projects
mweparser.cpp 1.11 KiB
Newer Older
Bartosz Broda's avatar
Bartosz Broda committed
#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