From cee3b953c92809f06897d6d41e192163b91efef2 Mon Sep 17 00:00:00 2001 From: Bartosz Broda <bartosz.broda@gmail.com> Date: Mon, 13 Jun 2011 22:29:55 +0200 Subject: [PATCH] add preliminary impl. of IsHere for fixed LU --- libmwereader/mwe.cpp | 51 +++++++++++++++++++++++++++++++------- libmwereader/mwe.h | 14 +++++++++++ libmwereader/mweparser.cpp | 8 +++--- 3 files changed, 59 insertions(+), 14 deletions(-) diff --git a/libmwereader/mwe.cpp b/libmwereader/mwe.cpp index 046b644..e76aaf4 100644 --- a/libmwereader/mwe.cpp +++ b/libmwereader/mwe.cpp @@ -1,15 +1,48 @@ #include "mwe.h" +#include <boost/algorithm/string.hpp> namespace Corpus2{ - LexicalUnit::LexicalUnit(const std::string &base, - boost::shared_ptr<Wccl::Operator<Wccl::Bool> > condition, - boost::shared_ptr<Wccl::Operator<Wccl::Bool> > head_cond, - std::map<std::string, std::string> variables) - : condition_(condition), - head_cond_(head_cond), - variables_(variables), - base_(base) - { +LexicalUnit::LexicalUnit(const std::string &base, + boost::shared_ptr<Wccl::Operator<Wccl::Bool> > condition, + boost::shared_ptr<Wccl::Operator<Wccl::Bool> > head_cond, + std::map<std::string, std::string> variables) + : condition_(condition), + head_cond_(head_cond), + variables_(variables), + base_(base), + nowhere_(Wccl::Position()) +{ + // noop +} + +FixedLU::FixedLU(const std::string &base, + boost::shared_ptr<Wccl::Operator<Wccl::Bool> > condition, + boost::shared_ptr<Wccl::Operator<Wccl::Bool> > head_cond, + std::map<std::string, std::string> variables) + : LexicalUnit(base, condition, head_cond, variables) +{ +} + +bool FixedLU::IsHere(const Wccl::SentenceContext &sc, + std::set<size_t> &out_position) +{ + boost::shared_ptr<const Wccl::Bool> pResult = condition_->apply(sc); + if(pResult->get_value() == false) + return false; + + foreach(const std::string&varname, condition_->valid_variable_names()){ + if(boost::algorithm::starts_with(varname, "Pos")){ + Wccl::Position pos = condition_->get<Wccl::Position>(varname); + if(pos.equals(nowhere_)){ + std::string errmsg("Position for found MWE cannot be zero."); + errmsg += " Offending unit: " + base_; + throw Wccl::WcclError(errmsg); + } + out_position.insert( sc.get_abs_position(pos) ); + } } + return true; +} + }//ns Corpus2 diff --git a/libmwereader/mwe.h b/libmwereader/mwe.h index 7508b6b..f62f78f 100644 --- a/libmwereader/mwe.h +++ b/libmwereader/mwe.h @@ -16,15 +16,29 @@ public: boost::shared_ptr<Wccl::Operator<Wccl::Bool> > head_cond, std::map<std::string, std::string> variables ); + + virtual bool IsHere(const Wccl::SentenceContext& sc, + std::set<size_t> &out_position) = 0; + protected: boost::shared_ptr<Wccl::Operator<Wccl::Bool> > condition_; boost::shared_ptr<Wccl::Operator<Wccl::Bool> > head_cond_; std::map<std::string, std::string> variables_; std::string base_; + + const Wccl::Position nowhere_; }; class FixedLU : public LexicalUnit { +public: + FixedLU(const std::string &base, + boost::shared_ptr<Wccl::Operator<Wccl::Bool> > condition, + boost::shared_ptr<Wccl::Operator<Wccl::Bool> > head_cond, + std::map<std::string, std::string> variables + ); + virtual bool IsHere(const Wccl::SentenceContext& sc, + std::set<size_t> &out_position); }; diff --git a/libmwereader/mweparser.cpp b/libmwereader/mweparser.cpp index e0f1c5f..5f4e88d 100644 --- a/libmwereader/mweparser.cpp +++ b/libmwereader/mweparser.cpp @@ -60,11 +60,9 @@ namespace Corpus2 { MWEBuilder::BoolOpPtr head = mwe_builder_->get_head_condition( head_cond_); - //const Corpus2::Tagset& tagset = Corpus2::get_named_tagset(tagset_); - - foreach(const std::string&varname, main->valid_variable_names()) - if(boost::algorithm::starts_with(varname, "Pos")) - std::cout << "Pozycja: " << varname << std::endl; + //foreach(const std::string&varname, main->valid_variable_names()) + //if(boost::algorithm::starts_with(varname, "Pos")) + //std::cout << "Pozycja: " << varname << std::endl; } -- GitLab