summaryrefslogtreecommitdiff
path: root/gi/pyp-topics/scripts/topics.py
blob: 0db1af712e51b8172639fe5ed7a3470e6e2e786a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#!/usr/bin/python

import sys

if len(sys.argv) != 2:
  print "Usage: topics.py words-per-topic"
  exit(1)

for t,line in enumerate(sys.stdin):
  tokens = line.split()
  terms = []
  for token in tokens:
    elements = token.rsplit(':',1)
    terms.append((int(elements[1]),elements[0]))
  terms.sort()
  terms.reverse()

  print "Topic %d:" % t
  map(lambda (x,y) : sys.stdout.write("   %s:%s\n" % (y,x)), terms[:int(sys.argv[1])])
  print