Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
F
fcs-clarin-endpoint-hamburg
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Arkhangelskiy, Timofey
fcs-clarin-endpoint-hamburg
Commits
0752838a
Commit
0752838a
authored
2 years ago
by
Arkhangelskiy, Timofey
Browse files
Options
Downloads
Patches
Plain Diff
Add conversion mechanism for corpus-specific POS
parent
8e4aefee
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
common/config.py
+5
-4
5 additions, 4 deletions
common/config.py
common/tsakorpus_response_parser.py
+23
-1
23 additions, 1 deletion
common/tsakorpus_response_parser.py
config/test.json
+5
-1
5 additions, 1 deletion
config/test.json
with
33 additions
and
6 deletions
common/config.py
+
5
−
4
View file @
0752838a
...
...
@@ -40,6 +40,7 @@ class ResourceConfig:
self
.
supported_layers
=
[]
self
.
resources
=
[]
self
.
search_lang_id
=
''
self
.
pos_convert
=
{}
self
.
query_timeout
=
60
...
...
@@ -47,16 +48,16 @@ class ResourceConfig:
if
type
(
self
.
__dict__
[
k
])
==
bool
)
self
.
intParams
=
set
(
k
for
k
in
self
.
__dict__
if
type
(
self
.
__dict__
[
k
])
==
int
)
self
.
lsParams
=
{}
self
.
lsParams
=
set
()
# dictionaries where values are strings
self
.
dict_sParams
=
{}
self
.
dict_sParams
=
{
'
pos_convert
'
}
# dictionaries where values are lists of strings
self
.
dict_lsParams
=
{}
self
.
dict_lsParams
=
set
()
# dictionaries where values are dictionaries {k: string}
self
.
dict_dParams
=
{}
self
.
dict_dParams
=
set
()
if
fnameConfig
is
not
None
and
os
.
path
.
exists
(
fnameConfig
):
self
.
load_settings
(
fnameConfig
)
...
...
This diff is collapsed.
Click to expand it.
common/tsakorpus_response_parser.py
+
23
−
1
View file @
0752838a
...
...
@@ -9,12 +9,32 @@ from .search_retrieve import Record
from
.diagnostics
import
Diagnostic
,
DiagnosticTypes
class
POSConvertor
:
"""
Convert corpus-specific parts of speech / grammar tags to
UPOS, using regexes correspondences set in the config.
"""
def
__init__
(
self
,
config
:
ResourceConfig
):
self
.
posConvert
=
config
.
pos_convert
self
.
posTests
=
[(
re
.
compile
(
k
),
v
)
for
k
,
v
in
self
.
posConvert
]
def
convert_pos
(
self
,
pos
):
"""
Convert corpus-specific POS tags to UPOS, if possible.
Ea
"""
for
k
,
v
in
self
.
posTests
:
if
k
.
search
(
pos
)
is
not
None
:
return
v
return
pos
class
TsakorpusResponseParser
:
"""
Parses responses from a Tsakorpus instance.
"""
def
__init__
(
self
):
pass
self
.
pc
=
None
# POS convertor, rebuilt with each parse call
def
parse_annotation
(
self
,
anno
,
segID
,
record
):
"""
...
...
@@ -37,6 +57,7 @@ class TsakorpusResponseParser:
for
node
in
posNodes
:
if
node
.
text
is
not
None
:
posText
=
re
.
sub
(
'
|[
\t\ufeff
]+
'
,
''
,
node
.
text
)
posText
=
self
.
pc
.
convert_pos
(
posText
)
pos
.
add
(
posText
)
if
len
(
pos
)
>
0
:
posStr
=
'
|
'
.
join
(
p
for
p
in
sorted
(
pos
))
...
...
@@ -119,6 +140,7 @@ class TsakorpusResponseParser:
instance. Return a list of Record objects and the total number of
records found.
"""
self
.
pc
=
POSConvertor
(
config
)
nRecords
=
0
if
'
n_sentences
'
in
response
:
nRecords
=
response
[
'
n_sentences
'
]
...
...
This diff is collapsed.
Click to expand it.
config/test.json
+
5
−
1
View file @
0752838a
...
...
@@ -4,5 +4,9 @@
"max_hits"
:
15
,
"platform"
:
"tsakorpus"
,
"resource_base_url"
:
"http://127.0.0.1:7342"
,
"search_lang_id"
:
"beserman"
"search_lang_id"
:
"beserman"
,
"pos_convert"
:
[
[
"
\\
bN
\\
b"
,
"NOUN"
],
[
"
\\
bV
\\
b"
,
"VERB"
]
]
}
\ No newline at end of file
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