Ejemplo n.º 1
0
def parse_etyl(template: str) -> Iterator[Ref]:
    mot = extract_named_argument(template, "mot")
    if mot is not None:
        yield Ref(word=mot, origin=None, kind="etyl")

    dif = extract_named_argument(template, "dif")
    if dif is not None:
        yield Ref(word=dif, origin=None, kind="etyl")

    if mot is None:
        separators = template.count("|")
        if separators >= 3:
            parts = template.split("|")
            yield Ref(word=parts[3], origin=None, kind="etyl")
Ejemplo n.º 2
0
def parse_affix(parts: List[str]) -> Iterator[Ref]:
    """This template shows the parts (morphemes) that make up a word, for use
    in etymology sections. Although it is called affix, it can be used for
    compounds too, like {{compound}}: https://en.wiktionary.org/wiki/Template:affix/documentation
    """
    if len(parts) > 2:
        yield Ref(origin=parts[1], word="".join(parts[2:]), kind="affix")
Ejemplo n.º 3
0
def parse_derived(parts: List[str]) -> Iterator[Ref]:
    """This template is used to format the etymology of terms derived from
    another language. it combines the functions of {{etyl}} and {{m}} into a
    single template, with fewer keystrokes and without writing out the language
    codes twice: https://en.wiktionary.org/wiki/Template:derived/documentation.
    """
    if len(parts) > 3:
        yield Ref(origin=parts[2], word=parts[3], kind="derived")
Ejemplo n.º 4
0
def parse_prefix(parts: List[str]) -> Iterator[Ref]:
    """https://en.wiktionary.org/wiki/Template:prefix/documentation"""
    if len(parts) == 2:
        yield Ref(origin=None, word=f"{parts[1]}-", kind="prefix")
        yield Ref(origin=None, word=parts[1], kind="prefix-")
    elif len(parts) == 3:
        yield Ref(origin=None, word=f"{parts[1]}- + {parts[2]}", kind="prefix")
        yield Ref(origin=None, word=parts[1], kind="prefix-")
        yield Ref(origin=None, word=parts[2], kind="-prefix")
    elif len(parts) == 4:
        yield Ref(origin=parts[1],
                  word=f"{parts[2]}- + {parts[3]}",
                  kind="prefix")
        yield Ref(origin=parts[1], word=parts[2], kind="prefix-")
        yield Ref(origin=parts[1], word=parts[3], kind="-prefix")
Ejemplo n.º 5
0
def parse_suffix(parts: List[str]) -> Iterator[Ref]:
    """https://en.wiktionary.org/wiki/Template:suffix/documentation"""
    if len(parts) == 2:
        yield Ref(origin=None, word=f"-{parts[1]}", kind="suffix")
        yield Ref(origin=None, word=parts[1], kind="-suffix")
    elif len(parts) == 3:
        yield Ref(origin=None, word=f"{parts[1]} + -{parts[2]}", kind="suffix")
        yield Ref(origin=None, word=parts[1], kind="suffix-")
        yield Ref(origin=None, word=parts[2], kind="-suffix")
    elif len(parts) == 4:
        yield Ref(origin=parts[1],
                  word=f"{parts[2]} + -{parts[3]}",
                  kind="suffix")
        yield Ref(origin=parts[1], word=parts[2], kind="suffix-")
        yield Ref(origin=parts[1], word=parts[3], kind="-suffix")
    # else:
    #     print("SUFFIX", parts)
    return None
Ejemplo n.º 6
0
def parse_blend(parts: List[str]) -> Iterator[Ref]:
    """https://en.wiktionary.org/wiki/Template:blend/documentation"""
    if len(parts) == 3:
        yield Ref(origin=None, word=f"{parts[1]} ~ {parts[2]}", kind="blend")
        yield Ref(origin=None, word=parts[1], kind="blend-")
        yield Ref(origin=None, word=parts[2], kind="-blend")
    elif len(parts) == 4:
        yield Ref(origin=parts[1],
                  word=f"{parts[2]} ~ {parts[3]}",
                  kind="blend")
        yield Ref(origin=parts[1], word=parts[2], kind="blend-")
        yield Ref(origin=parts[1], word=parts[3], kind="-blend")
Ejemplo n.º 7
0
def parse_clipping(parts: List[str]) -> Iterator[Ref]:
    """https://en.wiktionary.org/wiki/Template:clipping/documentation"""
    if len(parts) == 2:
        yield Ref(origin=None, word=parts[1], kind="clipping")
    elif len(parts) == 3:
        yield Ref(origin=parts[1], word=parts[2], kind="clipping")
Ejemplo n.º 8
0
def parse_borrowed(parts: List[str]) -> Iterator[Ref]:
    """This template is used to format the etymology of borrowings and
    loanwords: https://en.wiktionary.org/wiki/Template:borrowed/documentation
    """
    if len(parts) > 3:
        yield Ref(origin=parts[2], word=parts[3], kind="borrowed")
Ejemplo n.º 9
0
def parse_non_cognate(parts: List[str]) -> Iterator[Ref]:
    """https://en.wiktionary.org/wiki/Template:noncognate"""
    if len(parts) > 2:
        yield Ref(origin=parts[1], word=parts[2], kind="noncog")
Ejemplo n.º 10
0
def parse_cognate(parts: List[str]) -> Iterator[Ref]:
    """https://en.wiktionary.org/wiki/Template:cognate/documentation"""
    if len(parts) > 2:
        yield Ref(origin=parts[1], word=parts[2], kind="cognate")
Ejemplo n.º 11
0
def parse_semantic_loan(parts: List[str]) -> Iterator[Ref]:
    """https://en.wiktionary.org/wiki/Template:semantic_loan/documentation"""
    if len(parts) > 3:
        yield Ref(origin=parts[2], word=parts[3], kind="semantic-loan")
Ejemplo n.º 12
0
def parse_back_form(parts: List[str]) -> Iterator[Ref]:
    """https://en.wiktionary.org/wiki/Template:back-formation/documentation"""
    if len(parts) == 2:
        yield Ref(origin=None, word=parts[1], kind="back-formation")
    elif len(parts) == 3:
        yield Ref(origin=parts[1], word=parts[2], kind="back-formation")
Ejemplo n.º 13
0
def parse_lien(template: str) -> Iterator[Ref]:
    if template.count("|") == 2:
        parts = template.split("|")
        yield Ref(word=parts[1], origin=None, kind="lien")
Ejemplo n.º 14
0
def parse_recons(template: str) -> Iterator[Ref]:
    if template.count("|") == 1:
        yield Ref(word=template.split("|")[-1], origin=None, kind="recons")
Ejemplo n.º 15
0
def parse_link(link: str) -> Iterator[Ref]:
    if "|" in link:
        yield Ref(word=link.rsplit("|", 1)[-1], origin=None, kind="link")
    else:
        yield Ref(word=link, origin=None, kind="link")
Ejemplo n.º 16
0
def parse_compound(parts: List[str]) -> Iterator[Ref]:
    """https://en.wiktionary.org/wiki/Template:compound/documentation"""
    if len(parts) == 3:
        yield Ref(origin=None,
                  word=f"{parts[1]} + {parts[2]}",
                  kind="compound")
        yield Ref(origin=None, word=parts[1], kind="compound-")
        yield Ref(origin=None, word=parts[2], kind="-compound")
    elif len(parts) == 4:
        yield Ref(origin=parts[1],
                  word=f"{parts[2]} + {parts[3]}",
                  kind="compound")
        yield Ref(origin=parts[1], word=parts[2], kind="compound-")
        yield Ref(origin=parts[1], word=parts[3], kind="-compound")
    elif len(parts) == 5:
        yield Ref(
            origin=parts[1],
            word=f"{parts[2]} + {parts[3]} + {parts[4]}",
            kind="compound",
        )
        yield Ref(origin=parts[1], word=parts[2], kind="compound-")
        yield Ref(origin=parts[1], word=parts[3], kind="-compound-")
        yield Ref(origin=parts[1], word=parts[4], kind="-compound")
    elif len(parts) == 6:
        yield Ref(
            origin=parts[1],
            word=f"{parts[2]} + {parts[3]} + {parts[4]} + {parts[5]}",
            kind="compound",
        )
        yield Ref(origin=parts[1], word=parts[2], kind="compound-")
        yield Ref(origin=parts[1], word=parts[3], kind="-compound-")
        yield Ref(origin=parts[1], word=parts[4], kind="-compound-")
        yield Ref(origin=parts[1], word=parts[5], kind="-compound")
Ejemplo n.º 17
0
def parse_inherited(parts: List[str]) -> Iterator[Ref]:
    """This template is used to format the etymology of terms inherited from an
    earlier stage of the same language: https://en.wiktionary.org/wiki/Template:inherited.
    """
    if len(parts) > 3:
        yield Ref(origin=parts[2], word=parts[3], kind="inherit")
Ejemplo n.º 18
0
def parse_short_for(parts: List[str]) -> Iterator[Ref]:
    """https://en.wiktionary.org/wiki/Template:clipping/documentation"""
    if len(parts) > 2:
        yield Ref(origin=None, word=parts[1], kind="short-for")
Ejemplo n.º 19
0
def deserialize_ref(ref: str) -> Optional[Ref]:
    try:
        word, kind, origin = ref.strip().split("|")
        return Ref(word=word, kind=kind, origin=origin or None)
    except ValueError:
        return None