Franzosi

violence.py

# transforms a Pajek's temporal network in temporal matrix
#   with open("violence.p","rb") as p: V = pickle.load(p)
# Vladimir Batagelj, 17. mar 2014
# http://www.diveintopython3.net/serializing.html

import os, re, pickle, json
from timeR import *

os.chdir('C:/Users/batagelj/work/Python/temporal/violence')
n = 314
clu = open('similar.clu','r')
k = 0; cl = [0]*n
line = clu.readline()
while True:
   line = clu.readline()
   if not line: break
   num = eval(line.strip())
   k = k+1
   cl[k] = num
clu.close()

cn = 29
W = [[ [] for i in range(cn)] for j in range(cn)]

net = open('violence.dat','r')
while True:
   line = net.readline()
   if not line: break
   L = re.split('\s+',line.strip())
   u = eval(L[1]); v = eval(L[2]); w = eval(L[3])
   t = eval(L[4][1:-1])
   cu = cl[u]; cv =cl[v]
   W[cu][cv] = sum(W[cu][cv],[(t,t+1,w)])
net.close()

names = [ "undefined", "?", "people", "police", "land owners", "anarchists",
   "fascists", "communists", "workers (agricultural)", "socialists",
   "clericals", "war affected", "protesters", "strike breakers", "management",
   "workers", "the right", "entrepreneurs", "populars", "students",
   "catholics", "shop keepers", "teachers", "priests", "republicans",
   "thugs", "prisoners/arrested", "foreigners", "liberals" ]

time = []
for i in ["19","20","21","22"]:
   for j in ["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"]:
      time.append(j+"-"+i)
      
listMatrix(W,names,False)
violence = {}

violence['tit'] = 'R. Franzosi: "Red Years" and "Black Years"'
violence['num'] = cn
violence['nam'] = names
violence['tim'] = time
violence['mat'] = W
with open("violence.p","wb") as p: pickle.dump(violence,p)
with open('violence.json',mode='w',encoding='utf-8') as f:
   json.dump(violence,f,indent=2)
tq/time/franzosi.txt · Last modified: 2016/05/26 08:18 by vlado
 
Except where otherwise noted, content on this wiki is licensed under the following license: CC Attribution-Noncommercial-Share Alike 3.0 Unported
Recent changes RSS feed Donate Powered by PHP Valid XHTML 1.0 Valid CSS Driven by DokuWiki