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

Use DefaultFunction in RelativePosition

- since the default value for Position is Nowhere now.
Also, remove reduntant header and change stream to ostream in to_strings
parent 94996f92
Branches
No related merge requests found
...@@ -7,10 +7,9 @@ namespace Wccl { ...@@ -7,10 +7,9 @@ namespace Wccl {
RelativePosition::BaseRetValPtr RelativePosition::apply_internal( RelativePosition::BaseRetValPtr RelativePosition::apply_internal(
const FunExecContext &context) const const FunExecContext &context) const
{ {
static const Constant<Position> nowhere((Position(Position::Nowhere)));
const RetValPtr& orig_pos = pos_expr_->apply(context); const RetValPtr& orig_pos = pos_expr_->apply(context);
if(orig_pos->get_value() == Position::Nowhere) { if(orig_pos->get_value() == Position::Nowhere) {
return nowhere.apply(context); return detail::DefaultFunction<Position>()->apply(context);
} }
const SentenceContext& sc = context.sentence_context(); const SentenceContext& sc = context.sentence_context();
return RetValPtr(new Position(offset_ + sc.get_rel_position(*orig_pos))); return RetValPtr(new Position(offset_ + sc.get_rel_position(*orig_pos)));
...@@ -18,7 +17,7 @@ RelativePosition::BaseRetValPtr RelativePosition::apply_internal( ...@@ -18,7 +17,7 @@ RelativePosition::BaseRetValPtr RelativePosition::apply_internal(
std::string RelativePosition::to_string(const Corpus2::Tagset &tagset) const std::string RelativePosition::to_string(const Corpus2::Tagset &tagset) const
{ {
std::stringstream ss; std::ostringstream ss;
ss << pos_expr_->to_string(tagset); ss << pos_expr_->to_string(tagset);
if(offset_ >= 0) { if(offset_ >= 0) {
ss << " + " << offset_; ss << " + " << offset_;
...@@ -30,7 +29,7 @@ std::string RelativePosition::to_string(const Corpus2::Tagset &tagset) const ...@@ -30,7 +29,7 @@ std::string RelativePosition::to_string(const Corpus2::Tagset &tagset) const
std::string RelativePosition::to_raw_string() const std::string RelativePosition::to_raw_string() const
{ {
std::stringstream ss; std::ostringstream ss;
ss << pos_expr_->to_raw_string(); ss << pos_expr_->to_raw_string();
if(offset_ >= 0) { if(offset_ >= 0) {
ss << " + " << offset_; ss << " + " << offset_;
......
...@@ -2,7 +2,6 @@ ...@@ -2,7 +2,6 @@
#define LIBWCCL_OPS_FUNCTIONS_POSITION_RELATIVEPOSITION_H #define LIBWCCL_OPS_FUNCTIONS_POSITION_RELATIVEPOSITION_H
#include <libwccl/ops/function.h> #include <libwccl/ops/function.h>
#include <libwccl/ops/formatters.h>
#include <libwccl/values/position.h> #include <libwccl/values/position.h>
namespace Wccl { namespace 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