这是我用于情感分析的代码,但我一直收到潜在的错误。
def valence2(word):
if(dictionary.filter(dictionary.Word == word).count()>0):
val = dictionary.filter(dictionary.Word == word).select('VALENCE')
return val.collect()[0]['VALENCE']
def sentiment(in_vec):
out_vec = []
for t in in_vec:
val = valence2(t)
if val != None:
out_vec.append(val)
return out_vec
sentiment_udf = udf(lambda x: sentiment(x), ArrayType(FloatType()))
basetable_sentiment = (
basetable_common
.withColumn("sentimentVector",sentiment_udf(basetable_common.best_words))
)
py4j.Py4JException:方法 getnewargs ([])不存在