Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
S
Sciencebeam Gym
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package Registry
Container Registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Sciencebeam
Sciencebeam Gym
Commits
bc0c2085
Commit
bc0c2085
authored
7 years ago
by
Daniel Ecer
Browse files
Options
Downloads
Patches
Plain Diff
fixed token indices incorrect when str filter removes characters
parent
20b389c3
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
sciencebeam_gym/preprocess/annotation/matching_annotator.py
+3
-3
3 additions, 3 deletions
sciencebeam_gym/preprocess/annotation/matching_annotator.py
sciencebeam_gym/preprocess/annotation/matching_annotator_test.py
+26
-0
26 additions, 0 deletions
...beam_gym/preprocess/annotation/matching_annotator_test.py
with
29 additions
and
3 deletions
sciencebeam_gym/preprocess/annotation/matching_annotator.py
+
3
−
3
View file @
bc0c2085
...
...
@@ -73,9 +73,9 @@ class SequenceWrapper(object):
self
.
str_filter_f
=
str_filter_f
self
.
tokens
=
tokens
self
.
token_str_list
=
[
structured_document
.
get_text
(
t
)
or
''
for
t
in
tokens
]
self
.
tokens_as_str
=
'
'
.
join
(
self
.
token_str_list
)
if
str_filter_f
:
self
.
tokens_as_str
=
str_filter_f
(
self
.
tokens_as_str
)
self
.
token_str_list
=
[
str_filter_f
(
s
)
for
s
in
self
.
token_str_list
]
self
.
tokens_as_str
=
'
'
.
join
(
self
.
token_str_list
)
def
tokens_between
(
self
,
index_range
):
start
,
end
=
index_range
...
...
@@ -307,7 +307,7 @@ class TargetAnnotationMatchFinder(object):
get_logger
().
debug
(
'
all_matches (bonding=%s): %s
'
,
self
.
target_annotation
.
bonding
,
all_matches
)
if
not
self
.
target_annotation
.
bonding
or
len
(
all_matches
)
>
1
:
if
not
self
.
target_annotation
.
bonding
or
len
(
all_matches
)
>
1
or
self
.
target_annotation
.
name
==
'
author
'
:
for
m
in
all_matches
:
yield
m
else
:
...
...
This diff is collapsed.
Click to expand it.
sciencebeam_gym/preprocess/annotation/matching_annotator_test.py
+
26
−
0
View file @
bc0c2085
...
...
@@ -15,6 +15,7 @@ from sciencebeam_gym.preprocess.annotation.target_annotation import (
from
sciencebeam_gym.preprocess.annotation.matching_annotator
import
(
normalise_str
,
MatchingAnnotator
,
SequenceWrapper
,
THIN_SPACE
,
EN_DASH
,
EM_DASH
...
...
@@ -72,6 +73,31 @@ class TestNormaliseStr(object):
def
test_should_replace_en_dash_with_hyphen
(
self
):
assert
normalise_str
(
EN_DASH
)
==
'
-
'
class
TestSequenceWrapper
(
object
):
def
test_should_find_all_tokens_without_str_filter
(
self
):
text
=
'
this is matching
'
tokens
=
_tokens_for_text
(
text
)
doc
=
_document_for_tokens
([
tokens
])
seq
=
SequenceWrapper
(
doc
,
tokens
)
assert
str
(
seq
)
==
text
assert
list
(
seq
.
tokens_between
((
0
,
len
(
text
))))
==
tokens
def
test_should_find_tokens_between_without_str_filter
(
self
):
text
=
'
this is matching
'
tokens
=
_tokens_for_text
(
text
)
doc
=
_document_for_tokens
([
tokens
])
seq
=
SequenceWrapper
(
doc
,
tokens
)
assert
str
(
seq
)
==
text
assert
list
(
seq
.
tokens_between
((
6
,
7
)))
==
[
tokens
[
1
]]
def
test_should_find_tokens_between_adjusted_indices_due_to_str_filter
(
self
):
text
=
'
this is matching
'
tokens
=
_tokens_for_text
(
text
)
doc
=
_document_for_tokens
([
tokens
])
seq
=
SequenceWrapper
(
doc
,
tokens
,
str_filter_f
=
lambda
s
:
s
.
replace
(
'
th
'
,
''
))
assert
str
(
seq
)
==
'
is is matching
'
assert
list
(
seq
.
tokens_between
((
4
,
5
)))
==
[
tokens
[
1
]]
class
TestMatchingAnnotator
(
object
):
def
test_should_not_fail_on_empty_document
(
self
):
doc
=
SimpleStructuredDocument
(
lines
=
[])
...
...
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