Ejemplo n.º 1
0
def gexf_champ(years_bins,scores,champs,nb_label,dico_termes,sep_label,dist_type,distance_champ,niveau,seuil_net_champ):
	legende_noeuds={}
	legende_noeuds_id={}
	for inter in range(len(years_bins)):
		try:
			os.mkdir(path_req + 'gexf')
		except:
			pass
		nodes_chp = {}
		level={}
		
		
		dist_mat_chp_temp = {}
		#on met d'abord des labels à tous les champs
		for x,leschamps in champs.iteritems():
			if inter==x:
				for champ1 in leschamps:
					if not leschamps.index(champ1) in nodes_chp:
						etiquette,etiquette_id=labellize(leschamps.index(champ1),inter,scores,champs,nb_label,dico_termes,sep_label)
						nodes_chp[leschamps.index(champ1)] = etiquette
						level[leschamps.index(champ1)]=niveau
						legende_noeuds[(inter,leschamps.index(champ1))]=etiquette
						legende_noeuds_id[(inter,leschamps.index(champ1))]=etiquette_id
		
		for x,dist in distance_champ.iteritems():
			if inter==x[2]:
				
				champ1 = x[0]
				champ2 = x[1]

				if not champ1 in nodes_chp:
					etiquette,etiquette_id=labellize(champ1,inter,scores,champs,nb_label,dico_termes,sep_label)
					nodes_chp[champ1] = etiquette
					level[champ1]=niveau
					legende_noeuds[(inter,champ1)]=etiquette
					legende_noeuds_id[(inter,champ1)]=etiquette_id
					
				if not champ2 in nodes_chp:
					etiquette,etiquette_id=labellize(champ2,inter,scores,champs,nb_label,dico_termes,sep_label)
					nodes_chp[champ2] = etiquette
					legende_noeuds[(inter,champ2)]=etiquette
					legende_noeuds_id[(inter,champ2)]=etiquette_id
				if dist>seuil_net_champ and champ1!=champ2:
					dist_mat_chp_temp[(champ1,champ2)]=dist
		sortie = path_req + 'gexf/' + 'reseau_champ'+'_' +str(niveau)+'_'+ dist_type +'_'+str(years_bins[inter][0])+'-'+str(years_bins[inter][-1])+'.gexf'
		
		for x in nodes_chp:
			level[x]=niveau
		
		gexf.gexf_builder(nodes_chp,dist_mat_chp_temp,sortie,level)	
	return legende_noeuds,legende_noeuds_id	
Ejemplo n.º 2
0
					dic = {}	
				else:
					dic = dist_mat_temp_res[int(x[0])]
				dic[int(x[1])]=float(y)
				dist_mat_temp_res[int(x[0])] = dic
			dist_mat_temp_res_10 = fonctions.seuiller(dist_mat_temp_res,10)
			print 'on construit maintenant dist_mat pour chaque periode ' + str(inter)
			for x,y in dist_mat_temp.iteritems():
				dist_mat[(int(x[0]),int(x[1]),int(inter))]=y
			for x,y in dist_mat_temp_res_10.iteritems():
				for u in y:
					dist_mat_10[(int(x),int(u[0]),int(inter))]=u[1]
			level={}
			for x in dico_termes:
				level[x]=1
			gexf.gexf_builder(dico_termes,dist_mat_temp,fichier_gexf,level)
			
		fonctions.ecrire_dico(dico_termes,dico_termes,dico_termes,1)
		print 'dicos ecrits'
		#fonctions.dumpingin(p_cooccurrences,'p_cooccurrences'+name_date)
		fonctions.dumpingin(dist_mat_10,'dist_mat_10'+name_date)
		print 'on a dumpé distmat_10: top 10 de chaque terme'
		fonctions.dumpingin(dist_mat,'dist_mat'+name_date)
		print 'on a dumpé distmat'
		
		try: 
			fonctions_bdd.detruire_table(name_bdd,'sem_weighted')
		except: pass
		#fonctions_bdd.creer_table_sem(name_bdd,'sem')
		fonctions_bdd.creer_table_sem_periode_valuee(name_bdd,'sem_weighted')
		lienssem_weighted=[]
Ejemplo n.º 3
0
def union_map(niv_max, seuil_net_champ):
    print seuil_net_champ
    for inter in range(len(years_bins)):
        noeuds = {}
        multi_level_edges = {}
        map_edges = {}
        level = {}
        indexs = {}
        index = 0
        print " temps : " + str(inter)
        if 1:
            for niveau in range(niv_max):
                niveau = niveau + 1
                fichier_leg = open(
                    path_req
                    + "legendes"
                    + "/"
                    + "legendes"
                    + "niv_"
                    + str(niveau)
                    + "_"
                    + dist_type
                    + "_"
                    + str(years_bins[inter][0])
                    + "-"
                    + str(years_bins[inter][-1])
                    + ".txt",
                    "r",
                )
                lignes = fichier_leg.readlines()
                for ligne in lignes:
                    index = index + 1
                    lignev = ligne[:-1].split("\t")
                    indexs[str(niveau) + "_" + str(lignev[0])] = index
                    noeuds[index] = lignev[1]
                    level[index] = str(niveau)
            for niveau in range(niv_max):
                niveau = niveau + 1
                fichier_lex = open(
                    path_req
                    + "lexique"
                    + "/"
                    + "lexique_one_step_"
                    + "niv_"
                    + str(niveau)
                    + "_"
                    + dist_type
                    + "_"
                    + str(years_bins[inter][0])
                    + "-"
                    + str(years_bins[inter][-1])
                    + ".txt",
                    "r",
                )
                fichier_res = open(
                    path_req
                    + "reseau"
                    + "/"
                    + "reseauCF_"
                    + "niv_"
                    + str(niveau)
                    + "_"
                    + dist_type
                    + "_"
                    + str(years_bins[inter][0])
                    + "-"
                    + str(years_bins[inter][-1])
                    + ".txt",
                    "r",
                )

                lignes_res = fichier_res.readlines()
                for ligne in lignes_res:
                    lignev = ligne[:-1].split("\t")
                    # 	print 'ici'
                    # 	print lignev
                    # 	print float(lignev[2])
                    if float(lignev[2]) > seuil_net_champ:
                        map_edges[(indexs[str(niveau) + "_" + lignev[0]], indexs[str(niveau) + "_" + lignev[1]])] = str(
                            lignev[2]
                        )
                lignes_lex = fichier_lex.readlines()
                print fichier_lex
                if niveau > 1:
                    for ligne in lignes_lex:
                        lignev = ligne[:-1].split("\t")
                        for dessous in lignev[1].split(" "):
                            map_edges[
                                (
                                    indexs[str(niveau) + "_" + str(lignev[0])],
                                    indexs[str(niveau - 1) + "_" + str(dessous)],
                                )
                            ] = "1"
                            map_edges[
                                (
                                    indexs[str(niveau - 1) + "_" + str(dessous)],
                                    indexs[str(niveau) + "_" + str(lignev[0])],
                                )
                            ] = "1"
                            # except:
                            # 	pass
                            # print map_edges
        sortie = (
            path_req
            + "gexf/"
            + "reseau_multilevel_champ"
            + "_"
            + dist_type
            + "_"
            + str(years_bins[inter][0])
            + "-"
            + str(years_bins[inter][-1])
            + ".gexf"
        )
        gexf.gexf_builder(noeuds, map_edges, sortie, level)