示例#1
0
 def synsets(self, word, pos=None):
     synsets = []
     words_file_name = 'all.{}'.format(
         self._lang) if pos == None else '{}.{}'.format(pos, self._lang)
     with utils.read_file('{}/words/{}'.format(PYIWN_DATA_HOME,
                                               words_file_name)) as fo:
         for line in fo:
             sp = utils.clean_line(line)
             if word == sp[1]:
                 synset_id = sp[0]
                 pos = sp[2] if pos == None and len(sp) == 3 else pos
                 break
     synset_file_name = 'all.{}'.format(
         self._lang) if pos == None else '{}.{}'.format(pos, self._lang)
     with utils.read_file('{}/synsets/{}'.format(PYIWN_DATA_HOME,
                                                 synset_file_name)) as fo:
         for line in fo:
             sp = utils.clean_line(line)
             synset_data = utils.synset_data(sp, pos)
             if word in synset_data[2]:
                 synset_id, head_word, lemma_names, pos, gloss, examples = synset_data[
                     0], synset_data[1], synset_data[2], synset_data[
                         3], synset_data[4], synset_data[5]
                 synsets.append(
                     Synset(synset_id, head_word, lemma_names, pos, gloss,
                            examples))
     return synsets
示例#2
0
 def all_synsets(self, pos=None):
     synsets = []
     synset_file_name = 'all.{}'.format(self._lang) if pos == None else '{}.{}'.format(pos, self._lang)
     with utils.read_file('{}/synsets/{}'.format(PYIWN_DATA_HOME, synset_file_name)) as fo:
         for line in fo:
             sp = utils.clean_line(line)
             synset_data = utils.synset_data(sp, pos)
             synset_id, head_word, lemma_names, pos, gloss, examples = synset_data[0], synset_data[1], synset_data[2], synset_data[3], synset_data[4], synset_data[5]
             synsets.append(Synset(synset_id, head_word, lemma_names, pos, gloss, examples))
     return synsets
示例#3
0
 def gradation(self):
     with utils.read_file('{}/synset_relations/gradation'.format(PYIWN_DATA_HOME)) as fo:
         for line in fo:
             if str(self._synset.synset_id()) in line:
                 sp = line.split('\t')
                 synset_id_list = [int(sp[0]), int(sp[2]), int(sp[4])]
                 break
     synsets = []
     with utils.read_file('{}/synsets/{}.hindi'.format(PYIWN_DATA_HOME, self._synset.pos())) as fo:
         for line in fo:
             sp = utils.clean_line(line)
             if int(sp[0]) in synset_id_list:
                 synset_data = utils.synset_data(sp, self._synset.pos())
                 synset_id, head_word, lemma_names, pos, gloss, examples = synset_data[0], synset_data[1], synset_data[2], synset_data[3], synset_data[4], synset_data[5]
                 synsets.append(Synset(synset_id, head_word, lemma_names, pos, gloss, examples))
     return {'low': synsets[0], 'medium': synsets[1], 'high': synsets[2]}
示例#4
0
 def antonym(self):
     antonym_synset_id = -1
     with utils.read_file('{}/synset_relations/antonyms'.format(PYIWN_DATA_HOME)) as fo:
         for line in fo:
             if self._name in line:
                 antonym_synset_id = int(line.split('\t')[2])
                 break
     synsets = []
     with utils.read_file('{}/synsets/{}.hindi'.format(PYIWN_DATA_HOME, self._synset.pos())) as fo:
         for line in fo:
             sp = utils.clean_line(line)
             if int(sp[0]) == antonym_synset_id:
                 synset_data = utils.synset_data(sp, self._synset.pos())
                 synset_id, head_word, lemma_names, pos, gloss, examples = synset_data[0], synset_data[1], synset_data[2], synset_data[3], synset_data[4], synset_data[5]
                 synsets.append(Synset(synset_id, head_word, lemma_names, pos, gloss, examples))
     return synsets
示例#5
0
 def _relations(self, relation):
     synset_id_list = []
     with utils.read_file('{}/synset_relations/{}.{}'.format(PYIWN_DATA_HOME, relation, self._pos)) as fo:
         for line in fo:
             sp = utils.clean_line(line)
             sp[0] = int(sp[0])
             if self._synset_id == sp[0]:
                 synset_id_list = [int(idx) for idx in sp[1].split(',')]
                 break
     synsets = []
     with utils.read_file('{}/synsets/{}.hindi'.format(PYIWN_DATA_HOME, self._pos)) as fo:
         for line in fo:
             sp = utils.clean_line(line)
             if int(sp[0]) in synset_id_list:
                 synset_data = utils.synset_data(sp, self._pos)
                 synset_id, head_word, lemma_names, pos, gloss, examples = synset_data[0], synset_data[1], synset_data[2], synset_data[3], synset_data[4], synset_data[5]
                 synsets.append(Synset(synset_id, head_word, lemma_names, pos, gloss, examples))
     return synsets