自动检测文本中的标记

时间:2012-03-16 08:59:30

标签: c# .net algorithm tags keyword

是否有任何库或算法可以自动检测文本中的标签(忽略所选语言的常用词)?

这样的事情:

string[] keywords = GetKeyword("Your order is num #0123456789")

和关键字[]将包含“订单”和“#0123456789”......? 它存在吗?或者用户会自己选择每个文档的所有标签? :

3 个答案:

答案 0 :(得分:2)

对不起,我误解了这个问题。如果要查找特定单词,算法将取决于您的字符串。例如,您可以使用string.Split()从一个字符串生成一个单词数组,然后使用它,如下所示:

string[] words = string.Split("Your order is num #0123456789");
string orderNumber = "";
if(words.Contains("order") && w.StartsWith("#").Count > 0)
{
    orderNumber = words.Where(w=>w.StartsWith("#").FirstOrDefault();
}

这将首先从“您的订单号为#0123456789”生成一个单词数组,然后如果它包含单词“order”,它将会以“#”开头并选择该单词;

答案 1 :(得分:2)

foreach(string keyword in keywords) { // where keywords is a List<string>
    if ("Your order is num #0123456789".Contains(keyword)) {
        keywordsPresent.Add(keyword); // where keywordsPresent is a List<string>
    }
}

return keywordsPresent;

以上所做的并不适合您的#0123456789,为此添加更多逻辑来查找#或其他内容的索引......

答案 2 :(得分:1)

我认为可以使用很多不同的算法。其中一些很简单,另一些是超级复杂的。我可以建议你下一个基本方式:

  1. 将所有文字拆分为单词数组。
  2. 从数组中删除停用词。 (Goole“停止单词列表”以获取停止单词的完整列表。)
  3. 浏览数组并计算每个单词的数量。
  4. 根据数组中的“重量”对单词进行排序。
  5. 选择必要数量的标签。