# including the record of time


from glob import iglob
import shutil
import os
import time


t_start = time.time()
clingo_running_command = "../../gringo encoding_deterministic_newNaming_constrainIncorporated.lp ex.lp partialBK.lp | ../../unclasp  > hypothesis0.txt"
os.system(clingo_running_command)
t_taken = time.time()-t_start


in_file = open('hypothesis0.txt', "r")
out_file = open('hypothesis.pl', "w")
out_file_totalTime = open('oneTotalTime.txt', "w")



previous_line = ' '

for line in in_file:
	if previous_line.startswith('Answer:'):
        	hypothesis_line = line
	previous_line = line
	
hypothesis = hypothesis_line.split()
for i in range(len(hypothesis)):
	output_hypothesis = hypothesis[i] + '.' + '\n'
	out_file.write(output_hypothesis)


time_info=line.split()


if len(time_info)>2:
	time0=time_info[2]
	cputime=time0[:-1]+' ' #remove the last letter 's' which means seconds
else:
	cputime=str(t_taken)+' '
out_file_totalTime.write(cputime)
