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
261c5b03
Commit
261c5b03
authored
14 years ago
by
Adam Wardynski
Browse files
Options
Downloads
Patches
Plain Diff
text() match condition, matching given text.
parent
ce4d1483
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/matchtext.cpp
+49
-0
49 additions, 0 deletions
libwccl/ops/match/conditions/matchtext.cpp
libwccl/ops/match/conditions/matchtext.h
+51
-0
51 additions, 0 deletions
libwccl/ops/match/conditions/matchtext.h
with
101 additions
and
0 deletions
libwccl/CMakeLists.txt
+
1
−
0
View file @
261c5b03
...
...
@@ -65,6 +65,7 @@ SET(libwccl_STAT_SRC
ops/match/conditions/conjconditions.cpp
ops/match/conditions/isannotatedas.cpp
ops/match/conditions/longest.cpp
ops/match/conditions/matchtext.cpp
ops/match/conditions/oneof.cpp
ops/match/conditions/optionalmatch.cpp
ops/match/conditions/repeatedmatch.cpp
...
...
This diff is collapsed.
Click to expand it.
libwccl/ops/match/conditions/matchtext.cpp
0 → 100644
+
49
−
0
View file @
261c5b03
#include
<libwccl/ops/match/conditions/matchtext.h>
#include
<sstream>
#include
<libpwrutils/util.h>
namespace
Wccl
{
MatchResult
MatchText
::
apply
(
const
ActionExecContext
&
context
)
const
{
SentenceContext
&
sc
=
context
.
sentence_context
();
int
orig_iter
=
sc
.
get_position
();
UnicodeString
sent_frag
(
sc
.
at
(
orig_iter
)
->
orth
());
int
iter_pos
=
orig_iter
+
1
;
while
(
sent_frag
.
length
()
<=
text_
.
length
()
&&
iter_pos
<
sc
.
size
())
{
if
(
sc
.
at
(
iter_pos
)
->
wa
()
!=
PwrNlp
::
Whitespace
::
None
)
{
sent_frag
+=
" "
;
}
sent_frag
+=
sc
.
at
(
iter_pos
)
->
orth
();
++
iter_pos
;
}
if
(
sent_frag
!=
text_
)
{
return
MatchResult
();
}
boost
::
shared_ptr
<
MatchVector
>
v
(
new
MatchVector
());
for
(
int
i
=
orig_iter
;
i
<
iter_pos
;
++
i
)
{
v
->
append
(
boost
::
shared_ptr
<
TokenMatch
>
(
new
TokenMatch
(
i
));
}
// increase current sentence position to the point after the matched tokens.
sc
.
set_position
(
orig_iter
+
v
->
size
());
return
MatchResult
(
v
);
}
std
::
string
MatchText
::
to_string
(
const
Corpus2
::
Tagset
&
)
const
{
std
::
ostringstream
os
;
os
<<
name
()
<<
"(
\"
"
<<
PwrNlp
::
to_utf8
(
text_
)
<<
"
\"
)"
;
return
os
.
str
();
}
std
::
ostream
&
MatchText
::
write_to
(
std
::
ostream
&
os
)
const
{
return
os
<<
name
()
<<
"(
\"
"
<<
PwrNlp
::
to_utf8
(
text_
)
<<
"
\"
)"
;
}
}
/* end ns Wccl */
This diff is collapsed.
Click to expand it.
libwccl/ops/match/conditions/matchtext.h
0 → 100644
+
51
−
0
View file @
261c5b03
#ifndef LIBWCCL_OPS_MATCH_CONDITIONS_MATCHTEXT_H
#define LIBWCCL_OPS_MATCH_CONDITIONS_MATCHTEXT_H
#include
<libwccl/ops/match/matchcondition.h>
#include
<libwccl/ops/function.h>
#include
<unicode/unistr.h>
namespace
Wccl
{
/**
* text() match condition - matches a text
*/
class
MatchText
:
public
MatchCondition
{
public:
MatchText
(
const
UnicodeString
&
text
)
:
text_
(
text
)
{
BOOST_ASSERT
(
!
text_
.
isEmpty
());
}
/**
* @returns Name of the Condition.
*/
std
::
string
name
()
const
{
return
"text"
;
}
/**
* Applies the condition to the given execution context.
* If a match is found, the current sentence Position is increased
* by the amount of matched tokens.
*/
MatchResult
apply
(
const
ActionExecContext
&
context
)
const
;
/**
* @returns String representation of the Condition
*/
std
::
string
to_string
(
const
Corpus2
::
Tagset
&
tagset
)
const
;
protected
:
/**
* Writes the string representation of the Condition 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
UnicodeString
text_
;
};
}
/* end ns Wccl */
#endif // LIBWCCL_OPS_MATCH_CONDITIONS_MATCHTEXT_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