require "./mutate.cr" require "random" class Generator getter words : Array(String) def initialize(@words) end def sentence(f = 3, t = 9) words = [] of String nwords = f + Random.rand(t - f + 1) nwords.times do |time| word = @words[time % @words.size] word = word.capitalize if time == 0 words << word.mutate end return words.join(" ") + ". " end def paragraph(f = 4, t = 20) nsentences = f + Random.rand(t - f + 1) sentences = Array(String).new(nsentences) { sentence } return sentences.join("") end def subsection(f = 4, t = 20) title = "\\subsection{#{sentence(@words.size, @words.size)}}\n" nparas = f + Random.rand(t - f + 1) paras = Array(String).new(nparas) { paragraph } return title + paras.join("\n\n") end def section(f = 4, t = 20) title = "\\section{#{sentence(@words.size, @words.size)}}\n" nsections = f + Random.rand(t - f + 1) subsections = Array(String).new(nsections) { subsection } return title + paragraph + "\n\n" + subsections.join("\n\n") end def document(f = 2, t = 4) title = sentence(@words.size, @words.size) abstrct = paragraph(10, 10) nsections = f + Random.rand(t - f + 1) sections = Array(String).new(nsections) { section } prefix = "\\documentclass[10pt, draftclsnofoot,onecolumn]{IEEEtran}" + "\\def\\changemargin#1#2{\list{}{\\rightmargin#2\\leftmargin#1}\\item[]}" + "\\let\\endchangemargin=\\endlist" + "\\begin{document}" postfix = "\\end{document}" return prefix + "\\title{#{title}}\n\n\\maketitle\n\n\\begin{abstract}#{abstrct}\\end{abstract}\n\n\\pagebreak\n\n\\tableofcontents\\pagebreak" + sections.join("\n\n") + postfix end end WORDS = ["three", "day", "weekend"] generator = Generator.new WORDS puts generator.document