From 9ad17870c92398cd9a789d9b596ad8fe6d5a31aa Mon Sep 17 00:00:00 2001 From: Adam Wardynski <award@.(win7-laptop)> Date: Thu, 18 Nov 2010 22:50:19 +0100 Subject: [PATCH] Add some extra formatting functions --- libwccl/ops/formatters.cpp | 24 ++--- libwccl/ops/formatters.h | 191 ++++++++++++++++++++++++++++++++----- 2 files changed, 178 insertions(+), 37 deletions(-) diff --git a/libwccl/ops/formatters.cpp b/libwccl/ops/formatters.cpp index 2b6daca..a9bb0cf 100644 --- a/libwccl/ops/formatters.cpp +++ b/libwccl/ops/formatters.cpp @@ -7,26 +7,24 @@ namespace Wccl { std::string UnaryFunctionFormatter::to_raw_string( const FunctionBase& f, - const FunctionBase& arg_expr, + const std::string& arg_str, const char* open_bracket, const char* close_bracket) { std::stringstream ss; - ss << f.raw_operator_name() << open_bracket << arg_expr.to_raw_string() - << close_bracket; + ss << f.raw_operator_name() << open_bracket << arg_str << close_bracket; return ss.str(); } std::string UnaryFunctionFormatter::to_string( const Corpus2::Tagset& tagset, const FunctionBase& f, - const FunctionBase& arg_expr, + const std::string& arg_str, const char* open_bracket, const char* close_bracket) { std::stringstream ss; - ss << f.operator_name(tagset) << open_bracket << arg_expr.to_string(tagset) - << close_bracket; + ss << f.operator_name(tagset) << open_bracket << arg_str << close_bracket; return ss.str(); } @@ -35,23 +33,21 @@ std::string UnaryFunctionFormatter::to_string( std::string BinaryFunctionFormatter::to_string( const Corpus2::Tagset& tagset, const FunctionBase& f, - const FunctionBase& arg1_expr, - const FunctionBase& arg2_expr) + const std::string& arg1_str, + const std::string& arg2_str) { std::stringstream ss; - ss << f.operator_name(tagset) << "(" << arg1_expr.to_string(tagset) - << ", " << arg2_expr.to_string(tagset) << ")"; + ss << f.operator_name(tagset) << "(" << arg1_str << ", " << arg2_str << ")"; return ss.str(); } std::string BinaryFunctionFormatter::to_raw_string( const FunctionBase& f, - const FunctionBase& arg1_expr, - const FunctionBase& arg2_expr) + const std::string& arg1_str, + const std::string& arg2_str) { std::stringstream ss; - ss << f.raw_operator_name() << "(" << arg1_expr.to_raw_string() - << ", " << arg2_expr.to_raw_string() << ")"; + ss << f.raw_operator_name() << "(" << arg1_str << ", " << arg2_str << ")"; return ss.str(); } diff --git a/libwccl/ops/formatters.h b/libwccl/ops/formatters.h index 985ef6f..21cd119 100644 --- a/libwccl/ops/formatters.h +++ b/libwccl/ops/formatters.h @@ -10,33 +10,74 @@ namespace Wccl { */ struct UnaryFunctionFormatter { - /** - * String representation of an unary function. + /** + * @returns String representation of an unary function. + * It is in form of + * operator_name(arg_str) + * although the open and close brackets can be changed + * (some operators use []) + */ + static std::string to_string( + const Corpus2::Tagset& tagset, + const FunctionBase& f, + const std::string& arg_str, + const char* open_bracket = "(", + const char* close_bracket = ")"); + + /** + * @returns String representation of an unary function. * It is in form of - * operator_name(argument_expression_string) - * although the open and close brackets can be changed - * (some operators use []) - */ + * operator_name(argument_expression_string) + * although the open and close brackets can be changed + * (some operators use []) + */ static std::string to_string( const Corpus2::Tagset& tagset, const FunctionBase& f, const FunctionBase& arg_expr, const char* open_bracket = "(", + const char* close_bracket = ")") + { + return to_string( + tagset, + f, + arg_expr.to_string(tagset), + open_bracket, close_bracket); + } + /** + * @returns Raw string representation of an unary function. + * Does not require tagset, may contain internal info + * and/or be incomplete. It is in form of + * raw_operator_name(arg_str) + * although the open and close brackets can be changed + * (some operators use []) + */ + static std::string to_raw_string( + const FunctionBase& f, + const std::string& arg_str, + const char* open_bracket = "(", const char* close_bracket = ")"); - /** - * Raw string representation of an unary function. + /** + * @returns Raw string representation of an unary function. * Does not require tagset, may contain internal info * and/or be incomplete. It is in form of - * raw_operator_name(raw_argument_expression_string) - * although the open and close brackets can be changed - * (some operators use []) - */ + * raw_operator_name(raw_argument_expression_string) + * although the open and close brackets can be changed + * (some operators use []) + */ static std::string to_raw_string( const FunctionBase& f, const FunctionBase& arg_expr, const char* open_bracket = "(", - const char* close_bracket = ")"); + const char* close_bracket = ")") + { + return to_raw_string( + f, + arg_expr.to_raw_string(), + open_bracket, + close_bracket); + } }; /** @@ -44,27 +85,131 @@ struct UnaryFunctionFormatter */ struct BinaryFunctionFormatter { - /** - * String representation of a binary function. + /** + * @returns String representation of a binary function. + * It is in form of + * operator_name(arg1_str, arg2_str) + */ + static std::string to_string( + const Corpus2::Tagset& tagset, + const FunctionBase& f, + const std::string& arg1_str, + const std::string& arg2_str); + + /** + * @returns String representation of a binary function. * It is in form of - * operator_name(arg1_expr_string, arg2_expr_string) - */ + * operator_name(arg1_str, arg2_expr_string) + */ static std::string to_string( const Corpus2::Tagset& tagset, + const FunctionBase& f, + const std::string& arg1_str, + const FunctionBase& arg2_expr) + { + return to_string( + tagset, + f, + arg1_str, + arg2_expr.to_string(tagset)); + } + /** + * @returns String representation of a binary function. + * It is in form of + * operator_name(arg1_expr_string, arg2_str) + */ + static std::string to_string( + const Corpus2::Tagset& tagset, + const FunctionBase& f, + const FunctionBase& arg1_expr, + const std::string& arg2_str) + { + return to_string( + tagset, + f, + arg1_expr.to_string(tagset), + arg2_str); + } + + /** + * @returns String representation of a binary function. + * It is in form of + * operator_name(arg1_expr_string, arg2_expr_string) + */ + static std::string to_string( + const Corpus2::Tagset& tagset, + const FunctionBase& f, + const FunctionBase& arg1_expr, + const FunctionBase& arg2_expr) + { + return to_string( + tagset, + f, + arg1_expr.to_string(tagset), + arg2_expr.to_string(tagset)); + } + + /** + * @returns Raw string representation of a binary function. + * Does not require tagset, may contain internal info + * and/or be incomplete. It is in form of + * raw_op_name(arg1_str, arg2_str) + */ + static std::string to_raw_string( + const FunctionBase& f, + const std::string& arg1_str, + const std::string& arg2_str); + + /** + * @returns Raw string representation of a binary function. + * Does not require tagset, may contain internal info + * and/or be incomplete. It is in form of + * raw_op_name(arg1_str, raw_arg2_expr_string) + */ + static std::string to_raw_string( + const FunctionBase& f, + const std::string& arg1_str, + const FunctionBase& arg2_expr) + { + return to_raw_string( + f, + arg1_str, + arg2_expr.to_raw_string()); + } + + /** + * @returns Raw string representation of a binary function. + * Does not require tagset, may contain internal info + * and/or be incomplete. It is in form of + * raw_op_name(raw_arg1_expr_string, arg1_str) + */ + static std::string to_raw_string( const FunctionBase& f, const FunctionBase& arg1_expr, - const FunctionBase& arg2_expr); + const std::string& arg2_str) + { + return to_raw_string( + f, + arg1_expr.to_raw_string(), + arg2_str); + } - /** - * Raw string representation of a binary function. + /** + * @returns Raw string representation of a binary function. * Does not require tagset, may contain internal info * and/or be incomplete. It is in form of - * raw_op_name(raw_arg1_expr_string, raw_arg2_expr_string) - */ + * raw_op_name(raw_arg1_expr_string, raw_arg2_expr_string) + */ static std::string to_raw_string( const FunctionBase& f, const FunctionBase& arg1_expr, - const FunctionBase& arg2_expr); + const FunctionBase& arg2_expr) + { + return to_raw_string( + f, + arg1_expr.to_raw_string(), + arg2_expr.to_raw_string()); + } }; } /* end ns Wccl */ -- GitLab