BoboTiG / ebook-reader-dict

Finally decent dictionaries based on the Wiktionary for your beloved eBook reader. Daily updates & 14 locales supported so far.
http://www.tiger-222.fr/?d=2020/04/17/22/14/21-un-dictionnaire-alternatif-et-complet-pour-votre-liseuse
MIT License
425 stars 24 forks source link

[EL] Support "αρχ", "μσν" and "βλφρ" templates #1994

Closed chopinesque closed 8 months ago

chopinesque commented 8 months ago

Not sure how to add support for these templates?

output on wiktionary: παράσταση < μεσαιωνική ελληνική παράστασις < αρχαία ελληνική παρίστημι < αρχαία ελληνική παρά + ίστημι wiktionary source: : '''{{PAGENAME}}''' < {{μσν}} '''[[παράστασις]]''' < {{αρχ}} [[παρίστημι]] < {{αρχ}} [[παρά]] + [[ίστημι]]

output on ebook-reader-dict: παράσταση < {{μσν}} παράστασις < {{αρχ}} παρίστημι < {{αρχ}} παρά + ίστημι

Templates and their expansions

βλφρ = δείτε την έκφραση: αρχ = αρχαία ελληνική μσν = μεσαιωνική ελληνική μτφρ = (μεταφορικά) μτβ = (μεταβατικό)

chopinesque commented 8 months ago

I got a suggestion from the AI system "Consider using a dictionary to map template names to phrases to reduce code repetition." to deal with code like this:

    if tpl == "μτφρ":
        phrase = "μεταφορικά"
        if not data["0"]:
            phrase = term(phrase)
        return phrase

How could that be implemented?

I tried the code below but resulted in most of the templates not being expanded.

    from ..defaults import last_template_handler as default

    tpl, *parts = template
    data = extract_keywords_from(parts)

    if tpl == "γραπτηεμφ":
        phrase = f"η λέξη μαρτυρείται από το {parts[0]}"
        if not data["0"]:
            phrase = term(phrase)
        return phrase

    if tpl in ["λδδ", "dlbor"]:
        phrase = "(διαχρονικό δάνειο) "
        phrase += text_language(parts[0], data)
        phrase += f" {data['1'] or parts[2]}"
        return phrase

    if tpl in ["λ", "l", "link"]:
        return parts[0]

    if tpl in ["ετ", "ετικέτα"]:
        data["label"] = parts[0]
        return labels_output(data.get("text", ""), data)

    if tpl == "λόγιο":
        data["label"] = tpl
        return labels_output("", data)

    if tpl == "ουσ":
        text = italic("ουσιαστικοποιημένο")
        return text if data["0"] else f"({text})"

    if tpl == "βλφρ":
        phrase = "<i>δείτε την έκφραση</i>"
        if not data["0"]:
            phrase += ":"
        return phrase

    return default(template, locale, word)

def process_template(tpl, data):
    template_phrases = {
        "λενδ": "λόγιο ενδογενές δάνειο:",
        "μτφρ": "μεταφορικά",
        "αρχ": "αρχαία ελληνική",
        "μσν": "μεσαιωνική ελληνική",
        "μτβ": "μεταβατικό",
        "αμτβ": "αμετάβατο",
        "κτεπε": "κατʼ επέκταση",
    }

    if tpl in template_phrases:
        phrase = template_phrases[tpl]
        if not data["0"]:
            phrase = term(phrase)
        return phrase

    return None
BoboTiG commented 8 months ago

Do not worry about that for now. For a first pass, your code is fine.

FTR I just disabled the bot because it way too verbose , and reviews are made more difficult.

BoboTiG commented 8 months ago

And thanks for the patch 🍾 !