Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
I
ilp_keyboard_layout_optimization
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
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
Issue analytics
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
Björn Ludwig
ilp_keyboard_layout_optimization
Merge requests
!1
Introduce Chars
Code
Review changes
Check out branch
Download
Patches
Plain diff
Merged
Introduce Chars
introduce_chars
into
main
Overview
0
Commits
22
Pipelines
0
Changes
13
Merged
Björn Ludwig
requested to merge
introduce_chars
into
main
3 years ago
Overview
0
Commits
22
Pipelines
0
Changes
6
Expand
This improves the implementation by introducing a class to manage the characters
0
0
Merge request reports
Compare
version 1
version 7
10367c8b
3 years ago
version 6
9688927b
3 years ago
version 5
200ca4bf
3 years ago
version 4
6ccba81e
3 years ago
version 3
99bf72da
3 years ago
version 2
67ba0ce1
3 years ago
version 1
fb813af0
3 years ago
main (base)
and
version 2
latest version
c9e7d546
22 commits,
3 years ago
version 7
10367c8b
21 commits,
3 years ago
version 6
9688927b
20 commits,
3 years ago
version 5
200ca4bf
19 commits,
3 years ago
version 4
6ccba81e
18 commits,
3 years ago
version 3
99bf72da
16 commits,
3 years ago
version 2
67ba0ce1
13 commits,
3 years ago
version 1
fb813af0
10 commits,
3 years ago
Show latest version
6 files
+
242
−
112
Inline
Compare changes
Side-by-side
Inline
Show whitespace changes
Show one file at a time
Files
6
Search (e.g. *.vue) (Ctrl+P)
src/ilp_keyboard_layout_optimization/data_aquisition/chars.py
+
47
−
8
Options
@@ -2,19 +2,36 @@
__all__
=
[
"
Chars
"
]
from
typing
import
Optional
,
Union
import
string
from
itertools
import
product
from
typing
import
Optional
,
Tuple
,
Union
from
src.ilp_keyboard_layout_optimization
.type_aliases
import
CharTuple
from
.
.type_aliases
import
Bigram
,
CharTuple
class
Chars
:
"""
A unified interface to a collection of characters and corresponding bigrams
Parameters
----------
chars : str or CharTupel, optional
A string of concatenated (special) characters or a CharTupel of single
characters, that are supposed to be considered. Defaults to the most common
letters, numbers and punctuation in German texts.
"""
_chars
:
str
_monos
:
CharTuple
_bis
:
Tuple
[
Bigram
]
def
__init__
(
self
,
chars
:
Optional
[
Union
[
str
,
CharTuple
]]
=
None
):
if
chars
is
None
:
self
.
_chars
=
(
"""
abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890,
"""
r
"""
üöäÜÖÄß.:;-–…_[](){}^\/#!?+<>&$|~`*=%
"'
@
"""
string
.
ascii_lowercase
+
string
.
ascii_uppercase
+
string
.
digits
+
string
.
punctuation
+
"
üöäÜÖÄß–…
"
)
else
:
self
.
chars
=
chars
@@ -29,11 +46,33 @@ class Chars:
self
.
_chars
=
chars
else
:
# isinstance(chars, CharTuple):
self
.
_chars
=
""
.
join
(
char
for
char
in
chars
)
try
:
del
self
.
_monos
except
AttributeError
:
pass
try
:
del
self
.
_bis
except
AttributeError
:
pass
@property
def
char_tuple
(
self
)
->
CharTuple
:
return
self
.
_str2char_tuple
(
self
.
chars
)
def
monos
(
self
)
->
CharTuple
:
try
:
return
self
.
_monos
except
AttributeError
:
self
.
_monos
=
self
.
_str2char_tuple
(
self
.
chars
)
return
self
.
_monos
@staticmethod
def
_str2char_tuple
(
string
:
str
)
->
CharTuple
:
return
tuple
(
char
for
char
in
string
)
def
_str2char_tuple
(
char_str
:
str
)
->
CharTuple
:
return
tuple
(
char
for
char
in
char_str
)
@property
def
bis
(
self
):
try
:
return
self
.
_bis
except
AttributeError
:
self
.
_bis
=
tuple
(
""
.
join
(
bigram_tuple
)
for
bigram_tuple
in
product
(
self
.
chars
,
repeat
=
2
)
)
return
self
.
_bis
Loading