标签云在C# [英] Tag Cloud in C#

查看:234
本文介绍了标签云在C#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想提出一个小的 C#应用程序,并想提取一个简单的纯文本格式的标签云。有没有能做到这一点对我来说是功能?

I am making a small C# application and would like to extract a tag cloud from a simple plain text. Is there a function that could do that for me?

推荐答案

建立一个标签云,在我看来,由两部分组成过程:

Building a tag cloud is, as I see it, a two part process:

首先,你需要分割和计数您的令牌。取决于文件是如何构成的,以及该语言被写入,这可能是因为计数空格分隔单词一样容易。然而,这是一个非常幼稚的方法,因为象的话,一个,等...将具有最大的字计数,并不作为标记十分有用。我建议实行某种形式的字黑名单,以排除最常见的和无意义的标签。

First, you need to split and count your tokens. Depending on how the document is structured, as well as the language it is written in, this could be as easy as counting the space-separated words. However, this is a very naive approach, as words like the, of, a, etc... will have the biggest word-count and are not very useful as tags. I would suggest implementing some sort of word black list, in order to exclude the most common and meaningless tags.

一旦有结果的(标记,计数)的方式,你可以使用类似于下面的代码的内容:

Once you have the result in a (tag, count) way, you could use something similar to the following code:

(搜索是SearchRecordEntity的列表,SearchRecordEntity持有标签和其计数,SearchTagElement是SearchRecordEntity的子类具有TagCategory属性,和ProcessedTags是SearchTagElements的列表保持该结果)

(Searches is a list of SearchRecordEntity, SearchRecordEntity holds the tag and its count, SearchTagElement is a subclass of SearchRecordEntity that has the TagCategory attribute,and ProcessedTags is a List of SearchTagElements which holds the result)

double max = Searches.Max(x => (double)x.Count);
List<SearchTagElement> processedTags = new List<SearchTagElement>();

foreach (SearchRecordEntity sd in Searches)
{
    var element = new SearchTagElement();                    

    double count = (double)sd.Count;
    double percent = (count / max) * 100;                    

    if (percent < 20)
    {
        element.TagCategory = "smallestTag";
    }
    else if (percent < 40)
    {
        element.TagCategory = "smallTag";
    }
    else if (percent < 60)
    {
        element.TagCategory = "mediumTag";
    }
    else if (percent < 80)
    {
        element.TagCategory = "largeTag";
    }
    else
    {
        element.TagCategory = "largestTag";
    }

    processedTags.Add(element);
}

这篇关于标签云在C#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆