0

我对下面的代码有疑问:

class Review(label: Double, features:org.apache.spark.ml.linalg.Vector)

def transformDataTFIDF(plainText: RDD[String],reviewClass:String,label:Int,numTerms:Int): org.apache.spark.sql.Dataset[Review] = {
  val lemmatized = plainText.zipWithIndex.map(_.swap).mapPartitions(iter => {
    val pipeline = createNLPPipeline();
    iter.map{  case(id, contents) => (id.toString(),
      plainTextToLemmas(contents, stopWords, pipeline))
    };
  }).cache()
  val (termDocMatrix, termIds, docIds, idfs) = termDocumentMatrix(lemmatized, stopWords, numTerms, sc)
  val vectorizedReviewsMap = Map( reviewClass -> termDocMatrix)
  val ReviewsList = MutableList[Review]()
  val ReviewsVecRDD = vectorizedReviewsMap(reviewClass).collect().foreach(v => ReviewsList += Review(label,v.asML))
  ReviewsList.toDS()
}

我收到了这个错误:

<console>:73: error: not found: value MutableList
       val ReviewsList = MutableList [Review]()

你能告诉我该怎么做才能纠正它吗?

4

1 回答 1

2

MutableList存在到 Scala 2.12。它在 Scala 2.13 中被删除了你可能没有导入它。尝试:

import scala.collection.mutable
val ReviewsList = mutable.MutableList[Review]()

或者:

val ReviewsList = scala.collection.mutable.MutableList[Review]()

Scala 2.12的工作代码片段和Scala 2.13的相同非工作示例。

于 2021-02-08T17:23:58.213 回答