Advertisement
Guest User

Untitled

a guest
Oct 21st, 2016
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.98 KB | None | 0 0
  1. import re
  2. import codecs
  3. DICT_PATH = "dict/polishMorfologyDict.dic"
  4.  
  5. class PolishDict:
  6.     __content = ""
  7.  
  8.     def __init__(self):
  9.         self.__content = open(DICT_PATH, encoding = "windows-1252").read();
  10.  
  11.     def findInDict(self,wanted_word):
  12.         searched = re.search(r'' + wanted_word + '.*',self.__content)
  13.  
  14.         if(searched):
  15.             return self.normalizeFoundText(searched.group())
  16.         else:
  17.             return ""
  18.  
  19.     def normalizeFoundText(self,word):
  20.         word_form = self.searchWordForm(word)
  21.         wanted_word = re.search(r'^\w+' ,word)
  22.  
  23.         if(wanted_word):
  24.             wanted_word = wanted_word.group()
  25.             if(word_form != "N"):
  26.                 trim_index = re.search(r'\d' ,word)
  27.                 trim_index = trim_index.group()
  28.                 wanted_word = wanted_word[:-int(trim_index)]
  29.             return wanted_word
  30.  
  31.     def searchWordForm(self,string):
  32.         word_form = re.search(r',.*/' ,string)
  33.  
  34.         if(word_form):
  35.             word_form = word_form.group()
  36.             word_form = word_form[1:-1]
  37.             return word_form
  38.  
  39.  
  40.  
  41. Dict = PolishDict()
  42. print(Dict.findInDict("lewy"))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement