Normalizes the word for synsets() or Sentiwordnet[] by removing diacritics (PyWordNet does not take unicode).
(word)
| 64 | } |
| 65 | |
| 66 | def normalize(word): |
| 67 | """ Normalizes the word for synsets() or Sentiwordnet[] by removing diacritics |
| 68 | (PyWordNet does not take unicode). |
| 69 | """ |
| 70 | if not isinstance(word, basestring): |
| 71 | word = str(word) |
| 72 | if not isinstance(word, str): |
| 73 | try: word = word.encode("utf-8", "ignore") |
| 74 | except: |
| 75 | pass |
| 76 | for k, v in DIACRITICS.items(): |
| 77 | for v in v: |
| 78 | word = word.replace(v, k) |
| 79 | return word |
| 80 | |
| 81 | ### SYNSET ######################################################################################### |
| 82 |