0
我嘗試學習scala和特定文本minning(詞形化,TF-IDF矩陣和LSA)。Scala將[Seq [string]轉換爲[String]? (在詞形化後的TF-IDF)
我有一些文本我想要lemmatize並作出分類(LSA)。我在cloudera上使用spark。
所以我用了stanfordCore NLP fonction:
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矩陣,但這裏是我的問題: 斯坦福fonction使在RDD [序列[字符串]形成。 但是,我有一個錯誤。 我需要以[String]形式(而不是[Seq [string]]形式)使用RDD。
val (termDocMatrix, termIds, docIds, idfs) = termDocumentMatrix(lemmatized-text, stopWords, numTerms, sc)
有人知道如何將[Seq [string]]轉換爲[String]?
或者我需要更改我的要求之一?
感謝您的幫助。 對不起,如果這是一個愚蠢的問題和英語。
再見
對不起,我需要澄清我的問題。在[Seq [字符串形式]]中,詞典化函數做了一個RDD,但我只需要一個[字符串形式]給tf-idf。你知道一個形式爲[String]的詞形化功能嗎? –