Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
W
WCCL
Manage
Activity
Members
Labels
Plan
Issues
4
Issue boards
Milestones
Wiki
Redmine
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Analysers
WCCL
Commits
df485eda
Commit
df485eda
authored
14 years ago
by
Adam Wardynski
Browse files
Options
Downloads
Patches
Plain Diff
IsOutside, checks if Position is outside of a Sentence in given context
parent
171bb5b2
Branches
Branches containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
libwccl/ops/isoutside.h
+54
-0
54 additions, 0 deletions
libwccl/ops/isoutside.h
tests/positionpredicates.cpp
+50
-0
50 additions, 0 deletions
tests/positionpredicates.cpp
with
104 additions
and
0 deletions
libwccl/ops/isoutside.h
0 → 100644
+
54
−
0
View file @
df485eda
#ifndef LIBWCCL_OPS_ISOUTSIDE_H
#define LIBWCCL_OPS_ISOUTSIDE_H
#include
<libwccl/ops/predicate.h>
#include
<libwccl/ops/formatters.h>
#include
<libwccl/values/position.h>
namespace
Wccl
{
/**
* Predicate that checks if a position is outside of the sentence boundaries
*/
class
IsOutside
:
public
Predicate
{
public:
typedef
boost
::
shared_ptr
<
Function
<
Position
>
>
PosFunctionPtr
;
IsOutside
(
const
PosFunctionPtr
&
pos_expr
)
:
pos_expr_
(
pos_expr
)
{
BOOST_ASSERT
(
pos_expr_
);
}
virtual
std
::
string
to_string
(
const
Corpus2
::
Tagset
&
tagset
)
const
{
return
UnaryFunctionFormatter
::
to_string
(
tagset
,
*
this
,
*
pos_expr_
);
}
virtual
std
::
string
to_raw_string
()
const
{
return
UnaryFunctionFormatter
::
to_raw_string
(
*
this
,
*
pos_expr_
);
}
virtual
const
std
::
string
raw_operator_name
()
const
{
return
"outside"
;
}
protected
:
const
PosFunctionPtr
pos_expr_
;
/**
* Takes values of position from argument, and checks if it is outside of the
* sentence boundaries, in the given context (i.e. relative to current position)
* @returns True value if position is outside of the sentence boundaries, False otherwise.
*/
virtual
BaseRetValPtr
apply_internal
(
const
FunExecContext
&
context
)
const
{
const
boost
::
shared_ptr
<
const
Position
>&
pos
=
pos_expr_
->
apply
(
context
);
if
(
pos
->
is_outside
(
context
.
sentence_context
()))
{
return
Predicate
::
True
(
context
);
}
return
Predicate
::
False
(
context
);
}
};
}
/* end ns Wccl */
#endif // LIBWCCL_OPS_ISOUTSIDE_H
This diff is collapsed.
Click to expand it.
tests/positionpredicates.cpp
+
50
−
0
View file @
df485eda
...
...
@@ -5,6 +5,7 @@
#include
<libwccl/ops/constant.h>
#include
<libwccl/ops/isinside.h>
#include
<libwccl/ops/isoutside.h>
using
namespace
Wccl
;
...
...
@@ -96,6 +97,45 @@ BOOST_FIXTURE_TEST_CASE(is_inside_end, PosPredFix)
BOOST_CHECK
(
is_inside
.
apply
(
cx
)
->
get_value
());
}
BOOST_FIXTURE_TEST_CASE
(
is_outside_1
,
PosPredFix
)
{
IsOutside
is_outside
(
pos_one_constant
);
BOOST_CHECK
(
!
is_outside
.
apply
(
cx
)
->
get_value
());
sc
.
advance
();
BOOST_CHECK
(
is_outside
.
apply
(
cx
)
->
get_value
());
}
BOOST_FIXTURE_TEST_CASE
(
is_outside_minus1
,
PosPredFix
)
{
IsOutside
is_outside
(
pos_minus_one_constant
);
BOOST_CHECK
(
is_outside
.
apply
(
cx
)
->
get_value
());
sc
.
advance
();
BOOST_CHECK
(
!
is_outside
.
apply
(
cx
)
->
get_value
());
}
BOOST_FIXTURE_TEST_CASE
(
is_outside_nowhere
,
PosPredFix
)
{
IsOutside
is_outside
(
nowhere_constant
);
BOOST_CHECK
(
is_outside
.
apply
(
cx
)
->
get_value
());
sc
.
advance
();
BOOST_CHECK
(
is_outside
.
apply
(
cx
)
->
get_value
());
}
BOOST_FIXTURE_TEST_CASE
(
is_outside_begin
,
PosPredFix
)
{
IsOutside
is_outside
(
begin_constant
);
BOOST_CHECK
(
!
is_outside
.
apply
(
cx
)
->
get_value
());
sc
.
advance
();
BOOST_CHECK
(
!
is_outside
.
apply
(
cx
)
->
get_value
());
}
BOOST_FIXTURE_TEST_CASE
(
is_outside_end
,
PosPredFix
)
{
IsOutside
is_outside
(
end_constant
);
BOOST_CHECK
(
!
is_outside
.
apply
(
cx
)
->
get_value
());
sc
.
advance
();
BOOST_CHECK
(
!
is_outside
.
apply
(
cx
)
->
get_value
());
}
//------ to_string test cases -------
BOOST_FIXTURE_TEST_CASE
(
is_inside_to_string
,
PosPredFix
)
...
...
@@ -110,5 +150,15 @@ BOOST_FIXTURE_TEST_CASE(is_inside_to_raw_string, PosPredFix)
BOOST_CHECK_EQUAL
(
"inside(end)"
,
is_inside
.
to_raw_string
());
}
BOOST_FIXTURE_TEST_CASE
(
is_outside_to_string
,
PosPredFix
)
{
IsOutside
is_outside
(
begin_constant
);
BOOST_CHECK_EQUAL
(
"outside(begin)"
,
is_outside
.
to_string
(
tagset
));
}
BOOST_FIXTURE_TEST_CASE
(
is_outside_to_raw_string
,
PosPredFix
)
{
IsOutside
is_outside
(
nowhere_constant
);
BOOST_CHECK_EQUAL
(
"outside(nowhere)"
,
is_outside
.
to_raw_string
());
}
BOOST_AUTO_TEST_SUITE_END
()
This diff is collapsed.
Click to expand it.
Preview
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment