Skip to content

Commit 3044bcc

Browse files
committed
Add worflows - tests
1 parent 1b9bc23 commit 3044bcc

File tree

4 files changed

+199
-4
lines changed

4 files changed

+199
-4
lines changed

.github/workflows/build.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ jobs:
7272
source .venv/bin/activate
7373
#poetry run pytest
7474
poetry run coverage run -m pytest
75-
poetry run coverage report --fail-under=60
75+
poetry run coverage report --fail-under=20
7676
poetry run coverage xml -o coverage.xml
7777
7878
- name: Upload coverage report

koreader_highlights_2_anki/__main__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ def get_word_importance(sentence, language="en"):
7878

7979
stop_words_dict = {
8080
"en-US": set(stopwords.words("english")),
81+
"en": set(stopwords.words("english")),
8182
"fr": set(stopwords.words("french")),
8283
"de": set(stopwords.words("german")),
8384
"es": set(stopwords.words("spanish")),
@@ -110,6 +111,7 @@ def get_word_importance(sentence, language="en"):
110111
masked_index = (inputs.input_ids == tokenizer.mask_token_id).nonzero(
111112
as_tuple=True
112113
)[1]
114+
113115
predicted_token_id = torch.argmax(predictions[0, masked_index, :], dim=-1)
114116

115117
# Score based on the predicted token's probability
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,164 @@
1+
-- we can read Lua syntax here!
2+
return {
3+
["embedded_fonts"] = true,
4+
["smooth_scaling"] = false,
5+
["preferred_dictionaries"] = {},
6+
["nightmode_images"] = true,
7+
["gamma_index"] = 15,
8+
["bookmarks"] = {
9+
[1] = {
10+
["datetime"] = "2021-02-15 14:28:25",
11+
["chapter"] = "3. The Water Premium",
12+
["highlighted"] = true,
13+
["pos0"] = "/body/DocFragment[12]/body/div/section/p[13]/text()[1].0",
14+
["pos1"] = "/body/DocFragment[12]/body/div/section/p[13]/text()[3].33",
15+
["notes"] = "The factors that help boost Ryan Howell’s happiness for the longer term are the pursuit and attainment of personal goals and the adoption of meaningful activities. Suppose that Howell was planning",
16+
["page"] = "/body/DocFragment[12]/body/div/section/p[13]/text()[1].0",
17+
},
18+
[2] = {
19+
["chapter"] = "3. The Water Premium",
20+
["datetime"] = "2021-02-15 14:42:26",
21+
["notes"] = "in 3. The Water Premium",
22+
["page"] = "/body/DocFragment[12]/body/div/section/p[12]/text()[4].322",
23+
}
24+
},
25+
["rotation_mode"] = 0,
26+
["disable_fuzzy_search"] = false,
27+
["text_lang_embedded_langs"] = true,
28+
["hyphenation"] = true,
29+
["hyph_trust_soft_hyphens"] = false,
30+
["header_font_face"] = "Noto Sans",
31+
["hyph_force_algorithmic"] = false,
32+
["font_embolden"] = 0,
33+
["copt_font_weight"] = 0,
34+
["copt_font_hinting"] = 2,
35+
["copt_font_kerning"] = 3,
36+
["copt_word_expansion"] = 0,
37+
["line_space_percent"] = 100,
38+
["copt_font_gamma"] = 15,
39+
["hide_nonlinear_flows"] = false,
40+
["partial_md5_checksum"] = "d6146523c5f0ea5bb9855311960d490b",
41+
["page_overlap_style"] = "dim",
42+
["copt_view_mode"] = 0,
43+
["copt_h_page_margins"] = {
44+
[2] = 10,
45+
[1] = 10,
46+
},
47+
["render_dpi"] = 96,
48+
["copt_b_page_margin"] = 15,
49+
["copt_word_spacing"] = {
50+
[2] = 75,
51+
[1] = 95,
52+
},
53+
["word_spacing"] = {
54+
[2] = 75,
55+
[1] = 95,
56+
},
57+
["doc_props"] = {
58+
["language"] = "en",
59+
["series"] = "",
60+
["keywords"] = "Environmental Conservation & Protection\
61+
Life Sciences\
62+
Pollution Control\
63+
Political Science\
64+
Nature\
65+
Neuroscience\
66+
Self-Help\
67+
Environmental Science\
68+
Hydrology\
69+
Science / Life Sciences / Neuroscience\
70+
Technology & Engineering\
71+
Green Lifestyle\
72+
Environmental\
73+
Environmental Policy\
74+
Science\
75+
Earth Sciences\
76+
Public Policy",
77+
["authors"] = "Céline Cousteau\
78+
Wallace J. Nichols",
79+
["title"] = "Blue Mind: How Water Makes You Happier, More Connected and Better at What You Do",
80+
["description"] = "Why are we drawn to the ocean each summer? Why does being near water set our minds and bodies at ease? In Blue Mind, Wallace J. Nichols revolutionizes how we think about these questions, revealing the remarkable truth about the benefits of being in, on, under, or simply near water. Grounded in cutting-edge studies in neurobiology, cognitive psychology, economics, and medicine, and made real by stories of innovative scientists, doctors, athletes, artists, environmentalists, businesspeople and lovers of nature - stories that fascinate the mind and touch the heart - Blue Mind will awaken readers to the vital importance of water to the health and happiness of us all.",
81+
},
82+
["stats"] = {
83+
["language"] = "en",
84+
["md5"] = "d6146523c5f0ea5bb9855311960d490b",
85+
["highlights"] = 3,
86+
["notes"] = 0,
87+
["series"] = "",
88+
["authors"] = "Céline Cousteau\
89+
Wallace J. Nichols",
90+
["title"] = "Blue Mind: How Water Makes You Happier, More Connected and Better at What You Do",
91+
["pages"] = 444,
92+
},
93+
["doc_pages"] = 444,
94+
["percent_finished"] = 0.1463963963964,
95+
["copt_block_rendering_mode"] = 3,
96+
["copt_status_line"] = 1,
97+
["font_face"] = "Noto Serif",
98+
["copt_embedded_fonts"] = 1,
99+
["copt_embedded_css"] = 1,
100+
["cache_file_path"] = "./cache/cr3cache/Wallace_J._N-_You_Do.epub.30618d06.1.cr3",
101+
["cre_dom_version"] = 20200824,
102+
["last_xpointer"] = "/body/DocFragment[11]/body/div/section/p[23]/text()[2].63",
103+
["word_expansion"] = 0,
104+
["copt_sync_t_b_page_margins"] = 0,
105+
["highlight"] = {
106+
[77] = {
107+
[1] = {
108+
["datetime"] = "2021-02-15 14:28:25",
109+
["chapter"] = "3. The Water Premium",
110+
["pos0"] = "/body/DocFragment[12]/body/div/section/p[13]/text()[1].0",
111+
["pos1"] = "/body/DocFragment[12]/body/div/section/p[13]/text()[3].33",
112+
["drawer"] = "lighten",
113+
["text"] = "The factors that help boost Ryan Howell’s happiness for the longer term are the pursuit and attainment of personal goals and the adoption of meaningful activities. Suppose that Howell was planning",
114+
},
115+
},
116+
[75] = {
117+
[1] = {
118+
["datetime"] = "2021-02-15 14:24:18",
119+
["chapter"] = "3. The Water Premium",
120+
["pos0"] = "/body/DocFragment[12]/body/div/section/p[11]/text()[1].0",
121+
["pos1"] = "/body/DocFragment[12]/body/div/section/p[11]/text()[2].416",
122+
["drawer"] = "lighten",
123+
["text"] = "Here’s where our DNA enters the picture.9 Research psychologists Sonja Lyubomirsky, Kennon Sheldon, and David Schkade theorize that we each have a happiness “baseline” that is determined by three factors: (1) a genetically determined “set point” for happiness; (2) spending time in circumstances that make us happy; and (3) choosing happiness-generating activities and practices. They believe that while genetic predisposition accounts for around 50 percent",
124+
},
125+
},
126+
[76] = {
127+
[1] = {
128+
["datetime"] = "2021-02-15 14:25:06",
129+
["chapter"] = "3. The Water Premium",
130+
["pos0"] = "/body/DocFragment[12]/body/div/section/p[11]/text()[2].736",
131+
["pos1"] = "/body/DocFragment[12]/body/div/section/p[11]/a[2]/sup/text().2",
132+
["drawer"] = "lighten",
133+
["text"] = "The other 40 percent of our happiness is shaped by voluntarily pursuing personal goals through meaningful activities.10",
134+
},
135+
},
136+
},
137+
["copt_smooth_scaling"] = 0,
138+
["copt_rotation_mode"] = 0,
139+
["highlight_disabled"] = false,
140+
["copt_visible_pages"] = 1,
141+
["highlight_drawer"] = "lighten",
142+
["copt_render_dpi"] = 96,
143+
["gamma"] = 1,
144+
["font_size"] = 22,
145+
["font_hinting"] = 2,
146+
["hyph_soft_hyphens_only"] = false,
147+
["copt_line_spacing"] = 100,
148+
["config_panel_index"] = 1,
149+
["show_overlap_enable"] = false,
150+
["font_kerning"] = 3,
151+
["copt_font_size"] = 22,
152+
["copt_nightmode_images"] = 1,
153+
["render_mode"] = 0,
154+
["inverse_reading_order"] = false,
155+
["css"] = "./data/epub.css",
156+
["visible_pages"] = 1,
157+
["readermenu_tab_index"] = 7,
158+
["bookmarks_sorted"] = true,
159+
["floating_punctuation"] = 0,
160+
["embedded_css"] = true,
161+
["highlights_imported"] = true,
162+
["text_lang"] = "en-US",
163+
["copt_t_page_margin"] = 15,
164+
}

test_koreader_highlights_2_anki/test_main.py

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
1-
import unittest
21
import os
2+
import unittest
33

4-
from koreader_highlights_2_anki.__main__ import parse_lua_highlights_annotations
5-
4+
from koreader_highlights_2_anki.__main__ import parse_lua_highlights_annotations, parse_lua_highlights_bookmarks
65

76
ROOT_DIR = os.path.dirname(os.path.abspath(__file__))
87

@@ -42,6 +41,36 @@ def test_parse_lua_highlights_annotations(self):
4241
self.assertEqual(result["language"], expected_metadata["language"])
4342
self.assertEqual(result["entries"], expected_metadata["entries"])
4443

44+
def test_parse_lua_highlights_bookmarks(self):
45+
# Define the path to the Lua file
46+
filepath = os.path.join("Wallace J. Nichols - Blue Mind_ How Water Makes You Happier_ More Connected and Better at What You Do.sdr/metadata.epub.lua")
47+
filepath = os.path.join(ROOT_DIR, "resources", filepath)
48+
49+
# Call the function with the actual Lua file
50+
result = parse_lua_highlights_bookmarks(filepath)
51+
52+
# Expected output structure (modify according to your actual expected output)
53+
expected_metadata = {
54+
"title": "Blue Mind: How Water Makes You Happier, More Connected and Better at What You Do",
55+
"authors": "Céline Cousteau\nWallace J. Nichols",
56+
"language": "en",
57+
"entries": [
58+
{'chapter': '3. The Water Premium',
59+
'datetime': '2021-02-15 14:28:25',
60+
'notes': 'The factors that help boost Ryan Howell’s happiness for the longer '
61+
'term are the pursuit and attainment of personal goals and the '
62+
'adoption of meaningful activities. Suppose that Howell was '
63+
'planning',
64+
'page': '12'}
65+
],
66+
}
67+
68+
self.assertIsNotNone(result)
69+
self.assertEqual(result["title"], expected_metadata["title"])
70+
self.assertEqual(result["authors"], expected_metadata["authors"])
71+
self.assertEqual(result["language"], expected_metadata["language"])
72+
self.assertEqual(result["entries"], expected_metadata["entries"])
73+
4574

4675
if __name__ == '__main__':
4776
unittest.main()

0 commit comments

Comments
 (0)