2

I am looking for an algorithm to create Czech adverbs when given an adjective. I was looking for a decent set of rules, but I was not able to find anything comprehensive. Going from example words I have the following rules - in Python code, but it should be easy to understand even for nonprogrammers. So for example if a word ends with "lý", the last character is replaced with an e (resulting in "le").

def adjective_to_adverb(word: str) -> str:
    if word.endswith("lý") or word.endswith("sý"):
        return word[:-1] + "e"
    elif word.endswith("rý"):
        return word[:-2] + "ře"
    elif word.endswith("í"):
        return word[:-1] + "ě"
    elif word.endswith("cký"):
        return word[:-2] + "ky"
    elif word.endswith("ký"):
        return word[:-2] + "ce"
    elif word.endswith("ý"):
        return word[:-1] + "ě"
    else:
        raise ValueError(f"Adjective {word} does not end in a known suffix")

I think my rules are incomplete. What other cases would I need to handle?

2 Answers 2

1

I (hopefully) found some more rules, they are here.

def adjective_to_adverb(word: str) -> str:
    if word.endswith("lý") or word.endswith("sý"):
        return word[:-1] + "e"
    elif word.endswith("rý"):
        return word[:-2] + "ře"
    elif word.endswith("cí"): # Mostly these adverbs don't exist though
        return word[:-1] + "e"
    elif word.endswith("í"):
        return word[:-1] + "ě"
    elif word.endswith("chý"):
        return word[:-3] + "še"
    elif word.endswith("cký") or word.endswith("ský"):
        return word[:-2] + "ky"
    elif word.endswith("hý"):
        return word[:-2] + "ze"
    elif word.endswith("ký"):
        return word[:-2] + "ce"
    elif word.endswith("ý"):
        return word[:-1] + "ě"
    else:
        raise ValueError(f"Adjective {word} does not end in a known suffix")

Edit: Thanks a lot to Vladimir for finding what was missing, I now added it.

1
1

A cleaner way to implement the same logic:

def adjective_to_adverb(word: str) -> str:
    suffix_mapping = {
        "lý": "le",
        "sý": "se",
        "rý": "ře",
        "cí": "ce",  # Mostly these adverbs don't exist though
        "í": "ě",
        "chý": "še",
        "cký": "cky",
        "ský": "sky",
        "hý": "ze",
        "ký": "ce",
        "ý": "ě"
    }

    for suffix, replacement in suffix_mapping.items():
        if word.endswith(suffix):
            return word[:-len(suffix)] + replacement

    raise ValueError(f"Adjective {word} does not end in a known suffix")

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.