【发布时间】:2017-07-16 13:28:40
【问题描述】:
我尝试学习 scala,特别是文本挖掘(词形还原、TF-IDF 矩阵和 LSA)。
我想对一些文本进行词形还原并进行分类 (LSA)。我在 cloudera 上使用 spark。
所以我使用了 stanfordCore NLP 函数:
def plainTextToLemmas(text: String, stopWords: Set[String]): Seq[String] = {
val props = new Properties()
props.put("annotators", "tokenize, ssplit, pos, lemma")
val pipeline = new StanfordCoreNLP(props)
val doc = new Annotation(text)
pipeline.annotate(doc)
val lemmas = new ArrayBuffer[String]()
val sentences = doc.get(classOf[SentencesAnnotation])
for (sentence <- sentences; token <-sentence.get(classOf[TokensAnnotation])) {
val lemma = token.get(classOf[LemmaAnnotation])
if (lemma.length > 2 && !stopWords.contains(lemma)) {
lemmas += lemma.toLowerCase
}
}
lemmas
}
之后,我尝试制作一个 TF-IDF 矩阵,但这是我的问题: 斯坦福函数以 [Seq[string] 形式生成 RDD。 但是,我有一个错误。 我需要使用 [String] 形式的 RDD(而不是 [Seq[string]] 形式)。
val (termDocMatrix, termIds, docIds, idfs) = termDocumentMatrix(lemmatized-text, stopWords, numTerms, sc)
有人知道如何将 [Seq[string]] 转换为 [String]?
或者我需要更改我的请求之一?
感谢您的帮助。 对不起,如果这是一个愚蠢的问题和英语。
再见
【问题讨论】:
-
对不起,我需要澄清我的问题。 lemmatization fonction 在 [Seq[String form]] 中创建了一个 RDD,但我只需要一个用于 tf-idf 的 [String form]。你知道制作 [String] 形式的词形还原函数
标签: scala tf-idf lemmatization lsa