diff --git a/libwccl/ops/functions/bool/predicates/isinside.cpp b/libwccl/ops/functions/bool/predicates/isinside.cpp index a525d0bd03322e96bde0dd2021955b9cb6b298ae..a4a593a90c1816fed738e0b164d22fcce5694052 100644 --- a/libwccl/ops/functions/bool/predicates/isinside.cpp +++ b/libwccl/ops/functions/bool/predicates/isinside.cpp @@ -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 diff --git a/libwccl/ops/functions/bool/predicates/isoutside.cpp b/libwccl/ops/functions/bool/predicates/isoutside.cpp index d6228a667f5878c35712b5a0d4bb2edf62362310..5f6389e3086d244c3fb9cb89a5d067edbb2090f6 100644 --- a/libwccl/ops/functions/bool/predicates/isoutside.cpp +++ b/libwccl/ops/functions/bool/predicates/isoutside.cpp @@ -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 diff --git a/libwccl/ops/functions/bool/predicates/pointagreement.cpp b/libwccl/ops/functions/bool/predicates/pointagreement.cpp index 8395083a564f092ba40acb392471041591613a0a..6104f5e754c02cdcd1c5fd6e6b3b1053a8b8ede2 100644 --- a/libwccl/ops/functions/bool/predicates/pointagreement.cpp +++ b/libwccl/ops/functions/bool/predicates/pointagreement.cpp @@ -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); } diff --git a/libwccl/ops/functions/strset/getlemmas.cpp b/libwccl/ops/functions/strset/getlemmas.cpp index a1e9cbec7a7c258d9dbbde5f2a4bd77008a796f7..51539438b050b2aac67c558bc925b2aae7b756d2 100644 --- a/libwccl/ops/functions/strset/getlemmas.cpp +++ b/libwccl/ops/functions/strset/getlemmas.cpp @@ -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>(); diff --git a/libwccl/ops/functions/strset/getorth.cpp b/libwccl/ops/functions/strset/getorth.cpp index 0fd96ea9df44a06289beda7e6b9b0d117d802421..33371c4e4e9e77ab045d9fc17645f8f04a24f75e 100644 --- a/libwccl/ops/functions/strset/getorth.cpp +++ b/libwccl/ops/functions/strset/getorth.cpp @@ -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>(); diff --git a/libwccl/ops/functions/tset/catfilter.cpp b/libwccl/ops/functions/tset/catfilter.cpp index d16faefc3dfc87132161e905d80fb253cbf8ba77..b5e1b24e94c1f6d78a0509ad12a9d62d07bca493 100644 --- a/libwccl/ops/functions/tset/catfilter.cpp +++ b/libwccl/ops/functions/tset/catfilter.cpp @@ -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); } diff --git a/libwccl/ops/functions/tset/getsymbols.cpp b/libwccl/ops/functions/tset/getsymbols.cpp index 4e4a37659ad0c402ff57902d8af2817028a62adb..d23f6ec3140f6b5972a5f7282bd1ce0cb32c2e88 100644 --- a/libwccl/ops/functions/tset/getsymbols.cpp +++ b/libwccl/ops/functions/tset/getsymbols.cpp @@ -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); } diff --git a/libwccl/sentencecontext.h b/libwccl/sentencecontext.h index 7451d78c17bacf179c454ae02af0906a1a5028f5..1fecb3f84739e3424090afcb684f66d5c7ee2440 100644 --- a/libwccl/sentencecontext.h +++ b/libwccl/sentencecontext.h @@ -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; diff --git a/libwccl/values/position.cpp b/libwccl/values/position.cpp index 8b816c0c9ded32138cf6e925a241cfafc66cb171..41a5abaa7a1546941e55f0e5f4fd7acc99465a28 100644 --- a/libwccl/values/position.cpp +++ b/libwccl/values/position.cpp @@ -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); diff --git a/libwccl/values/position.h b/libwccl/values/position.h index 43984feb87455650376b389c9bb3c71007a5dd35..943f2805931d5c3f402655c755020e03ad71a222 100644 --- a/libwccl/values/position.h +++ b/libwccl/values/position.h @@ -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