private string ProcessSegment(ISentenceFragment sentenceFragment) { StringBuilder result = new StringBuilder(); result.Append(Process(sentenceFragment.MetricFragment, _templates.Metric)); var conjugations = GetConjugations(sentenceFragment.DataFragments); for (int i = 0; i < sentenceFragment.DataFragments.Count; i++) { if (i != 0) { result.Append(conjugations[i - 1]); } var dataFragment = sentenceFragment.DataFragments[i]; dataFragment.Units = sentenceFragment.MetricFragment.Metric.Units; // Trivial optimization (works only for two variables). // Instead of "were flat for A and were flat for B" we now get "were flat for A and B". if (i != 0 && dataFragment.Direction == DirectionType.FLAT && sentenceFragment.DataFragments[i - 1].Direction == DirectionType.FLAT) { _macroVariable.Get("DIR").Value = ""; } else { _macroVariable.Get("DIR").Value = " " + _direction.GetDirectionText(dataFragment.Direction); } var template = dataFragment.Direction == DirectionType.FLAT ? _templates.FlatData : _templates.Data; result.Append(Process(dataFragment, template)); result.Append(Process(dataFragment.VariableFragment, _templates.Variable)); } return(result.ToString()); }