Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
symspell
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
Package Registry
Container Registry
Operate
Environments
Terraform modules
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
symspell
Commits
3a7c234d
Commit
3a7c234d
authored
3 years ago
by
Michał Pogoda
Browse files
Options
Downloads
Patches
Plain Diff
Fixed styling with black
parent
de260011
Branches
master
Branches containing commit
No related merge requests found
Pipeline
#8235
passed with stage
in 26 seconds
Changes
1
Pipelines
2
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/worker.py
+14
-22
14 additions, 22 deletions
src/worker.py
with
14 additions
and
22 deletions
src/worker.py
+
14
−
22
View file @
3a7c234d
...
...
@@ -5,27 +5,19 @@ import numpy as np
class
WordSplit
(
object
):
def
__init__
(
self
):
<<<<<<<
HEAD
self
.
sym_spell
=
SymSpell
(
max_dictionary_edit_distance
=
0
,
prefix_length
=
7
)
self
.
sym_spell
.
load_dictionary
(
"
vocab.txt
"
,
term_index
=
0
,
count_index
=
1
)
=======
self
.
sym_spell
=
SymSpell
(
max_dictionary_edit_distance
=
0
,
prefix_length
=
7
)
self
.
sym_spell
.
load_dictionary
(
'
vocab.txt
'
,
term_index
=
0
,
count_index
=
1
)
with
open
(
'
vocab.txt
'
,
'
r
'
,
encoding
=
'
utf8
'
)
as
f
:
with
open
(
"
vocab.txt
"
,
"
r
"
,
encoding
=
"
utf8
"
)
as
f
:
self
.
vocab_data
=
f
.
readlines
()
self
.
frequeancy
=
[]
self
.
key_data
=
[]
for
line
in
self
.
vocab_data
:
self
.
frequeancy
.
append
(
int
(
line
.
split
(
"
"
)[
1
]))
self
.
key_data
.
append
(
line
.
split
(
"
"
[
0
]))
>>>>>>>
deployment
def
load_data
(
self
,
path
):
with
open
(
path
,
"
r
"
,
encoding
=
"
utf8
"
)
as
f
:
...
...
@@ -38,8 +30,8 @@ class WordSplit(object):
def
quantile_vocab
(
self
,
data
,
freq_vocab
,
path
):
filter_data
=
[]
for
key
in
data
:
filter_data
.
append
(
f
'
{
key
}
{
freq_vocab
}
'
.
replace
(
'
\n
'
,
''
)
+
'
\n
'
)
self
.
save_data
(
path
+
'
_joined
'
,
filter_data
)
filter_data
.
append
(
f
"
{
key
}
{
freq_vocab
}
"
.
replace
(
"
\n
"
,
""
)
+
"
\n
"
)
self
.
save_data
(
path
+
"
_joined
"
,
filter_data
)
def
check_if_exist
(
self
,
vocab
,
path
):
filter_data
=
[]
...
...
@@ -48,7 +40,7 @@ class WordSplit(object):
continue
else
:
filter_data
.
append
(
key
)
self
.
save_data
(
path
+
'
_joined
'
,
filter_data
)
self
.
save_data
(
path
+
"
_joined
"
,
filter_data
)
return
filter_data
def
handle_word_transfer
(
self
,
text
):
...
...
@@ -73,14 +65,14 @@ class WordSplit(object):
if
quantile
is
not
None
:
freq_vocab
=
np
.
quantile
(
self
.
frequeancy
,
quantile
)
self
.
quantile_vocab
(
filter_data
,
freq_vocab
,
vocab
)
self
.
sym_spell
.
load_dictionary
(
vocab
+
'
_v1
'
,
term_index
=
0
,
count_index
=
1
)
if
language
and
language
!=
'
pl
'
:
if
os
.
path
.
isfile
(
f
'
{
language
}
_vocab.txt
'
):
self
.
sym_spell
.
load_dictionary
(
f
'
{
language
}
_vocab.txt
'
,
term_index
=
0
,
count_index
=
1
)
self
.
sym_spell
.
load_dictionary
(
vocab
+
"
_v1
"
,
term_index
=
0
,
count_index
=
1
)
if
language
and
language
!=
"
pl
"
:
if
os
.
path
.
isfile
(
f
"
{
language
}
_vocab.txt
"
):
self
.
sym_spell
.
load_dictionary
(
f
"
{
language
}
_vocab.txt
"
,
term_index
=
0
,
count_index
=
1
)
if
os
.
path
.
isdir
(
input_file
):
folder
=
os
.
listdir
(
input_file
)
if
not
os
.
path
.
exists
(
output_file
):
...
...
@@ -106,9 +98,9 @@ class WordSplit(object):
text
.
append
(
result
.
corrected_string
+
"
\n
"
)
self
.
save_data
(
output_file
,
text
)
if
vocab
is
not
None
:
with
open
(
vocab
+
'
_joined,
'
,
'
r
'
)
as
f
:
with
open
(
vocab
+
"
_joined,
"
,
"
r
"
)
as
f
:
vocab_data
=
f
.
readlines
()
for
line
in
vocab_data
:
key
=
line
.
split
(
"
"
)[
0
]
self
.
sym_spell
.
delete_dictionary_entry
(
key
)
os
.
remove
(
vocab
+
'
_joined,
'
)
os
.
remove
(
vocab
+
"
_joined,
"
)
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