Skip to content
Snippets Groups Projects
Commit 1d5fd937 authored by Adam Wardynski's avatar Adam Wardynski
Browse files

Make CatFilter take Function<TSet> isntead of Corpus2::Tag.

parent aceed854
Branches
No related merge requests found
...@@ -8,8 +8,8 @@ std::string CatFilter::to_string(const Corpus2::Tagset& tagset) const ...@@ -8,8 +8,8 @@ std::string CatFilter::to_string(const Corpus2::Tagset& tagset) const
std::ostringstream os; std::ostringstream os;
os << name(tagset) << "(" os << name(tagset) << "("
<< pos_expr_->to_string(tagset) << ", " << pos_expr_->to_string(tagset) << ", "
<< tagset.get_attribute_name(selector_.get_values()) << ", " << selector_expr_-> to_string(tagset) << ", "
<< tagset.get_attribute_name(mask_.get_values()) << ")"; << mask_expr_-> to_string(tagset) << ")";
return os.str(); return os.str();
} }
...@@ -17,8 +17,8 @@ std::ostream& CatFilter::write_to(std::ostream& os) const ...@@ -17,8 +17,8 @@ std::ostream& CatFilter::write_to(std::ostream& os) const
{ {
return os << raw_name() << "(" return os << raw_name() << "("
<< *pos_expr_ << ", " << *pos_expr_ << ", "
<< selector_.raw_dump() << ", " << *selector_expr_ << ", "
<< mask_.raw_dump() << ")"; << *mask_expr_ << ")";
} }
CatFilter::BaseRetValPtr CatFilter::apply_internal(const FunExecContext& context) const CatFilter::BaseRetValPtr CatFilter::apply_internal(const FunExecContext& context) const
...@@ -29,14 +29,19 @@ CatFilter::BaseRetValPtr CatFilter::apply_internal(const FunExecContext& context ...@@ -29,14 +29,19 @@ CatFilter::BaseRetValPtr CatFilter::apply_internal(const FunExecContext& context
return detail::DefaultFunction<TSet>()->apply(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>(); boost::shared_ptr<TSet> tset = boost::make_shared<TSet>();
const Corpus2::Token* token = sc.at(*pos); const Corpus2::Token* token = sc.at(*pos);
foreach (const Corpus2::Lexeme& lexeme, token->lexemes()) { 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->combine_with(lexeme.tag());
} }
} }
tset->tag_ref().mask_with(mask_); tset->tag_ref().mask_with(mask);
return tset; return tset;
} }
......
...@@ -15,16 +15,22 @@ class CatFilter : public Function<TSet> ...@@ -15,16 +15,22 @@ class CatFilter : public Function<TSet>
{ {
public: public:
typedef boost::shared_ptr<Function<Position> > PosFunctionPtr; 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) CatFilter(
: selector_(selector), mask_(mask), pos_expr_(pos_expr) 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(pos_expr_);
BOOST_ASSERT(selector_expr_);
BOOST_ASSERT(mask_expr_);
} }
/** /**
* @returns String representation of the function in the form of: * @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; std::string to_string(const Corpus2::Tagset& tagset) const;
...@@ -36,8 +42,8 @@ public: ...@@ -36,8 +42,8 @@ public:
} }
protected: protected:
Corpus2::Tag selector_; const TSetFunctionPtr selector_expr_;
Corpus2::Tag mask_; const TSetFunctionPtr mask_expr_;
const PosFunctionPtr pos_expr_; const PosFunctionPtr pos_expr_;
...@@ -55,7 +61,7 @@ protected: ...@@ -55,7 +61,7 @@ protected:
/** /**
* Writes raw string representation of the function in the form of: * 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 * @note This version does not require tagset, but will be inclomplete
* and/or contain internal info. * and/or contain internal info.
* @returns Stream written to. * @returns Stream written to.
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment