Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#include <libwccl/ops/relativeposition.h>
#include <sstream>
#include <libwccl/ops/constant.h>
namespace Wccl {
RelativePosition::BaseRetValPtr RelativePosition::apply_internal(
const FunExecContext &context) const
{
static const Constant<Position> nowhere((Position(Position::Nowhere)));
const RetValPtr& orig_pos = pos_expr_->apply(context);
if(orig_pos->get_value() == Position::Nowhere) {
return nowhere.apply(context);
}
const SentenceContext& sc = context.sentence_context();
return RetValPtr(new Position(offset_ + sc.get_rel_position(*orig_pos)));
}
std::string RelativePosition::to_string(const Corpus2::Tagset &tagset) const
{
std::stringstream ss;
ss << pos_expr_->to_string(tagset);
if(offset_ >= 0) {
ss << " + " << offset_;
} else {
ss << " - " << -offset_;
}
return ss.str();
}
std::string RelativePosition::to_raw_string() const
{
std::stringstream ss;
ss << pos_expr_->to_raw_string();
if(offset_ >= 0) {
ss << " + " << offset_;
} else {
ss << " - " << -offset_;
}
return ss.str();
}
} /* end ns Wccl */