diff --git a/libwccl/ops/functions/tset/catfilter.cpp b/libwccl/ops/functions/tset/catfilter.cpp index 76fe1f40fa33136269cad718ae237d6b84cdb610..705e28a9062431606ea557cb233cd3bcfc1453c9 100644 --- a/libwccl/ops/functions/tset/catfilter.cpp +++ b/libwccl/ops/functions/tset/catfilter.cpp @@ -8,8 +8,8 @@ std::string CatFilter::to_string(const Corpus2::Tagset& tagset) const std::ostringstream os; os << name(tagset) << "(" << pos_expr_->to_string(tagset) << ", " - << tagset.get_attribute_name(selector_.get_values()) << ", " - << tagset.get_attribute_name(mask_.get_values()) << ")"; + << selector_expr_-> to_string(tagset) << ", " + << mask_expr_-> to_string(tagset) << ")"; return os.str(); } @@ -17,8 +17,8 @@ std::ostream& CatFilter::write_to(std::ostream& os) const { return os << raw_name() << "(" << *pos_expr_ << ", " - << selector_.raw_dump() << ", " - << mask_.raw_dump() << ")"; + << *selector_expr_ << ", " + << *mask_expr_ << ")"; } CatFilter::BaseRetValPtr CatFilter::apply_internal(const FunExecContext& context) const @@ -29,14 +29,19 @@ CatFilter::BaseRetValPtr CatFilter::apply_internal(const FunExecContext& context return detail::DefaultFunction<TSet>()->apply(context); } + const boost::shared_ptr<const TSet>& selector_tset = selector_expr_->apply(context); + const boost::shared_ptr<const TSet>& mask_tset = mask_expr_->apply(context); + const Corpus2::Tag& selector = selector_tset->get_value(); + const Corpus2::Tag& mask = mask_tset->get_value(); + boost::shared_ptr<TSet> tset = boost::make_shared<TSet>(); const Corpus2::Token* token = sc.at(*pos); foreach (const Corpus2::Lexeme& lexeme, token->lexemes()) { - if (!lexeme.tag().get_masked(selector_).is_null()) { + if (!lexeme.tag().get_masked(selector).is_null()) { tset->combine_with(lexeme.tag()); } } - tset->tag_ref().mask_with(mask_); + tset->tag_ref().mask_with(mask); return tset; } diff --git a/libwccl/ops/functions/tset/catfilter.h b/libwccl/ops/functions/tset/catfilter.h index d03cb6edca7164fe8abc6aca72daab15da8e41eb..71519baea5cab344e13b3f9fef24a2ac8097c7d9 100644 --- a/libwccl/ops/functions/tset/catfilter.h +++ b/libwccl/ops/functions/tset/catfilter.h @@ -15,16 +15,22 @@ class CatFilter : public Function<TSet> { public: typedef boost::shared_ptr<Function<Position> > PosFunctionPtr; + typedef boost::shared_ptr<Function<TSet> > TSetFunctionPtr; - CatFilter(const PosFunctionPtr& pos_expr, const Corpus2::Tag& selector, const Corpus2::Tag& mask) - : selector_(selector), mask_(mask), pos_expr_(pos_expr) + CatFilter( + const PosFunctionPtr& pos_expr, + const TSetFunctionPtr& selector, + const TSetFunctionPtr& mask) + : selector_expr_(selector), mask_expr_(mask), pos_expr_(pos_expr) { BOOST_ASSERT(pos_expr_); + BOOST_ASSERT(selector_expr_); + BOOST_ASSERT(mask_expr_); } /** * @returns String representation of the function in the form of: - * "catflt(pos_expr, selector, mask) + * "catflt(pos_expr, selector_expr, mask_expr) */ std::string to_string(const Corpus2::Tagset& tagset) const; @@ -36,8 +42,8 @@ public: } protected: - Corpus2::Tag selector_; - Corpus2::Tag mask_; + const TSetFunctionPtr selector_expr_; + const TSetFunctionPtr mask_expr_; const PosFunctionPtr pos_expr_; @@ -55,7 +61,7 @@ protected: /** * Writes raw string representation of the function in the form of: - * "catflt(pos_expr_raw_string, raw_selector, raw_mask) + * "catflt(pos_expr_raw_str, selector_expr_raw_str, mask_expr_raw_str) * @note This version does not require tagset, but will be inclomplete * and/or contain internal info. * @returns Stream written to.