def call(process, stdin): "Send command to a server and get stdout." output = process.stdin.write(stdin.strip() + '\n\n') line = "" while 1: l = process.stdout.readline() if not l.strip(): break line += l return line if __name__ == "__main__": startT = time.clock() sentence = '' gd = '' hisGen = HisGen(sys.argv[1], 'fea6.dat') enum_server = process(["python", "tagger_history_generator.py", "ENUM"]) his_server = process(["python", "tagger_decoder.py", "HISTORY"]) trF = open(sys.argv[2], 'r') gdF = open(sys.argv[3], 'r') for l, lg in izip(trF, gdF): if not l: break if l.strip() == '': history = call(enum_server, sentence) score = hisGen.genScore(sentence, history) pred = call(his_server, score) hisGen.update(pred, gd, sentence) sentence = '' gd = '' else: sentence += l
output = process.stdin.write(stdin.strip() + "\n\n") line = "" while 1: l = process.stdout.readline() if not l.strip(): break line += l return line if __name__ == "__main__": # Create a history server. gold_server = process(["python", "tagger_history_generator.py", "GOLD"]) enum_server = process(["python", "tagger_history_generator.py", "ENUM"]) his_server = process(["python", "tagger_decoder.py", "HISTORY"]) start_time = time.clock() hisGen = HisGen(sys.argv[2], 'fea.dat') sentence = '' while 1: l = sys.stdin.readline() if not l: break if l.strip() == '': history = call(enum_server, sentence.strip()) #print sentence score = hisGen.genScore(sentence, history) #print score out = call(his_server, score.strip()) out = out.strip().split('\n') sent = sentence.strip().split('\n') i = 0 for line in out[:-1]: line = line.strip().split(' ')