diff --git a/slda_input_files/reconstruct.py b/slda_input_files/reconstruct.py old mode 100644 new mode 100755 index f447a98..30821ff --- a/slda_input_files/reconstruct.py +++ b/slda_input_files/reconstruct.py @@ -7,19 +7,22 @@ parser.add_argument('term_file') args = parser.parse_args() + term_topic = file('tokens.txt', 'w+') + + terms = file(args.term_file).read().split('\n') i = 0 for line in file(args.model_file).readlines(): data = line.split(' ')[1:] - print str(i) + '\t', + term_topic.write( str(i) + '\t') for entry in data: entry = entry.split(':') term_index = int(entry[0]) term = str(terms[term_index]).replace(' ', '') term_count = int(entry[1]) - print ' '.join([term] * term_count), - print '\n', + term_topic.write( ' '.join([term] * term_count)) + print term_topic.write('\n') i += 1