Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
pos_converter
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
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
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
nlpworkers
pos_converter
Commits
077614de
Commit
077614de
authored
May 16, 2023
by
Paweł Walkowiak
Browse files
Options
Downloads
Plain Diff
Merge branch 'json2lemmas' into 'master'
Json2lemmas See merge request
!2
parents
fdebbc6f
e9779d57
No related branches found
No related tags found
1 merge request
!2
Json2lemmas
Pipeline
#10581
failed
May 24, 2023
Stage: check_style
Stage: tests
Stage: pages
Stage: build_master
Changes
4
Pipelines
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
.gitignore
+1
-0
1 addition, 0 deletions
.gitignore
lpmn_queries.json
+2
-0
2 additions, 0 deletions
lpmn_queries.json
src/converter.py
+23
-0
23 additions, 0 deletions
src/converter.py
tests/testdata/expected/remove_json_text_lemmas.txt
+1
-0
1 addition, 0 deletions
tests/testdata/expected/remove_json_text_lemmas.txt
with
27 additions
and
0 deletions
.gitignore
+
1
−
0
View file @
077614de
...
@@ -5,3 +5,4 @@
...
@@ -5,3 +5,4 @@
*__pycache__
*__pycache__
htmlcov
htmlcov
config-test.ini
config-test.ini
tests/testdata/output/postagger_lone_json/
This diff is collapsed.
Click to expand it.
lpmn_queries.json
+
2
−
0
View file @
077614de
{
{
"posconverter_lone"
:
{
"task"
:
[{
"posconverter"
:
{
"input_format"
:
"json"
,
"output_format"
:
"json"
,
"input_tagset"
:
"ud"
,
"output_tagset"
:
"identical"
,
"json_text"
:
false
}}],
"input"
:
"remove_json_text.json"
,
"expected"
:
"remove_json_text.json"
},
"posconverter_lone"
:
{
"task"
:
[{
"posconverter"
:
{
"input_format"
:
"json"
,
"output_format"
:
"json"
,
"input_tagset"
:
"ud"
,
"output_tagset"
:
"identical"
,
"json_text"
:
false
}}],
"input"
:
"remove_json_text.json"
,
"expected"
:
"remove_json_text.json"
},
"posconverter_lone_json2lemmas"
:
{
"task"
:
[{
"posconverter"
:
{
"input_format"
:
"json"
,
"output_format"
:
"lemmas"
,
"input_tagset"
:
"ud"
,
"output_tagset"
:
"identical"
,
"json_text"
:
false
}}],
"input"
:
"remove_json_text.json"
,
"expected"
:
"remove_json_text_lemmas.txt"
},
"post_spacy_tagger_json_text"
:
{
"task"
:
[{
"spacy"
:
{
"lang"
:
"en"
,
"method"
:
"tagger"
}},
{
"posconverter"
:
{
"input_format"
:
"json"
,
"output_format"
:
"json"
,
"input_tagset"
:
"ud"
,
"output_tagset"
:
"identical"
,
"json_text"
:
true
}}],
"input"
:
"post_spacy_input"
,
"expected"
:
"post_spacy_tagger_json_text_expected.json"
},
"post_spacy_tagger_json_text"
:
{
"task"
:
[{
"spacy"
:
{
"lang"
:
"en"
,
"method"
:
"tagger"
}},
{
"posconverter"
:
{
"input_format"
:
"json"
,
"output_format"
:
"json"
,
"input_tagset"
:
"ud"
,
"output_tagset"
:
"identical"
,
"json_text"
:
true
}}],
"input"
:
"post_spacy_input"
,
"expected"
:
"post_spacy_tagger_json_text_expected.json"
},
...
...
This diff is collapsed.
Click to expand it.
src/converter.py
+
23
−
0
View file @
077614de
...
@@ -36,6 +36,27 @@ def ccl_2_lemmas(input_file, output_file):
...
@@ -36,6 +36,27 @@ def ccl_2_lemmas(input_file, output_file):
f
.
write
(
"
\n
"
)
f
.
write
(
"
\n
"
)
def
json2lemmas
(
input_file
,
output_file
):
"""
Implementation of lemmas extracting function.
:param input_file: path to a json file with words lemmas,
output of MorphoDiTa or Wcrft2
:type input_file: str
:param output_file: path to resulting text file with words in lemma forms
:type output_file: str
"""
with
open
(
input_file
,
'
rt
'
,
encoding
=
'
utf-8
'
)
as
f
:
data
=
json
.
load
(
f
)
words
=
[]
with
open
(
output_file
,
'
wt
'
,
encoding
=
'
utf-8
'
)
as
f
:
for
token
in
data
[
'
tokens
'
]:
for
lexem
in
token
[
'
lexemes
'
]:
words
.
append
(
lexem
[
'
lemma
'
])
f
.
write
(
"
"
.
join
(
words
))
f
.
write
(
"
\n
"
)
def
_convert_tagset_in_token
(
token
,
tagset
):
def
_convert_tagset_in_token
(
token
,
tagset
):
"""
Function converting mstag in token (nkjp one) to
'
tagset
'
.
"""
Function converting mstag in token (nkjp one) to
'
tagset
'
.
...
@@ -162,6 +183,8 @@ class ConverterWorker(nlp_ws.NLPWorker):
...
@@ -162,6 +183,8 @@ class ConverterWorker(nlp_ws.NLPWorker):
shutil
.
copyfile
(
input_path
,
output_path
)
shutil
.
copyfile
(
input_path
,
output_path
)
elif
input_format
==
"
ccl
"
and
output_format
==
"
lemmas
"
:
elif
input_format
==
"
ccl
"
and
output_format
==
"
lemmas
"
:
ccl_2_lemmas
(
input_path
,
output_path
)
ccl_2_lemmas
(
input_path
,
output_path
)
elif
input_format
==
"
json
"
and
output_format
==
"
lemmas
"
:
json2lemmas
(
input_path
,
output_path
)
elif
input_format
==
"
ccl
"
and
output_format
==
"
json
"
:
elif
input_format
==
"
ccl
"
and
output_format
==
"
json
"
:
tagset
=
"
nkjp
"
tagset
=
"
nkjp
"
if
output_tagset
==
"
ud
"
:
if
output_tagset
==
"
ud
"
:
...
...
This diff is collapsed.
Click to expand it.
tests/testdata/expected/remove_json_text_lemmas.txt
0 → 100644
+
1
−
0
View file @
077614de
Nazywam się Jan Kowalski i mieszkać w Wrocław . mój rodzinny dom mieścić się przy aleji Jan Paweł II .
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