So, my current code looks something along the lines of
val tokens =
.read.option("wholetext", true).textFile(path)
.flatMap(line => line.split(" ")
.withColumn("filename", substring_index(input_file_name, "/", -1))
.groupBy(col("value"))
.agg(collect_list("filename") as "docs")
It reads in all text documents in path and creates a Dataframe that looks something like:
|word1 |[1.txt] |
|word2 |[2.txt] |
|word3 |[2.txt, 1.txt, 1.txt] |
Now I would like to take the lists and reduce them to something like this (sorry I don't actually know what a map looks like in Scala)
|word1 |[(1.txt, 1)] |
|word2 |[(2.txt, 1)] |
|word3 |[(1.txt, 2), (2.txt, 1)] |
In theory I know what to do: take the list entries, map them to (entry, 1) and then reduce them by adding up the count. But I have very little experience with Scala so I don't actually know how to write this into code.
As mentioned above, I would like to have the document names be the keys in a map, to make accessing the counts easier.