I am working with pyspark dataframe. I need to perform tf-idf and for that I am used prior steps of tokenizing, normalization, etc using spark NLP.
I have df that looks like this after applying tokenizer:
df.select('tokenizer').show(5, truncate = 130)
+----------------------------------------------------------------------------------------------------------------------------------+
| tokenized |
+----------------------------------------------------------------------------------------------------------------------------------+
|[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
The next step is to apply normalizer:
I want to set multiple clean up patterns:
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, df, jdfh]
-> expected output: [ehfufibf, jdfh]
I tried this:
tokenizer = Tokenizer()\
.setInputCols(['document'])\
.setOutputCol('tokenized')\
.setMinLength(3)
cleanup = ["[^A-Za-z]"]
normalizer = Normalizer()\
.setInputCols(['tokenized'])\
.setOutputCol('normalized')\
.setLowercase(True)\
.setCleanupPatterns(cleanup)
so far cleanup = ["[^A-Za-z]"]
fulfils the first condition. But now I get clean words which are less than 4 characters and I don't understand how to remove those words.
Help would be much appreciated !