From 1d5fd937b36fc3b13b6ad8b372f64f5999a310a0 Mon Sep 17 00:00:00 2001
From: Adam Wardynski <award@.(B-4.4.46a)>
Date: Tue, 7 Dec 2010 15:23:57 +0100
Subject: [PATCH] Make CatFilter take Function<TSet> isntead of Corpus2::Tag.

---
 libwccl/ops/functions/tset/catfilter.cpp | 17 +++++++++++------
 libwccl/ops/functions/tset/catfilter.h   | 18 ++++++++++++------
 2 files changed, 23 insertions(+), 12 deletions(-)

diff --git a/libwccl/ops/functions/tset/catfilter.cpp b/libwccl/ops/functions/tset/catfilter.cpp
index 76fe1f4..705e28a 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 d03cb6e..71519ba 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.
-- 
GitLab