Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
speller2
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Redmine
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
nlpworkers
speller2
Commits
7035bd0a
Commit
7035bd0a
authored
2 years ago
by
Tomasz Walkowiak
Browse files
Options
Downloads
Patches
Plain Diff
fixing speller (infinite processing for long words)
parent
b9d9540a
Branches
Branches containing commit
No related merge requests found
Pipeline
#9207
failed with stages
in 16 seconds
Changes
3
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
.gitignore
+7
-5
7 additions, 5 deletions
.gitignore
docker-compose.yml
+18
-0
18 additions, 0 deletions
docker-compose.yml
src/speller2_worker.py
+28
-12
28 additions, 12 deletions
src/speller2_worker.py
with
53 additions
and
17 deletions
.gitignore
100755 → 100644
+
7
−
5
View file @
7035bd0a
.idea/
# temp files
example_usage.py
example_text.txt
\ No newline at end of file
.coverage
/tests/.pytest_cache
.pytest_cache
.idea
*__pycache__
htmlcov
config-test.ini
This diff is collapsed.
Click to expand it.
docker-compose.yml
0 → 100644
+
18
−
0
View file @
7035bd0a
version
:
'
3'
services
:
polem4json
:
container_name
:
clarin_speller
build
:
./
working_dir
:
/home/worker/
entrypoint
:
-
python
-
main.py
-
service
volumes
:
-
./src:/home/worker/src
-
./main.py:/home/worker/main.py
-
./config-test.ini:/home/worker/config.ini
-
/samba:/samba
environment
:
-
PYTHONUNBUFFERED=1
This diff is collapsed.
Click to expand it.
src/speller2_worker.py
+
28
−
12
View file @
7035bd0a
...
...
@@ -2,10 +2,27 @@
import
logging
import
nlp_ws
from
autocorrect
import
Speller
from
autocorrect
import
Speller
,
Word
_log
=
logging
.
getLogger
(
__name__
)
class
SpellerFixed
(
Speller
):
"""
Fixes orginal speller in case of long words
"""
def
__init__
(
self
,
lang
=
"
en
"
):
super
().
__init__
(
lang
)
def
get_candidates
(
self
,
word
):
w
=
Word
(
word
,
self
.
lang
,
self
.
only_replacements
)
if
self
.
fast
or
len
(
word
)
>
15
:
candidates
=
self
.
existing
([
word
])
or
self
.
existing
(
w
.
typos
())
or
[
word
]
else
:
candidates
=
(
self
.
existing
([
word
])
or
self
.
existing
(
w
.
typos
())
or
self
.
existing
(
w
.
double_typos
())
or
[
word
]
)
return
[(
self
.
nlp_data
.
get
(
c
,
0
),
c
)
for
c
in
candidates
]
class
Speller2Worker
(
nlp_ws
.
NLPWorker
):
"""
Implements nlp_worker for text error correction service.
"""
...
...
@@ -14,24 +31,23 @@ class Speller2Worker(nlp_ws.NLPWorker):
def
static_init
(
cls
,
config
):
"""
One time static initialisation.
"""
_log
.
log
(
logging
.
INFO
,
"
Worker started loading static models
"
)
cls
.
_model
=
{
'
pl
'
:
Speller
(
'
pl
'
),
'
ru
'
:
Speller
(
'
ru
'
),
'
en
'
:
Speller
(
'
en
'
),
'
uk
'
:
Speller
(
'
uk
'
)}
cls
.
_model
=
{
'
pl
'
:
Speller
Fixed
(
'
pl
'
),
'
ru
'
:
Speller
Fixed
(
'
ru
'
),
'
en
'
:
Speller
Fixed
(
'
en
'
),
'
uk
'
:
Speller
Fixed
(
'
uk
'
)}
_log
.
log
(
logging
.
INFO
,
"
Worker finished loading static models
"
)
def
process
(
self
,
input_file
,
task_options
,
output_file
):
"""
Starting nlp process.
"""
_log
.
info
(
"
Processing
"
)
language
=
task_options
.
get
(
'
lang
'
,
'
pl
'
)
model
=
self
.
_model
.
get
(
language
)
data
=
self
.
_read_file
(
input_file
)
corrected_data
=
[
model
(
line
)
for
line
in
data
.
split
(
'
\n
'
)]
with
open
(
output_file
,
'
w
'
,
encoding
=
'
utf-8
'
)
as
f
:
f
.
write
(
'
\n
'
.
join
(
corrected_data
)
)
with
open
(
input_file
,
'
r
'
,
encoding
=
'
utf-8
'
)
as
f
:
with
open
(
output_file
,
'
w
'
,
encoding
=
'
utf-8
'
)
as
f_out
:
for
line
in
f
.
readlines
():
corrected_data
=
model
(
line
)
f_out
.
write
(
corrected_data
)
f_out
.
write
(
"
\n
"
)
@classmethod
def
_read_file
(
cls
,
input_path
):
...
...
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