using DelimitedFiles

words1 = readdlm("./examples/forceAlingned.jl/words.txt")

words2 = readdlm("./examples/forceAlingned.jl/aenesa.txt")

words = [words1[:,1] words2[:,3] words2[:,4]]


# set item info
class = "IntervalTier"
name = "Words"
size1 = size(words)[1]
xmin = words[1,:][2]
xmax = words[end,:][3]


# print(" "^4*"item [10]:\n")
# print(" "^8*"name = \""*name*"\" \n")
# print(" "^8*"xmin = "*string(xmin)*" \n")
# print(" "^8*"xmax = "*string(xmax)*" \n")
# print(" "^8*"intervals: size = "*string(size1)*" \n")
# for i in 1:size1
#     print(" "^8*"intervals ["*string(i)*"]:\n")
#     print(" "^12*"xmin = "*string(words[i,:][2])*" \n")
#     print(" "^12*"xmax = "*string(words[i,:][3])*" \n")
#     print(" "^12*"text = "*string(words[i,:][1])*" \n")
# end


open("./examples/forceAlingned.jl/aenesa_results.TextGrid", "a") do file
    write(file, " "^4*"item [10]:\n")
    write(file, " "^8*"class = \""*class*"\" \n")
    write(file, " "^8*"name = \""*name*"\" \n")
    write(file, " "^8*"xmin = "*string(xmin)*" \n")
    write(file, " "^8*"xmax = "*string(xmax)*" \n")
    write(file, " "^8*"intervals: size = "*string(size1)*" \n")
    for i in 1:size1
        write(file, " "^8*"intervals ["*string(i)*"]:\n")
        write(file, " "^12*"xmin = "*string(words[i,:][2])*" \n")
        write(file, " "^12*"xmax = "*string(words[i,:][3])*" \n")
        write(file, " "^12*"text = \""*string(words[i,:][1])*"\" \n")
    end
end
