【问题标题】:Compare 2 lists of objects, return percentage match c#比较2个对象列表,返回百分比匹配c#
【发布时间】:2015-12-29 19:47:43
【问题描述】:

我正在寻找比较两个对象列表;了解语料库的语言。参考列表由 txt 构建。语料库也一样。

列出参考/列出语料库

    public Canagram(string anagram, int frequency,int percentage)
    {
        anagram = Anagram;         // exemple "a"
        frequency = Frequency;     // how many "a" in the txt 
        percentage = Percentage;   // what's the percentage compared to the other anagram
    }

目标是将每个列表上的每个字谜与百分比匹配,并返回这两个列表之间的全局百分比匹配。

    public static int percentage(List<Canagram> reference, List<Canagram> corpus)
    {

        //don"t know how to compare this two list properly and return % match

        return (int) percentage of match;
    }

谢谢!

【问题讨论】:

  • 你到底在比较什么?你是在比较anagram 还是anagram * frequency,还是...?
  • 我想比较语料库的所有字谜(如果它在参考列表中)并比较这个字谜的百分比,以便以后知道这个语料库中使用了哪种语言。例如,我从 french.txt/spanish.txt/english.txt 得到列表字谜 -> 我想通过将他的字谜列表与其他字谜列表进行比较来了解 text.txt 的语言

标签: c# list compare percentage listobject


【解决方案1】:

不确定这是否是您想要的,但可以尝试以下方法:

int cnt = reference.Count;
int matches = 0;
foreach (var phrase in reference)
{
if (corpus.Contains(phrase))
    matches++
}
double percent = (double)matches / (double)cnt;

您可能需要修改类型以便它可以与标准 Contains 一起使用,或者您必须编写自定义 MyContains 以便您确定。

以上内容我没有编译,请原谅错别字,但我相信你应该明白了。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-06-26
    • 2019-10-30
    • 1970-01-01
    相关资源
    最近更新 更多