Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Automatically handle compound words #16

Open
lsmith77 opened this issue Nov 26, 2023 · 0 comments
Open

Automatically handle compound words #16

lsmith77 opened this issue Nov 26, 2023 · 0 comments

Comments

@lsmith77
Copy link

lsmith77 commented Nov 26, 2023

I have some code roughly like the following to automatically handle compound words not support explicitly.

nouns = Nouns()
result = nouns[word]
if len(result) == 0:
    if "-" in word:
        words = word.split("-")
        word = words[-1]
        words = "-".join(words[0:-1]) + "-"
        lower = False
    else:
        words = nouns.parse_compound(word)
        if len(words) < 2:
            return []

        word = words[-1]
        words = "".join(words[0:-1])
        lower = True

    result = nouns[word]
    if len(result) == 0:
        return []

    for i in range(len(result)):
        lemma = result[i]["lemma"].lower() if lower else result[i]["lemma"]
        result[i]["lemma"] = words + lemma
        for flexion in result[i]["flexion"]:
            flexion_expanded = (
                result[i]["flexion"][flexion].lower()
                if lower
                else result[i]["flexion"][flexion]
            )

            result[i]["flexion"][flexion] = words + flexion_expanded

return result

Would you welcome a PR adding this natively? Potentially via some config variable.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant