Skip to content

Commit

Permalink
Add IPA field
Browse files Browse the repository at this point in the history
Closes #18
  • Loading branch information
abdnh committed Feb 21, 2023
1 parent e94be45 commit c5ec088
Show file tree
Hide file tree
Showing 9 changed files with 108 additions and 47 deletions.
33 changes: 20 additions & 13 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,60 +5,67 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [1.3.0] - 2023-02-22

### Added

- Added IPA field.

## [1.2.1] - 2022-11-27

### Fixed

- Fix a critical error preventing the add-on from working in most situations (https://github.com/abdnh/anki-zim-reader/issues/16).
- Fix a critical error preventing the add-on from working in most situations (https://github.com/abdnh/anki-zim-reader/issues/16).

## [1.2.0] - 2022-11-23

### Added

- Add window to browse imported files.
- Add window to browse imported files.

## [1.1.0] - 2022-11-05

### Added

- Add support for Turkish Wiktionary.
- Add support for Turkish Wiktionary.

### Changed

- Format example sentences as a list.
- Format example sentences as a list.

## [0.0.3] - 2022-10-18

### Added

- Allow customizing editor/browser shortcuts from the settings interface.
- Use [Libzim](https://github.com/openzim/libzim) on Linux and macOS to parse the ZIM files. This should work better than ZIMply.
- Allow customizing editor/browser shortcuts from the settings interface.
- Use [Libzim](https://github.com/openzim/libzim) on Linux and macOS to parse the ZIM files. This should work better than ZIMply.

### Changed

- Extract m/f/n gender abbreviations for the German parser instead of the full names.
- Extract m/f/n gender abbreviations for the German parser instead of the full names.

### Fixed

- Fix issue with inflection table extraction for the Greek parser.
- Fix "internal server error" being shown for some missing words in the pop-up dictionary.
- Fix issue with inflection table extraction for the Greek parser.
- Fix "internal server error" being shown for some missing words in the pop-up dictionary.

## [0.0.2] - 2022-10-08

### Added

- Support Anki versions 2.1.46>=,<=2.1.50
- Support image extraction for Greek and Spanish dictionaries.
- Support Anki versions 2.1.46>=,<=2.1.50
- Support image extraction for Greek and Spanish dictionaries.

### Fixed

- Fix images added by the add-on not being resized correctly using Anki's image resizer.
- Fix images added by the add-on not being resized correctly using Anki's image resizer.

## [0.0.1] - 2022-10-06

Initial release.

[unreleased]: https://github.com/abdnh/anki-zim-reader/compare/1.2.1...HEAD
[unreleased]: https://github.com/abdnh/anki-zim-reader/compare/1.3.0...HEAD
[1.3.0]: https://github.com/abdnh/anki-zim-reader/compare/1.2.1...1.3.0
[1.2.1]: https://github.com/abdnh/anki-zim-reader/compare/1.2.0...1.2.1
[1.2.0]: https://github.com/abdnh/anki-zim-reader/compare/1.1.0...1.2.0
[1.1.0]: https://github.com/abdnh/anki-zim-reader/compare/1.0.0...1.1.0
Expand Down
91 changes: 58 additions & 33 deletions designer/main.ui
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<x>0</x>
<y>0</y>
<width>474</width>
<height>372</height>
<height>392</height>
</rect>
</property>
<property name="windowTitle">
Expand All @@ -26,13 +26,6 @@
</item>
<item>
<layout class="QFormLayout" name="formLayout">
<item row="11" column="1">
<widget class="QPushButton" name="addButton">
<property name="text">
<string>Add</string>
</property>
</widget>
</item>
<item row="0" column="0">
<widget class="QLabel" name="label_6">
<property name="text">
Expand All @@ -46,30 +39,6 @@
<item row="0" column="1">
<widget class="QComboBox" name="fileComboBox"/>
</item>
<item row="1" column="1">
<widget class="QComboBox" name="parserComboBox"/>
</item>
<item row="2" column="1">
<widget class="QComboBox" name="wordFieldComboBox"/>
</item>
<item row="3" column="1">
<widget class="QComboBox" name="definitionFieldComboBox"/>
</item>
<item row="4" column="1">
<widget class="QComboBox" name="exampleFieldComboBox"/>
</item>
<item row="5" column="1">
<widget class="QComboBox" name="genderFieldComboBox"/>
</item>
<item row="6" column="1">
<widget class="QComboBox" name="POSFieldComboBox"/>
</item>
<item row="7" column="1">
<widget class="QComboBox" name="inflectionFieldComboBox"/>
</item>
<item row="8" column="1">
<widget class="QComboBox" name="translationFieldComboBox"/>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label_8">
<property name="text">
Expand All @@ -80,6 +49,9 @@
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QComboBox" name="parserComboBox"/>
</item>
<item row="2" column="0">
<widget class="QLabel" name="label">
<property name="text">
Expand All @@ -90,6 +62,9 @@
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QComboBox" name="wordFieldComboBox"/>
</item>
<item row="3" column="0">
<widget class="QLabel" name="label_2">
<property name="text">
Expand All @@ -100,6 +75,9 @@
</property>
</widget>
</item>
<item row="3" column="1">
<widget class="QComboBox" name="definitionFieldComboBox"/>
</item>
<item row="4" column="0">
<widget class="QLabel" name="label_3">
<property name="text">
Expand All @@ -110,6 +88,9 @@
</property>
</widget>
</item>
<item row="4" column="1">
<widget class="QComboBox" name="exampleFieldComboBox"/>
</item>
<item row="5" column="0">
<widget class="QLabel" name="label_4">
<property name="text">
Expand All @@ -120,6 +101,9 @@
</property>
</widget>
</item>
<item row="5" column="1">
<widget class="QComboBox" name="genderFieldComboBox"/>
</item>
<item row="6" column="0">
<widget class="QLabel" name="label_5">
<property name="text">
Expand All @@ -130,6 +114,9 @@
</property>
</widget>
</item>
<item row="6" column="1">
<widget class="QComboBox" name="POSFieldComboBox"/>
</item>
<item row="7" column="0">
<widget class="QLabel" name="label_9">
<property name="text">
Expand All @@ -140,6 +127,9 @@
</property>
</widget>
</item>
<item row="7" column="1">
<widget class="QComboBox" name="inflectionFieldComboBox"/>
</item>
<item row="8" column="0">
<widget class="QLabel" name="label_10">
<property name="text">
Expand All @@ -150,6 +140,9 @@
</property>
</widget>
</item>
<item row="8" column="1">
<widget class="QComboBox" name="translationFieldComboBox"/>
</item>
<item row="9" column="0">
<widget class="QLabel" name="label_7">
<property name="text">
Expand All @@ -163,18 +156,50 @@
<item row="9" column="1">
<widget class="QComboBox" name="imageFieldComboBox"/>
</item>
<item row="10" column="0" colspan="2">
<item row="10" column="0">
<widget class="QLabel" name="label_11">
<property name="text">
<string>I&amp;PA</string>
</property>
<property name="buddy">
<cstring>ipaFieldComboBox</cstring>
</property>
</widget>
</item>
<item row="11" column="0" colspan="2">
<widget class="QCheckBox" name="skipNonEmptyCheckBox">
<property name="text">
<string>Skip non-empty fields</string>
</property>
</widget>
</item>
<item row="12" column="1">
<widget class="QPushButton" name="addButton">
<property name="text">
<string>Add</string>
</property>
</widget>
</item>
<item row="10" column="1">
<widget class="QComboBox" name="ipaFieldComboBox"/>
</item>
</layout>
</item>
</layout>
</widget>
<tabstops>
<tabstop>fileComboBox</tabstop>
<tabstop>parserComboBox</tabstop>
<tabstop>wordFieldComboBox</tabstop>
<tabstop>definitionFieldComboBox</tabstop>
<tabstop>exampleFieldComboBox</tabstop>
<tabstop>genderFieldComboBox</tabstop>
<tabstop>POSFieldComboBox</tabstop>
<tabstop>inflectionFieldComboBox</tabstop>
<tabstop>translationFieldComboBox</tabstop>
<tabstop>imageFieldComboBox</tabstop>
<tabstop>ipaFieldComboBox</tabstop>
<tabstop>skipNonEmptyCheckBox</tabstop>
<tabstop>addButton</tabstop>
</tabstops>
<resources/>
Expand Down
1 change: 1 addition & 0 deletions src/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,6 @@
"inflection_field": "",
"translation_field": "",
"image_field": "",
"ipa_field": "",
"skip_non_empty": false
}
1 change: 1 addition & 0 deletions src/dictionaries/dictionary.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ class DictEntry:
inflections: str
translations: str
images: str
ipa: str


class ZIMDict:
Expand Down
6 changes: 6 additions & 0 deletions src/dictionaries/german.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ def lookup(self, query: str, dictionary: ZIMDict) -> DictEntry | None:
inflections_list = []
translations_list = []
images: list[str] = []
ipa = ""

entries = german_details.select('details[data-level="3"]')
for entry in entries:
Expand Down Expand Up @@ -70,6 +71,10 @@ def lookup(self, query: str, dictionary: ZIMDict) -> DictEntry | None:
if translations_table:
translations_list.append(translations_table.decode())

ipa_el = german_details.select_one(".ipa")
if ipa_el:
ipa = f"/{ipa_el.get_text()}/"

return DictEntry(
query,
definitions,
Expand All @@ -79,4 +84,5 @@ def lookup(self, query: str, dictionary: ZIMDict) -> DictEntry | None:
"<br>".join(inflections_list),
"<br>".join(translations_list),
"".join(images),
ipa,
)
7 changes: 7 additions & 0 deletions src/dictionaries/greek.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ def lookup(self, query: str, dictionary: ZIMDict) -> DictEntry | None:
inflections = ""
translations = ""
images: list[str] = []
ipa = ""

greek_el = None
for lang_id in self.LANG_IDS:
Expand All @@ -114,6 +115,11 @@ def lookup(self, query: str, dictionary: ZIMDict) -> DictEntry | None:
imgs = save_images(dictionary, parent_details)
images.extend(img.decode() for img in imgs)
strip_images(parent_details)

ipa_el = parent_details.select_one('[title="ΔΦΑ"]')
if ipa_el:
ipa = ipa_el.next_sibling.next_sibling.get_text().strip(":").strip()

for entry in parent_details.select("details"):
summary_el = entry.find("summary")
translation_h = entry.select_one("#Μεταφράσεις")
Expand Down Expand Up @@ -164,4 +170,5 @@ def lookup(self, query: str, dictionary: ZIMDict) -> DictEntry | None:
inflections,
translations,
"".join(images),
ipa,
)
4 changes: 4 additions & 0 deletions src/dictionaries/spanish.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ def lookup(self, query: str, dictionary: ZIMDict) -> DictEntry | None:
inflections = ""
translations = ""
images: list[str] = []
ipa = []

spanish_el = soup.select_one("#Español")
if spanish_el:
parent_details = spanish_el.find_parents("details")[0]
Expand All @@ -51,6 +53,7 @@ def lookup(self, query: str, dictionary: ZIMDict) -> DictEntry | None:
imgs = save_images(dictionary, parent_details)
images.extend(img.decode() for img in imgs)
strip_images(parent_details)
ipa = [f"/{el.get_text()}/" for el in parent_details.select(".ipa")]
for entry in parent_details.select("details"):
summary_el = entry.find("summary")
translation_h = entry.select_one("#Traducciones")
Expand Down Expand Up @@ -84,4 +87,5 @@ def lookup(self, query: str, dictionary: ZIMDict) -> DictEntry | None:
inflections,
translations,
"".join(images),
" ".join(ipa),
)
5 changes: 4 additions & 1 deletion src/dictionaries/turkish.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ def lookup(self, query: str, dictionary: ZIMDict) -> DictEntry | None:
pos_list = []
inflection_tables = []
translations = ""

images = [img.decode() for img in save_images(dictionary, turkish_details)]
ipa = []

entries = turkish_details.select('details[data-level="3"]')
# Some entries have data-level="4", and we detect them using the "headword" class
Expand Down Expand Up @@ -57,6 +57,8 @@ def lookup(self, query: str, dictionary: ZIMDict) -> DictEntry | None:
if translation_el:
translations = translation_el.decode()

ipa = [el.get_text() for el in turkish_details.select(".IPA")]

return DictEntry(
query,
definitions,
Expand All @@ -66,4 +68,5 @@ def lookup(self, query: str, dictionary: ZIMDict) -> DictEntry | None:
"<br>".join(inflection_tables),
translations,
"".join(images),
" ".join(ipa),
)
Loading

0 comments on commit c5ec088

Please sign in to comment.