Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
W
WCCL
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Redmine
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Analysers
WCCL
Commits
171bb5b2
Commit
171bb5b2
authored
Nov 19, 2010
by
Adam Wardynski
Browse files
Options
Downloads
Patches
Plain Diff
IsInside, checks if position is within sentence in given context.
parent
1358e2fe
No related branches found
No related tags found
No related merge requests found
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
libwccl/ops/isinside.h
+54
-0
54 additions, 0 deletions
libwccl/ops/isinside.h
tests/CMakeLists.txt
+1
-0
1 addition, 0 deletions
tests/CMakeLists.txt
tests/positionpredicates.cpp
+114
-0
114 additions, 0 deletions
tests/positionpredicates.cpp
with
169 additions
and
0 deletions
libwccl/ops/isinside.h
0 → 100644
+
54
−
0
View file @
171bb5b2
#ifndef LIBWCCL_OPS_ISINSIDE_H
#define LIBWCCL_OPS_ISINSIDE_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 within sentence boundaries
*/
class
IsInside
:
public
Predicate
{
public:
typedef
boost
::
shared_ptr
<
Function
<
Position
>
>
PosFunctionPtr
;
IsInside
(
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
"inside"
;
}
protected
:
const
PosFunctionPtr
pos_expr_
;
/**
* Takes values of position from argument, and checks if it is inside sentence
* boundaries.
* @returns True value if position is within 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_inside
(
context
.
sentence_context
()))
{
return
Predicate
::
True
(
context
);
}
return
Predicate
::
False
(
context
);
}
};
}
/* end ns Wccl */
#endif // LIBWCCL_OPS_ISINSIDE_H
This diff is collapsed.
Click to expand it.
tests/CMakeLists.txt
+
1
−
0
View file @
171bb5b2
...
@@ -11,6 +11,7 @@ add_executable(tests
...
@@ -11,6 +11,7 @@ add_executable(tests
logicalpredicates.cpp
logicalpredicates.cpp
main.cpp
main.cpp
position.cpp
position.cpp
positionpredicates.cpp
regex.cpp
regex.cpp
strsetfunctions.cpp
strsetfunctions.cpp
values.cpp
values.cpp
...
...
This diff is collapsed.
Click to expand it.
tests/positionpredicates.cpp
0 → 100644
+
114
−
0
View file @
171bb5b2
#include
<boost/test/unit_test.hpp>
#include
<boost/bind.hpp>
#include
<boost/shared_ptr.hpp>
#include
<libcorpus2/sentence.h>
#include
<libwccl/ops/constant.h>
#include
<libwccl/ops/isinside.h>
using
namespace
Wccl
;
BOOST_AUTO_TEST_SUITE
(
position_predicates
)
struct
PosPredFix
{
PosPredFix
()
:
s
(
boost
::
make_shared
<
Corpus2
::
Sentence
>
()),
sc
(
s
),
tagset
(),
cx
(
sc
,
boost
::
make_shared
<
Variables
>
()),
pos_one
(
1
),
pos_minus_one
(
-
1
),
nowhere
(
Position
::
Nowhere
),
begin
(
Position
::
Begin
),
end
(
Position
::
End
),
pos_one_constant
(
new
Constant
<
Position
>
(
pos_one
)),
pos_minus_one_constant
(
new
Constant
<
Position
>
(
pos_minus_one
)),
nowhere_constant
(
new
Constant
<
Position
>
(
nowhere
)),
begin_constant
(
new
Constant
<
Position
>
(
begin
)),
end_constant
(
new
Constant
<
Position
>
(
end
))
{
Corpus2
::
Token
*
the_token
=
new
Corpus2
::
Token
(
"ZZ"
,
PwrNlp
::
Whitespace
::
ManySpaces
);
Corpus2
::
Tag
t1
(
Corpus2
::
mask_t
(
0
));
Corpus2
::
Lexeme
l1
(
"aaa"
,
t1
);
Corpus2
::
Lexeme
l2
(
"bbb"
,
t1
);
the_token
->
add_lexeme
(
l1
);
the_token
->
add_lexeme
(
l2
);
s
->
append
(
the_token
);
s
->
append
(
the_token
->
clone
());
}
boost
::
shared_ptr
<
Corpus2
::
Sentence
>
s
;
SentenceContext
sc
;
Corpus2
::
Tagset
tagset
;
FunExecContext
cx
;
Position
pos_one
;
Position
pos_minus_one
;
Position
nowhere
;
Position
begin
;
Position
end
;
boost
::
shared_ptr
<
Function
<
Position
>
>
pos_one_constant
;
boost
::
shared_ptr
<
Function
<
Position
>
>
pos_minus_one_constant
;
boost
::
shared_ptr
<
Function
<
Position
>
>
nowhere_constant
;
boost
::
shared_ptr
<
Function
<
Position
>
>
begin_constant
;
boost
::
shared_ptr
<
Function
<
Position
>
>
end_constant
;
};
BOOST_FIXTURE_TEST_CASE
(
is_inside_1
,
PosPredFix
)
{
IsInside
is_inside
(
pos_one_constant
);
BOOST_CHECK
(
is_inside
.
apply
(
cx
)
->
get_value
());
sc
.
advance
();
BOOST_CHECK
(
!
is_inside
.
apply
(
cx
)
->
get_value
());
}
BOOST_FIXTURE_TEST_CASE
(
is_inside_minus1
,
PosPredFix
)
{
IsInside
is_inside
(
pos_minus_one_constant
);
BOOST_CHECK
(
!
is_inside
.
apply
(
cx
)
->
get_value
());
sc
.
advance
();
BOOST_CHECK
(
is_inside
.
apply
(
cx
)
->
get_value
());
}
BOOST_FIXTURE_TEST_CASE
(
is_inside_nowhere
,
PosPredFix
)
{
IsInside
is_inside
(
nowhere_constant
);
BOOST_CHECK
(
!
is_inside
.
apply
(
cx
)
->
get_value
());
sc
.
advance
();
BOOST_CHECK
(
!
is_inside
.
apply
(
cx
)
->
get_value
());
}
BOOST_FIXTURE_TEST_CASE
(
is_inside_begin
,
PosPredFix
)
{
IsInside
is_inside
(
begin_constant
);
BOOST_CHECK
(
is_inside
.
apply
(
cx
)
->
get_value
());
sc
.
advance
();
BOOST_CHECK
(
is_inside
.
apply
(
cx
)
->
get_value
());
}
BOOST_FIXTURE_TEST_CASE
(
is_inside_end
,
PosPredFix
)
{
IsInside
is_inside
(
end_constant
);
BOOST_CHECK
(
is_inside
.
apply
(
cx
)
->
get_value
());
sc
.
advance
();
BOOST_CHECK
(
is_inside
.
apply
(
cx
)
->
get_value
());
}
//------ to_string test cases -------
BOOST_FIXTURE_TEST_CASE
(
is_inside_to_string
,
PosPredFix
)
{
IsInside
is_inside
(
end_constant
);
BOOST_CHECK_EQUAL
(
"inside(end)"
,
is_inside
.
to_string
(
tagset
));
}
BOOST_FIXTURE_TEST_CASE
(
is_inside_to_raw_string
,
PosPredFix
)
{
IsInside
is_inside
(
end_constant
);
BOOST_CHECK_EQUAL
(
"inside(end)"
,
is_inside
.
to_raw_string
());
}
BOOST_AUTO_TEST_SUITE_END
()
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
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