【发布时间】:2021-06-30 04:10:32
【问题描述】:
我正在使用 pyspark 数据框。
我的 df 看起来像这样:
df.select('words').show(5, truncate = 130)
+----------------------------------------------------------------------------------------------------------------------------------+
| words |
+----------------------------------------------------------------------------------------------------------------------------------+
|[content, type, multipart, alternative, boundary, nextpart, da, df, nextpart, da, df, content, type, text, plain, charset, asci...|
|[receive, ameurht, eop, eur, prod, protection, outlook, com, cyprmb, namprd, prod, outlook, com, https, via, cyprca, namprd, pr...|
|[plus, every, photographer, need, mm, lens, digital, photography, school, email, newsletter, http, click, aweber, com, ct, l, m...|
|[content, type, multipart, alternative, boundary, nextpart, da, beb, nextpart, da, beb, content, type, text, plain, charset, as...|
|[original, message, customer, service, mailto, ilpjmwofnst, qssadxnvrvc, narrig, stepmotherr, eviews, com, send, thursday, dece...|
+----------------------------------------------------------------------------------------------------------------------------------+
only showing top 5 rows
我需要在words 列上使用spark NLP 中的LanguageDetectorDL array<strings> 类型,这样它就可以检测到英语并仅保留英语单词并删除其他单词。
我已经使用DocumentAssembler()将数据转换为注解格式:
documentAssembler = DocumentAssembler().setInputCol('words').setOutputCol('document')
但是我不知道如何在专栏中使用LanguageDetectorDL并摆脱非英语单词?
【问题讨论】:
-
很难在单词级别检测语言 - 没有足够的信息进行可靠检测...
-
@AlexOtt 感谢您的调查。如果我将 array
转换回字符串,即如果我有句子,那么有可能吗? -
比如有句
protection outlook com cyprmb namprd prod outlook com,那么有没有可能得到protection outlook com prod outlook com? -
我不确定这是否可能 - 前提是您将使用某种字典查找或类似的东西。
-
但是你为什么需要它?如果您正在做某种文本分类或类似的事情,那么这些词很可能具有非常低的 TF-IDF 或其他度量,并且将被排除在“字典”之外
标签: python apache-spark pyspark johnsnowlabs-spark-nlp