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
c99e4150
Commit
c99e4150
authored
14 years ago
by
Adam Wardynski
Browse files
Options
Downloads
Patches
Plain Diff
Relabel Action, replacing POS for lexemes meeting a condition.
parent
040683b2
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
libwccl/CMakeLists.txt
+1
-0
1 addition, 0 deletions
libwccl/CMakeLists.txt
libwccl/ops/actions/relabel.cpp
+45
-0
45 additions, 0 deletions
libwccl/ops/actions/relabel.cpp
libwccl/ops/actions/relabel.h
+72
-0
72 additions, 0 deletions
libwccl/ops/actions/relabel.h
with
118 additions
and
0 deletions
libwccl/CMakeLists.txt
+
1
−
0
View file @
c99e4150
...
@@ -29,6 +29,7 @@ SET(libwccl_STAT_SRC
...
@@ -29,6 +29,7 @@ SET(libwccl_STAT_SRC
exception.cpp
exception.cpp
ops/action.cpp
ops/action.cpp
ops/actions/delete.cpp
ops/actions/delete.cpp
ops/actions/relabel.cpp
ops/actions/select.cpp
ops/actions/select.cpp
ops/formatters.cpp
ops/formatters.cpp
ops/functions/bool/iteration.cpp
ops/functions/bool/iteration.cpp
...
...
This diff is collapsed.
Click to expand it.
libwccl/ops/actions/relabel.cpp
0 → 100644
+
45
−
0
View file @
c99e4150
#include
<libwccl/ops/actions/relabel.h>
#include
<libpwrutils/foreach.h>
#include
<sstream>
namespace
Wccl
{
Bool
Relabel
::
execute
(
const
ActionExecContext
&
context
)
const
{
Bool
changed
(
false
);
Corpus2
::
mask_t
replace_wclass
=
replace_with_
->
apply
(
context
)
->
get_value
().
get_pos
();
int
abs_pos
=
context
.
sentence_context
().
get_abs_position
(
*
pos_
->
apply
(
context
));
if
(
context
.
sentence_context
().
is_inside
(
abs_pos
))
{
Corpus2
::
Token
&
token
=
*
context
.
sentence_context
().
at
(
abs_pos
);
std
::
vector
<
Corpus2
::
Lexeme
>
original
(
token
.
lexemes
());
token
.
lexemes
().
clear
();
foreach
(
Corpus2
::
Lexeme
&
lexeme
,
original
)
{
token
.
add_lexeme
(
lexeme
);
if
(
condition_
->
apply
(
context
)
->
get_value
())
{
changed
.
set_value
(
true
);
lexeme
.
set_tag
(
Corpus2
::
Tag
(
replace_wclass
,
lexeme
.
tag
().
get_values
()));
}
token
.
lexemes
().
pop_back
();
}
token
.
lexemes
()
=
original
;
}
return
changed
;
}
std
::
string
Relabel
::
to_string
(
const
Corpus2
::
Tagset
&
tagset
)
const
{
std
::
ostringstream
os
;
os
<<
name
()
<<
"("
<<
pos_
->
to_string
(
tagset
)
<<
", "
<<
replace_with_
->
to_string
(
tagset
)
<<
", "
<<
condition_
->
to_string
(
tagset
)
<<
")"
;
return
os
.
str
();
}
std
::
ostream
&
Relabel
::
write_to
(
std
::
ostream
&
os
)
const
{
os
<<
name
()
<<
"("
<<
*
pos_
<<
", "
<<
*
replace_with_
<<
", "
<<
*
condition_
<<
")"
;
return
os
;
}
}
/* end ns Wccl */
This diff is collapsed.
Click to expand it.
libwccl/ops/actions/relabel.h
0 → 100644
+
72
−
0
View file @
c99e4150
#ifndef LIBWCCL_OPS_RELABEL_DELETE_H
#define LIBWCCL_OPS_RELABEL_DELETE_H
#include
<libwccl/ops/action.h>
#include
<libwccl/values/position.h>
#include
<libwccl/values/bool.h>
#include
<libwccl/ops/function.h>
namespace
Wccl
{
/**
* Action to change part of speech for lexemes that meet a condition.
*/
class
Relabel
:
public
Action
{
public:
typedef
boost
::
shared_ptr
<
Function
<
Position
>
>
PosFunctionPtr
;
typedef
boost
::
shared_ptr
<
Function
<
Bool
>
>
BoolFunctionPtr
;
typedef
boost
::
shared_ptr
<
Function
<
TSet
>
>
TSetFunctionPtr
;
Relabel
(
const
TSetFunctionPtr
&
replace_with
,
const
BoolFunctionPtr
&
condition
,
const
PosFunctionPtr
&
pos
=
detail
::
CurrentPos
())
:
pos_
(
pos
),
condition_
(
condition
),
replace_with_
(
replace_with
)
{
BOOST_ASSERT
(
pos_
);
BOOST_ASSERT
(
condition_
);
BOOST_ASSERT
(
replace_with_
);
}
/**
* @returns Name of the function.
*/
std
::
string
name
()
const
{
return
"relabel"
;
}
/**
* @returns String representation of the Action
*/
std
::
string
to_string
(
const
Corpus2
::
Tagset
&
tagset
)
const
;
protected
:
/**
* Writes string representation of the Action to
* an output stream.
* @returns Stream written to.
* @note May be incomplete and/or containt internal info.
*/
std
::
ostream
&
write_to
(
std
::
ostream
&
ostream
)
const
;
/**
* Executes the Action on given context: for all lexemes
* that meet given condition, change their part of speech
* to the part of speech given by provided TSet function.
* No action is done if position points outside sentence.
* @returns True if there were any changes made; False otherwise
*/
Bool
execute
(
const
ActionExecContext
&
context
)
const
;
private
:
const
PosFunctionPtr
pos_
;
const
BoolFunctionPtr
condition_
;
const
TSetFunctionPtr
replace_with_
;
};
}
/* end ns Wccl */
#endif // LIBWCCL_OPS_RELABEL_DELETE_H
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