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]的词形化功能吗? –