【发布时间】:2015-05-06 11:37:25
【问题描述】:
这是我的数据:
review/text: The product picture and part number match, but they together do not math the description.
review/text: A necessity for the Garmin. Used the adapter to power the unit on my motorcycle. Works like a charm.
review/text: This power supply did the job and got my computer back online in a hurry.
review/text: Not only did the supply work. it was easy to install, a lot quieter than the PowMax that fried.
review/text: This is an awesome power supply that was extremely easy to install.
review/text: I had my doubts since best buy would end up charging me $60. at the time I bought my camera for the card and the cable.
review/text: Amazing... Installed the board, and that's it, no driver needed. Work great, no error messages.
我试过了:
import org.apache.spark.{SparkContext, SparkConf}
object test12 {
def filterfunc(s: String): Array[((String))] = {
s.split( """\.""")
.map(_.split(" ")
.filter(_.nonEmpty)
.map(_.replaceAll( """\W""", "")
.toLowerCase)
.filter(_.nonEmpty)
.flatMap(x=>x)
}
def main(args: Array[String]): Unit = {
val conf1 = new SparkConf().setAppName("pre2").setMaster("local")
val sc = new SparkContext(conf1)
val rdd = sc.textFile("data/2012/2012.txt")
val stopWords = sc.broadcast(List[String]("reviewtext", "a", "about", "above", "according", "accordingly", "across", "actually",...)
var grouped_doc_words = rdd.flatMap({ (line) =>
val words = line.map(filterfunc).filter(word_filter.value))
words.map(w => {
(line.hashCode(), w)
})
}).groupByKey()
}
}
我想生成这个输出:
doc1: product picture number match together not math description.
doc2: necessity garmin. adapter power unit my motorcycle. works like charm.
doc3: power supply job computer online hurry.
doc4: not supply work. easy install quieter powmax fried.
...
一些例外:1- (not , n't , non , none) 不发出 2- 所有点 (.) 符号都必须保持
我上面的代码不太好用。
【问题讨论】:
-
您能解释一下您希望做什么吗?您是否要过滤掉一组单词,但保留所有以句点结尾的单词?
-
我相信他正在尝试为情绪分析准备文本,因此他需要对其进行标记以“提高性能”
-
@ohruunuruus,必须过滤掉哪个单词并不重要,我想要像上面这样的输出。
-
@eliasah ,是的,它用于情绪分析。
-
你想要的输出是什么?据我所知,您为生成该输出所做的只是过滤掉一些单词,并将“review/text:”替换为“docN:”。请说明输出的要求。 1)过滤词。 2)关于经期的一些事情。 3) 显然是标记化,尽管您的输出不一定意味着标记化。
标签: scala text apache-spark