def select_linkage(sent, num_linkages): """ Поиск наиболее точной структуры предложения Аргументы: sent - предложение с пометками num_linkages - количество вариантов структур предложения Возвращаемое значение: linkage - структура предложения выданная парсером """ ind = 1 is_good = False is_v_or_n = False linkage = clg.linkage_create(0, sent, parse_opts) for num in range(clg.linkage_get_num_words(linkage)): if (clg.linkage_get_word(linkage, num).find(".v") >= 0 or clg.linkage_get_word(linkage, num).find(".n") >= 0): is_v_or_n = True while (ind < num_linkages and is_good == False): for i in range(clg.linkage_get_num_links(linkage)): if (clg.linkage_get_link_label(linkage, i).find("W") == 0): if (clg.linkage_get_word(linkage, clg.linkage_get_link_rword(linkage, i)).find(".v") >= 0 or clg.linkage_get_word(linkage, clg.linkage_get_link_rword(linkage, i)).find(".n") >= 0): is_good = True if (is_good == False and is_v_or_n == True and ind < num_linkages): clg.linkage_delete(linkage) linkage = clg.linkage_create(ind, sent, parse_opts) ind += 1 return linkage
def link(self, i): return Link(self, i, self.word(clg.linkage_get_link_lword(self._obj, i)), clg.linkage_get_link_llabel(self._obj, i), clg.linkage_get_link_rlabel(self._obj, i), self.word(clg.linkage_get_link_rword(self._obj, i)))
def link_analiz(i, linkage, actions_index, objects_index, conditions_index): """ Распределение индексов слов на дейсвие, объект и условие в зависимости от связи Аргументы: i - индекс связи в структуре предложения linkage - структура предложения выданная парсером actions_index - индексы слов действий objects_index - индексы слов объектов conditions_index - индексы слов условий """ if (clg.linkage_get_link_label(linkage, i).find("W") == 0): actions_index.append(clg.linkage_get_link_rword(linkage, i)) if (clg.linkage_get_link_label(linkage, i).find("Sp") == 0): actions_index.append(clg.linkage_get_link_lword(linkage, i)) elif (clg.linkage_get_link_label(linkage, i).find("I") == 0): if (len(clg.linkage_get_link_label(linkage, i)) == 1): actions_index.append(clg.linkage_get_link_rword(linkage, i)) elif (clg.linkage_get_link_label(linkage, i)[1] != "I"): actions_index.append(clg.linkage_get_link_rword(linkage, i)) elif (clg.linkage_get_link_label(linkage, i).find("MV") == 0 and clg.linkage_get_link_label(linkage, i)[2] != "I"): if (clg.linkage_get_link_lword(linkage, i) in objects_index or clg.linkage_get_link_lword(linkage, i) in actions_index): objects_index.append(clg.linkage_get_link_rword(linkage, i)) elif (clg.linkage_get_link_lword(linkage, i) in conditions_index): conditions_index.append(clg.linkage_get_link_rword(linkage, i)) elif (clg.linkage_get_link_label(linkage, i).find("SI") == 0): objects_index.append(clg.linkage_get_link_rword(linkage, i)) elif (clg.linkage_get_link_label(linkage, i) == "E"): conditions_index.append(clg.linkage_get_link_rword(linkage, i)) elif (clg.linkage_get_link_label(linkage, i).find("E") == 0 and clg.linkage_get_link_label(linkage, i)[1].islower() == True): conditions_index.append(clg.linkage_get_link_rword(linkage, i)) elif (clg.linkage_get_link_label(linkage, i).find("EI") == 0): conditions_index.append(clg.linkage_get_link_lword(linkage, i)) elif (clg.linkage_get_link_label(linkage, i).find("J") == 0): conditions_index.append(clg.linkage_get_link_rword(linkage, i)) elif (clg.linkage_get_link_label(linkage, i).find("A") == 0 and clg.linkage_get_link_label(linkage, i)[1].islower() == True): if (clg.linkage_get_link_rword(linkage, i) in objects_index): objects_index.append(clg.linkage_get_link_lword(linkage, i)) elif (clg.linkage_get_link_rword(linkage, i) in conditions_index): conditions_index.append(clg.linkage_get_link_lword(linkage, i)) elif (clg.linkage_get_link_label(linkage, i).find("AXP") == 0): if (clg.linkage_get_link_rword(linkage, i) in objects_index): objects_index.append(clg.linkage_get_link_lword(linkage, i)) elif (clg.linkage_get_link_rword(linkage, i) in conditions_index): conditions_index.append(clg.linkage_get_link_lword(linkage, i)) elif (clg.linkage_get_link_label(linkage, i).find("PI") == 0): if (clg.linkage_get_link_rword(linkage, i) in objects_index): objects_index.append(clg.linkage_get_link_lword(linkage, i)) elif (clg.linkage_get_link_rword(linkage, i) in conditions_index): conditions_index.append(clg.linkage_get_link_lword(linkage, i)) elif (clg.linkage_get_link_label(linkage, i).find("M") == 0 and clg.linkage_get_link_label(linkage, i)[1] != "V"): if (clg.linkage_get_link_lword(linkage, i) in conditions_index): conditions_index.append(clg.linkage_get_link_rword(linkage, i)) else: objects_index.append(clg.linkage_get_link_rword(linkage, i))