繁体   English   中英

包含int和字符串的列表列表,需要根据TrackBar输出具有最高int值的X字符串(不是排序列表)

[英]A List of Lists containing int and string, need to output X strings with highest int values based on TrackBar (not a sorted list)

我有一个列表结构为:

"Then a sentence woop", 340 
"and another one",      256
"in order they appear", 700
"in a linked file",     304

该列表包含文本文件每个段落中得分最高的句子。 我需要输出每个句子,但是使用轨迹栏减少了显示的数量。

因此,删除得分最低的句子,问题是列表按原文中句子的出现顺序排列,并且输出必须按此顺序排列。 因此,如果我有上面列表的跟踪栏,它将得到4分。 如果我将其移至第3点,句子2将消失,第2点,句子2和4将消失。

生成列表的代码是:

    public List<ScoredSentence> buildSummarySentenceList()
    {
        List<ScoredSentence> ultimateScoreslist = new List<ScoredSentence>();
        scoreCoord2 = -1;
        for (int x1 = 0; x1 < results.Length; x1++)
        {
            List<ScoredSentence> paragraphsScorelist = new List<ScoredSentence>();
            for (int x2 = 0; x2 < results[x1].Length; x2++)
            {
                scoreCoord2++;
                paragraphsScorelist.Add(new ScoredSentence(results[x1][x2], intersectionSentenceScores[scoreCoord2]));
            }
            var maxValue = paragraphsScorelist.Max(s => s.score);

            string topSentence = paragraphsScorelist.First(s => s.score == maxValue).sentence;
            int topScore = paragraphsScorelist.First(s => s.score == maxValue).score;

            ultimateScoreslist.Add(new ScoredSentence(topSentence, topScore));
        }
        return ultimateScoreslist;
    }

    public class ScoredSentence
    {
        public string sentence { get; set; }
        public int score { get; set; }

        public ScoredSentence(string sentence, int score)
        {
            this.sentence = sentence;
            this.score = score;
        }
    }

该代码循环通过一个锯齿状的数组和一个句子到句子分数的列表,从而得到一个列表,如顶部所示。

目前,我输出每个句子,并将跟踪栏设置为只要有句子:

    protected void summaryOutput()
    {
        List<ScoredSentence> ultimateScoreslist = buildSummarySentenceList();
        trackBSummaryPercent.Maximum = ultimateScoreslist.Count;
        lblNoOfLines.Text += trackBSummaryPercent.Maximum.ToString();
        //make 2 lists for the reduction????
        for (var x = 0; x < ultimateScoreslist.Count; x++)
        {
            TextboxSummary.Text += ultimateScoreslist[x].sentence + "\n";
        }
    }

我已经想到在轨迹栏的每个onchange刻度上都有第二个克隆列表并删除最低值条目。 然后,当栏向上移动时,将丢失的条目从克隆列表中移回。 我不喜欢这种方法,因为例如当我当前的测试文本长100个段落时,它可能会导致程序速度问题,而移动轨迹栏太多可能会使它变慢。

将显示的属性添加到您的ScoredSentence对象。 然后,只要列表更改或轨迹栏选择更改,就对其运行此方法以更新显示的元素集。 主列表应始终按照您希望其显示的顺序进行排序。 numberToDisplay可以通过您用来从UI转到项目数的任何方式来计算。

public void OnUpdate()
{
   var orderedEnumerable = ScoresList.OrderByDescending (s => s.Score);

   foreach (var s in orderedEnumerable.Take (numberToDisplay)) 
   {
      s.Displayed = true;
   }
   foreach (var s in orderedEnumerable.Skip(numberToDisplay)) 
   {
      s.Displayed = false;
   }
}

然后在需要显示时使用以下内容代替列表

ScoredSentences.Where(s=> s.Displayed);

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM