def generate_graphs(sim_thresholds,word_groups,lexicons, plot_graphs = True, show_pos = True, write_graphs = True, connect_to_animal = True, animal_sim = 0.4, overwrite = False): all_graphs = {} for sim in sim_thresholds: g = WordsGraph(20,sim,'hub-categories-prob-random',0,0.00001,20,0,1,'map') #print 'this part loaded' for w in word_groups: for _l in lexicons: name = '_'.join([_l,w,str(sim)]) if connect_to_animal: name = ''.join([name,'_A',str(animal_sim)]) fpath = "graphs/" + name + '.graphml' if not overwrite: if os.path.isfile(fpath): print(name + " exists, skipping") continue print(name) graph = g.create_final_graph(word_groups[w],lexicons[_l],8500,'COS') #connect to word animal for learned data if connect_to_animal: for word in word_groups[w]: #don't connect animal to itself if word == 'animal:N': continue a_sim = evaluate.calculate_similarity(8500,lexicons[_l].meaning(word),lexicons[_l].meaning('animal:N'),'COS') #learner.acquisition_score(word) if a_sim >= animal_sim: e = graph.add_edge(graph.vs.find(label='animal:N').index,graph.vs.find(label=word).index) graph.edge_properties['distance'][e] = 1-a_sim all_graphs[name] = graph if plot_graphs: plot_graph(graph,name,show_pos) if write_graphs: write_graphxl(graph,fpath) return all_graphs
def get_animal_sim(graph,l1,l2): return evaluate.calculate_similarity(8500,l1.meaning(word),l2.meaning('animal:N'),'COS')