Advertisement
Guest User

Q7

a guest
Apr 23rd, 2019
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Scala 1.59 KB | None | 0 0
  1. [SHELL]
  2. echo "Old MACDONALD had a farm E-I-E-I-O And on his farm he had
  3. a cow E-I-E-I-O With a moo moo here And a moo moo there Here a
  4. moo there a moo Everywhere a moo moo Old MacDonald had a farm
  5. E-I-E-I-O" > doc01.txt
  6. echo "Old MACDONALD had a farm E-I-E-I-O And on his farm he had a
  7. pig E-I-E-I-O With a oink oink here And a oink oink there Here
  8. a oink there a oink Everywhere a oink oink Old MacDonald had a
  9. farm E-I-E-I-O" > doc02.txt
  10. echo "Old MACDONALD had a farm E-I-E-I-O And on his farm he had a
  11. duck E-I-E-I-O With a quack quack here And a quack quack there
  12. Here a quack there a quack Everywhere a quack quack Old
  13. MacDonald had a farm E-I-E-I-O" > doc03.txt
  14. echo "Old MACDONALD had a farm E-I-E-I-O And on his farm he had a
  15. horse E-I-E-I-O With a neigh neigh here And a neigh neigh there
  16. Here a neigh there a neigh Everywhere a neigh neigh Old
  17. MacDonald had a farm E-I-E-I-O" > doc04.txt
  18. echo "Old MACDONALD had a farm E-I-E-I-O And on his farm he had a
  19. lamb E-I-E-I-O With a baa baa here And a baa baa there Here a
  20. baa there a baa Everywhere a baa baa Old MacDonald had a farm
  21. E-I-E-I-O" > doc05.txt
  22.  
  23. hdfs dfs -mkdir /Q7_dir
  24. hdfs dfs -put doc*.txt /Q7_dir
  25. hdfs dfs -ls /Q7_dir
  26.  
  27.  
  28. [CODE]
  29. val Q7Data=sc.wholeTextFiles("hdfs://127.0.0.1:9000/Q7_dir/")
  30.  
  31. val invIndex = Q7Data.map{case (fname,content) =>
  32.     val contSplited=content.toLowerCase.split("\\s+").groupBy(x=>x).mapValues(x=>x.length)
  33.     val result=contSplited.map(x=>(x._1,
  34. (fname.takeRight(9))))
  35.     result
  36. }.flatMap(x=>x).groupByKey().sortByKey(true)
  37.  
  38. invIndex.foreach(println)
  39.  
  40. [截圖]
  41. https://imgur.com/a/gHN2VB5.jpg
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement