Skip to main content
 首页 » 编程设计

c#之使用数组 c# 删除停用词

2024年02月06日11虾米姐

我有一个停用词字符串数组和输入文本字符串数组,即

string[] stopWords = File.ReadAllLines(@"C:\stopWords.txt"); 

和

con.Open(); 
SqlCommand query = con.CreateCommand(); 
query.CommandText = "select p_abstract from aminer_paper where pid between 1 and 500 and DATALENGTH(p_abstract) != 0"; 
 
SqlDataReader reader = query.ExecuteReader(); 
 
var summary = new List<string>(); 
while(reader.Read()) 
{ 
    summary.Add(reader["p_abstract"].ToString()); 
} 
 
reader.Close(); 
 
string[] input_Texts = summary.ToArray(); 

现在,我必须使用这些 stopWords 数组从 input_Texts 数组中删除。 我使用了以下技术但没有工作,在访问两个数组索引时很奇怪。例如,在 input_Texts 数组的索引 0 处获取第一个文本,即

input_Texts[0] 

然后匹配stopWords数组中的所有词串即

// have to match all the indexes of stopWords[] with input_Texts[0] 
stopWords[]    

然后在从 input_Texts 数组的索引 0 文本中删除所有 stopWords 之后,必须对 input_Texts 数组中的所有文本重复它。

任何建议和经过修改的代码示例都将受到高度赞赏并予以确认。

谢谢。

请您参考如下方法:

试试这个:

string[] result = input_Texts.Except(stopWords).ToArray();