Exemplo n.º 1
0
def generate_timely_graph(visited: List[str], string2candidate: Dict[str, CandidateFeature]):
	#generate id
	id2candidate: Dict[str, int] = {}
	for counter in range(len(visited)):
		id2candidate[visited[counter]] = counter

	import gexf

	gexf = gexf.Gexf('Felix Neutatz', '28-11-2012')
	# make an undirected dynamical graph
	graph = gexf.addGraph('directed', 'dynamic', '28-11-2012')
	edge_counter = 0
	current_time = 0

	id2candidate['__root__'] = -1
	graph.addNode(-1, '__root__', start=str(0.0))

	for v_i in range(len(visited)):
		id2candidate[visited[v_i]] = v_i
		graph.addNode(v_i, visited[v_i], start=str(current_time))

		current_candidate = string2candidate[visited[v_i]]
		current_time += string2candidate[str(current_candidate)].runtime_properties['execution_time']
		if not isinstance(current_candidate, RawFeature):
			for p in current_candidate.parents:
				graph.addEdge(edge_counter, id2candidate[str(p)], id2candidate[str(current_candidate)], start=str(current_time))
				edge_counter += 1
		else:
			graph.addEdge(edge_counter, id2candidate['__root__'], id2candidate[str(current_candidate)], start=str(current_time))

	gexf.write(open('/tmp/dynamic_graph.gexf', "wb+"))
Exemplo n.º 2
0
monthreader = csv.reader(
    open("C:\Users\CRAZY\PycharmProjects\Small_Projects\NMProject\MonthData.csv", "rb"))

rowno = 0
for row in monthreader:
    if rowno == 0:
        rowno += 1
        continue
    if rowno == 1:
        rowno += 1
        month = monthreader[2]
        G = networkx.DiGraph()
        G.add_node(monthreader[0])
        G.add_node(monthreader[1])
        G.add_edge(monthreader[0],monthreader[1],weight=monthreader[3])
    else:
        if monthreader[2] == month:
            if not G.has_node(monthreader[0])
            G.add_node(monthreader[0])
            G.add_node(monthreader[1])
            G.add_edge(monthreader[0], monthreader[1], weight=monthreader[3])

gexf = gexf.Gexf('Your Name','28-11-2012')
#make an undirected dynamical graph
graph = gexf.addGraph('undirected','dynamic','28-11-2012',timeformat='date')
#you add nodes with a unique id
graph.addNode(Source,"source_id")
#make edge with unique id, the edge has time duration from start to end
graph.addEdge(edge_id,Source,Target,start = Date , end = Date)
#write the gexf format to fileout
gexf.write(fileOut)
Exemplo n.º 3
0
sys.path.append('../gexf')
from gexf import Gexf, GexfImport

df = pd.read_csv('article_similarity_filtered.csv', delimiter=',', index_col=0)
dates = pd.read_csv('master_articles-scraped_filtered_aritcles.csv',
                    delimiter=',')

rows = list(df.index)
rows.remove('Article URL')
cols = list(df.columns.values)
num = len(rows)
cols.remove('Article URL.1')

gexf = Gexf("emCOMP", "Article Similarity")
graph = gexf.addGraph("undirected", "static", "Article Similarity")

#add nodes
for r in rows:
    graph.addNode(r, dates.loc[r, "updated_domain"])

#add edges
count = 0
count_r = 0
for r in rows:
    print("r" + str(count_r))
    for c in cols:
        #can be adapted for directed graph
        if (df.loc[r, c] > .85):
            r_date = datetime.datetime.strptime(str(dates.loc[r, "first_ts"]),
                                                '%Y-%m-%d %H:%M:%S')
# def graphBuild(nodeList, edgeList):
#     # for indexs in nodeList.index:
#     # graphCon.add_node(nodeList.node[indexs].strip())
#     # 上面注释了的代码是添加节点,不过也可以不需要,因为下面添加边的时候,边两端的节点会自动添加到网络中
#     for indexs in edgeList.index:
#         countryGraph.add_edge(edgeList.edgeNode1[indexs].strip(), edgeList.edgeNode2[indexs].strip(),
#                               weight=edgeList.numCount[indexs])  # 添加边与权重

# graphBuild(nodeList, edgeList)  # 运行网络构建函数

# # 输出网络
# nx.write_gexf(countryGraph, gexfPath + 'graph_' + dataTime + 'c1.gexf')  # 输出为Gephi格式
# print("ss")
# print(gexf)
gexf = Gexf("Gephi.org", "A Web network")
graph = gexf.addGraph("undirected", "static", "A Web network")
atr1 = graph.addNodeAttribute('Modularity_class',
                              force_id='modularity_class',
                              type='integer')
atr2 = graph.addNodeAttribute('country', force_id='country', type='string')
atr3 = graph.addNodeAttribute('nodenumber',
                              force_id='nodenumber',
                              type='integer')
# atr3 = graph.addNodeAttribute('frog',type='boolean',defaultValue='true')
eatr1 = graph.addEdgeAttribute('country1',
                               force_id='country1',
                               type='string',
                               defaultValue='country1')
eatr2 = graph.addEdgeAttribute('country2',
                               force_id='country2',
                               type='string',

#gephx is xml, which does not support accents, so we need to remove them
def remove_accents(word):
    return ''.join(x for x in unicodedata.normalize('NFKD', word)
                   if x in string.ascii_letters)


df = pd.read_csv('authors_counts.csv', delimiter=',', index_col=0)

rows = list(df.index)
cols = list(df.columns.values)
num = len(rows)

gexf = Gexf("emCOMP", "Authors")
G = gexf.addGraph("directed", "static", "Authors")

unreadable_names = {}
#add nodes
for r in rows:
    #gephx needs unicode, make sure the string is unicode
    if isinstance(unicode(r, "utf-8"), str):
        print "ordinary string"
    elif isinstance(unicode(r, "utf-8"), unicode):
        print "unicode string"
    #Checking myself
    print(r)
    print(remove_accents(unicode(r, "utf-8")))
    new_string = remove_accents(unicode(r, "utf-8"))
    count = 0
    if (len(new_string) == 0):
import gexf
import string

import sys

sys.path.append('../gexf')
from gexf import Gexf, GexfImport

df = pd.read_csv('domain_path_count_65.csv', delimiter=',', index_col=0)

rows = list(df.index)
cols = list(df.columns.values)
num = len(rows)

gexf = Gexf("emCOMP", "Authors")
G = gexf.addGraph("undirected", "static", "Domain Counts")

unreadable_names = {}
#add nodes
for r in rows:
    print(r)
    G.addNode(r, r)

#add edges
count = 0
count_r = 0
for r in rows:
    print("r" + str(count_r))
    for c in cols:
        if (not r == c):
            tot = df.loc[r, c] + df.loc[c, r]