Skip to content

Commit

Permalink
wiktextract: disable categories by default with option to enable it
Browse files Browse the repository at this point in the history
  • Loading branch information
ilius committed Dec 18, 2024
1 parent 26f13ed commit 3666cdd
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 8 deletions.
1 change: 1 addition & 0 deletions doc/p/wiktextract.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
| example_padding | `10px 20px` | str | Padding for examples (css value) |
| audio | `True` | bool | Enable audio |
| audio_formats | `['ogg', 'mp3']` | list | List of audio formats to use |
| categories | `False` | bool | Enable categories |

### Dependencies for reading

Expand Down
8 changes: 7 additions & 1 deletion plugins-meta/index.json
Original file line number Diff line number Diff line change
Expand Up @@ -1820,6 +1820,11 @@
"class": "ListOption",
"type": "list",
"comment": "List of audio formats to use"
},
"categories": {
"class": "BoolOption",
"type": "bool",
"comment": "Enable categories"
}
},
"canRead": true,
Expand All @@ -1833,7 +1838,8 @@
"audio_formats": [
"ogg",
"mp3"
]
],
"categories": false
},
"readDepends": {
"lxml": "lxml"
Expand Down
20 changes: 13 additions & 7 deletions pyglossary/plugins/wiktextract.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,9 @@
"audio_formats": ListOption(
comment="List of audio formats to use",
),
"categories": BoolOption(
comment="Enable categories",
),
}


Expand All @@ -98,6 +101,8 @@ class Reader:

_audio_formats: list[str] = ["ogg", "mp3"]

_categories: bool = False

topicStyle = (
"color:white;"
"background:green;"
Expand Down Expand Up @@ -167,7 +172,7 @@ def __iter__(self) -> Iterator[EntryType]:
def warning(self, msg: str) -> None:
self._warnings[msg] += 1

def makeEntry(self, data: dict[str, Any]) -> EntryType:
def makeEntry(self, data: dict[str, Any]) -> EntryType: # noqa: PLR0912
from lxml import etree as ET

glos = self._glos
Expand Down Expand Up @@ -234,12 +239,13 @@ def br() -> Element:
with hf.element("div"):
hf.write(f"Etymology: {etymology}")

categories = []
for sense in senses:
senseCats = sense.get("categories")
if senseCats:
categories += senseCats
self.writeSenseCategories(hf_, categories)
if self._categories:
categories = []
for sense in senses:
senseCats = sense.get("categories")
if senseCats:
categories += senseCats
self.writeSenseCategories(hf_, categories)

defi = f.getvalue().decode("utf-8")
# defi = defi.replace("\xa0", " ") # do we need to do this?
Expand Down

0 comments on commit 3666cdd

Please sign in to comment.