如何在 Normalizer (spark nlp) 中使用多个清理模式?

问题描述

我正在使用 pyspark 数据框。我需要执行 tf-idf,为此我使用了使用 spark NLP 进行标记化、标准化等的先前步骤。

在应用分词器后,我的 df 看起来像这样:

df.select('tokenizer').show(5,truncate = 130)

+----------------------------------------------------------------------------------------------------------------------------------+
|                                                                                                                  tokenized       |
+----------------------------------------------------------------------------------------------------------------------------------+
|[content,type,multipart,alternative,boundary,nextpart,da,df,content,text,plain,charset,asci...|
|[receive,ameurht,eop,eur,prod,protection,outlook,com,cyprmb,namprd,https,via,cyprca,pr...|
|[plus,every,photographer,need,mm,lens,digital,photography,school,email,newsletter,http,click,aweber,ct,l,m...|
|[content,beb,as...|
|[original,message,customer,service,mailto,ilpjmwofnst,qssadxnvrvc,narrig,stepmotherr,eviews,send,thursday,dece...|
+----------------------------------------------------------------------------------------------------------------------------------+
only showing top 5 rows

下一步是应用规范化器:

我想设置多个清理模式:

1) remove all numerics and numerics from words
-> example: [jhghgb56,5897t95,fhgbg4,7474,hfgbgb]
-> expected output: [jhghgb,fhgbg,hfgbgb]

2) remove all words less than 4
-> example: [gfh,ehfufibf,hi,jdfh]
-> expected output: [ehfufibf,jdfh]

我试过了:

tokenizer = Tokenizer()\
     .setInputCols(['document'])\
     .setoutputCol('tokenized')\
     .setMinLength(3)

cleanup = ["[^A-Za-z]"]
normalizer = normalizer()\
     .setInputCols(['tokenized'])\
     .setoutputCol('normalized')\
     .setLowercase(True)\
     .setCleanupPatterns(cleanup)

到目前为止 cleanup = ["[^A-Za-z]"] 满足第一个条件。但是现在我得到了少于 4 个字符的干净单词,我不明白如何删除这些单词。 非常感谢您的帮助!

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...