def merge_sentences2(input_dict): """ Merges the input sentences in XML according to the specified method. """ method = input_dict['method'] merged_sen, id_to_sent = set(), {} ids_list = [] for i, sentsXML in enumerate(input_dict['sentences']): sents = nlp.parse_def_sentences2(sentsXML) ids = set(map(lambda x: x['id'], sents)) ids_list.append(ids) # Save the map from id to sentence for sent in sents: id_to_sent[sent['id']] = sent if i == 0 and method != 'intersection_two': merged_sen = ids if method == 'union': merged_sen = merged_sen | ids elif method == 'intersection': merged_sen = merged_sen & ids elif method == 'intersection_two': # Skip the current set of sentences # and intersect it with the others. for ids_alt in ids_list[:i] + ids_list[i + 1:]: # As long as (at least) two sets agree with a sentence it # will be in the resulting set. merged_sen = merged_sen | (ids_alt & ids) return { 'merged_sentences': nlp.sentences_to_xml2([id_to_sent[sid] for sid in merged_sen]) }
def merge_sentences2(input_dict): """ Merges the input sentences in XML according to the specified method. """ method = input_dict["method"] merged_sen, id_to_sent = set(), {} ids_list = [] for i, sentsXML in enumerate(input_dict["sentences"]): sents = nlp.parse_def_sentences2(sentsXML) ids = set(map(lambda x: x["id"], sents)) ids_list.append(ids) # Save the map from id to sentence for sent in sents: id_to_sent[sent["id"]] = sent if i == 0 and method != "intersection_two": merged_sen = ids if method == "union": merged_sen = merged_sen | ids elif method == "intersection": merged_sen = merged_sen & ids elif method == "intersection_two": # Skip the current set of sentences # and intersect it with the others. for ids_alt in ids_list[:i] + ids_list[i + 1 :]: # As long as (at least) two sets agree with a sentence it # will be in the resulting set. merged_sen = merged_sen | (ids_alt & ids) return {"merged_sentences": nlp.sentences_to_xml2([id_to_sent[sid] for sid in merged_sen])}
def definition_sentences_viewer2(request, input_dict, output_dict, widget): """ Parses the input XML and displays the definition sentences given as input. @author: Anze Vavpetic, 2012 """ ids_sentence = input_dict["ids_sentence"] == "true" ids_article = input_dict["ids_article"] == "true" text_sentence = input_dict["text_sentence"] == "true" sentences = nlp.parse_def_sentences2(input_dict['candidates']) return render(request, 'visualizations/def_sentences2.html',{'widget' : widget, 'sentences' : sentences, 'ids_sentence': ids_sentence, 'ids_article': ids_article, 'text_sentence':text_sentence})