#!/usr/bin/python # Dan Richert 2005 # dan.richert@gmail.com import sys, re if len(sys.argv)<3: print """ t_vis Dan Richert -- dan.richert@gmail.com usage: t_vis """ sys.exit() def remove_nonletters(s): return re.sub('[^a-zA-Z]', '', s) from textvis import * weight = int(sys.argv[1]) text = open(sys.argv[2]).read().split() ps_basename = sys.argv[3] palette = colors() pos = POS() vis = vis(ps_basename) max_x = 8.5*72 max_y = 11.0*72 x = max_x y = max_y for word in text: v = pos.get_word_value(word) #try a couple different ways of getting a value for the word if v == 0: v = pos.get_word_value(remove_nonletters(word)) if v == 0: v = pos.get_word_value(remove_nonletters(word).lower()) if v == 0: v = pos.get_word_value(remove_nonletters(word).upper()) if v: v = v+weight color = palette.get_color(v) #switch unknowns to white to reduce visual density test = 0 for i in color: test = test+i if test == 0: color = [1.0, 1.0, 1.0] ##### vis.draw_box(color, x, y) x += 6 if x >= max_x: x = 0 y -= 6 if y <= 0: vis.new_file() x = max_x y = max_y vis.close_last_file()