diff --git a/libwccl/ops/affix.cpp b/libwccl/ops/affix.cpp index 934787d8a1051003089451dde0c23f6c1718f10f..c9bc7e0d23320ba02030fd4de8f9e22fda099e7f 100644 --- a/libwccl/ops/affix.cpp +++ b/libwccl/ops/affix.cpp @@ -8,14 +8,14 @@ namespace Wccl { std::string Affix::to_string(const Corpus2::Tagset& tagset) const { std::stringstream str; - str << operator_name(tagset) << "(" << strset_expr_->to_string(tagset) + str << name(tagset) << "(" << strset_expr_->to_string(tagset) << ", " << affix_length_ << ")"; return str.str(); } std::string Affix::to_raw_string() const { std::stringstream str; - str << raw_operator_name() << "(" << strset_expr_->to_raw_string() + str << raw_name() << "(" << strset_expr_->to_raw_string() << ", " << affix_length_ << ")"; return str.str(); } diff --git a/libwccl/ops/affix.h b/libwccl/ops/affix.h index f52129dc297a42d0bbe2d46c3302868b775f6018..ddda767a7b6d546baf1881c17cff28404fd03a64 100644 --- a/libwccl/ops/affix.h +++ b/libwccl/ops/affix.h @@ -26,7 +26,7 @@ public: * String representation of the operator in form of: * "affix(strset_expr_string)" */ - virtual std::string to_string(const Corpus2::Tagset& tagset) const; + std::string to_string(const Corpus2::Tagset& tagset) const; /** * String representation of conditional operator in form of: @@ -34,9 +34,12 @@ public: * This version does not require tagset, but may be inclomplete * and/or contain internal info. */ - virtual std::string to_raw_string() const; + std::string to_raw_string() const; - virtual const std::string raw_operator_name() const { + /** + * @returns Name of the function: "affix" + */ + std::string raw_name() const { return "affix"; } @@ -48,7 +51,7 @@ protected: * 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 FunExecContext& context) const; + BaseRetValPtr apply_internal(const FunExecContext& context) const; }; } /* end ns Wccl */ diff --git a/libwccl/ops/and.cpp b/libwccl/ops/and.cpp index 7cf39ec821457440d75c2771b39dd648b6a7d945..2c18f4765a792cc2669859326fdebb45e746ed96 100644 --- a/libwccl/ops/and.cpp +++ b/libwccl/ops/and.cpp @@ -15,8 +15,4 @@ And::BaseRetValPtr And::apply_internal(const FunExecContext& context) const return Predicate::True(context); } -const std::string And::raw_operator_name() const { - return "and"; -} - } /* end ns Wccl */ diff --git a/libwccl/ops/and.h b/libwccl/ops/and.h index 46b74a37d6188e230eb8b2ef5d24e50046ff1209..88b019dff224288bbd98d032379f04013b49d528 100644 --- a/libwccl/ops/and.h +++ b/libwccl/ops/and.h @@ -16,16 +16,21 @@ public: { } + /** + * @returns Name of the function: "and" + */ + std::string raw_name() const { + return "and"; + } + protected : /** * "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 FunExecContext& context) const; + BaseRetValPtr apply_internal(const FunExecContext& context) const; - virtual const std::string raw_operator_name() const; }; } /* end ns Wccl */ diff --git a/libwccl/ops/conditional.h b/libwccl/ops/conditional.h index 80398fdfa8ba996f1a64887e6830e8d2962830f0..03485d028766c7c0f2b116a0ec3600074fd160ae 100644 --- a/libwccl/ops/conditional.h +++ b/libwccl/ops/conditional.h @@ -36,19 +36,22 @@ public: /** * String representation of conditional operator in form of: - * "if cond_expr_string then iftrue_expr_string else iffalse_expr_string" + * "if(cond_expr_string, iftrue_expr_string, iffalse_expr_string)" */ - virtual std::string to_string(const Corpus2::Tagset& tagset) const; + std::string to_string(const Corpus2::Tagset& tagset) const; /** * String representation of conditional operator in form of: - * "if cond_expr_raw_s then iftrue_expr_raw_s else iffalse_expr_raw_s" + * "if(cond_expr_raw_s, iftrue_expr_raw_s, iffalse_expr_raw_s)" * This version does not require tagset, but may be inclomplete * and/or contain internal info. */ - virtual std::string to_raw_string() const; + std::string to_raw_string() const; - virtual const std::string raw_operator_name() const { + /** + * @returns Name of the function: "if" + */ + std::string raw_name() const { return "if"; } @@ -68,7 +71,7 @@ protected: * iftrue_expression. If predicate is false, evalute and return value * of iffalse_expression. */ - virtual BaseRetValPtr apply_internal(const FunExecContext& context) const { + BaseRetValPtr apply_internal(const FunExecContext& context) const { if(this->cond_expr_->apply(context)->get_value()) { return iftrue_expr_->apply(context); } @@ -97,20 +100,23 @@ public: } /** - * String representation of conditional operator in form of: + * @returns String representation of conditional operator in form of: * "? if_true_expr_string ? cond_expr_string" */ - virtual std::string to_string(const Corpus2::Tagset& tagset) const; + std::string to_string(const Corpus2::Tagset& tagset) const; /** - * String representation of conditional operator in form of: + * @returns String representation of conditional operator in form of: * "? if_true_expr_raw_string ? cond_expr_raw_string" - * This version does not require tagset, but may be inclomplete + * @note This version does not require tagset, but may be inclomplete * and/or contain internal info. */ - virtual std::string to_raw_string() const; + std::string to_raw_string() const; - virtual const std::string raw_operator_name() const { + /** + * @returns Name of the function: "?". + */ + std::string raw_name() const { return "?"; } }; @@ -119,8 +125,8 @@ template<class T> std::string Conditional<T>::to_raw_string() const { std::stringstream ss; - ss << boost::format("%1% %2% then %3% else %4%") - % this->raw_operator_name() + ss << boost::format("%1%(%2%, %3%, %4%)") + % this->raw_name() % this->cond_expr_->to_raw_string() % this->iftrue_expr_->to_raw_string() % this->iffalse_expr_->to_raw_string(); @@ -131,8 +137,8 @@ template<class T> std::string Conditional<T>::to_string(const Corpus2::Tagset &tagset) const { std::stringstream ss; - ss << boost::format("%1% %2% then %3% else %4%") - % this->operator_name(tagset) + ss << boost::format("%1%(%2%, %3%, %4%)") + % this->name(tagset) % this->cond_expr_->to_string(tagset) % this->iftrue_expr_->to_string(tagset) % this->iffalse_expr_->to_string(tagset); @@ -145,7 +151,7 @@ std::string ConditionalOp<T>::to_raw_string() const { std::stringstream ss; ss << boost::format("%1% %2% ? %3%") - % this->raw_operator_name() + % this->raw_name() % this->iftrue_expr_->to_raw_string() % this->cond_expr_->to_raw_string(); return ss.str(); @@ -156,7 +162,7 @@ std::string ConditionalOp<T>::to_string(const Corpus2::Tagset &tagset) const { std::stringstream ss; ss << boost::format("%1% %2% ? %3%") - % this->operator_name(tagset) + % this->name(tagset) % this->iftrue_expr_->to_string(tagset) % this->cond_expr_->to_string(tagset); return ss.str(); diff --git a/libwccl/ops/constant.h b/libwccl/ops/constant.h index c9bb5d83cb74dde62d8de1ebde72ec153cc48384..3620c5595a38d2ceb5aa959dcf66a0a145f58fbb 100644 --- a/libwccl/ops/constant.h +++ b/libwccl/ops/constant.h @@ -23,22 +23,31 @@ public: { BOOST_ASSERT(value_); } - + + /** + * @returns Name of the function: "const". + */ + std::string raw_name() const { + return "const"; + } + /** - * Operator name for constant is string representation of its value + * @returns String representation of the Constant, which is the + * the string representation of the underlying Value. */ - virtual const std::string operator_name(const Corpus2::Tagset& tagset) const { + std::string to_string(const Corpus2::Tagset& tagset) const { return value_->to_string(tagset); } /** - * Operator name for constant is string representation of its value, - * tagset-independent in this case + * @returns String representation of the Constant that does + * not require a tagset. It is same as raw string representation + * of underlying Value. + * @note May be incomplete and/or containt internal info. */ - virtual const std::string raw_operator_name() const { + std::string to_raw_string() const { return value_->to_raw_string(); } - protected : typedef FunctionBase::BaseRetValPtr BaseRetValPtr ; /** diff --git a/libwccl/ops/equals.h b/libwccl/ops/equals.h index 3aea68bc89c34fec1120168d8dd8df757c41d758..06bc4add9f87aa2f87d2ed44c827df6786782e66 100644 --- a/libwccl/ops/equals.h +++ b/libwccl/ops/equals.h @@ -61,15 +61,28 @@ public: BOOST_ASSERT(arg2_expr_); } - virtual std::string to_string(const Corpus2::Tagset& tagset) const { + /** + * @returns String representation of the function in form of: + * "equals(arg1_expr_string, arg2_expr_string)" + */ + std::string to_string(const Corpus2::Tagset& tagset) const { return BinaryFunctionFormatter::to_string(tagset, *this, *arg1_expr_, *arg2_expr_); } - virtual std::string to_raw_string() const { + /** + * @returns String representation of the function in form of: + * "equals(arg1_expr_raw_string, arg2_expr_raw_string)". + * @note This version does not require tagset but may be incomplete + * and/or contain internal info. + */ + std::string to_raw_string() const { return BinaryFunctionFormatter::to_raw_string(*this, *arg1_expr_, *arg2_expr_); } - virtual const std::string raw_operator_name() const { + /** + * @returns Name of the function: "equals". + */ + std::string raw_name() const { return "equals"; } @@ -81,7 +94,7 @@ protected: * Take values of arguments from expressions and return True if they are equal, * False otherwise. */ - virtual BaseRetValPtr apply_internal(const FunExecContext& context) const { + BaseRetValPtr apply_internal(const FunExecContext& context) const { return EqualityComparer<T>::apply( *(this->arg1_expr_->apply(context)), *(this->arg2_expr_->apply(context)), diff --git a/libwccl/ops/expression.h b/libwccl/ops/expression.h new file mode 100644 index 0000000000000000000000000000000000000000..8d3e71a84c6c9cf8e351faf13dfc063c176a8061 --- /dev/null +++ b/libwccl/ops/expression.h @@ -0,0 +1,28 @@ +#ifndef LIBWCCL_OPS_EXPRESSION_H +#define LIBWCCL_OPS_EXPRESSION_H + +#include <libcorpus2/tagset.h> +#include <boost/noncopyable.hpp> + +namespace Wccl { + +/** + * Abstract base class for WCCL expressions + */ +class Expression : public boost::noncopyable { +public: + /** + * @returns String representation of the expression. + */ + virtual std::string to_string(const Corpus2::Tagset& tagset) const = 0; + /** + * @returns String representation of the expression that does not + * require a tagset. + * @note Might be incomplete and/or contain internal info. + */ + virtual std::string to_raw_string() const = 0; +}; + +} /* end ns Wccl */ + +#endif // LIBWCCL_OPS_EXPRESSION_H diff --git a/libwccl/ops/formatters.cpp b/libwccl/ops/formatters.cpp index a9bb0cfe7c51e4bdccfa90f8017135f5250a30e1..122bc8eb1ee5e3b4763bf7a9651c900d1b799e5b 100644 --- a/libwccl/ops/formatters.cpp +++ b/libwccl/ops/formatters.cpp @@ -12,7 +12,7 @@ std::string UnaryFunctionFormatter::to_raw_string( const char* close_bracket) { std::stringstream ss; - ss << f.raw_operator_name() << open_bracket << arg_str << close_bracket; + ss << f.raw_name() << open_bracket << arg_str << close_bracket; return ss.str(); } @@ -24,7 +24,7 @@ std::string UnaryFunctionFormatter::to_string( const char* close_bracket) { std::stringstream ss; - ss << f.operator_name(tagset) << open_bracket << arg_str << close_bracket; + ss << f.name(tagset) << open_bracket << arg_str << close_bracket; return ss.str(); } @@ -37,7 +37,7 @@ std::string BinaryFunctionFormatter::to_string( const std::string& arg2_str) { std::stringstream ss; - ss << f.operator_name(tagset) << "(" << arg1_str << ", " << arg2_str << ")"; + ss << f.name(tagset) << "(" << arg1_str << ", " << arg2_str << ")"; return ss.str(); } @@ -47,7 +47,7 @@ std::string BinaryFunctionFormatter::to_raw_string( const std::string& arg2_str) { std::stringstream ss; - ss << f.raw_operator_name() << "(" << arg1_str << ", " << arg2_str << ")"; + ss << f.raw_name() << "(" << arg1_str << ", " << arg2_str << ")"; return ss.str(); } diff --git a/libwccl/ops/functions.h b/libwccl/ops/functions.h index bda875158b4cbadd0e65ac282d3a27178077c2a5..ea3b55d08bb72b504472c6232254480a241559fe 100644 --- a/libwccl/ops/functions.h +++ b/libwccl/ops/functions.h @@ -6,7 +6,7 @@ #include <boost/mpl/assert.hpp> #include <boost/type_traits/is_base_of.hpp> -#include <libwccl/ops/operator.h> +#include <libwccl/ops/expression.h> #include <libwccl/values/value.h> #include <libwccl/ops/funexeccontext.h> @@ -15,8 +15,26 @@ namespace Wccl { /** * Abstract base class for WCCL operators that are functions returning a Value */ -class FunctionBase : public Operator { +class FunctionBase : public Expression +{ +public: + /** + * @returns Name of the function. By default it is same as raw name. + */ + virtual const std::string name(const Corpus2::Tagset&) const { + return raw_name(); + } + /** + * @returns A representation of function's name that does + * not require a tagset. + * @note May be incomplete and/or contain internal info. + */ + virtual std::string raw_name() const = 0; protected: + /** + * Base type returned after application of function + * (shared pointer to a const Value) + */ typedef boost::shared_ptr<const Value> BaseRetValPtr; /** * Applies the function for the given execution context. diff --git a/libwccl/ops/intersects.h b/libwccl/ops/intersects.h index 39ed2723a42b66a5e2dab9c744f42a11c9d9b8de..82fdd3cecb81ba2f46e241905db1d53609bf53ca 100644 --- a/libwccl/ops/intersects.h +++ b/libwccl/ops/intersects.h @@ -17,7 +17,10 @@ public: { } - virtual const std::string raw_operator_name() const { + /** + * @returns Name of the function: "inter" + */ + std::string raw_name() const { return "inter"; } @@ -26,7 +29,7 @@ protected: * Take values for both sets and return True if they intersect, * False otherwise. */ - virtual BaseRetValPtr apply_internal(const FunExecContext& context) const { + 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); return Predicate::evaluate(set1->intersects(*set2), context); diff --git a/libwccl/ops/isinside.h b/libwccl/ops/isinside.h index 0acbb86e86e911ebbbbd914edf2383b1d69bf629..7ea1f1f69c83f01bd02c13b247ce204575974f6a 100644 --- a/libwccl/ops/isinside.h +++ b/libwccl/ops/isinside.h @@ -20,15 +20,26 @@ public: BOOST_ASSERT(pos_expr_); } - virtual std::string to_string(const Corpus2::Tagset& tagset) const { + /** + * @returns String representation of the function in the form of: + * "inside(arg_expr_string)" + */ + std::string to_string(const Corpus2::Tagset& tagset) const { return UnaryFunctionFormatter::to_string(tagset, *this, *pos_expr_); } - virtual std::string to_raw_string() const { + /** + * @returns String representation of the function in the form of: + * "inside(arg_expr_raw_string)" + */ + std::string to_raw_string() const { return UnaryFunctionFormatter::to_raw_string(*this, *pos_expr_); } - virtual const std::string raw_operator_name() const { + /** + * @returns Name of the function: "inside" + */ + std::string raw_name() const { return "inside"; } @@ -40,7 +51,7 @@ protected: * boundaries. * @returns True value if position is within sentence boundaries, False otherwise. */ - virtual BaseRetValPtr apply_internal(const FunExecContext& context) const { + BaseRetValPtr apply_internal(const FunExecContext& context) const { const boost::shared_ptr<const Position>& pos = pos_expr_->apply(context); return Predicate::evaluate(pos->is_inside(context.sentence_context()), context); } diff --git a/libwccl/ops/isoutside.h b/libwccl/ops/isoutside.h index f32591ddabeff1c4681fbcb11c762b2037e59c90..17322e70d553c39dbcc5ec3036427bedcda7553a 100644 --- a/libwccl/ops/isoutside.h +++ b/libwccl/ops/isoutside.h @@ -20,15 +20,26 @@ public: BOOST_ASSERT(pos_expr_); } - virtual std::string to_string(const Corpus2::Tagset& tagset) const { + /** + * @returns String representation of the function in the form of: + * "outside(arg_expr_string)" + */ + std::string to_string(const Corpus2::Tagset& tagset) const { return UnaryFunctionFormatter::to_string(tagset, *this, *pos_expr_); } - virtual std::string to_raw_string() const { + /** + * @returns String representation of the function in the form of: + * "outside(arg_expr_raw_string)" + */ + std::string to_raw_string() const { return UnaryFunctionFormatter::to_raw_string(*this, *pos_expr_); } - virtual const std::string raw_operator_name() const { + /** + * @returns Name of the function: "outside" + */ + std::string raw_name() const { return "outside"; } @@ -40,7 +51,7 @@ protected: * sentence boundaries, in the given context (i.e. relative to current position) * @returns True value if position is outside of the sentence boundaries, False otherwise. */ - virtual BaseRetValPtr apply_internal(const FunExecContext& context) const { + BaseRetValPtr apply_internal(const FunExecContext& context) const { const boost::shared_ptr<const Position>& pos = pos_expr_->apply(context); return Predicate::evaluate(pos->is_outside(context.sentence_context()), context); } diff --git a/libwccl/ops/issubsetof.h b/libwccl/ops/issubsetof.h index 0fd276ffbd0248710a1e960145d6aeb63a0452bb..d8536de600bf65bf63ee2671cf1cc7d08370ded8 100644 --- a/libwccl/ops/issubsetof.h +++ b/libwccl/ops/issubsetof.h @@ -6,7 +6,8 @@ namespace Wccl { /** - * Class that realises a predicate checking if one set is a subset of another + * Class that realises a predicate checking if one set is in another. + * Almost like being a subset of, but empty set is considered not to be "in". */ template <class T> class IsSubsetOf : public SetPredicate<T> @@ -19,7 +20,10 @@ public: { } - virtual const std::string raw_operator_name() const { + /** + * @returns Name of the function: "in" + */ + std::string raw_name() const { return "in"; } @@ -27,10 +31,11 @@ protected: /** * 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. + * @returns True if the possible subset is inside set compared to. + * @note Take note this is not true "subset" function, because empty + * set is considered not to be "in" any other set so False is returned. */ - virtual BaseRetValPtr apply_internal(const FunExecContext& context) const { + BaseRetValPtr apply_internal(const FunExecContext& context) const { boost::shared_ptr<T> possible_subset = this->set1_expr_->apply(context); if(!possible_subset->empty()) { diff --git a/libwccl/ops/logicalpredicate.cpp b/libwccl/ops/logicalpredicate.cpp index c00be52f9917551dedcdaff931119d4b63ff3e81..66945abad4aac2ee7efa30f856781b9a0ee4ec75 100644 --- a/libwccl/ops/logicalpredicate.cpp +++ b/libwccl/ops/logicalpredicate.cpp @@ -7,7 +7,7 @@ namespace Wccl { std::string LogicalPredicate::to_string(const Corpus2::Tagset& tagset) const { std::stringstream ss; - ss << operator_name(tagset) << "("; + ss << name(tagset) << "("; BoolFunctionPtrVector::const_iterator it = expressions_->begin(); while(it != expressions_->end()) { ss << (*it)->to_string(tagset); @@ -22,7 +22,7 @@ std::string LogicalPredicate::to_string(const Corpus2::Tagset& tagset) const std::string LogicalPredicate::to_raw_string() const { std::stringstream ss; - ss << raw_operator_name() << "("; + ss << raw_name() << "("; BoolFunctionPtrVector::const_iterator it = expressions_->begin(); while(it != expressions_->end()) { ss << (*it)->to_raw_string(); diff --git a/libwccl/ops/logicalpredicate.h b/libwccl/ops/logicalpredicate.h index 02c6280c3a2b451b390a94f25e274bc8711f9093..7d439b6d503d8c7ceea63802a5b330b1a15498f4 100644 --- a/libwccl/ops/logicalpredicate.h +++ b/libwccl/ops/logicalpredicate.h @@ -26,7 +26,7 @@ public: * String representation of the logical predicate, realised by default * as "operator_name(expr1_string, ..., exprn_string)" */ - virtual std::string to_string(const Corpus2::Tagset& tagset) const; + std::string to_string(const Corpus2::Tagset& tagset) const; /** * String representation of the logical predicate, realised by default @@ -34,7 +34,7 @@ public: * (this version doesn't require tagset, but may be incomplete and/or * contain internal info) */ - virtual std::string to_raw_string() const; + std::string to_raw_string() const; protected: const boost::shared_ptr<BoolFunctionPtrVector> expressions_; diff --git a/libwccl/ops/nor.cpp b/libwccl/ops/nor.cpp index 50a8a4c82c4c04dd6d85fc13185ab8aa01cf7943..480025ba9ce65129dba3620fffb24bf1df6e1997 100644 --- a/libwccl/ops/nor.cpp +++ b/libwccl/ops/nor.cpp @@ -14,8 +14,4 @@ Nor::BaseRetValPtr Nor::apply_internal(const FunExecContext& context) const return Predicate::True(context); } -const std::string Nor::raw_operator_name() const { - return "not"; -} - } /* end ns Wccl */ diff --git a/libwccl/ops/nor.h b/libwccl/ops/nor.h index 1b5e10a7d1819cba9b1de93602a1218070b10dee..6374ad8a0adb5b1cc4b91285b0bf77b4b0aa2d45 100644 --- a/libwccl/ops/nor.h +++ b/libwccl/ops/nor.h @@ -17,6 +17,13 @@ public: { } + /** + * @returns Name of the function: "not" + */ + std::string raw_name() const { + return "not"; + } + protected : /** * "Nor" (aka "not") predicate evaluates expressions one by one in order @@ -24,9 +31,8 @@ protected : * to True is found. * If all of the expressions were False, True is returned. */ - virtual BaseRetValPtr apply_internal(const FunExecContext&) const; + BaseRetValPtr apply_internal(const FunExecContext&) const; - virtual const std::string raw_operator_name() const; }; } /* end ns Wccl */ diff --git a/libwccl/ops/or.cpp b/libwccl/ops/or.cpp index af3d03e22e1679d9875540d171496f5ead2da836..24ce20197f28147ee75297f10d22a00b6d44fb3e 100644 --- a/libwccl/ops/or.cpp +++ b/libwccl/ops/or.cpp @@ -14,8 +14,4 @@ Or::BaseRetValPtr Or::apply_internal(const FunExecContext& context) const return Predicate::False(context); } -const std::string Or::raw_operator_name() const { - return "or"; -} - } /* end ns Wccl */ diff --git a/libwccl/ops/or.h b/libwccl/ops/or.h index 22b359748b2d620e2f146e596709386bdd9f61dc..0a60d69b0fdbcf1a641887831ac47613bd559809 100644 --- a/libwccl/ops/or.h +++ b/libwccl/ops/or.h @@ -16,15 +16,20 @@ public: { } + /** + * @returns Name of the function: "or" + */ + std::string raw_name() const { + return "or"; + } protected : /** * "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 FunExecContext&) const; + BaseRetValPtr apply_internal(const FunExecContext&) const; - virtual const std::string raw_operator_name() const; }; } /* end ns Wccl */ diff --git a/libwccl/ops/regex.cpp b/libwccl/ops/regex.cpp index c059324c40964ca801cb849aab2f54bdeac6d456..1d0ac3679f73926de025ed1ad04c6d7db9c08257 100644 --- a/libwccl/ops/regex.cpp +++ b/libwccl/ops/regex.cpp @@ -60,14 +60,14 @@ Regex::Regex(const Regex::StrSetFunctionPtr &strset_expr, const UnicodeString &p std::string Regex::to_string(const Corpus2::Tagset& tagset) const { std::stringstream ss; - ss << operator_name(tagset) << "(" << strset_expr_->to_string(tagset) + ss << name(tagset) << "(" << strset_expr_->to_string(tagset) << ", \"" << PwrNlp::to_utf8(patstr_) << "\")"; //TODO: utf escaping? return ss.str(); } std::string Regex::to_raw_string() const { std::stringstream ss; - ss << raw_operator_name() << "(" << strset_expr_->to_raw_string() + ss << raw_name() << "(" << strset_expr_->to_raw_string() << ", \"" << PwrNlp::to_utf8(patstr_) << "\")"; //TODO: utf escaping? return ss.str(); } diff --git a/libwccl/ops/regex.h b/libwccl/ops/regex.h index 7c87cf90628aa446b7ea71562abdab5f4fc7cf7f..1c738c15314a206a5f1b558374f9572e8600a4e2 100644 --- a/libwccl/ops/regex.h +++ b/libwccl/ops/regex.h @@ -21,20 +21,23 @@ public: Regex(const StrSetFunctionPtr& strset_expr, const UnicodeString& patstr); /** - * String representation of the operator in form of: + * @returns String representation of the function in form of: * "regex(strset_expr_string, regex_string)" */ - virtual std::string to_string(const Corpus2::Tagset& tagset) const; + std::string to_string(const Corpus2::Tagset& tagset) const; /** - * String representation of conditional operator in form of: + * @returns String representation of the function in form of: * "regex(strset_expr_raw_string, regex_string)" - * This version does not require tagset, but may be inclomplete + * @note This version does not require a tagset, but may be inclomplete * and/or contain internal info. */ - virtual std::string to_raw_string() const; + std::string to_raw_string() const; - virtual const std::string raw_operator_name() const { + /** + * @returns Name of the function: "regex" + */ + std::string raw_name() const { return "regex"; } @@ -45,7 +48,7 @@ protected: * return false if a string not matching expression is found. * Return true if all strings matched the regular espression. */ - virtual BaseRetValPtr apply_internal(const FunExecContext& context) const; + BaseRetValPtr apply_internal(const FunExecContext& context) const; private: const StrSetFunctionPtr strset_expr_; diff --git a/libwccl/ops/relativeposition.h b/libwccl/ops/relativeposition.h index 2fb9961b4bf416a0784bb441a44eef0bcdf9dc11..dc27cae15f0601b90cc2680fd2d4e693a5fdbd2b 100644 --- a/libwccl/ops/relativeposition.h +++ b/libwccl/ops/relativeposition.h @@ -22,12 +22,22 @@ public: BOOST_ASSERT(pos_expr_); } - virtual std::string to_string(const Corpus2::Tagset& tagset) const; - - virtual std::string to_raw_string() const; + /** + * @returns String representation of the function in the form of: + * "arg_expr_string [+-] offset" + */ + std::string to_string(const Corpus2::Tagset& tagset) const; + /** + * @returns String representation of the function in the form of: + * "arg_expr_raw_string [+-] offset" + */ + std::string to_raw_string() const; - virtual const std::string raw_operator_name() const { - return "+"; + /** + * @returns Name of the function: "relpos" + */ + std::string raw_name() const { + return "relpos"; } protected: @@ -49,7 +59,7 @@ protected: * @returns Position that is shifted by the represented offset relative * to the Position being passed as argument to Operator. */ - virtual BaseRetValPtr apply_internal(const FunExecContext& context) const; + BaseRetValPtr apply_internal(const FunExecContext& context) const; }; } /* end ns Wccl */ diff --git a/libwccl/ops/setpredicate.h b/libwccl/ops/setpredicate.h index c8e0ca92ccab482abef7d936a332c03d068ac4b8..8886b5b0e2b59cf48a3a21bf83733d43ff95160c 100644 --- a/libwccl/ops/setpredicate.h +++ b/libwccl/ops/setpredicate.h @@ -27,11 +27,21 @@ public: BOOST_ASSERT(set2_expr_); } - virtual std::string to_string(const Corpus2::Tagset& tagset) const { + /** + * @returns String representation of the function in form of: + * "name_string(arg1_expr_string, arg2_expr_string)" + */ + std::string to_string(const Corpus2::Tagset& tagset) const { return BinaryFunctionFormatter::to_string(tagset, *this, *set1_expr_, *set2_expr_); } - virtual std::string to_raw_string() const { + /** + * @returns String representation of the function in form of: + * "raw_name_string(arg1_expr_raw_string, arg2_expr_raw_string)" + * @note This version does not require a tagset, but may be inclomplete + * and/or contain internal info. + */ + std::string to_raw_string() const { return BinaryFunctionFormatter::to_raw_string(*this, *set1_expr_, *set2_expr_); } diff --git a/libwccl/ops/tolower.h b/libwccl/ops/tolower.h index 6f7bd305dc807b0a31fedac153ddd430aa2781fe..28175f10b53cddc98c8ae0d17b678ec2a2e17bb3 100644 --- a/libwccl/ops/tolower.h +++ b/libwccl/ops/tolower.h @@ -21,20 +21,23 @@ public: } /** - * String representation of the operator in form of: + * @returns String representation of the function in the form of: * "lower(strset_expr_string)" */ - virtual std::string to_string(const Corpus2::Tagset& tagset) const; + std::string to_string(const Corpus2::Tagset& tagset) const; /** - * String representation of conditional operator in form of: + * @returns String representation of the function in the form of: * "lower(strset_expr_raw_string)" - * This version does not require tagset, but may be inclomplete + * @note This version does not require tagset, but may be inclomplete * and/or contain internal info. */ - virtual std::string to_raw_string() const; + std::string to_raw_string() const; - virtual const std::string raw_operator_name() const { + /** + * @returns Name of the function: "lower" + */ + std::string raw_name() const { return "lower"; } @@ -45,7 +48,7 @@ protected: * 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 FunExecContext& context) const; + BaseRetValPtr apply_internal(const FunExecContext& context) const; }; } /* end ns Wccl */ diff --git a/libwccl/ops/toupper.h b/libwccl/ops/toupper.h index c3414d3c1bfe548aad67e2f6bf58f7a9d1f8c454..e550e5474d2c45c62e571ed6c9dd9949e31ab0ab 100644 --- a/libwccl/ops/toupper.h +++ b/libwccl/ops/toupper.h @@ -21,23 +21,25 @@ public: } /** - * String representation of the operator in form of: + * @returns String representation of the function in the form of: * "upper(strset_expr_string)" */ - virtual std::string to_string(const Corpus2::Tagset& tagset) const; + std::string to_string(const Corpus2::Tagset& tagset) const; /** - * String representation of conditional operator in form of: + * @returns String representation of the function in the form of: * "upper(strset_expr_raw_string)" - * This version does not require tagset, but may be inclomplete + * @note This version does not require tagset, but may be inclomplete * and/or contain internal info. */ - virtual std::string to_raw_string() const; + std::string to_raw_string() const; - virtual const std::string raw_operator_name() const { + /** + * @returns Name of the function: "upper" + */ + std::string raw_name() const { return "upper"; } - protected: const StrSetFunctionPtr strset_expr_; @@ -45,7 +47,7 @@ protected: * 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 FunExecContext& context) const; + BaseRetValPtr apply_internal(const FunExecContext& context) const; }; } /* end ns Wccl */ diff --git a/libwccl/ops/vargetter.h b/libwccl/ops/vargetter.h index 922408635f1daed7b8332d97761ec710185c81b9..d6f07ecc479f409e2418679c32379859a154c061 100644 --- a/libwccl/ops/vargetter.h +++ b/libwccl/ops/vargetter.h @@ -5,7 +5,6 @@ namespace Wccl { - /** * Operator that returns value of a variable of given type T */ @@ -18,18 +17,17 @@ public: } /** - * @returns Operator name for variable getter, we assume "$", although real - * string representation depends on given Value's var_repr function + * @returns Function name for variable getter: "getvar" */ - virtual const std::string raw_operator_name() const { - return "$"; + std::string raw_name() const { + return "getvar"; } /** * @returns String representation of the variable getter which is * equal to string representation of the underlying variable. */ - virtual std::string to_raw_string() const { + std::string to_raw_string() const { return T::var_repr(var_acc_.get_name()); } @@ -37,15 +35,16 @@ public: * @returns String representation of the variable getter which is * equal to string representation of the underlying variable. */ - virtual std::string to_string(const Corpus2::Tagset&) const { + std::string to_string(const Corpus2::Tagset&) const { return T::var_repr(var_acc_.get_name()); } + protected: typedef FunctionBase::BaseRetValPtr BaseRetValPtr; /** * Return value held by the underlying variable. */ - virtual BaseRetValPtr apply_internal(const FunExecContext& context) const { + BaseRetValPtr apply_internal(const FunExecContext& context) const { return context.variables()->get_fast(var_acc_); } diff --git a/libwccl/ops/varsetter.h b/libwccl/ops/varsetter.h index 0dcbbcecaf6479548e5f7322d8094673b703d2c0..4bfbdc901ae2c3697e3efa970a42227325be608b 100644 --- a/libwccl/ops/varsetter.h +++ b/libwccl/ops/varsetter.h @@ -23,17 +23,19 @@ public: } /** - * @returns Operator name for variable setter, "setvar" + * @returns Function name for variable setter: "setvar" */ - virtual const std::string raw_operator_name() const { + std::string raw_name() const { return "setvar"; } /** * @returns String representation of the variable setter which is * setvar(var_repr, arg_expr_str) + * @note This version does not require a tagset, but may be incomplete + * and/or contain internal info. */ - virtual std::string to_raw_string() const { + std::string to_raw_string() const { return BinaryFunctionFormatter::to_raw_string( *this, T::var_repr(var_acc_.get_name()), @@ -44,7 +46,7 @@ public: * @returns String representation of the variable setter which is * setvar(var_repr, arg_raw_expr_str) */ - virtual std::string to_string(const Corpus2::Tagset& tagset) const { + std::string to_string(const Corpus2::Tagset& tagset) const { return BinaryFunctionFormatter::to_string( tagset, *this, @@ -56,7 +58,7 @@ protected: * Evaluate argument expression and assign the result to underlying variable. * @returns True. */ - virtual BaseRetValPtr apply_internal(const FunExecContext& context) const { + BaseRetValPtr apply_internal(const FunExecContext& context) const { context.variables()->get_fast(var_acc_)->set_value( arg_expr_->apply(context)->get_value()); return Predicate::True(context); diff --git a/tests/conditional.cpp b/tests/conditional.cpp index cfa78ab32f504c9853c03f3d9c9f9ed667b53a17..e6e5d55b036601ffb1501919739bab303c23d3e4 100644 --- a/tests/conditional.cpp +++ b/tests/conditional.cpp @@ -119,7 +119,7 @@ BOOST_FIXTURE_TEST_CASE(cond_to_string, CondFixStrSet) true_constant, empty_strset_expr, one_elem_strset_expr)); - std::string expected = "if True then [] else [\"oNe\"]"; + std::string expected = "if(True, [], [\"oNe\"])"; BOOST_CHECK_EQUAL(expected, cond->to_string(tagset)); } @@ -128,7 +128,7 @@ BOOST_FIXTURE_TEST_CASE(cond_to_string_raw, CondFixStrSet) boost::shared_ptr<Conditional<StrSet> > cond(new Conditional<StrSet>( true_constant, one_elem_strset_expr)); - std::string expected = "if True then [\"oNe\"] else []"; + std::string expected = "if(True, [\"oNe\"], [])"; BOOST_CHECK_EQUAL(expected, cond->to_string(tagset)); }