I have following data which has id, text. I want to find frequently occurring words from the text column across rows for the same "id". I don't want to consider frequently occurring words in the same row (sentence in text column). I tried using TF-IDF Algorithm to achieve it.
id,text
1,Interface Down GigabitEthernet0/1/2 null .
1,Interface Gi0/1/2 Down on node BMAC69RT01
1,Interface Down MEth0/0/1 null .
1,Interface MEth0/0/1 Down on node
2,Interface Up FastEthernet0/0/0 null
2,Interface Fa0/0/0 Down on node
First i created tokens from the text column
val tokenizer = new Tokenizer().setInputCol("text").setOutputCol("words")
Then i tried using countvectorizer and IDF to get the commonly used words.I think countvectorizer is not needed here as i don't need to consider term frequency in the same sentence.
val countVectors = new CountVectorizer()
.setInputCol("words")
.setOutputCol("vectorText")
val idf = new IDF().setInputCol("vectorText").setOutputCol("features")
This gives me an output as follows
|1 |(11,[0,1,2,6],[0.0,0.15415067982725836,0.3364722366212129,1.252762968495368])
|1 |(11,[0,1,2,3,4,5,8],[0.0,0.3083013596545167,0.3364722366212129,1.1192315758708453,0.5596157879354227,0.5596157879354227,1.252762968495368])
|1 |(11,[0,1,2,3],[0.0,0.15415067982725836,0.3364722366212129,0.5596157879354227])
|1 |(11,[0,1,3,4,5],[0.0,0.15415067982725836,0.5596157879354227,0.5596157879354227,0.5596157879354227])
|2 |(11,[0,2,7,9],[0.0,0.3364722366212129,1.252762968495368,1.252762968495368])
|2 |(11,[0,1,4,5,10],[0.0,0.15415067982725836,0.5596157879354227,0.5596157879354227,1.252762968495368])
I know the above output gives me features and frequency for each word. But from the above output how can i get the real words and its frequency. I want a output similar to the below output. Any other algorithm available in spark to achieve below output
Label | (Word, Frequency)
1, | (Interface, 4) (Down, 4) (null, 2) (on, 2)
2, | (Interface, 2)