Closed chopinesque closed 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
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.
And thanks for the patch 🍾 !
Not sure how to add support for these templates?
output on wiktionary:
παράσταση < μεσαιωνική ελληνική παράστασις < αρχαία ελληνική παρίστημι < αρχαία ελληνική παρά + ίστημι
wiktionary source: :'''{{PAGENAME}}''' < {{μσν}} '''[[παράστασις]]''' < {{αρχ}} [[παρίστημι]] < {{αρχ}} [[παρά]] + [[ίστημι]]
output on ebook-reader-dict:
παράσταση < {{μσν}} παράστασις < {{αρχ}} παρίστημι < {{αρχ}} παρά + ίστημι
Templates and their expansions
βλφρ = δείτε την έκφραση: αρχ = αρχαία ελληνική μσν = μεσαιωνική ελληνική μτφρ = (μεταφορικά) μτβ = (μεταβατικό)