Skip to content

Commit

Permalink
Work Area: Update Profiler - Readability - OSMAN
Browse files Browse the repository at this point in the history
  • Loading branch information
BLKSerene committed May 20, 2024
1 parent 1157cc8 commit b0f1579
Show file tree
Hide file tree
Showing 29 changed files with 880 additions and 153 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
- Settings: Settings - Part-of-speeach Tagging - Tagsets - Mapping Settings - Allow editing of tagset mapping of Stanza's Armenian (Eastern), Armenian (Western), Basque, Buryat (Russia), Danish, French, Greek (Modern), Hebrew (Modern), Hungarian, Ligurian, Manx, Marathi, Nigerian Pidgin, Pomak, Portuguese, Russian, Sanskrit, Sindhi, Sorbian (Upper), and Telugu part-of-speech taggers
- Utils: Update custom stop word lists
- Work Area: Dependency Parser - Sentence - Highlight heads and dependents
- Work Area: Update Profiler - Readability - OSMAN

### 📌 Bugfixes
- Utils: Fix downloading of Stanza models
Expand Down
69 changes: 33 additions & 36 deletions doc/doc.md

Large diffs are not rendered by default.

3 changes: 0 additions & 3 deletions pylintrc
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,6 @@ disable=
# C0301, C0302
line-too-long,
too-many-lines,
# C0413, C0415
wrong-import-position,
import-outside-toplevel,

# R0401
cyclic-import,
Expand Down
14 changes: 13 additions & 1 deletion tests/tests_measures/test_measures_readability.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ def __init__(self, tokens_multilevel, lang = 'eng_us'):

test_text_ara_0 = Wl_Test_Text(TOKENS_MULTILEVEL_0, lang = 'ara')
test_text_ara_12 = Wl_Test_Text(TOKENS_MULTILEVEL_12, lang = 'ara')
test_text_ara_faseeh = Wl_Test_Text([[[['\u064B\u064B\u0621']]]], lang = 'ara')

test_text_deu_0 = Wl_Test_Text(TOKENS_MULTILEVEL_0, lang = 'deu_de')
test_text_deu_12 = Wl_Test_Text(TOKENS_MULTILEVEL_12, lang = 'deu_de')
Expand Down Expand Up @@ -685,18 +686,28 @@ def test_nws():
assert nws_deu_12_3 == 0.2963 * ms + 0.1905 * sl - 1.1144
assert nws_eng_12 == 'no_support'

def test__get_num_syls_ara():
assert wl_measures_readability._get_num_syls_ara('') == 0
assert wl_measures_readability._get_num_syls_ara('\u064E\u0627') == 2
assert wl_measures_readability._get_num_syls_ara('\u064Ea') == 1
assert wl_measures_readability._get_num_syls_ara('\u064E') == 1
assert wl_measures_readability._get_num_syls_ara('\u064B') == 2

def test_osman():
osman_ara_0 = wl_measures_readability.osman(main, test_text_ara_0)
osman_ara_12 = wl_measures_readability.osman(main, test_text_ara_12)
osman_ara_faseeh = wl_measures_readability.osman(main, test_text_ara_faseeh)
osman_eng_12 = wl_measures_readability.osman(main, test_text_eng_12)

print('OSMAN:')
print(f'\tara/0: {osman_ara_0}')
print(f'\tara/12: {osman_ara_12}')
print(f'\tara/faseeh: {osman_ara_faseeh}')
print(f'\teng/12: {osman_eng_12}')

assert osman_ara_0 == 'text_too_short'
assert osman_ara_12 == 200.791 - 1.015 * (12 / 3) - 24.181 * ((3 + 23 + 3 + 0) / 12)
assert osman_ara_12 == 200.791 - 1.015 * (12 / 3) - 24.181 * ((3 + 26 + 3 + 0) / 12)
assert osman_ara_faseeh == 200.791 - 1.015 * (1 / 1) - 24.181 * ((0 + 5 + 1 + 1) / 1)
assert osman_eng_12 == 'no_support'

def test_rix():
Expand Down Expand Up @@ -857,6 +868,7 @@ def test_wheeler_smiths_readability_formula():
test_eflaw()
test_nwl()
test_nws()
test__get_num_syls_ara()
test_osman()
test_rix()
test_smog_grade()
Expand Down
19 changes: 19 additions & 0 deletions tests/tests_utils/test_misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,24 @@ def test_change_file_owner_to_user():

os.remove('test')

class Widget:
def parent(self):
return 'parent'

def test_find_wl_main():
class Widget:
def parent(self):
return main

widget = Widget()
widget.main = 'test'

assert wl_misc.find_wl_main(widget) == 'test'

del widget.main

assert wl_misc.find_wl_main(widget) == main

def test_get_wl_ver():
assert re.search(r'^[0-9]+\.[0-9]+\.[0-9]$', str(wl_misc.get_wl_ver()))

Expand Down Expand Up @@ -109,6 +127,7 @@ def test_normalize_nums():
test_get_linux_distro()
test_change_file_owner_to_user()

test_find_wl_main()
test_get_wl_ver()
test_wl_get_proxies()
test_wl_download()
Expand Down
55 changes: 55 additions & 0 deletions tests/tests_utils/test_threading.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
# ----------------------------------------------------------------------
# Wordless: Tests - Utilities - Threading
# Copyright (C) 2018-2024 Ye Lei (叶磊)
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
# ----------------------------------------------------------------------

from tests import wl_test_init
from wordless.wl_dialogs import wl_dialogs_misc
from wordless.wl_utils import wl_threading

main = wl_test_init.Wl_Test_Main()

def test_wl_worker():
dialog_progress = wl_dialogs_misc.Wl_Dialog_Progress(main, 'test')
wl_threading.Wl_Worker(main, dialog_progress, lambda: None)

def test_wl_worker_no_progress():
wl_threading.Wl_Worker_No_Progress(main, lambda: None)

def test_wl_worker_no_callback():
dialog_progress = wl_dialogs_misc.Wl_Dialog_Progress(main, 'test')
wl_threading.Wl_Worker_No_Callback(main, dialog_progress)

def test_wl_thread():
dialog_progress = wl_dialogs_misc.Wl_Dialog_Progress(main, 'test')
worker = wl_threading.Wl_Worker(main, dialog_progress, lambda: None)
worker.run = lambda: None

wl_threading.Wl_Thread(worker)

def test_wl_thread_no_progress():
worker = wl_threading.Wl_Worker_No_Progress(main, lambda: None)
worker.run = lambda: None

wl_threading.Wl_Thread_No_Progress(worker).start_worker()

if __name__ == '__main__':
test_wl_worker()
test_wl_worker_no_progress()
test_wl_worker_no_callback()

test_wl_thread()
test_wl_thread_no_progress()
Empty file added tests/tests_widgets/__init__.py
Empty file.
164 changes: 164 additions & 0 deletions tests/tests_widgets/test_boxes.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,164 @@
# ----------------------------------------------------------------------
# Wordless: Tests - Widgets - Boxes
# Copyright (C) 2018-2024 Ye Lei (叶磊)
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
# ----------------------------------------------------------------------

from tests import wl_test_init
from wordless.wl_widgets import wl_boxes

main = wl_test_init.Wl_Test_Main()

def test_wl_combo_box():
wl_boxes.Wl_Combo_Box(main)

def test_wl_combo_box_adjustable():
wl_boxes.Wl_Combo_Box_Adjustable(main)

def test_wl_combo_box_enums():
combo_box_enums = wl_boxes.Wl_Combo_Box_Enums(main, {'test1': 1, 'test2': 2})
assert combo_box_enums.get_val() == 1

combo_box_enums.set_val(2)
assert combo_box_enums.get_val() == 2

def test_wl_combo_box_yes_no():
combo_box_yes_no = wl_boxes.Wl_Combo_Box_Yes_No(main)
assert combo_box_yes_no.get_yes_no()

combo_box_yes_no.set_yes_no(False)
assert not combo_box_yes_no.get_yes_no()

def test_wl_combo_box_lang():
wl_boxes.Wl_Combo_Box_Lang(main)

def test_wl_combo_box_encoding():
wl_boxes.Wl_Combo_Box_Encoding(main)

def test_wl_combo_box_measure():
mapping_measures = list(list(main.settings_global['mapping_measures'].values())[0].items())

combo_box_measure = wl_boxes.Wl_Combo_Box_Measure(main, list(main.settings_global['mapping_measures'])[0])
assert combo_box_measure.get_measure() == mapping_measures[0][1]

combo_box_measure.set_measure(mapping_measures[1][1])
assert combo_box_measure.get_measure() == mapping_measures[1][1]

def test_wl_combo_box_file_to_filter():
table = wl_test_init.Wl_Test_Table(main)
table.settings['file_area']['files_open'] = [{'selected': True, 'name': 'test'}]

combo_box_file_to_filter = wl_boxes.Wl_Combo_Box_File_To_Filter(main, table)
combo_box_file_to_filter.table_item_changed()

def test_wl_combo_box_file():
combo_box_file = wl_boxes.Wl_Combo_Box_File(main)
combo_box_file.wl_files_changed()
combo_box_file.get_file()

def test_wl_combo_box_font_family():
wl_boxes.Wl_Combo_Box_Font_Family(main)

def test_wl_spin_box():
wl_boxes.Wl_Spin_Box(main)

def test_wl_spin_box_window():
spin_box_window = wl_boxes.Wl_Spin_Box_Window(main)
spin_box_window.setValue(-100)
spin_box_window.stepBy(1)
spin_box_window.setValue(-100)
spin_box_window.stepBy(1)

def test_wl_spin_box_font_size():
wl_boxes.Wl_Spin_Box_Font_Size(main)

def test_wl_spin_box_font_weight():
wl_boxes.Wl_Spin_Box_Font_Weight(main)

def test_wl_double_spin_box():
wl_boxes.Wl_Double_Spin_Box(main)

def test_wl_double_spin_box_alpha():
wl_boxes.Wl_Double_Spin_Box_Alpha(main)

def test_wl_spin_box_no_limit():
_, checkbox_no_limit = wl_boxes.wl_spin_box_no_limit(main, double = True)

checkbox_no_limit.setChecked(True)
checkbox_no_limit.setChecked(False)

wl_boxes.wl_spin_box_no_limit(main, double = False)

def test_wl_spin_boxes_min_max():
spin_box_min, spin_box_max = wl_boxes.wl_spin_boxes_min_max(main, double = True)

spin_box_min.setValue(100)
spin_box_max.setValue(1)

wl_boxes.wl_spin_boxes_min_max(main, double = False)

def test_wl_spin_boxes_min_max_no_limit():
_, checkbox_min_no_limit, _, checkbox_max_no_limit = wl_boxes.wl_spin_boxes_min_max_no_limit(main, double = True)

checkbox_min_no_limit.setChecked(True)
checkbox_min_no_limit.setChecked(False)
checkbox_max_no_limit.setChecked(True)
checkbox_max_no_limit.setChecked(False)

wl_boxes.wl_spin_boxes_min_max_no_limit(main, double = False)

def test_wl_spin_boxes_min_max_sync():
checkbox_sync, _, spin_box_min, _, spin_box_max = wl_boxes.wl_spin_boxes_min_max_sync(main, double = True)

checkbox_sync.setChecked(True)
spin_box_min.setValue(100)
spin_box_max.setValue(100)

wl_boxes.wl_spin_boxes_min_max_sync(main, double = False)

def test_wl_spin_boxes_min_max_sync_window():
checkbox_sync, _, spin_box_left, _, spin_box_right = wl_boxes.wl_spin_boxes_min_max_sync_window(main)

checkbox_sync.setChecked(True)
spin_box_left.setValue(100)
spin_box_right.setValue(100)

wl_boxes.wl_spin_boxes_min_max_sync_window(main)

if __name__ == '__main__':
test_wl_combo_box()
test_wl_combo_box_adjustable()
test_wl_combo_box_enums()
test_wl_combo_box_yes_no()
test_wl_combo_box_lang()
test_wl_combo_box_encoding()
test_wl_combo_box_measure()
test_wl_combo_box_file_to_filter()
test_wl_combo_box_file()
test_wl_combo_box_font_family()

test_wl_spin_box()
test_wl_spin_box_window()
test_wl_spin_box_font_size()
test_wl_spin_box_font_weight()

test_wl_double_spin_box()
test_wl_double_spin_box_alpha()

test_wl_spin_box_no_limit()
test_wl_spin_boxes_min_max()
test_wl_spin_boxes_min_max_no_limit()
test_wl_spin_boxes_min_max_sync()
test_wl_spin_boxes_min_max_sync_window()
47 changes: 47 additions & 0 deletions tests/tests_widgets/test_buttons.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# ----------------------------------------------------------------------
# Wordless: Tests - Widgets - Buttons
# Copyright (C) 2018-2024 Ye Lei (叶磊)
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
# ----------------------------------------------------------------------

from PyQt5.QtWidgets import QLineEdit

from tests import wl_test_init
from wordless.wl_widgets import wl_buttons

main = wl_test_init.Wl_Test_Main()

def test_wl_button():
wl_buttons.Wl_Button('test', main)

def test_wl_button_browse():
wl_buttons.Wl_Button_Browse(main, 'test', QLineEdit(), 'test', ['test'])

def test_wl_button_color():
button = wl_buttons.Wl_Button_Color(main)
button.get_color()
button.set_color('test')

wl_buttons.wl_button_color(main, allow_transparent = True)
wl_buttons.wl_button_color(main, allow_transparent = False)

def test_wl_button_restore_defaults():
wl_buttons.Wl_Button_Restore_Defaults(main, 'test')

if __name__ == '__main__':
test_wl_button()
test_wl_button_browse()
test_wl_button_color()
test_wl_button_restore_defaults()
28 changes: 28 additions & 0 deletions tests/tests_widgets/test_editors.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# ----------------------------------------------------------------------
# Wordless: Tests - Widgets - Editors
# Copyright (C) 2018-2024 Ye Lei (叶磊)
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
# ----------------------------------------------------------------------

from tests import wl_test_init
from wordless.wl_widgets import wl_editors

main = wl_test_init.Wl_Test_Main()

def test_wl_text_browser():
wl_editors.Wl_Text_Browser(main)

if __name__ == '__main__':
test_wl_text_browser()
Loading

0 comments on commit b0f1579

Please sign in to comment.