def getFrameData(frame_id): frame = fn.frame_by_id(frame_id) f_name = frame.name f_elem = frame.FE f_lus = frame.lexUnit f_ctx = getFrameContext(frame) return f_name, f_elem, f_lus, f_ctx
def getFrameWords(frame_id): frame = fn.frame_by_id(frame_id) f_name = frame.name f_elem = list(frame.FE.keys()) f_lus = frame.lexUnit lus_names_list = [] lu_keys = f_lus.keys() for l in lu_keys: lus_names_list.append(f_lus[l].lexemes[0].name) return f_name, f_elem, lus_names_list
def build_fn_data(frame_id): frame_name, frame_elements, lexical_units = {}, {}, {} f = fn.frame_by_id(frame_id) frame_name[f.name] = '' for fe in f.FE.keys(): frame_elements[fe] = '' for lu in f.lexUnit.keys(): lexical_units[lu] = '' return [frame_name, frame_elements, lexical_units]
def print_frame(id): f = fn.frame_by_id(id) print('NAME: {}[{}]\tDEF: {}'.format(f.name, f.ID, f.definition)) print('\n____ FEs ____') FEs = f.FE.keys() for fe in FEs: fed = f.FE[fe] print('\tFE: {}\tDEF: {}'.format(fe, fed.definition)) print(fed.definition) print('\n____ LUs ____') LUs = f.lexUnit.keys() for lu in LUs: print(lu)
def get_frame(frame_id): f = fn.frame_by_id(frame_id) return f
# getFrameSetForStudent('Tabasso') # student: Tabasso # ID: 133 frame: Process_start # ID: 2980 frame: Transition_to_a_situation # ID: 405 frame: Performing_arts # ID: 1927 frame: Scope # ID: 2590 frame: Business_closure frame_ids = [133, 2980, 405, 1927, 2590] with open(config["output"] + 'results.csv', "w", encoding="utf-8") as out: print("Assigning Synsets...") for frame in frame_ids: f = fn.frame_by_id(frame) ctx_f, ctx_w = populate_contexts(f, "Frame name") sense_name = bag_of_words(ctx_f, ctx_w) out.write("Frame name, {0}, Wordnet Synset, {1}\n".format(f.name, sense_name)) ctx_f, ctx_w = populate_contexts(f, "FEs") i = 0 while i < len(ctx_f) - 2: fe = [ctx_f[i], ctx_f[i + 1]] sense_fes = bag_of_words(fe, ctx_w) out.write("Frame elements, {0}, Wordnet Synset, {1}\n".format(fe[0], sense_fes)) i += 2 ctx_f, ctx_w = populate_contexts(f, "LUs")
if __name__ == "__main__": # frame_ids = [8, 2286, 2246, 1490, !2582] Paragallo # frame_ids = [!1303, 2076, 56, 723, !710] paragallo # frame_ids = [1071, 1083, 1017, 2625, 731] PARAGALLO # getFrameSetForStudent('PARAGALLO') # student: PARAGALLO # ID: 1071 frame: People_by_vocation (vocation) # ID: 1083 frame: Subjective_influence (influence) # ID: 1017 frame: Noise_makers (makers) attenzione esiste noisemakers # ID: 2625 frame: Relational_location (location) # ID: 731 frame: Becoming_silent (silent) #get the frames frames = [fn.frame_by_id(id) for id in [1071, 1083, 1017, 2625, 731]] #get the golden data reader = csv.DictReader(open('./part2/exercise2/input/gold.txt'), delimiter='\t') #row={'FrameId': '1071', 'name': 'People_by_vocation', 'sense': 'career.n.01', 'type': 'name'} gold_data = [row for row in reader] #function to find the gold syn in file find_gold_syn = lambda fId, type, name: next(gold[ 'sense'] for gold in gold_data if gold["FrameId"] == str(fId) and gold[ "type"] == type and gold["name"] == name.replace(' ', '_')) with open('./part2/exercise2/output/results.csv', "w", encoding="utf-8") as out: row_template = '{}\t{}\t{}\t{}\t{}\t{}\n' out.write(
ctx_s = ctx_s | {word.lower()} ctx_i = ctx_s & ctx_w v = len(ctx_i) + 1 if v > m: ctx_max = ctx_i m = v s_max = s ctx_s = set() return s_max ids = getFrameSetForStudent('Ramundo') synsets = {} for i in ids: list = [] f = fn.frame_by_id(i) print('*********SYNSETS FOR {}************'.format(f.name)) sentence = str(f.name).split('_') r = reggente(sentence) print('Synset for {} is {}'.format(r, fn_disambiguation_context(f, r))) list.append((r.lower(), fn_disambiguation_context(f, r))) FEs = f.FE.keys() for fe in FEs: fes = fe.replace('_', ' ') print('Synset for {} is {}'.format(fes, fn_disambiguation_context(f, fes))) list.append((fes.lower(), fn_disambiguation_context(f, fes))) LUs = f.lexUnit.keys() for lu in LUs: lus = lu.split('.') print('Synset for {} is {}'.format(