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
c7f5fdc2
Commit
c7f5fdc2
authored
13 years ago
by
Adam Wardynski
Browse files
Options
Downloads
Patches
Plain Diff
longest - condition that takes longest possible variant.
parent
f5ad754f
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/conditions/longest.cpp
+61
-0
61 additions, 0 deletions
libwccl/ops/match/conditions/longest.cpp
libwccl/ops/match/conditions/longest.h
+52
-0
52 additions, 0 deletions
libwccl/ops/match/conditions/longest.h
with
114 additions
and
0 deletions
libwccl/CMakeLists.txt
+
1
−
0
View file @
c7f5fdc2
...
@@ -55,6 +55,7 @@ SET(libwccl_STAT_SRC
...
@@ -55,6 +55,7 @@ SET(libwccl_STAT_SRC
ops/functions/tset/getsymbols.cpp
ops/functions/tset/getsymbols.cpp
ops/functions/tset/getsymbolsinrange.cpp
ops/functions/tset/getsymbolsinrange.cpp
ops/match/conditions/conjconditions.cpp
ops/match/conditions/conjconditions.cpp
ops/match/conditions/longest.cpp
ops/match/conditions/oneof.cpp
ops/match/conditions/oneof.cpp
ops/match/conditions/optionalmatch.cpp
ops/match/conditions/optionalmatch.cpp
ops/match/conditions/repeatedmatch.cpp
ops/match/conditions/repeatedmatch.cpp
...
...
This diff is collapsed.
Click to expand it.
libwccl/ops/match/conditions/longest.cpp
0 → 100644
+
61
−
0
View file @
c7f5fdc2
#include
<libwccl/ops/match/conditions/longest.h>
#include
<libwccl/values/matchvector.h>
#include
<sstream>
#include
<libpwrutils/foreach.h>
namespace
Wccl
{
Longest
::
Longest
(
const
boost
::
shared_ptr
<
std
::
vector
<
ConjConditions
>
>&
variants
)
:
_variants
(
variants
)
{
BOOST_ASSERT
(
_variants
);
BOOST_ASSERT
(
!
_variants
->
empty
());
}
MatchResult
Longest
::
apply
(
const
ActionExecContext
&
context
)
const
{
int
orig_pos
=
context
.
sentence_context
().
get_position
();
int
longest_pos
=
orig_pos
;
MatchResult
longest
;
foreach
(
const
ConjConditions
&
variant
,
*
_variants
)
{
MatchResult
res
=
variant
.
apply
(
context
);
int
cur_pos
=
context
.
sentence_context
().
get_position
();
if
(
res
.
matched
()
&&
longest_pos
<
cur_pos
)
{
longest_pos
=
cur_pos
;
longest
=
res
;
}
context
.
sentence_context
().
set_position
(
orig_pos
);
}
context
.
sentence_context
().
set_position
(
longest_pos
);
return
longest
;
}
std
::
string
Longest
::
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
&
Longest
::
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/longest.h
0 → 100644
+
52
−
0
View file @
c7f5fdc2
#ifndef LIBWCCL_OPS_MATCH_CONDITIONS_LONGEST_H
#define LIBWCCL_OPS_MATCH_CONDITIONS_LONGEST_H
#include
<libwccl/ops/match/conditions/conjconditions.h>
namespace
Wccl
{
/**
* Class for "longest" condition of match
*/
class
Longest
:
public
MatchCondition
{
public:
Longest
(
const
boost
::
shared_ptr
<
std
::
vector
<
ConjConditions
>
>&
variants
);
/**
* @returns Name of the condition.
*/
std
::
string
name
()
const
{
return
"longest"
;
}
/**
* Applies the condition to the given execution context.
* Inner match variants are executed one by one to check which
* one is the longest one. If any match variants were found to be "true",
* the one that produced the longest match is returned with "true".
* 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_LONGEST_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