簡體   English   中英

從龐大的文本語料庫中刪除停用詞的最有效方法是什么?

[英]what is the most efficient way of removing stop words from huge text corpus ?

我想知道從龐大的文本語料庫中刪除停用詞的有效方法。 目前,我的方法是將停用詞轉換為正則表達式,以使文本行與正則表達式匹配並將其刪除。

例如

String regex ="\\b(?:a|an|the|was|i)\\b\\s*";
 String line = "hi this is regex approach of stop word removal";
 String lineWithoutStopword = line.replaceAll(regex,"");

有沒有其他有效的方法可以刪除巨大的小詞句中的停用詞。

謝謝

使用Spark,一種方法是在用詞標記后從文本中減去停用詞。

val text = sc.textFile('huge.txt')
val stopWords = sc.textFile('stopwords.txt')
val words = text.flatMap(line => line.split("\\W"))
val clean = words.subtract(stopwords)

如果您需要處理非常大的文本文件(>> GBs),將停用詞集視為可以廣播給每個工作人員的內存結構會更有效。

代碼將像這樣更改:

val stopWords = sc.textFile('stopwords.txt')
val stopWordSet = stopWords.collect.toSet
val stopWordSetBC = sc.broadcast(stopWordSet)
val words = text.flatMap(line => line.split("\\W"))
val clean = words.mapPartitions{iter =>
    val stopWordSet = stopWordSetBC.value
    iter.filter(word => !stopWordSet.contains(word))
}

請注意,為了使其正常工作,有必要對原始文本中的單詞進行標准化。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM