def merge_sentences(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_sentences(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_xml([id_to_sent[sid] for sid in merged_sen])}
def merge_sentences(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_sentences(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_xml([id_to_sent[sid] for sid in merged_sen]) }
def definition_sentences_viewer(request, input_dict, output_dict, widget): """ Parses the input XML and displays the definition sentences given as input. @author: Anze Vavpetic, 2012 """ sentences = nlp.parse_def_sentences(input_dict['candidates']) return render(request, 'visualizations/def_sentences.html',{'widget' : widget, 'sentences' : sentences})