I don't think the problem is well-defined or single-solution. Surely the
simplest solution, given a single output and the data that produced it is
to simply encode the entire output text in the template and ignore the data.
Instead, I think you need a matching corpus - i.e. a list of pairs of
output and input. Once you have that, I expect you would basically run a
diff-type algorithm across pairs of outputs looking to build an invariant
list (i.e. the elements of the template that never change) paired with a
variant list (the elements that change), to be interleaved in the template.
I don't think there is any simple or valid path to go from there to a fully
worked out template, given the level of coding permissible in templates.
But you could do a series of heuristics to match clear elements. For
example, having your list of variants, you would run a match against the
content of that variant in each output against all the inputs looking for
simple matches that hold true across the entire corpus, and replace these
with simple substitutions in the template, marking them completed in your
list of variants.
Then you would run the same comparison looking for substring matches (to
attempt to capture simple substitutions that are chained (e.g.
{{.Salutation}} {{.FirstName}} {{.LastName}} in a naive name implementation
is going to show up as a single variant block in the analysis, so your
first heuristic will fail to find a match).
Finding repeated complex sub-elements of a template and matching them; or
matching summary values such as subtotals and grand totals or worse,
averages that have been formatted to less than the default number of
digits? I suspect you are going well off the end of what is achievable with
simple pattern matching, so if that is your normal interview fare, I pity
your interviewees.
--
You received this message because you are subscribed to the Google Groups
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.