基本上我想标记段落的每个单词,然后执行停用词删除。这将是我的算法的预处理数据。
问问题
1156 次
3 回答
2
您可以删除所有标点符号并将字符串拆分为空格。
string s = "This is, a sentence.";
s = s.Replace(",","").Replace(".");
string words[] = s.split(" ");
于 2011-09-30T15:36:23.253 回答
0
您可以将所有分隔符号和停用词存储在常量或数据库中:
public static readonly char[] WordsSeparators = {
' ', '\t', '\n', '\n', '\r', '\u0085'
};
public static readonly string[] StopWords = {
"stop", "word", "is", "here"
};
删除所有波动。拆分文本和过滤器:
var words = new List<string>();
var stopWords = new HashSet<string>(TextOperationConstants.StopWords);
foreach (var term in text.Split(TextOperationConstants.WordsSeparators))
{
if (String.IsNullOrWhiteSpace(term)) continue;
if (stopWords.Contains(term)) continue;
words .Add(term);
}
于 2017-01-23T15:05:31.593 回答
0
如果从文本文件或任何文本中读取,您可以:
char[] dele = { ' ', ',', '.', '\t', ';', '#', '!' };
List<string> allLinesText = File.ReadAllText(text file).Split(dele).ToList();
然后您可以将停用词转换为字典并将您的文档保存到列表中
foreach (KeyValuePair<string, string> word in StopWords)
{
if (list.contain(word.key))
list.RemovAll(s=>s==word.key);
}
于 2017-01-23T06:51:41.853 回答