Skip to content
Snippets Groups Projects
Commit c9bce4af authored by Bartlomiej's avatar Bartlomiej
Browse files

Fix tests

parent 45e0daf7
Branches
No related tags found
1 merge request!11Clarin json support
Pipeline #14291 failed
Showing
with 42 additions and 147 deletions
image: 'python:3.8'
stages:
- check_style
# - test
- test
- build
- build_clarin_json
......@@ -18,10 +18,10 @@ docstyle:
script:
- tox -v -e docstyle
#auto_tests:
# stage: test
# script:
# - tox -v -e tests
auto_tests:
stage: test
script:
- tox -v -e tests
build_image:
stage: build
......
......@@ -33,7 +33,7 @@ if __name__ == "__main__":
"--configuration",
type=str,
default="ccl",
choices=["ccl", "wiktorner_jsonl"],
choices=["ccl", "wiktorner_jsonl", "wiktorner_jsonl_txt_output"],
help="Configuration of the anonymizer",
)
args = parser.parse_args()
......
This diff is collapsed.
--index-url https://pypi.clarin-pl.eu/simple/
lpmn_client_biz
clarin-json
nlp-ws
regex==2020.10.28
......
......@@ -81,7 +81,6 @@ class WiktorNERInputParser(InputParser):
# Morphosyntactic annotations
if content.tokens:
for token in content.tokens():
if token.start and token.stop:
if token.lexemes:
for lexeme in token.lexemes:
if lexeme.disamb and lexeme.disamb is True:
......@@ -102,7 +101,6 @@ class WiktorNERInputParser(InputParser):
# NER annotations
if content.spans:
for entity in content.spans('ner'):
if entity.start and entity.stop:
if entity.type:
annotations.append(
(entity.start, entity.stop, NerAnnotation(entity.type))
......
......@@ -76,7 +76,6 @@ class SequentialJSONLPipeline(Pipeline):
)
result.append({"text": replaced_input})
if self._concat_to_txt:
result_text = ""
for item in result:
......
......@@ -20,7 +20,7 @@ def test_wiktorner_jsonl_readme_example():
assert (
result
== '{"text": "ROZDZIAŁ I. CO NIECO O SAMEJ PIPIDÓWCE Przede wszystkim muszę'
== '{"text": "ROZDZIAŁ I. CO NIECO O SAMEJ [MIEJSCE] Przede wszystkim muszę'
" uprzedzić z góry czytelników, aby się daremnie nie trudzili nad"
" szukaniem wyżej wyrażonego miasteczka na mapach [MIEJSCE] i [MIEJSCE],"
" bo go tam nie znajdą. Nie dlatego, jakoby [MIEJSCE] nie istniała w"
......
......@@ -19,7 +19,7 @@ def test_wiktorner_jsonl_configuration():
assert (
result
== '{"text": "ROZDZIAŁ I. CO NIECO O SAMEJ PIPIDÓWCE Przede wszystkim muszę'
== '{"text": "ROZDZIAŁ I. CO NIECO O SAMEJ [MIEJSCE] Przede wszystkim muszę'
" uprzedzić z góry czytelników, aby się daremnie nie trudzili nad szukaniem"
" wyżej wyrażonego miasteczka na mapach [MIEJSCE] i [MIEJSCE], bo go tam nie"
" znajdą. Nie dlatego, jakoby [MIEJSCE] nie istniała w rzeczywistości i była"
......
......@@ -20,10 +20,9 @@ def test_wiktorner_jsonl_txt_output_configuration():
"./tests/integration/"
"wiktorner_jsonl_txt_output_configuration/wiktorner_jsonl.jsonl"
)
assert (
result
== "ROZDZIAŁ I. CO NIECO O SAMEJ PIPIDÓWCE Przede wszystkim muszę uprzedzić z"
== "ROZDZIAŁ I. CO NIECO O SAMEJ [MIEJSCE] Przede wszystkim muszę uprzedzić z"
" góry czytelników, aby się daremnie nie trudzili nad szukaniem wyżej"
" wyrażonego miasteczka na mapach [MIEJSCE] i [MIEJSCE], bo go tam nie"
" znajdą. Nie dlatego, jakoby [MIEJSCE] nie istniała w rzeczywistości i była"
......@@ -33,16 +32,5 @@ def test_wiktorner_jsonl_txt_output_configuration():
" pozwolenie zamienienia jej na inną. Podobne zamiany nazwisk praktykują się"
" dość często w [MIEJSCE], szczególnie u pojedynczych osób, które nie czując"
" się na siłach uszlachetnienia sobą, swymi czynami własnego nazwiska, chcą"
" nazwiskiem uszlachetnić siebie, i tak np. ROZDZIAŁ I. CO NIECO O SAMEJ"
" PIPIDÓWCE Przede wszystkim muszę uprzedzić z góry czytelników, aby się"
" daremnie nie trudzili nad szukaniem wyżej wyrażonego miasteczka na mapach"
" [MIEJSCE] i [MIEJSCE], bo go tam nie znajdą. Nie dlatego, jakoby [MIEJSCE]"
" nie istniała w rzeczywistości i była tylko wytworem fantazji autora, ale"
" po prostu dlatego, że mieszkańcy owego sławnego grodu, urosłszy z czasem w"
" ambicję, uważali tę nazwę jako ubliżającą ich powadze i podali do c. k."
" namiestnictwa pokorną prośbę o pozwolenie zamienienia jej na inną. Podobne"
" zamiany nazwisk praktykują się dość często w [MIEJSCE], szczególnie u"
" pojedynczych osób, które nie czując się na siłach uszlachetnienia sobą,"
" swymi czynami własnego nazwiska, chcą nazwiskiem uszlachetnić siebie, i"
" tak np."
" nazwiskiem uszlachetnić siebie, i tak np."
)
"""Tests for WiktorNERInputParser."""
from src.annotations import MorphosyntacticAnnotation, NerAnnotation
from src.input_parsers.wiktor_ner import WiktorNERInputParser
example_json = """{
"filename": "test_filename",
"text": "Marek Kowalski pojechał do Wrocławia.",
"tokens": [
{
"index": 1,
"position": [0,5],
"orth": "Marek",
"lexemes": [
{
"lemma": "Marek",
"mstag": "subst:sg:nom:m1",
"disamb": true
}
]
},
{
"index": 2,
"position": [6,14],
"orth": "Kowalski",
"lexemes": [
{
"lemma": "Kowalski",
"mstag": "subst:sg:nom:m1",
"disamb": true
}
]
},
{
"index": 3,
"position": [15,23],
"orth": "pojechał",
"lexemes": [
{
"lemma": "pojechać",
"mstag": "praet:sg:m1:perf",
"disamb": true
}
]
},
{
"index": 4,
"position": [24,26],
"orth": "do",
"lexemes": [
{
"lemma": "do",
"mstag": "prep:gen",
"disamb": true
}
]
},
{
"index": 5,
"position": [27,36],
"orth": "Wrocławia",
"lexemes": [
{
"lemma": "Wrocław",
"mstag": "subst:sg:gen:m3",
"disamb": true
}
]
},
{
"index": 6,
"position": [36,37],
"orth": ".",
"lexemes": [
{
"lemma": ".",
"mstag": "interp",
"disamb": true
}
]
}
],
"entities": [
{
"text": "Marek Kowalski",
"type": "nam_liv",
"tokens": [0, 2],
"positions": [0, 14]
},
{
"text": "Wrocławia",
"type": "nam_loc",
"tokens": [4, 5],
"positions": [27, 36]
}
]
}"""
import clarin_json
def test_wiktor_ner_input_parser():
"""Test WiktorNERInputParser."""
parser = WiktorNERInputParser()
with clarin_json.open('example_inputs/ner_test.jsonl', 'r') as f:
for example_json in f:
text, annotations = parser.parse(example_json)
assert text == "Marek Kowalski pojechał do Wrocławia."
assert len(annotations) == 8
assert (0, 14, NerAnnotation("nam_liv")) in annotations
assert (27, 36, NerAnnotation("nam_loc")) in annotations
assert (0, 14, NerAnnotation("nam_liv_person")) in annotations
assert (27, 36, NerAnnotation("nam_loc_gpe_city")) in annotations
assert (0, 5, MorphosyntacticAnnotation("subst:sg:nom:m1", "Marek")) in annotations
assert (
......
......@@ -41,7 +41,7 @@ def test_sequential_jsonl_pipeline():
)
with NamedTemporaryFile() as f:
f.write(b'{"text": "ala ma kota"}\n{"text": "ala ma kota"}')
f.write(b'{"id": 1, "text": "ala ma kota"}\n{"id":2, "text": "ala ma kota"}')
f.flush()
result = pipeline.run(f.name)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment