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
dd0777c6
Commit
dd0777c6
authored
Jan 13, 2011
by
Adam Wardynski
Browse files
Options
Downloads
Patches
Plain Diff
Unify to treat underspecified lexemes as meeting agreement.
So such lexemes are always left in the end.
parent
eb6a353f
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
libwccl/ops/actions/unify.cpp
+38
-19
38 additions, 19 deletions
libwccl/ops/actions/unify.cpp
with
38 additions
and
19 deletions
libwccl/ops/actions/unify.cpp
+
38
−
19
View file @
dd0777c6
...
@@ -25,33 +25,35 @@ Bool Unify::execute(const ActionExecContext& context) const
...
@@ -25,33 +25,35 @@ Bool Unify::execute(const ActionExecContext& context) const
const
boost
::
shared_ptr
<
const
TSet
>&
attribs
=
attribs_expr_
->
apply
(
context
);
const
boost
::
shared_ptr
<
const
TSet
>&
attribs
=
attribs_expr_
->
apply
(
context
);
std
::
vector
<
std
::
vector
<
Corpus2
::
Lexeme
>
>
remainings
;
std
::
vector
<
std
::
vector
<
Corpus2
::
Lexeme
>
>
remainings
;
std
::
vector
<
std
::
vector
<
Corpus2
::
Lexeme
>
>
underspecifieds
;
// first pass - cut lexemes that don't match agreement attribs at all
// first pass - cut lexemes that don't match agreement attribs at all
for
(
int
i
=
abs_left
;
i
<=
abs_right
;
++
i
)
{
for
(
int
i
=
abs_left
;
i
<=
abs_right
;
++
i
)
{
Corpus2
::
Token
&
curr_tok
=
*
sc
.
at
(
i
);
Corpus2
::
Token
&
curr_tok
=
*
sc
.
at
(
i
);
std
::
vector
<
Corpus2
::
Lexeme
>
remaining
;
std
::
vector
<
Corpus2
::
Lexeme
>
remaining
;
std
::
vector
<
Corpus2
::
Lexeme
>
underspecified
;
foreach
(
Corpus2
::
Lexeme
&
lexeme
,
curr_tok
.
lexemes
())
{
foreach
(
Corpus2
::
Lexeme
&
lexeme
,
curr_tok
.
lexemes
())
{
if
(
attribs
->
matching_categories
(
lexeme
.
tag
())
>
0
)
{
if
(
attribs
->
matching_categories
(
lexeme
.
tag
())
>
0
)
{
remaining
.
push_back
(
lexeme
);
remaining
.
push_back
(
lexeme
);
}
else
{
underspecified
.
push_back
(
lexeme
);
}
}
}
}
remainings
.
push_back
(
remaining
);
remainings
.
push_back
(
remaining
);
underspecifieds
.
push_back
(
underspecified
);
}
}
// second pass - leave only lexemes that are in agreement
// second pass - leave only lexemes that are in agreement
// with at least one lexeme from previous non-empty-after-1st-pass token
// with at least one lexeme from previous non-empty-after-1st-pass token
int
previous
=
remainings
.
size
()
-
1
;
int
previous
=
remainings
.
size
()
-
1
;
// at first, "previous" is the last token not emptied after 1st pass
// at first, "previous" is the last token not emptied after 1st pass
while
((
previous
>
0
)
&&
(
remainings
[
previous
].
size
()
==
0
))
{
while
((
previous
>
0
)
&&
(
remainings
[
previous
].
empty
()
))
{
previous
--
;
previous
--
;
}
}
for
(
size_t
i
=
0
;
i
<
remainings
.
size
();
++
i
)
{
for
(
size_t
i
=
0
;
i
<
remainings
.
size
();
++
i
)
{
// proceed only for tokens that have lexemes that could go into agreement
// proceed only for tokens that have lexemes that could go into agreement
// (i.e. are not emptied after 1st pass)
// (i.e. are not emptied after 1st pass)
if
(
remainings
[
i
].
size
()
>
0
)
{
if
(
!
remainings
[
i
].
empty
())
{
std
::
vector
<
Corpus2
::
Lexeme
>&
prev_rem
=
remainings
[
previous
];
const
std
::
vector
<
Corpus2
::
Lexeme
>&
prev_rem
=
remainings
[
previous
];
// next time around "previous" will be the current one
previous
=
i
;
std
::
vector
<
Corpus2
::
Lexeme
>
curr_rem
;
std
::
vector
<
Corpus2
::
Lexeme
>
curr_rem
;
// get only lexemes that agree with a lexeme from previous token
// get only lexemes that agree with a lexeme from previous token
foreach
(
const
Corpus2
::
Lexeme
&
curr_lex
,
remainings
[
i
])
{
foreach
(
const
Corpus2
::
Lexeme
&
curr_lex
,
remainings
[
i
])
{
...
@@ -63,28 +65,45 @@ Bool Unify::execute(const ActionExecContext& context) const
...
@@ -63,28 +65,45 @@ Bool Unify::execute(const ActionExecContext& context) const
}
}
}
}
}
}
if
(
curr_rem
.
size
()
==
0
)
{
if
(
curr_rem
.
empty
())
{
// no lexemes left, means no agreement possible, so can't unify - abort with no changes
if
(
underspecifieds
[
i
].
empty
())
{
// there is no agreement possible, abort with no changes
changed
.
set_value
(
false
);
changed
.
set_value
(
false
);
return
changed
;
return
changed
;
}
else
{
// there were underspecified lexemes, they will be left in the end
// so agreement is met anyway, however we need to mark that
// changes were made because we removed some lexemes that did not
// meet agreement;
// "previous" index has to be left alone though, pointing at previous
// token that still had some agreedable lexemes
changed
.
set_value
(
true
);
}
}
}
else
{
// some non-underspecified lexemes are left, so
// next time around, "previous" token is going to be the current one
previous
=
i
;
// there were changes only if we actually removed something
if
(
curr_rem
.
size
()
!=
remainings
[
i
].
size
())
{
if
(
curr_rem
.
size
()
!=
remainings
[
i
].
size
())
{
changed
.
set_value
(
true
);
changed
.
set_value
(
true
);
remainings
[
i
]
=
curr_rem
;
remainings
[
i
]
=
curr_rem
;
}
}
}
}
}
}
}
// finally assign remaining tokens accordingly,
// finally assign remaining lexemes to original tokens
// leaving intact the tokens that did not have agreeable lexemes at all
if
(
changed
.
get_value
())
{
if
(
changed
.
get_value
())
{
for
(
size_t
i
=
0
;
i
<
remainings
.
size
();
++
i
)
{
for
(
size_t
i
=
0
;
i
<
remainings
.
size
();
++
i
)
{
if
(
remainings
[
i
].
size
()
>
0
)
{
if
(
remainings
[
i
].
size
()
>
0
)
{
sc
.
at
(
i
+
abs_left
)
->
lexemes
()
=
remainings
[
i
];
std
::
vector
<
Corpus2
::
Lexeme
>&
lexemes
=
sc
.
at
(
i
+
abs_left
)
->
lexemes
();
lexemes
=
remainings
[
i
];
// underspecced lexemes meet agreement too, so leave them in the end, if any
foreach
(
const
Corpus2
::
Lexeme
&
lex
,
underspecifieds
[
i
])
{
lexemes
.
push_back
(
lex
);
}
}
}
}
}
}
}
return
changed
;
return
changed
;
}
}
...
...
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