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
4
Merged
Björn Ludwig
requested to merge
introduce_chars
into
main
3 years ago
Overview
0
Commits
22
Pipelines
0
Changes
4
Expand
This improves the implementation by introducing a class to manage the characters
0
0
Merge request reports
Viewing commit
96ac13b9
Prev
Next
Show latest version
4 files
+
61
−
44
Inline
Compare changes
Side-by-side
Inline
Show whitespace changes
Show one file at a time
Files
4
Search (e.g. *.vue) (Ctrl+P)
Unverified
96ac13b9
refactor(type_aliases): rename some type aliases, the module itself and include all in __all__
· 96ac13b9
Björn Ludwig
authored
3 years ago
src/ilp_keyboard_layout_optimization/data_aquisition/chars.py
0 → 100644
+
78
−
0
Options
"""
This module contains the class providing a unified interface for character sets
"""
__all__
=
[
"
Chars
"
]
import
string
from
itertools
import
product
from
typing
import
Optional
,
Tuple
,
Union
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
=
(
string
.
ascii_lowercase
+
string
.
ascii_uppercase
+
string
.
digits
+
string
.
punctuation
+
"
üöäÜÖÄß–…
"
)
else
:
self
.
chars
=
chars
@property
def
chars
(
self
)
->
str
:
return
self
.
_chars
@chars.setter
def
chars
(
self
,
chars
:
Union
[
str
,
CharTuple
]):
if
isinstance
(
chars
,
str
):
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
monos
(
self
)
->
CharTuple
:
try
:
return
self
.
_monos
except
AttributeError
:
self
.
_monos
=
self
.
_str2char_tuple
(
self
.
chars
)
return
self
.
_monos
@staticmethod
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