Posted By

pauliehaha on 03/23/10


Tagged

seo keywords


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

khouser


Keyword Extraction


 / Published in: C#
 

Very simple, single keyword extraction algorithm.

  1. public string[] GetKeywords(string text)
  2. {
  3. string[] stop = {"about","after","all","also","an","and","another","any","are","as","at","be","because","been","before","being","between","both","but","by","came","can","come","could","did","do","does","each","else","for","from","get","got","has","had","he","have","her","here","him","himself","his","how","if","in","into","is","it","its","just","like","make","many","me","might","more","most","much","must","my","never","now","of","on","only","or","other","our","out","over","re","said","same","see","should","since","so","some","still","such","take","than","that","the","their","them","then","there","these","they","this","those","through","to","too","under","up","use","very","want","was","way","we","well","were","what","when","where","which","while","who","will","with","would","you","your","a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z","$","£","1","2","3","4","5","6","7","8","9","0"};
  4.  
  5. char[] splitChars = {' ', '\''};
  6. string[] words = text.Split(splitChars);
  7. words.Except(stop);
  8. var keywordCount = (from keyword in words
  9. group keyword by keyword into g
  10. select new { Keyword = g.Key, Count = g.Count() });
  11. return keywordCount.OrderByDescending(k => k.Count).Select(k => .Keyword).Take(5).ToArray();
  12. }

Report this snippet  

You need to login to post a comment.