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

Add some extra formatting functions

parent 1bd51e39
Branches
No related merge requests found
......@@ -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();
}
......
......@@ -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 */
......
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