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
f886a617
Commit
f886a617
authored
14 years ago
by
Adam Wardynski
Browse files
Options
Downloads
Patches
Plain Diff
MatchOperator - operator for match rules.
parent
ed5f2256
Branches
Branches 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/match/matchoperator.cpp
+56
-0
56 additions, 0 deletions
libwccl/ops/match/matchoperator.cpp
libwccl/ops/match/matchoperator.h
+61
-0
61 additions, 0 deletions
libwccl/ops/match/matchoperator.h
with
118 additions
and
0 deletions
libwccl/CMakeLists.txt
+
1
−
0
View file @
f886a617
...
...
@@ -55,6 +55,7 @@ SET(libwccl_STAT_SRC
ops/functions/tset/getsymbols.cpp
ops/functions/tset/getsymbolsinrange.cpp
ops/match/conditions/tokencondition.cpp
ops/match/matchoperator.cpp
ops/rulesequence.cpp
ops/tagaction.cpp
ops/tagactions/delete.cpp
...
...
This diff is collapsed.
Click to expand it.
libwccl/ops/match/matchoperator.cpp
0 → 100644
+
56
−
0
View file @
f886a617
#include
<libwccl/ops/match/matchoperator.h>
#include
<libpwrutils/foreach.h>
#include
<sstream>
namespace
Wccl
{
const
char
*
MatchOperator
::
IterationPosVarName
=
"$_"
;
boost
::
shared_ptr
<
MatchVector
>
MatchOperator
::
execute
(
boost
::
shared_ptr
<
Position
>
iter_pos
,
const
ActionExecContext
&
context
)
const
{
boost
::
shared_ptr
<
MatchVector
>
matches
(
new
MatchVector
());
int
orig_iter_pos
=
iter_pos
->
get_value
();
foreach
(
const
boost
::
shared_ptr
<
const
MatchCondition
>&
cond
,
_conditions
)
{
MatchResult
res
=
cond
->
apply
(
iter_pos
,
context
);
if
(
res
.
matched
())
{
matches
->
append
(
res
.
get_match
());
}
else
{
matches
.
reset
(
new
MatchVector
());
iter_pos
->
set_value
(
orig_iter_pos
+
1
);
return
matches
;
}
}
return
matches
;
}
std
::
string
MatchOperator
::
to_string
(
const
Corpus2
::
Tagset
&
tagset
)
const
{
std
::
ostringstream
ostream
;
ostream
<<
name
()
<<
"("
;
for
(
size_t
i
=
0
;
i
<
_conditions
.
size
();
++
i
)
{
if
(
i
!=
0
)
{
ostream
<<
", "
;
}
ostream
<<
_conditions
[
i
]
->
to_string
(
tagset
);
}
ostream
<<
")"
;
return
ostream
.
str
();
}
std
::
ostream
&
MatchOperator
::
write_to
(
std
::
ostream
&
ostream
)
const
{
ostream
<<
name
()
<<
"("
;
for
(
size_t
i
=
0
;
i
<
_conditions
.
size
();
++
i
)
{
if
(
i
!=
0
)
{
ostream
<<
", "
;
}
ostream
<<
*
_conditions
[
i
];
}
ostream
<<
")"
;
return
ostream
;
}
}
/* end ns Wccl */
This diff is collapsed.
Click to expand it.
libwccl/ops/match/matchoperator.h
0 → 100644
+
61
−
0
View file @
f886a617
#ifndef LIBWCCL_OPS_MATCH_MATCHOPERATOR_H
#define LIBWCCL_OPS_MATCH_MATCHOPERATOR_H
#include
<libwccl/ops/match/matchcondition.h>
#include
<libwccl/values/matchvector.h>
namespace
Wccl
{
/**
* Operator that realizes "match" functionality for match rules
*/
class
MatchOperator
:
public
Expression
{
public:
static
const
char
*
IterationPosVarName
;
MatchOperator
(
const
std
::
vector
<
boost
::
shared_ptr
<
const
MatchCondition
>
>&
conditions
)
:
_conditions
(
conditions
)
{
}
/**
* @returns Name of the operator.
*/
std
::
string
name
()
const
{
return
"match"
;
}
/**
* @returns String representation of the Action
*/
std
::
string
to_string
(
const
Corpus2
::
Tagset
&
tagset
)
const
;
protected
:
/**
* Writes string representation of the operator 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 operator on given context.
* @returns Vector of matches corresponding to match conditions,
* if all conditions were met. In such case position $_ is advanced past matched tokens.
* Empty MatchVector is returned if any of conditions was not met.
* In such case Position $_ is advanced by 1.
* @param iter_pos Pointer to the variable $_ from context's Variables
* @param context Execution context - current sentence and Variables to operate on
*/
boost
::
shared_ptr
<
MatchVector
>
execute
(
boost
::
shared_ptr
<
Position
>
iter_pos
,
const
ActionExecContext
&
context
)
const
;
private
:
const
std
::
vector
<
boost
::
shared_ptr
<
const
MatchCondition
>
>
_conditions
;
};
}
/* end ns Wccl */
#endif // LIBWCCL_OPS_MATCH_MATCHOPERATOR_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