A cartoon network?
Never-mind, I put my glasses on!
Never-mind, I put my glasses on!
From noun to verb
|
A cartoon network?
Never-mind, I put my glasses on!
May-23-2017, 11:18 PM
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?
May-23-2017, 11:28 PM
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
May-24-2017, 08:05 AM
Oh yeah, you're right
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?
May-24-2017, 09:49 AM
You check against an empty list. It evaluates to False:
In [1]: bool([]) Out[1]: FalseSo 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
May-24-2017, 10:59 AM
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?
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.
May-24-2017, 08:43 PM
@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
May-24-2017, 11:18 PM
Yes
if some_list == []: is like if not some_list: Thanks for the correction |
|