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

Move check for Position in SentenceContext to the context.

It is coherent now with the SentenceContext::is_inside(int abs_pos)
- SentenceContext::is_inside(Position pos) is added, while
Position::is_inside(SentenceContext) is removed
parent 82651c7b
Branches
No related merge requests found
......@@ -6,7 +6,7 @@ namespace Wccl {
IsInside::BaseRetValPtr IsInside::apply_internal(const FunExecContext& context) const
{
const boost::shared_ptr<const Position>& pos = pos_expr_->apply(context);
return Predicate::evaluate(pos->is_inside(context.sentence_context()), context);
return Predicate::evaluate(context.sentence_context().is_inside(*pos), context);
}
std::string IsInside::to_string(const Corpus2::Tagset& tagset) const
......
......@@ -6,7 +6,7 @@ namespace Wccl {
IsOutside::BaseRetValPtr IsOutside::apply_internal(const FunExecContext& context) const
{
const boost::shared_ptr<const Position>& pos = pos_expr_->apply(context);
return Predicate::evaluate(pos->is_outside(context.sentence_context()), context);
return Predicate::evaluate(context.sentence_context().is_outside(*pos), context);
}
std::string IsOutside::to_string(const Corpus2::Tagset& tagset) const
......
......@@ -26,11 +26,11 @@ PointAgreement::BaseRetValPtr PointAgreement::apply_internal(const FunExecContex
const SentenceContext& sc = context.sentence_context();
const boost::shared_ptr<const Position>& pos1 = pos1_expr_->apply(context);
if (pos1->is_outside(sc)) {
if (sc.is_outside(*pos1)) {
return Predicate::False(context);
}
const boost::shared_ptr<const Position>& pos2 = pos2_expr_->apply(context);
if (pos2->is_outside(sc)) {
if (sc.is_outside(*pos2)) {
return Predicate::False(context);
}
......
......@@ -18,7 +18,7 @@ GetLemmas::BaseRetValPtr GetLemmas::apply_internal(const FunExecContext& context
{
const boost::shared_ptr<const Position>& pos = pos_expr_->apply(context);
const SentenceContext& sc = context.sentence_context();
if(pos->is_outside(sc)) {
if (sc.is_outside(*pos)) {
return detail::DefaultFunction<StrSet>()->apply(context);
}
boost::shared_ptr<StrSet> u_set = boost::make_shared<StrSet>();
......
......@@ -18,7 +18,7 @@ GetOrth::BaseRetValPtr GetOrth::apply_internal(const FunExecContext& context) co
{
const boost::shared_ptr<const Position>& pos = pos_expr_->apply(context);
const SentenceContext& sc = context.sentence_context();
if(pos->is_outside(sc)) {
if (sc.is_outside(*pos)) {
return detail::DefaultFunction<StrSet>()->apply(context);
}
boost::shared_ptr<StrSet> u_set = boost::make_shared<StrSet>();
......
......@@ -25,7 +25,7 @@ CatFilter::BaseRetValPtr CatFilter::apply_internal(const FunExecContext& context
{
const boost::shared_ptr<const Position>& pos = pos_expr_->apply(context);
const SentenceContext& sc = context.sentence_context();
if (pos->is_outside(sc)) {
if (sc.is_outside(*pos)) {
return detail::DefaultFunction<TSet>()->apply(context);
}
......
......@@ -28,7 +28,7 @@ GetSymbols::BaseRetValPtr GetSymbols::apply_internal(const FunExecContext& conte
{
const boost::shared_ptr<const Position>& pos = pos_expr_->apply(context);
const SentenceContext& sc = context.sentence_context();
if(pos->is_outside(sc)) {
if(sc.is_outside(*pos)) {
return detail::DefaultFunction<TSet>()->apply(context);
}
......
......@@ -57,6 +57,21 @@ public:
return abs_pos >= 0 && abs_pos < size();
}
/// Checks if the the given position is valid (in sentence bounds)
bool is_inside(const Position& pos) const {
return is_inside(get_abs_position(pos));
}
/// Checks if the the given absolute position is outside sentence, including nowhere
bool is_outside(int abs_pos) const {
return !is_inside(abs_pos);
}
/// Checks if the the given position is outside sentence, including nowhere
bool is_outside(const Position& pos) const {
return !is_inside(get_abs_position(pos));
}
/// Position setter
void set_position(int new_position) {
position_ = new_position;
......
......@@ -27,12 +27,6 @@ std::string Position::var_repr(const std::string &var_name)
return ss.str();
}
bool Position::is_inside(const SentenceContext& context) const
{
int abs_position = context.get_abs_position(*this);
return context.is_inside(abs_position);
}
bool Position::equals(const Position& other, const SentenceContext& context) const
{
return context.get_abs_position(*this) == context.get_abs_position(other);
......
......@@ -48,17 +48,6 @@ public:
/// Value override
std::string to_raw_string() const;
/**
* @returns True if Position is within bounds of a sentence, false otherwise.
*/
bool is_inside(const SentenceContext& context) const;
/**
* @returns True if Position is outside of bounds of a sentence, false otherwise.
*/
bool is_outside(const SentenceContext& context) const {
return !is_inside(context);
}
/**
* @returns True if underlying position values are equal, false otherwise.
* @note This version does not take into account sentence context, only
......
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