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
f5ad754f
Commit
f5ad754f
authored
Apr 4, 2011
by
Adam Wardynski
Browse files
Options
Downloads
Patches
Plain Diff
oneof - condition that accepts first matched variant.
parent
c79a05b8
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/CMakeLists.txt
+1
-0
1 addition, 0 deletions
libwccl/CMakeLists.txt
libwccl/ops/match/conditions/oneof.cpp
+54
-0
54 additions, 0 deletions
libwccl/ops/match/conditions/oneof.cpp
libwccl/ops/match/conditions/oneof.h
+51
-0
51 additions, 0 deletions
libwccl/ops/match/conditions/oneof.h
with
106 additions
and
0 deletions
libwccl/CMakeLists.txt
+
1
−
0
View file @
f5ad754f
...
...
@@ -55,6 +55,7 @@ SET(libwccl_STAT_SRC
ops/functions/tset/getsymbols.cpp
ops/functions/tset/getsymbolsinrange.cpp
ops/match/conditions/conjconditions.cpp
ops/match/conditions/oneof.cpp
ops/match/conditions/optionalmatch.cpp
ops/match/conditions/repeatedmatch.cpp
ops/match/conditions/tokencondition.cpp
...
...
This diff is collapsed.
Click to expand it.
libwccl/ops/match/conditions/oneof.cpp
0 → 100644
+
54
−
0
View file @
f5ad754f
#include
<libwccl/ops/match/conditions/oneof.h>
#include
<libwccl/values/matchvector.h>
#include
<sstream>
#include
<libpwrutils/foreach.h>
namespace
Wccl
{
OneOf
::
OneOf
(
const
boost
::
shared_ptr
<
std
::
vector
<
ConjConditions
>
>&
variants
)
:
_variants
(
variants
)
{
BOOST_ASSERT
(
_variants
);
BOOST_ASSERT
(
!
_variants
->
empty
());
}
MatchResult
OneOf
::
apply
(
const
ActionExecContext
&
context
)
const
{
int
orig_pos
=
context
.
sentence_context
().
get_position
();
foreach
(
const
ConjConditions
&
variant
,
*
_variants
)
{
MatchResult
res
=
variant
.
apply
(
context
);
if
(
res
.
matched
())
{
return
res
;
}
context
.
sentence_context
().
set_position
(
orig_pos
);
}
return
MatchResult
();
}
std
::
string
OneOf
::
to_string
(
const
Corpus2
::
Tagset
&
tagset
)
const
{
std
::
ostringstream
ostream
;
ostream
<<
name
()
<<
"("
;
for
(
size_t
i
=
0
;
i
<
_variants
->
size
();
++
i
)
{
if
(
i
!=
0
)
{
ostream
<<
", "
;
}
ostream
<<
"variant"
<<
_variants
->
at
(
i
).
to_string
(
tagset
);
}
ostream
<<
")"
;
return
ostream
.
str
();
}
std
::
ostream
&
OneOf
::
write_to
(
std
::
ostream
&
ostream
)
const
{
ostream
<<
name
()
<<
"("
;
for
(
size_t
i
=
0
;
i
<
_variants
->
size
();
++
i
)
{
if
(
i
!=
0
)
{
ostream
<<
", "
;
}
ostream
<<
"variant"
<<
_variants
->
at
(
i
);
}
return
ostream
<<
")"
;
}
}
/* end ns Wccl */
This diff is collapsed.
Click to expand it.
libwccl/ops/match/conditions/oneof.h
0 → 100644
+
51
−
0
View file @
f5ad754f
#ifndef LIBWCCL_OPS_MATCH_CONDITIONS_ONEOF_H
#define LIBWCCL_OPS_MATCH_CONDITIONS_ONEOF_H
#include
<libwccl/ops/match/conditions/conjconditions.h>
namespace
Wccl
{
/**
* Class for "oneof" condition of match
*/
class
OneOf
:
public
MatchCondition
{
public:
OneOf
(
const
boost
::
shared_ptr
<
std
::
vector
<
ConjConditions
>
>&
variants
);
/**
* @returns Name of the condition.
*/
std
::
string
name
()
const
{
return
"oneof"
;
}
/**
* Applies the condition to the given execution context.
* Inner match variants are executed one by one until a "true" one is found.
* Once a "true" variant is found, it is returned with "true" MatchResult.
* If there was no "true" match variant, "false" is returned instead.
* If a match is found, the current sentence Position is increased
* as to point one token after all the matched tokens, otherwise
* it stays unchanged.
*/
MatchResult
apply
(
const
ActionExecContext
&
context
)
const
;
/**
* @returns String representation of the MatchCondition
*/
std
::
string
to_string
(
const
Corpus2
::
Tagset
&
tagset
)
const
;
protected
:
/**
* Writes string representation of the MatchCondition 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
;
private
:
const
boost
::
shared_ptr
<
std
::
vector
<
ConjConditions
>
>
_variants
;
};
}
/* end ns Wccl */
#endif // LIBWCCL_OPS_MATCH_CONDITIONS_ONEOF_H
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