diff --git a/libwccl/ops/affix.cpp b/libwccl/ops/affix.cpp index 892a3c0a41dd1719beb5d1514ef28aaa3040a903..59562af17c1d5f4c1977d70d8f23b089770283f4 100644 --- a/libwccl/ops/affix.cpp +++ b/libwccl/ops/affix.cpp @@ -20,7 +20,7 @@ std::string Affix::to_raw_string() const { return str.str(); } -Affix::BaseRetValPtr Affix::apply_internal(const SentenceContext& context) const +Affix::BaseRetValPtr Affix::apply_internal(const FunExecContext& context) const { if(affix_length_ == 0) { return strset_expr_->apply(context); diff --git a/libwccl/ops/affix.h b/libwccl/ops/affix.h index fc38e5947564c9626e4480728c8415ec347f3018..f52129dc297a42d0bbe2d46c3302868b775f6018 100644 --- a/libwccl/ops/affix.h +++ b/libwccl/ops/affix.h @@ -1,7 +1,6 @@ #ifndef LIBWCCL_OPS_AFFIX_H #define LIBWCCL_OPS_AFFIX_H -#include <boost/shared_ptr.hpp> #include <libwccl/values/strset.h> #include <libwccl/ops/functions.h> @@ -45,13 +44,11 @@ protected: const StrSetFunctionPtr strset_expr_; const int affix_length_; - typedef FunctionBase::BaseRetValPtr BaseRetValPtr; - /** * Get a string set from the argument expression and return copy of the set * with all strings converted into prefixes or suffixes of given length */ - virtual BaseRetValPtr apply_internal(const SentenceContext& context) const; + virtual BaseRetValPtr apply_internal(const FunExecContext& context) const; }; } /* end ns Wccl */ diff --git a/libwccl/ops/and.cpp b/libwccl/ops/and.cpp index 758ce19d4acfe63f1271b27bcbb46c31e055375c..0e119a7c9192b2b510a913a25f7ab0dc19c9b1f6 100644 --- a/libwccl/ops/and.cpp +++ b/libwccl/ops/and.cpp @@ -1,8 +1,11 @@ #include <libwccl/ops/and.h> +#include <boost/foreach.hpp> +#undef foreach +#define foreach BOOST_FOREACH namespace Wccl { -And::BaseRetValPtr And::apply_internal(const SentenceContext &context) const +And::BaseRetValPtr And::apply_internal(const FunExecContext& context) const { foreach(boost::shared_ptr< Function<Bool> > expression, *expressions_) { if(!(expression->apply(context)->get_value())) { diff --git a/libwccl/ops/and.h b/libwccl/ops/and.h index 9e3b50efc5a2716b8bddbbe4fa257724a6f5538a..46b74a37d6188e230eb8b2ef5d24e50046ff1209 100644 --- a/libwccl/ops/and.h +++ b/libwccl/ops/and.h @@ -1,9 +1,6 @@ #ifndef LIBWCCL_OPS_AND_H #define LIBWCCL_OPS_AND_H -#include <boost/foreach.hpp> -#define foreach BOOST_FOREACH - #include <libwccl/ops/logicalpredicate.h> namespace Wccl { @@ -20,14 +17,13 @@ public: } protected : - typedef FunctionBase::BaseRetValPtr BaseRetValPtr ; - /** * "And" predicate evaluates each expression from left to right, * and returns False once an expression evaluating to False is found. * If all expressions were True, it returns True. */ - virtual BaseRetValPtr apply_internal(const SentenceContext&) const; + virtual BaseRetValPtr apply_internal( + const FunExecContext& context) const; virtual const std::string raw_operator_name() const; }; diff --git a/libwccl/ops/conditional.h b/libwccl/ops/conditional.h index dfae9327ba6987c879b83c3b3b190b7bb9dfbea6..80398fdfa8ba996f1a64887e6830e8d2962830f0 100644 --- a/libwccl/ops/conditional.h +++ b/libwccl/ops/conditional.h @@ -1,17 +1,15 @@ #ifndef LIBWCCL_OPS_CONDITIONAL_H #define LIBWCCL_OPS_CONDITIONAL_H -#include <boost/shared_ptr.hpp> #include <boost/mpl/list.hpp> -#include <boost/mpl/assert.hpp> #include <boost/mpl/count.hpp> -#include <libwccl/ops/predicate.h> -#include <libwccl/ops/formatters.h> -#include <libwccl/ops/constant.h> - #include <sstream> #include <boost/format.hpp> +#include <libwccl/ops/predicate.h> +#include <libwccl/ops/constant.h> +#include <libwccl/ops/formatters.h> + namespace Wccl { /** @@ -65,13 +63,12 @@ protected: } typedef FunctionBase::BaseRetValPtr BaseRetValPtr; - /** * Evaluate the predicate. If it is true, evaluate and return value of * iftrue_expression. If predicate is false, evalute and return value * of iffalse_expression. */ - virtual BaseRetValPtr apply_internal(const SentenceContext& context) const { + virtual BaseRetValPtr apply_internal(const FunExecContext& context) const { if(this->cond_expr_->apply(context)->get_value()) { return iftrue_expr_->apply(context); } diff --git a/libwccl/ops/constant.h b/libwccl/ops/constant.h index 67f15ef1dca997168dc1f6188785272a614e7442..c5c933f0d229a7150daa74dc53770be61861028e 100644 --- a/libwccl/ops/constant.h +++ b/libwccl/ops/constant.h @@ -42,11 +42,10 @@ public: protected : typedef FunctionBase::BaseRetValPtr BaseRetValPtr ; - /** * Applying Constant function returns the held value of a constant */ - virtual BaseRetValPtr apply_internal(const SentenceContext&) const { + virtual BaseRetValPtr apply_internal(const FunExecContext&) const { return BaseRetValPtr (new T(*value_)); } diff --git a/libwccl/ops/equals.h b/libwccl/ops/equals.h index 7864afd24661f01a2c3c847aa8963d797976e22d..0b1b6d48d106f89824237d0aace0709cb7b0bc88 100644 --- a/libwccl/ops/equals.h +++ b/libwccl/ops/equals.h @@ -1,9 +1,7 @@ #ifndef LIBWCCL_OPS_EQUALS_H #define LIBWCCL_OPS_EQUALS_H -#include <boost/shared_ptr.hpp> #include <boost/mpl/list.hpp> -#include <boost/mpl/assert.hpp> #include <boost/mpl/count.hpp> #include <libwccl/ops/predicate.h> #include <libwccl/ops/formatters.h> @@ -41,13 +39,11 @@ protected: const ArgFunctionPtr arg1_expr_; const ArgFunctionPtr arg2_expr_; - typedef FunctionBase::BaseRetValPtr BaseRetValPtr; - /** * Take values of arguments from expressions and return True if they are equal, * False otherwise. */ - virtual BaseRetValPtr apply_internal(const SentenceContext& context) const { + virtual BaseRetValPtr apply_internal(const FunExecContext& context) const { boost::shared_ptr<T> arg1 = this->arg1_expr_->apply(context); boost::shared_ptr<T> arg2 = this->arg2_expr_->apply(context); if(arg1->equals(*arg2)) { @@ -94,7 +90,7 @@ protected: * Take values of arguments from expressions and return True if they are equal, * False otherwise. */ - virtual BaseRetValPtr apply_internal(const SentenceContext& context) const { + virtual BaseRetValPtr apply_internal(const FunExecContext& context) const { boost::shared_ptr<Position> arg1 = this->arg1_expr_->apply(context); boost::shared_ptr<Position> arg2 = this->arg2_expr_->apply(context); if(arg1->equals(*arg2)) { diff --git a/libwccl/ops/formatters.h b/libwccl/ops/formatters.h index cc7a089efef674f0dea45483e13116c89658291f..985ef6fdb7ae6bd769bebec1598358ca69616313 100644 --- a/libwccl/ops/formatters.h +++ b/libwccl/ops/formatters.h @@ -1,10 +1,6 @@ #ifndef LIBWCCL_OPS_FORMATTERS_H #define LIBWCCL_OPS_FORMATTERS_H -#include <boost/shared_ptr.hpp> - -#include <libcorpus2/tagset.h> - #include <libwccl/ops/functions.h> namespace Wccl { diff --git a/libwccl/ops/functions.h b/libwccl/ops/functions.h index 81395756b0a278b44deed8754719a031e8cb17b8..34acfe01ce2757d61c23b2356e9cefcd93f14531 100644 --- a/libwccl/ops/functions.h +++ b/libwccl/ops/functions.h @@ -8,7 +8,7 @@ #include <libwccl/ops/operator.h> #include <libwccl/values/value.h> -#include <libwccl/sentencecontext.h> +#include <libwccl/ops/funexeccontext.h> namespace Wccl { @@ -21,7 +21,7 @@ protected: /** * Applies the function, given the sentence context. */ - virtual BaseRetValPtr apply_internal(const SentenceContext& context) const = 0; + virtual BaseRetValPtr apply_internal(const FunExecContext& context) const = 0; }; /** @@ -44,7 +44,7 @@ public: * type of Value (as shared pointer). Uses apply_internal which has to * be specified in derived classes. */ - RetValPtr apply(const SentenceContext& context) const { + RetValPtr apply(const FunExecContext& context) const { RetValPtr v = boost::dynamic_pointer_cast<T>(apply_internal(context)); BOOST_ASSERT(v); return v; diff --git a/libwccl/ops/funexeccontext.h b/libwccl/ops/funexeccontext.h new file mode 100644 index 0000000000000000000000000000000000000000..4a41cccb41bc61b35ea18bdb784da22b658e2597 --- /dev/null +++ b/libwccl/ops/funexeccontext.h @@ -0,0 +1,47 @@ +#ifndef LIBWCCL_OPS_FUNEXECCONTEXT_H +#define LIBWCCL_OPS_FUNEXECCONTEXT_H + +#include <boost/noncopyable.hpp> +#include <libwccl/variables.h> +#include <libwccl/sentencecontext.h> + +namespace Wccl { + +/** + * Class holding execution context of a functional operator + * i.e. state that the function should operate on. + */ +class FunExecContext : public boost::noncopyable { +public: + FunExecContext( const SentenceContext& sentence_context, + const boost::shared_ptr<Variables>& vars) + : sentence_context_(sentence_context), vars_(vars) + { + } + + /** + * @returns Context of a sentence the operator is applied to. + * @note Functional operators should not change sentence state, + * hence the const reference. + */ + const SentenceContext& sentence_context() const { + return sentence_context_; + } + + /** + * @returns Pointer to variables the operator should operate with. + * @note Variables should be accesible to modifications, but overall + * object should not get replaced, hence the const pointer. + */ + const boost::shared_ptr<Variables>& variables() const { + return vars_; + } + +private: + const SentenceContext& sentence_context_; + const boost::shared_ptr<Variables> vars_; +}; + +} /* end ns Wccl */ + +#endif // LIBWCCL_OPS_FUNEXECCONTEXT_H diff --git a/libwccl/ops/intersects.h b/libwccl/ops/intersects.h index 87308f4d04bb0b8e4c80da4dea2e5ef7a9df1fe2..9a3a160e6f78ae69a24151b71ac4421f64eba839 100644 --- a/libwccl/ops/intersects.h +++ b/libwccl/ops/intersects.h @@ -1,15 +1,7 @@ #ifndef LIBWCCL_OPS_INTERSECTS_H #define LIBWCCL_OPS_INTERSECTS_H -#include <boost/shared_ptr.hpp> - -#include <libcorpus2/tagset.h> - -#include <libwccl/values/strset.h> -#include <libwccl/values/tset.h> -#include <libwccl/values/bool.h> #include <libwccl/ops/setpredicate.h> -#include <libwccl/ops/formatters.h> namespace Wccl { @@ -20,8 +12,6 @@ template <class T> class Intersects : public SetPredicate<T> { public: - typedef typename SetPredicate<T>::SetFunctionPtr SetFunctionPtr; - Intersects(const SetFunctionPtr& set1_expr, const SetFunctionPtr& set2_expr) : SetPredicate<T>(set1_expr, set2_expr) { @@ -32,14 +22,11 @@ public: } protected: - - typedef typename SetPredicate<T>::BaseRetValPtr BaseRetValPtr; - /** * Take values for both sets and return True if they intersect, * False otherwise. */ - virtual BaseRetValPtr apply_internal(const SentenceContext& context) const { + virtual BaseRetValPtr apply_internal(const FunExecContext& context) const { boost::shared_ptr<T> set1 = this->set1_expr_->apply(context); boost::shared_ptr<T> set2 = this->set2_expr_->apply(context); if(set1->is_subset_of(*set2)) { diff --git a/libwccl/ops/issubsetof.h b/libwccl/ops/issubsetof.h index 55692a2a0b95ed38e736a7a6e927cebf1c88537e..685e8332a6ee2c5642dead2b9b08b5d98409bb5a 100644 --- a/libwccl/ops/issubsetof.h +++ b/libwccl/ops/issubsetof.h @@ -1,15 +1,7 @@ #ifndef LIBWCCL_OPS_ISSUBSETOF_H #define LIBWCCL_OPS_ISSUBSETOF_H -#include <boost/shared_ptr.hpp> - -#include <libcorpus2/tagset.h> - -#include <libwccl/values/strset.h> -#include <libwccl/values/tset.h> -#include <libwccl/values/bool.h> #include <libwccl/ops/setpredicate.h> -#include <libwccl/ops/formatters.h> namespace Wccl { @@ -32,16 +24,13 @@ public: } protected: - - typedef typename SetPredicate<T>::BaseRetValPtr BaseRetValPtr; - /** * Take value of possible subset in question. If it is an empty set, return False. * Otherwise, take value of the set that is being compared to. * Return True if the possible subset is indeed a subset of the compared set, * otherwise return False. */ - virtual BaseRetValPtr apply_internal(const SentenceContext& context) const { + virtual BaseRetValPtr apply_internal(const FunExecContext& context) const { boost::shared_ptr<T> possible_subset = this->set1_expr_->apply(context); if(!possible_subset->empty()) { boost::shared_ptr<T> set_compared_to = this->set2_expr_->apply(context); diff --git a/libwccl/ops/logicalpredicate.h b/libwccl/ops/logicalpredicate.h index 384c962a39973ba6a519bf754f09be6023e02354..02c6280c3a2b451b390a94f25e274bc8711f9093 100644 --- a/libwccl/ops/logicalpredicate.h +++ b/libwccl/ops/logicalpredicate.h @@ -2,9 +2,6 @@ #define LIBWCCL_OPS_LOGICALPREDICATE_H #include <vector> -#include <boost/shared_array.hpp> -#include <boost/assert.hpp> -#include <libcorpus2/tagset.h> #include <libwccl/ops/predicate.h> diff --git a/libwccl/ops/nor.cpp b/libwccl/ops/nor.cpp index d547da31a6841ed0cb713b2dd57eef385e44c05f..4798819f4c94b09201c0f40de504b598181e1baf 100644 --- a/libwccl/ops/nor.cpp +++ b/libwccl/ops/nor.cpp @@ -1,8 +1,10 @@ #include <libwccl/ops/nor.h> +#include <boost/foreach.hpp> +#define foreach BOOST_FOREACH namespace Wccl { -Nor::BaseRetValPtr Nor::apply_internal(const SentenceContext &context) const +Nor::BaseRetValPtr Nor::apply_internal(const FunExecContext& context) const { foreach(BoolFunctionPtr expression, *expressions_) { if(expression->apply(context)->get_value()) { diff --git a/libwccl/ops/nor.h b/libwccl/ops/nor.h index e826365d15ad622e067322eba8eb514e456d9989..1b5e10a7d1819cba9b1de93602a1218070b10dee 100644 --- a/libwccl/ops/nor.h +++ b/libwccl/ops/nor.h @@ -1,9 +1,6 @@ #ifndef LIBWCCL_OPS_NOR_H #define LIBWCCL_OPS_NOR_H -#include <boost/foreach.hpp> -#define foreach BOOST_FOREACH - #include <libwccl/ops/logicalpredicate.h> namespace Wccl { @@ -21,15 +18,13 @@ public: } protected : - typedef FunctionBase::BaseRetValPtr BaseRetValPtr ; - /** * "Nor" (aka "not") predicate evaluates expressions one by one in order * from left to right, and False is returned once an expression evaluating * to True is found. * If all of the expressions were False, True is returned. */ - virtual BaseRetValPtr apply_internal(const SentenceContext&) const; + virtual BaseRetValPtr apply_internal(const FunExecContext&) const; virtual const std::string raw_operator_name() const; }; diff --git a/libwccl/ops/or.cpp b/libwccl/ops/or.cpp index 7d9cf16240cd045a54e778a7ade37f88778d1bb8..bdce8c62131ed1ecbb7dff9d64cec0b60a09f05d 100644 --- a/libwccl/ops/or.cpp +++ b/libwccl/ops/or.cpp @@ -1,8 +1,10 @@ #include <libwccl/ops/or.h> +#include <boost/foreach.hpp> +#define foreach BOOST_FOREACH namespace Wccl { -Or::BaseRetValPtr Or::apply_internal(const SentenceContext &context) const +Or::BaseRetValPtr Or::apply_internal(const FunExecContext& context) const { foreach(BoolFunctionPtr expression, *expressions_) { if(expression->apply(context)->get_value()) { diff --git a/libwccl/ops/or.h b/libwccl/ops/or.h index 574f9bd80b0bee2abd0b808bbfc3d77ea30b1b23..22b359748b2d620e2f146e596709386bdd9f61dc 100644 --- a/libwccl/ops/or.h +++ b/libwccl/ops/or.h @@ -1,9 +1,6 @@ #ifndef LIBWCCL_OPS_OR_H #define LIBWCCL_OPS_OR_H -#include <boost/foreach.hpp> -#define foreach BOOST_FOREACH - #include <libwccl/ops/logicalpredicate.h> namespace Wccl { @@ -20,14 +17,12 @@ public: } protected : - typedef FunctionBase::BaseRetValPtr BaseRetValPtr ; - /** * "Or" predicate evaluates expressions one by one in order from left to right, * and True is returned once an expression evaluating to True is found. * If all of the expressions were False, False is returned. */ - virtual BaseRetValPtr apply_internal(const SentenceContext&) const; + virtual BaseRetValPtr apply_internal(const FunExecContext&) const; virtual const std::string raw_operator_name() const; }; diff --git a/libwccl/ops/predicate.h b/libwccl/ops/predicate.h index d4d84ec44057c17b6671c3b5c7e4e6180cb343bc..f064bee6d765f0dc5ce1f5cb6a5626af3a97a239 100644 --- a/libwccl/ops/predicate.h +++ b/libwccl/ops/predicate.h @@ -1,11 +1,9 @@ #ifndef LIBWCCL_OPS_PREDICATE_H #define LIBWCCL_OPS_PREDICATE_H -#include <boost/shared_ptr.hpp> #include <boost/scoped_ptr.hpp> #include <libwccl/values/bool.h> -#include <libwccl/ops/functions.h> #include <libwccl/ops/constant.h> namespace Wccl { diff --git a/libwccl/ops/regex.cpp b/libwccl/ops/regex.cpp index 8b44177334f9bd9ea8f47d3677bc7a8092b1ba6e..0c4dca7319b83672f79da0464cbbed1efba77ee1 100644 --- a/libwccl/ops/regex.cpp +++ b/libwccl/ops/regex.cpp @@ -1,4 +1,7 @@ #include <libwccl/ops/regex.h> +#include <boost/foreach.hpp> +#define foreach BOOST_FOREACH + #include <sstream> #include <libpwrutils/util.h> @@ -69,8 +72,8 @@ std::string Regex::to_raw_string() const { return ss.str(); } -Regex::BaseRetValPtr Regex::apply_internal(const SentenceContext& context) const { - const boost::shared_ptr<StrSet >& set = strset_expr_->apply(context); +Regex::BaseRetValPtr Regex::apply_internal(const FunExecContext& context) const { + const boost::shared_ptr<StrSet>& set = strset_expr_->apply(context); if(set->empty()) { return Predicate::False->apply(context); } diff --git a/libwccl/ops/regex.h b/libwccl/ops/regex.h index 63784f0c80ec260232e4483a586a2f0350175553..7c87cf90628aa446b7ea71562abdab5f4fc7cf7f 100644 --- a/libwccl/ops/regex.h +++ b/libwccl/ops/regex.h @@ -1,12 +1,9 @@ #ifndef LIBWCCL_OPS_REGEX_H #define LIBWCCL_OPS_REGEX_H -#include <boost/shared_ptr.hpp> -#include <boost/scoped_ptr.hpp> #include <unicode/regex.h> #include <libwccl/exception.h> -#include <libwccl/values/bool.h> #include <libwccl/values/strset.h> #include <libwccl/ops/predicate.h> @@ -42,15 +39,13 @@ public: } protected: - typedef FunctionBase::BaseRetValPtr BaseRetValPtr; - /** * Get a string set from the argument expression, * apply regular expression to each string one by one, * return false if a string not matching expression is found. * Return true if all strings matched the regular espression. */ - virtual BaseRetValPtr apply_internal(const SentenceContext& context) const; + virtual BaseRetValPtr apply_internal(const FunExecContext& context) const; private: const StrSetFunctionPtr strset_expr_; diff --git a/libwccl/ops/setpredicate.h b/libwccl/ops/setpredicate.h index 5ca8c578b15069e2dbfefa4d03e293dbd9497574..c8e0ca92ccab482abef7d936a332c03d068ac4b8 100644 --- a/libwccl/ops/setpredicate.h +++ b/libwccl/ops/setpredicate.h @@ -1,11 +1,12 @@ #ifndef LIBWCCL_OPS_SETPREDICATE_H #define LIBWCCL_OPS_SETPREDICATE_H -#include <boost/shared_ptr.hpp> #include <boost/mpl/list.hpp> -#include <boost/mpl/assert.hpp> #include <boost/mpl/count.hpp> #include <libwccl/ops/predicate.h> +#include <libwccl/values/strset.h> +#include <libwccl/values/tset.h> + #include <libwccl/ops/formatters.h> namespace Wccl { @@ -37,8 +38,6 @@ public: protected: const SetFunctionPtr set1_expr_; const SetFunctionPtr set2_expr_; - - typedef FunctionBase::BaseRetValPtr BaseRetValPtr; }; } /* end ns Wccl */ diff --git a/libwccl/ops/tolower.cpp b/libwccl/ops/tolower.cpp index d553cc75a861566c63d80e0dd336775d0a6b900d..52ad8c39aa2fbf912287a57be29b568d4af32846 100644 --- a/libwccl/ops/tolower.cpp +++ b/libwccl/ops/tolower.cpp @@ -12,7 +12,7 @@ std::string ToLower::to_raw_string() const { return UnaryFunctionFormatter::to_raw_string(*this, *strset_expr_); } -ToLower::BaseRetValPtr ToLower::apply_internal(const SentenceContext& context) const { +ToLower::BaseRetValPtr ToLower::apply_internal(const FunExecContext& context) const { const boost::shared_ptr<StrSet >& set = strset_expr_->apply(context); boost::shared_ptr<StrSet > l_set = boost::make_shared<StrSet>(); //TODO: should tolower be a method of StrSet as well? diff --git a/libwccl/ops/tolower.h b/libwccl/ops/tolower.h index 8edcba2e150804fd74de69c402b33c1cfa4c088b..6f7bd305dc807b0a31fedac153ddd430aa2781fe 100644 --- a/libwccl/ops/tolower.h +++ b/libwccl/ops/tolower.h @@ -1,7 +1,6 @@ #ifndef LIBWCCL_OPS_TOLOWER_H #define LIBWCCL_OPS_TOLOWER_H -#include <boost/shared_ptr.hpp> #include <libwccl/values/strset.h> #include <libwccl/ops/functions.h> @@ -42,13 +41,11 @@ public: protected: const StrSetFunctionPtr strset_expr_; - typedef FunctionBase::BaseRetValPtr BaseRetValPtr; - /** * Get a string set from the argument expression and return copy of the set * with all strings in lower case form */ - virtual BaseRetValPtr apply_internal(const SentenceContext& context) const; + virtual BaseRetValPtr apply_internal(const FunExecContext& context) const; }; } /* end ns Wccl */ diff --git a/libwccl/ops/toupper.cpp b/libwccl/ops/toupper.cpp index 1e94d31adbca270f6cc8410a4cedec39d3e50657..ec55211cb0aa4f253f352d3ed9393d5115771dd1 100644 --- a/libwccl/ops/toupper.cpp +++ b/libwccl/ops/toupper.cpp @@ -12,7 +12,7 @@ std::string ToUpper::to_raw_string() const { return UnaryFunctionFormatter::to_raw_string(*this, *strset_expr_); } -ToUpper::BaseRetValPtr ToUpper::apply_internal(const SentenceContext& context) const { +ToUpper::BaseRetValPtr ToUpper::apply_internal(const FunExecContext& context) const { const boost::shared_ptr<StrSet >& set = strset_expr_->apply(context); boost::shared_ptr<StrSet > u_set = boost::make_shared<StrSet>(); //TODO: should tolower be a method of StrSet as well? diff --git a/libwccl/ops/toupper.h b/libwccl/ops/toupper.h index 6491d92304d8714b2038f7e138e3d630d10665be..c3414d3c1bfe548aad67e2f6bf58f7a9d1f8c454 100644 --- a/libwccl/ops/toupper.h +++ b/libwccl/ops/toupper.h @@ -1,7 +1,6 @@ #ifndef LIBWCCL_OPS_TOUPPER_H #define LIBWCCL_OPS_TOUPPER_H -#include <boost/shared_ptr.hpp> #include <libwccl/values/strset.h> #include <libwccl/ops/functions.h> @@ -42,13 +41,11 @@ public: protected: const StrSetFunctionPtr strset_expr_; - typedef FunctionBase::BaseRetValPtr BaseRetValPtr; - /** * Get a string set from the argument expression and return copy of the set * with all strings in upper case form */ - virtual BaseRetValPtr apply_internal(const SentenceContext& context) const; + virtual BaseRetValPtr apply_internal(const FunExecContext& context) const; }; } /* end ns Wccl */ diff --git a/tests/conditional.cpp b/tests/conditional.cpp index 5b482e2b6b6d0993ad662bfc7394310919eca205..cfa78ab32f504c9853c03f3d9c9f9ed667b53a17 100644 --- a/tests/conditional.cpp +++ b/tests/conditional.cpp @@ -20,6 +20,7 @@ struct CondFix { CondFix() : sc(boost::make_shared<Corpus2::Sentence>()), + cx(sc, boost::make_shared<Variables>()), tagset(), true_value(true), false_value(false), @@ -28,6 +29,7 @@ struct CondFix { } SentenceContext sc; + FunExecContext cx; Corpus2::Tagset tagset; Bool true_value; @@ -78,7 +80,7 @@ BOOST_FIXTURE_TEST_CASE(true_condition_strset, CondFixStrSet) iftrue_strset_expr, iffalse_strset_expr)); - BOOST_CHECK(iftrue_strset.equals(*(cond->apply(sc)))); + BOOST_CHECK(iftrue_strset.equals(*(cond->apply(cx)))); } BOOST_FIXTURE_TEST_CASE(false_condition_strset, CondFixStrSet) @@ -88,7 +90,7 @@ BOOST_FIXTURE_TEST_CASE(false_condition_strset, CondFixStrSet) iftrue_strset_expr, iffalse_strset_expr)); - BOOST_CHECK(iffalse_strset.equals(*(cond->apply(sc)))); + BOOST_CHECK(iffalse_strset.equals(*(cond->apply(cx)))); } BOOST_FIXTURE_TEST_CASE(true_condition_op_strset, CondFixStrSet) @@ -97,7 +99,7 @@ BOOST_FIXTURE_TEST_CASE(true_condition_op_strset, CondFixStrSet) true_constant, iftrue_strset_expr)); - BOOST_CHECK(iftrue_strset.equals(*(cond->apply(sc)))); + BOOST_CHECK(iftrue_strset.equals(*(cond->apply(cx)))); } BOOST_FIXTURE_TEST_CASE(false_condition_op_strset, CondFixStrSet) @@ -106,7 +108,7 @@ BOOST_FIXTURE_TEST_CASE(false_condition_op_strset, CondFixStrSet) false_constant, iftrue_strset_expr)); - BOOST_CHECK(empty_strset.equals(*(cond->apply(sc)))); + BOOST_CHECK(empty_strset.equals(*(cond->apply(cx)))); } //------ to_string test cases ------- diff --git a/tests/constant_tests.cpp b/tests/constant_tests.cpp index 8939e9566a2f2a0981a77ae2179ccd220c1306f2..b4754c7a8f3749bf109dac8bb08b84299ccfb23e 100644 --- a/tests/constant_tests.cpp +++ b/tests/constant_tests.cpp @@ -16,6 +16,7 @@ struct BoolFix { BoolFix() : sc(boost::make_shared<Corpus2::Sentence>()), + cx(sc, boost::make_shared<Variables>()), tagset(), true_value(true), false_value(false), @@ -24,6 +25,7 @@ struct BoolFix { } SentenceContext sc; + FunExecContext cx; Corpus2::Tagset tagset; Bool true_value; @@ -35,9 +37,9 @@ struct BoolFix BOOST_FIXTURE_TEST_CASE(bool_apply, BoolFix) { BOOST_CHECK_EQUAL(true, true_value.get_value()); - BOOST_CHECK_EQUAL(true, true_constant.apply(sc)->get_value()); + BOOST_CHECK_EQUAL(true, true_constant.apply(cx)->get_value()); BOOST_CHECK_EQUAL(false, false_value.get_value()); - BOOST_CHECK_EQUAL(false, false_constant.apply(sc)->get_value()); + BOOST_CHECK_EQUAL(false, false_constant.apply(cx)->get_value()); } BOOST_FIXTURE_TEST_CASE(bool_to_string, BoolFix) @@ -58,12 +60,12 @@ BOOST_FIXTURE_TEST_CASE(bool_to_raw_string, BoolFix) BOOST_FIXTURE_TEST_CASE(bool_value_preserved, BoolFix) { - boost::shared_ptr<Bool> v = true_constant.apply(sc); + boost::shared_ptr<Bool> v = true_constant.apply(cx); v->set_value(false); - BOOST_CHECK_EQUAL(true, true_constant.apply(sc)->get_value()); - v = false_constant.apply(sc); + BOOST_CHECK_EQUAL(true, true_constant.apply(cx)->get_value()); + v = false_constant.apply(cx); v->set_value(true); - BOOST_CHECK_EQUAL(false, false_constant.apply(sc)->get_value()); + BOOST_CHECK_EQUAL(false, false_constant.apply(cx)->get_value()); } BOOST_AUTO_TEST_SUITE_END() diff --git a/tests/logicalpredicates.cpp b/tests/logicalpredicates.cpp index 5bb4f21ab59b85e82a71de376bcae96d4c3aa478..0de82f5923f552cdd608f71b25edfc3b1a653a03 100644 --- a/tests/logicalpredicates.cpp +++ b/tests/logicalpredicates.cpp @@ -23,7 +23,8 @@ struct PredFix true_value(true), false_value(false), true_constant(new Constant<Bool>(true_value)), - false_constant(new Constant<Bool>(false_value)) + false_constant(new Constant<Bool>(false_value)), + cx(sc, boost::make_shared<Variables>()) { } SentenceContext sc; @@ -33,12 +34,14 @@ struct PredFix Bool false_value; LogicalPredicate::BoolFunctionPtr true_constant; LogicalPredicate::BoolFunctionPtr false_constant; + + FunExecContext cx; }; BOOST_FIXTURE_TEST_CASE(predicate_constants, PredFix) { - BOOST_CHECK_EQUAL(true, Predicate::True->apply(sc)->get_value()); - BOOST_CHECK_EQUAL(false, Predicate::False->apply(sc)->get_value()); + BOOST_CHECK_EQUAL(true, Predicate::True->apply(cx)->get_value()); + BOOST_CHECK_EQUAL(false, Predicate::False->apply(cx)->get_value()); } BOOST_FIXTURE_TEST_CASE(and_1arg, PredFix) @@ -46,10 +49,10 @@ BOOST_FIXTURE_TEST_CASE(and_1arg, PredFix) boost::shared_ptr<And::BoolFunctionPtrVector> v(new And::BoolFunctionPtrVector()); v->push_back(true_constant); And pred_and(v); - BOOST_CHECK_EQUAL(true, pred_and.apply(sc)->get_value()); + BOOST_CHECK_EQUAL(true, pred_and.apply(cx)->get_value()); v->clear(); v->push_back(false_constant); - BOOST_CHECK_EQUAL(false, pred_and.apply(sc)->get_value()); + BOOST_CHECK_EQUAL(false, pred_and.apply(cx)->get_value()); } @@ -61,7 +64,7 @@ BOOST_FIXTURE_TEST_CASE(and_2arg, PredFix) v->push_back(arg1 != 0 ? true_constant : false_constant); v->push_back(arg2 != 0 ? true_constant : false_constant); And pred_and(v); - BOOST_CHECK_EQUAL((arg1 != 0) && (arg2 != 0), pred_and.apply(sc)->get_value()); + BOOST_CHECK_EQUAL((arg1 != 0) && (arg2 != 0), pred_and.apply(cx)->get_value()); } } } @@ -76,7 +79,7 @@ BOOST_FIXTURE_TEST_CASE(and_3arg, PredFix) v->push_back(arg2 != 0 ? true_constant : false_constant); v->push_back(arg3 != 0 ? true_constant : false_constant); And pred_and(v); - BOOST_CHECK_EQUAL((arg1 != 0) && (arg2 != 0) && (arg3 != 0), pred_and.apply(sc)->get_value()); + BOOST_CHECK_EQUAL((arg1 != 0) && (arg2 != 0) && (arg3 != 0), pred_and.apply(cx)->get_value()); } } } @@ -87,10 +90,10 @@ BOOST_FIXTURE_TEST_CASE(or_1arg, PredFix) boost::shared_ptr<Or::BoolFunctionPtrVector> v(new Or::BoolFunctionPtrVector()); v->push_back(true_constant); Or pred_or(v); - BOOST_CHECK_EQUAL(true, pred_or.apply(sc)->get_value()); + BOOST_CHECK_EQUAL(true, pred_or.apply(cx)->get_value()); v->clear(); v->push_back(false_constant); - BOOST_CHECK_EQUAL(false, pred_or.apply(sc)->get_value()); + BOOST_CHECK_EQUAL(false, pred_or.apply(cx)->get_value()); } @@ -102,7 +105,7 @@ BOOST_FIXTURE_TEST_CASE(or_2arg, PredFix) v->push_back(arg1 != 0 ? true_constant : false_constant); v->push_back(arg2 != 0 ? true_constant : false_constant); Or pred_or(v); - BOOST_CHECK_EQUAL((arg1 != 0) || (arg2 != 0), pred_or.apply(sc)->get_value()); + BOOST_CHECK_EQUAL((arg1 != 0) || (arg2 != 0), pred_or.apply(cx)->get_value()); } } } @@ -117,7 +120,7 @@ BOOST_FIXTURE_TEST_CASE(or_3arg, PredFix) v->push_back(arg2 != 0 ? true_constant : false_constant); v->push_back(arg3 != 0 ? true_constant : false_constant); Or pred_or(v); - BOOST_CHECK_EQUAL((arg1 != 0) || (arg2 != 0) || (arg3 != 0), pred_or.apply(sc)->get_value()); + BOOST_CHECK_EQUAL((arg1 != 0) || (arg2 != 0) || (arg3 != 0), pred_or.apply(cx)->get_value()); } } } @@ -128,10 +131,10 @@ BOOST_FIXTURE_TEST_CASE(nor_1arg, PredFix) boost::shared_ptr<Nor::BoolFunctionPtrVector> v(new Nor::BoolFunctionPtrVector()); v->push_back(true_constant); Nor pred_nor(v); - BOOST_CHECK_EQUAL(false, pred_nor.apply(sc)->get_value()); + BOOST_CHECK_EQUAL(false, pred_nor.apply(cx)->get_value()); v->clear(); v->push_back(false_constant); - BOOST_CHECK_EQUAL(true, pred_nor.apply(sc)->get_value()); + BOOST_CHECK_EQUAL(true, pred_nor.apply(cx)->get_value()); } @@ -143,7 +146,7 @@ BOOST_FIXTURE_TEST_CASE(nor_2arg, PredFix) v->push_back(arg1 != 0 ? true_constant : false_constant); v->push_back(arg2 != 0 ? true_constant : false_constant); Nor pred_nor(v); - BOOST_CHECK_EQUAL(!((arg1 != 0) || (arg2 != 0)), pred_nor.apply(sc)->get_value()); + BOOST_CHECK_EQUAL(!((arg1 != 0) || (arg2 != 0)), pred_nor.apply(cx)->get_value()); } } } @@ -158,7 +161,7 @@ BOOST_FIXTURE_TEST_CASE(nor_3arg, PredFix) v->push_back(arg2 != 0 ? true_constant : false_constant); v->push_back(arg3 != 0 ? true_constant : false_constant); Nor pred_nor(v); - BOOST_CHECK_EQUAL(!((arg1 != 0) || (arg2 != 0) || (arg3 != 0)), pred_nor.apply(sc)->get_value()); + BOOST_CHECK_EQUAL(!((arg1 != 0) || (arg2 != 0) || (arg3 != 0)), pred_nor.apply(cx)->get_value()); } } } diff --git a/tests/regex.cpp b/tests/regex.cpp index f0b87e1b551c361d9bc938bda07ea0638a76fbc1..8884567a3ebaa0207679b56b86f12f5a33a2e7b4 100644 --- a/tests/regex.cpp +++ b/tests/regex.cpp @@ -18,11 +18,13 @@ struct RegexFix { RegexFix() : sc(boost::make_shared<Corpus2::Sentence>()), - tagset() + tagset(), + cx(sc, boost::make_shared<Variables>()) { } SentenceContext sc; Corpus2::Tagset tagset; + FunExecContext cx; }; BOOST_FIXTURE_TEST_CASE(positive_sanity_check, RegexFix) @@ -31,7 +33,7 @@ BOOST_FIXTURE_TEST_CASE(positive_sanity_check, RegexFix) sanity.insert("word"); boost::shared_ptr<Function<StrSet> > sanity_expr(new Constant<StrSet>(sanity)); Regex r(sanity_expr, "word"); - BOOST_CHECK(r.apply(sc)->get_value()); + BOOST_CHECK(r.apply(cx)->get_value()); } BOOST_FIXTURE_TEST_CASE(negative_sanity_check, RegexFix) @@ -40,7 +42,7 @@ BOOST_FIXTURE_TEST_CASE(negative_sanity_check, RegexFix) sanity.insert("word"); boost::shared_ptr<Function<StrSet> > sanity_expr(new Constant<StrSet>(sanity)); Regex r(sanity_expr, "Word"); - BOOST_CHECK(!r.apply(sc)->get_value()); + BOOST_CHECK(!r.apply(cx)->get_value()); } //TODO: need more regex tests... @@ -65,4 +67,4 @@ BOOST_AUTO_TEST_CASE(regex_to_raw_string) BOOST_CHECK_EQUAL("regex([\"word\"], \"Word\")", r.to_raw_string()); } -BOOST_AUTO_TEST_SUITE_END() \ No newline at end of file +BOOST_AUTO_TEST_SUITE_END() diff --git a/tests/strsetfunctions.cpp b/tests/strsetfunctions.cpp index bf0ecc996e44c7ccd5a07c5204fdf39ca8800608..d87b40272c0070486b7b45686056692287780f9e 100644 --- a/tests/strsetfunctions.cpp +++ b/tests/strsetfunctions.cpp @@ -20,6 +20,7 @@ struct StrSetFix StrSetFix() : sc(boost::make_shared<Corpus2::Sentence>()), tagset(), + cx(sc, boost::make_shared<Variables>()), strset(), strset_expr() { @@ -36,6 +37,7 @@ struct StrSetFix } SentenceContext sc; Corpus2::Tagset tagset; + FunExecContext cx; StrSet strset; boost::shared_ptr<Function<StrSet> > strset_expr; @@ -55,7 +57,7 @@ BOOST_FIXTURE_TEST_CASE(lower, StrSetFix) ToLower to_lower(strset_expr); - BOOST_CHECK(lowerset.equals(*to_lower.apply(sc))); + BOOST_CHECK(lowerset.equals(*to_lower.apply(cx))); } BOOST_FIXTURE_TEST_CASE(upper, StrSetFix) @@ -72,7 +74,7 @@ BOOST_FIXTURE_TEST_CASE(upper, StrSetFix) ToUpper to_upper(strset_expr); - BOOST_CHECK(upperset.equals(*to_upper.apply(sc))); + BOOST_CHECK(upperset.equals(*to_upper.apply(cx))); } BOOST_FIXTURE_TEST_CASE(prefix, StrSetFix) @@ -89,7 +91,7 @@ BOOST_FIXTURE_TEST_CASE(prefix, StrSetFix) Affix prefix(strset_expr, 7); - BOOST_CHECK(prefixset.equals(*prefix.apply(sc))); + BOOST_CHECK(prefixset.equals(*prefix.apply(cx))); } BOOST_FIXTURE_TEST_CASE(suffix, StrSetFix) @@ -106,13 +108,13 @@ BOOST_FIXTURE_TEST_CASE(suffix, StrSetFix) Affix suffix(strset_expr, -7); - BOOST_CHECK(suffixset.equals(*suffix.apply(sc))); + BOOST_CHECK(suffixset.equals(*suffix.apply(cx))); } BOOST_FIXTURE_TEST_CASE(affix_0, StrSetFix) { Affix affix_0(strset_expr, 0); - BOOST_CHECK(strset.equals(*affix_0.apply(sc))); + BOOST_CHECK(strset.equals(*affix_0.apply(cx))); } BOOST_FIXTURE_TEST_CASE(lower_locale, StrSetFix) @@ -135,7 +137,7 @@ BOOST_FIXTURE_TEST_CASE(lower_locale, StrSetFix) ToLower to_lower(boost::shared_ptr<Function<StrSet> >( new Constant<StrSet>(upperset))); - BOOST_CHECK(lowerset.equals(*to_lower.apply(sc))); + BOOST_CHECK(lowerset.equals(*to_lower.apply(cx))); } BOOST_FIXTURE_TEST_CASE(upper_locale, StrSetFix) @@ -158,7 +160,7 @@ BOOST_FIXTURE_TEST_CASE(upper_locale, StrSetFix) ToUpper to_upper(boost::shared_ptr<Function<StrSet> >( new Constant<StrSet>(lowerset))); - BOOST_CHECK(upperset.equals(*to_upper.apply(sc))); + BOOST_CHECK(upperset.equals(*to_upper.apply(cx))); } BOOST_FIXTURE_TEST_CASE(lower_empty, StrSetFix) @@ -168,7 +170,7 @@ BOOST_FIXTURE_TEST_CASE(lower_empty, StrSetFix) ToLower to_lower(boost::shared_ptr<Function<StrSet> >( new Constant<StrSet>(emptyset))); - BOOST_CHECK(emptyset.equals(*to_lower.apply(sc))); + BOOST_CHECK(emptyset.equals(*to_lower.apply(cx))); } BOOST_FIXTURE_TEST_CASE(upper_empty, StrSetFix) @@ -178,7 +180,7 @@ BOOST_FIXTURE_TEST_CASE(upper_empty, StrSetFix) ToUpper to_upper(boost::shared_ptr<Function<StrSet> >( new Constant<StrSet>(emptyset))); - BOOST_CHECK(emptyset.equals(*to_upper.apply(sc))); + BOOST_CHECK(emptyset.equals(*to_upper.apply(cx))); } //------ to_string test cases -------