Skip to content
Snippets Groups Projects
Select Git revision
  • 85ec635b4bd6980ccfd6580ead46041751e22251
  • master default protected
  • fix-words-ann
  • wccl-rules-migration
  • develop
5 results

formatters.h

Blame
  • user avatar
    Adam Wardynski authored
    cee27d09
    History
    formatters.h 2.65 KiB
    #ifndef LIBWCCL_OPS_FORMATTERS_H
    #define LIBWCCL_OPS_FORMATTERS_H
    
    #include <libwccl/ops/function.h>
    
    namespace Wccl {
    
    /**
     * Class that formats unary functions as string
     */
    struct UnaryFunctionFormatter
    {
    	/** 
    	 * @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 [])
    	 */
    	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);
    	}
    };
    
    /**
     * Class that formats binary functions as string
     */
    struct BinaryFunctionFormatter
    {
    	/** 
    	 * @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_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));
    	}
    };
    
    } /* end ns Wccl */
    
    
    #endif // LIBWCCL_OPS_FORMATTERS_H