Example #1
0
def makeGexf():
    raw_file_name = "gexf_format_test.csv"
    #raw_file_name = "HKALL_tags_RT10count.csv"
    gexf = Gexf("Ching-Ya Lin", "Keyword relation by hours.")
    graph = gexf.addGraph("undirected", "dynamic", "graph!", "datetime")
    wid = graph.addNodeAttribute("Weight", "1", "integer", "dynamic")
    ewid = graph.addEdgeAttribute("EdgeWeight", "1", "integer", "dynamic")

    if (1):
        f = codecs.open(raw_file_name, "r", "utf-8")
        #with open(raw_file_name, 'r') as f:
        reader = csv.reader(f)
        w_d = defaultdict()  #weight_dictionary for all keywords
        e_w_d = defaultdict()  #edge
        for row in reader:
            #row = [x.decode('utf8') for x in rowx]
            tt = time.strptime(row[0], "%Y-%m-%d %H")
            rtt = time.strftime("%Y-%m-%d %H:00:00", tt)
            words = row[1].split('/')
            templist = []  #one row list to help addEdge
            for w in words:
                # useless : w = w.encode('utf8')
                #print w
                #print chardet.detect(w)
                templist.append(w)
                if graph.nodeExists(w):
                    n = graph.nodes[w]
                    v = w_d[w] + 1
                    #v = int(n.attributes[int(wid)]["value"])
                    #n.attributes will get the initial value which we don't want.
                    n.addAttribute(wid, str(v), rtt)
                    w_d[w] = v
                else:
                    new = graph.addNode(w, w, rtt)
                    new.addAttribute(wid, "1", rtt)
                    w_d[w] = 1

            for w1 in templist:
                for w2 in templist:
                    if w1 != w2:
                        s1 = w1 + w2
                        s2 = w2 + w1
                        if graph.edgeExists(s1):
                            e = graph.edges[s1]
                            val = e_w_d[s1] + 1
                            e.addAttribute(ewid, str(val), rtt)
                            e_w_d[s1] = val
                        elif graph.edgeExists(s2):
                            e = graph.edges[s2]
                            val = e_w_d[s2] + 1
                            e.addAttribute(ewid, str(val), rtt)
                            e_w_d[s2] = val
                        else:
                            enew = graph.addEdge(s1, w1, w2, 1, rtt)
                            enew.addAttribute(ewid, "1", rtt)
                            e_w_d[s1] = 1
                templist.remove(w1)

    output_file = open("eventhr.gexf", "w")
    gexf.write(output_file)
Example #2
0
 def __init__(self, input_file, version, cloud_storage_client, creator, name):
   self.version = version
   self.input_file = input_file
   self.cloud_storage_client = cloud_storage_client
   self.gexf = Gexf(creator, name)
   self.graph = self.gexf.addGraph("directed", "static", name)
Example #3
0
#!/usr/bin/python

import sys, pprint

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

# test helloworld.gexf
gexf = Gexf("Paul Girard", "A hello world! file")
graph = gexf.addGraph("directed", "static", "a hello world graph")

graph.addNode("0", "hello")
graph.addNode("1", "World")
graph.addEdge("0", "0", "1")

output_file = open("helloworld.gexf", "w")
gexf.write(output_file)

# test GexfImport
f = open("gexf.net.dynamics_openintervals.gexf")
gexf_import = Gexf.importXML(f)
f.close()
f = open("gexf.net.dynamics_openintervals.gexf")
gexf_import2 = Gexf.importXML(f)
f.close()
print "test gexf comparision " + str(gexf_import == gexf_import2)

graph = gexf_import.graphs[0]
# display nodes list
for node_id, node in graph.nodes.iteritems():
    print node.label
Example #4
0
endtime  = time.strptime("20131014080000","%Y%m%d%H%M%S")

# event type matching the @type to be returned from elasticsearch
evttype = "apache-access"


# field and time period to be used for edge detection
relatedfield = "clientip"
relatetimeout = 5

# debug messages ?
verbose = True


# create the graph
gexf = Gexf("es2gexf","logstash graph")
graph=gexf.addGraph("directed","dynamic","logstash graph","dateTime")

# define the node attributes in the graph
attrType = graph.addNodeAttribute("type", "null", "String","static","type")
attrMessage = graph.addNodeAttribute("message", "null", "String","static","message")
attrSource_host = graph.addNodeAttribute("source_host", "null", "String","static","source_host")
attrSource_path = graph.addNodeAttribute("source_path", "null", "String","static","source_path")	  
attrClientip = graph.addNodeAttribute("clientip", "null", "String","static","clientip")
attrVerb = graph.addNodeAttribute("verb", "null", "String","static","verb")
attrResponse = graph.addNodeAttribute("response", "null", "integer","static","response")
attrRequest = graph.addNodeAttribute("request", "null", "String","static","request")
attrBytes = graph.addNodeAttribute("bytes", "null", "integer","static","bytes")
attrAgent = graph.addNodeAttribute("agent", "null", "String","static","agent")
attrReferrer = graph.addNodeAttribute("referrer", "null", "String","static","referrer")
Example #5
0
#
# gexf_converter - A part of PPAS implementation
# Convert the Apriori results into gexf format.
#
# Code written by Xander Wang on 17th April, 2018.
#
# Institute of Distributed Computing, Chuzhou University.

from _gexf import Gexf

# test helloworld.gexf
gexf = Gexf("Gephi.org", "A Web network")
graph = gexf.addGraph("directed", "static", "A Web network")

atr1 = graph.addNodeAttribute('url', type='string')
atr2 = graph.addNodeAttribute('indegree', type='float')
atr3 = graph.addNodeAttribute('frog', type='boolean', defaultValue='true')

tmp = graph.addNode("0", "Gephi")
tmp.addAttribute(atr1, "http://gephi.org")
tmp.addAttribute(atr2, '1')

tmp = graph.addNode("1", "Webatlas")
tmp.addAttribute(atr1, "http://webatlas.fr")
tmp.addAttribute(atr2, '2')

tmp = graph.addNode("2", "RTGI")
tmp.addAttribute(atr1, "http://rtgi.fr")
tmp.addAttribute(atr2, '1')

tmp = graph.addNode("3", "BarabasiLab")