比较两个对象列表,返回匹配百分比c#

本文关键字:返回 百分比 列表 对象 两个 比较 | 更新日期: 2023-09-27 18:15:37

我正在寻找比较两个对象列表;掌握语料库中的语言。参考列表是由一个txt文件构建的。语料库也一样。

list Ref/list Corpus

    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;
    }

谢谢!

比较两个对象列表,返回匹配百分比c#

不确定这是你想要的,但也许可以尝试这样做:

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,以便您可以确定。

我还没有编译上面的代码,所以请原谅我的拼写错误,但我相信你应该得到jist。