如何根据标签列表自动从文章生成标签?

| 当用户写文章时,我想根据用户在现有标签列表上的书写内容自动生成标签。 例如,我有一个类似的列表: 曼哈顿 布鲁克林区 皇后区 .... 如果用户撰写包含这些关键词的文章,它将出现在标签中。 例如用户标题为:“今天我在曼哈顿滑行”,那么曼哈顿应该包含标签。 我曾考虑过foreach标签列表,但是如果标签列表很大,那将非常慢。 你们有自动生成标签的解决方案吗?还是有解决此问题的想法? 提前致谢。     
已邀请:
根据您拥有的标签数量,在这种情况下,尝试处理可能会效果很好。通过特里,您可以构建标签前缀的树数据结构。例如,如果您有诸如\“ A \”,\“ to \”,\“ tea \”,\“ ted \”,\“ ten \”,\“ i \”,\“ in \”,和\“ inn \”,那么您将构建以下\“前缀树\”:
+ - i - + i + - n - + in + - n - + inn +
  - A - + A +
  - t - + t + - o - + to +
              - e - + te + - n - + ten +
                           - a - + tea +
                           - d - + ted +
在此树中,\“-字符-\”表示边缘,\“ +字符串+ \”表示节点。构建完这个Trie之后,我将想象以下算法:
TrieNode root = rootOfTrie;
TrieNode current = root;

while (still typing)
{
   switch (key pressed)
   {
      case letter:

         if (current == null)
            break;

         bool found = false;

         foreach (successor trie edge)
         {
            if (edge.Letter == letter)
            {
               current = sucessor edge.node;
               found = true;
               break;
            }
         }

         if (!found)
            current = null;

         break;

      case whitespace:

         if (current != root && current != null && trie node is tag)
            suggest node current as tag;

         current = root;
         break;

      case backspace:

         // You may want to handle this case by back-tracking in the trie.

         current = null;
         break;

      default:

         current = null;
         break;
   }
}
在Wikipedia上阅读更多trie数据结构:http://en.wikipedia.org/wiki/Trie     
想法-客户端+服务器端解决方案: 您可能有一个标题文本字段,然后是另一个带有文章正文的输入(文本区域)。您需要一个事件,当用户离开标题输入(或输入文本区域输入)时将触发该事件。然后,您可以从textarea抓取文本并将其与可用标签列表进行比较(如果您有数百个标签,这可能会很慢)。 如何比较:假设,在服务器端,您生成了可用标签列表,并且确实将该列表设置为页面上某些隐藏字段的内容。然后在客户端,您可以读取该隐藏字段的内容并将标签列表加载到某个列表变量中。 (或者您可以为此使用ajax。取决于您的技能)。现在,您有了可用标签的列表和一个句子(文章标题)。您可以拆分该句子并选择每个单词长于2个字符(例如),然后检查该标签列表是否包含给定的单词(针对您从拆分中获得的每个单词)。 伪代码:
foreach(string word in titleSplit)
{
    if (listOfTags.contains(word))
    {
        // You have matching word-tag.
        // Add it\'s text into your tags element, or to some collection
        // which will be processed later on.
        tags.add(word);
    }
}
我需要更具体的上下文来提供更具体的答案(想法):)     
使用HashSet来存储标签。 下面的文章供参考: http://social.msdn.microsoft.com/Forums/zh-CN/csharplanguage/thread/6a994e32-efc3-4f4b-8b60-ab357d5c1020/     

要回复问题请先登录注册