Python Forum
Thread Rating:
  • 2 Vote(s) - 2.5 Average
  • 1
  • 2
  • 3
  • 4
  • 5
From noun to verb
#11
A cartoon network?
Never-mind, I put my glasses on!
Reply
#12
I tried it and got this:

    noun = gn.lemmatise(noun)
    poss_verb = ""
    while gn.synsets(poss_verb, pos='v') == []:
        try:
            if noun[-2:] == "st":
                poss_verb = noun + "eln"
                continue
            elif noun[-2:] == "st":
                poss_verb = "fasten" # test
                continue
        except:
            return []
But: the second if-condition is never reached...could you tell me why? And would you implement the rules ("ohne Umlaut", http://www.canoo.net/services/Wordformat...uffig.html) the same way or how would you do that?
Reply
#13
Your second condition is never met because it is the exact same condition as the first.
Craig "Ichabod" O'Brien - xenomind.com
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures
Reply
#14
Oh yeah, you're right Wall 
Thanks for your remark.

Now, this wokrs:

    try:
        if noun[-2:] == "st":
            poss_verb = noun.lower() + "eln"
            if gn.synsets(poss_verb, pos='v') == []:
                poss_verb = noun.lower() + "ern"
            if gn.synsets(poss_verb, pos='v') == []:
                poss_verb = noun.lower().replace('u', 'ü') + "eln"
            if gn.synsets(poss_verb, pos='v') == []:
                poss_verb = noun.lower().replace('a', 'ä') + "igen" 
            return poss_verb

    except:
        return []
But question: Is it possible to write this a bit nicer / smoother, or is there no other way?
Reply
#15
You check against an empty list. It evaluates to False:
In [1]: bool([])
Out[1]: False
So you can just:
    try:
        if noun[-2:] == "st":
            poss_verb = noun.lower() + "eln"
            if gn.synsets(poss_verb, pos='v'):
                poss_verb = noun.lower() + "ern"

            if gn.synsets(poss_verb, pos='v'):
                poss_verb = noun.lower().replace('u', 'ü') + "eln"

            if gn.synsets(poss_verb, pos='v'):
                poss_verb = noun.lower().replace('a', 'ä') + "igen"

            return poss_verb
 
    except:
        return None
"As they say in Mexico 'dosvidaniya'. That makes two vidaniyas."
https://freedns.afraid.org
Reply
#16
All right thanks a lot!

One last question: How would you implement "exceptional" words for which there is no rule?
Example:
Klasse --> klassifizieren
Adresse --> adressieren
Schablone --> schablonisieren

Would you save this as dictionary, or how?
Reply
#17
Catching a general exception just with except: is not a good practice. What happens if the data can't be loaded. You return None or [] and you're thinking that something with your code is wrong or data is corrupted or something else.
Do some tests to see the most error you may get.

You can chain the exceptions one after another.
"As they say in Mexico 'dosvidaniya'. That makes two vidaniyas."
https://freedns.afraid.org
Reply
#18
@wavic, shouldn't there be nots in all of the ifs in your last bit of code. That is, isn't if some_list == []: equivalent to if not some_list:?
Craig "Ichabod" O'Brien - xenomind.com
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures
Reply
#19
Yes if some_list == []: is like if not some_list:
Thanks for the correction
"As they say in Mexico 'dosvidaniya'. That makes two vidaniyas."
https://freedns.afraid.org
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020