Béa*_*nac 6 scala stanford-nlp nosuchelementexception apache-spark
我之前遇到过类似的问题,但我正在寻找一个可以回答的问题.我正在使用spark-corenlp在电子邮件中获得Sentiment分数.有时候,情绪()会在某些输入上崩溃(也许它太长了,也许它有意想不到的特征).它没有告诉我它在某些情况下崩溃,只是返回Column sentiment('email).因此,当我尝试show()超出某个点或save()我的数据框时,我得到一个java.util.NoSuchElementException因为sentiment()必须在该行没有返回任何内容.
我的初始代码是加载数据,并sentiment()如spark-corenlpAPI 所示应用.
val customSchema = StructType(Array(
StructField("contactId", StringType, true),
StructField("email", StringType, true))
)
// Load dataframe
val df = sqlContext.read
.format("com.databricks.spark.csv")
.option("delimiter","\t") // Delimiter is tab
.option("parserLib", "UNIVOCITY") // Parser, which deals better with the email formatting
.schema(customSchema) // Schema of the table
.load("emails") // Input file
val sent = df.select('contactId, sentiment('email).as('sentiment)) // Add sentiment analysis output to dataframe
Run Code Online (Sandbox Code Playgroud)
我试图过滤null和NaN值:
val sentFiltered = sent.filter('sentiment.isNotNull)
.filter(!'sentiment.isNaN)
.filter(col("sentiment").between(0,4))
Run Code Online (Sandbox Code Playgroud)
我甚至试图通过SQL查询来做到这一点:
sent.registerTempTable("sent")
val test = sqlContext.sql("SELECT * FROM sent WHERE sentiment IS NOT NULL")
Run Code Online (Sandbox Code Playgroud)
我不知道是什么输入导致spark-corenlp崩溃.我该怎么知道?另外,如何从col("情绪")中过滤这些不存在的值?否则,我应该尝试捕获异常并忽略该行吗?这甚至可能吗?
| 归档时间: |
|
| 查看次数: |
856 次 |
| 最近记录: |