Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
nerval
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Named Entity Recognition
nerval
Commits
032c2267
Commit
032c2267
authored
2 years ago
by
Yoann Schneider
Browse files
Options
Downloads
Patches
Plain Diff
Allow spaces in label (followup)
parent
de1275d2
No related branches found
No related tags found
1 merge request
!25
Allow spaces in label (followup)
Pipeline
#104020
passed
2 years ago
Stage: test
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
nerval/parse.py
+6
-2
6 additions, 2 deletions
nerval/parse.py
tests/test_parse_bio.py
+15
-5
15 additions, 5 deletions
tests/test_parse_bio.py
with
21 additions
and
7 deletions
nerval/parse.py
+
6
−
2
View file @
032c2267
...
...
@@ -5,7 +5,7 @@ from pathlib import Path
NOT_ENTITY_TAG
=
"
O
"
BEGINNING_POS
=
[
"
B
"
,
"
S
"
,
"
U
"
]
REGEX_IOB_LINE
=
re
.
compile
(
r
"
^(
.
*) ([BIESLU
O
]-
?
.*)$
"
)
REGEX_IOB_LINE
=
re
.
compile
(
r
"
^(
\S
*) (
(?:
[BIESLU]-
|O)
.*)$
"
)
REGEX_LABEL
=
re
.
compile
(
r
"
[BIESLU]-(.*)$
"
)
...
...
@@ -45,7 +45,11 @@ def parse_line(index: int, line: str, path: Path):
assert
match_iob
return
match_iob
.
group
(
1
,
2
)
word
,
label
=
match_iob
.
group
(
1
,
2
)
# We should have either one - (BLIU-) or none at all (O)
assert
label
.
count
(
"
-
"
)
<=
1
return
word
,
label
except
AssertionError
:
raise
(
Exception
(
...
...
This diff is collapsed.
Click to expand it.
tests/test_parse_bio.py
+
15
−
5
View file @
032c2267
...
...
@@ -4,7 +4,7 @@ from pathlib import Path
import
pytest
from
nerval
import
evaluate
from
nerval.parse
import
parse_line
from
nerval.parse
import
get_type_label
,
parse_line
expected_parsed_annot
=
{
"
entity_count
"
:
{
"
All
"
:
3
,
"
DAT
"
:
1
,
"
LOC
"
:
1
,
"
PER
"
:
1
},
...
...
@@ -199,6 +199,7 @@ def test_parse_bio_no_input():
(
(
"
Hi B-ORG
"
,
"
Hi
"
,
"
B-ORG
"
),
(
"
Hi B-Org or maybe not org
"
,
"
Hi
"
,
"
B-Org or maybe not org
"
),
(
"
1258 B-Date et Lieu
"
,
"
1258
"
,
"
B-Date et Lieu
"
),
),
)
def
test_parse_line
(
line
,
word
,
label
):
...
...
@@ -207,11 +208,20 @@ def test_parse_line(line, word, label):
@pytest.mark.parametrize
(
"
line
"
,
(
(
"
HiB-ORG
"
),
(
"
HiB-ORG or maybe not
"
),
),
((
"
HiB-ORG
"
),
(
"
HiB-ORG or maybe not
"
),
(
"
Hello B-surname and L-ocation
"
)),
)
def
test_parse_line_crash
(
line
):
with
pytest
.
raises
(
Exception
):
parse_line
(
index
=
0
,
line
=
line
,
path
=
Path
(
""
))
@pytest.mark.parametrize
(
"
label, expected_type
"
,
(
(
"
B-ORG
"
,
"
ORG
"
),
(
"
B-Date et Lieu
"
,
"
Date et Lieu
"
),
(
"
I-Date et Lieu
"
,
"
Date et Lieu
"
),
),
)
def
test_get_type_label
(
label
,
expected_type
):
assert
get_type_label
(
label
)
==
expected_type
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