diff --git a/libmwereader/mwe.cpp b/libmwereader/mwe.cpp index 897c80eaac94beb4b94337fae60f9ab8d933e942..6bd065a6751f9079cd9d14cc4b4b8e29da1bda94 100644 --- a/libmwereader/mwe.cpp +++ b/libmwereader/mwe.cpp @@ -19,7 +19,7 @@ LexicalUnit::LexicalUnit(const std::string &base, } bool LexicalUnit::IsHere(const Wccl::SentenceContext &sc, - std::set<size_t> &out_position) + std::set<size_t> &out_position) const { boost::shared_ptr<const Wccl::Bool> pResult = condition_->apply(sc); if(pResult->get_value() == false) @@ -39,6 +39,8 @@ bool LexicalUnit::IsHere(const Wccl::SentenceContext &sc, return true; } +//////////////////////////////////////////////////////////////////// +// TODO realy needed? FixedLU::FixedLU(const std::string &base, boost::shared_ptr<Wccl::Operator<Wccl::Bool> > condition, @@ -56,12 +58,14 @@ FlexLU::FlexLU(const std::string &base, { } -MWEIndex::MWEIndex() -{ +//////////////////////////////////////////////////////////////////// +MWEIndex::MWEIndex() : index_(), empty_() +{ + // noop } -void MWEIndex::add_lexicalunit(LexicalUnitPtr lu) +void MWEIndex::add_lexicalunit(LexicalUnit::Ptr lu) { foreach(const std::string& base, lu->get_potential_bases()){ value_type::iterator find = index_.find(base); @@ -75,4 +79,13 @@ void MWEIndex::add_lexicalunit(LexicalUnitPtr lu) } } +const MWEIndex::luvec& MWEIndex::get_potential_lu(const std::string &base){ + value_type::iterator find = index_.find(base); + if(find == index_.end()){ // not found -> return empty + return empty_; + } + + return (find->second); +} + }//ns Corpus2 diff --git a/libmwereader/mwe.h b/libmwereader/mwe.h index 0676ad0036e4135aeae49a54390a24f590a1ee61..e0ee53c3efa747a2ffba418a2a0f300922427fde 100644 --- a/libmwereader/mwe.h +++ b/libmwereader/mwe.h @@ -31,14 +31,14 @@ public: * \returns true if this lexical unit was found here */ virtual bool IsHere(const Wccl::SentenceContext& sc, - std::set<size_t> &out_positions) ; + std::set<size_t> &out_positions) const; const std::string & get_base() const{ return base_;} const strmap & get_variables() const{ return variables_;} const strset& get_potential_bases() const{ return potential_bases_;} - + typedef boost::shared_ptr<LexicalUnit> Ptr; protected: boost::shared_ptr<Wccl::Operator<Wccl::Bool> > condition_; @@ -51,7 +51,7 @@ protected: const Wccl::Position nowhere_; }; -typedef boost::shared_ptr<LexicalUnit> LexicalUnitPtr; + // TODO: czy bedzie potrzebny podzial na fix/flex w kodzie? @@ -59,9 +59,9 @@ 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 + LexicalUnit::BoolOpPtr condition, + LexicalUnit::BoolOpPtr head_cond, + LexicalUnit::strmap variables ); }; @@ -69,9 +69,9 @@ class FlexLU : public LexicalUnit { public: FlexLU(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::BoolOpPtr condition, + LexicalUnit::BoolOpPtr head_cond, + LexicalUnit::strmap variables ); }; @@ -79,16 +79,22 @@ public: class MWEIndex // lub base -> vector<LexicalUnit> { public: + typedef std::vector<LexicalUnit::Ptr> luvec; + MWEIndex(); - void add_lexicalunit(LexicalUnitPtr lu); + void add_lexicalunit(LexicalUnit::Ptr lu); + + const luvec& get_potential_lu(const std::string& base); protected: - typedef std::vector<LexicalUnitPtr> luvec; + typedef boost::unordered_map<std::string,luvec> value_type; value_type index_; + + const luvec empty_; }; }// ns Corpus2 diff --git a/libmwereader/mweparser.cpp b/libmwereader/mweparser.cpp index c8fd91e5557142e03b38a149d2e181bc75df57e3..cda56745dc33ef33f2798fce26e74aac9a37ac1e 100644 --- a/libmwereader/mweparser.cpp +++ b/libmwereader/mweparser.cpp @@ -60,17 +60,18 @@ namespace Corpus2 { MWEBuilder::BoolOpPtr head = mwe_builder_->get_head_condition( head_cond_); - LexicalUnitPtr lu; if(group_type_ == "fix"){ // group_name_ -> lower case - lu = LexicalUnitPtr(new FixedLU(mwe_base_, main, head, - variables_)); + mwe_index_.add_lexicalunit( LexicalUnit::Ptr(new FixedLU(mwe_base_, main, head, + variables_))); } else if(group_type_ == "flex"){ - lu = LexicalUnitPtr(new FlexLU(mwe_base_, main, head, - variables_)); + mwe_index_.add_lexicalunit(LexicalUnit::Ptr(new FlexLU(mwe_base_, main, head, + variables_))); } else { throw Wccl::WcclError("Unknown type of lexical unit:" + group_type_); } + + } std::string MWEParser::get_attribute(const AttributeList& attributes,