Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- [SHELL]
- echo "Old MACDONALD had a farm E-I-E-I-O And on his farm he had
- a cow E-I-E-I-O With a moo moo here And a moo moo there Here a
- moo there a moo Everywhere a moo moo Old MacDonald had a farm
- E-I-E-I-O" > doc01.txt
- echo "Old MACDONALD had a farm E-I-E-I-O And on his farm he had a
- pig E-I-E-I-O With a oink oink here And a oink oink there Here
- a oink there a oink Everywhere a oink oink Old MacDonald had a
- farm E-I-E-I-O" > doc02.txt
- echo "Old MACDONALD had a farm E-I-E-I-O And on his farm he had a
- duck E-I-E-I-O With a quack quack here And a quack quack there
- Here a quack there a quack Everywhere a quack quack Old
- MacDonald had a farm E-I-E-I-O" > doc03.txt
- echo "Old MACDONALD had a farm E-I-E-I-O And on his farm he had a
- horse E-I-E-I-O With a neigh neigh here And a neigh neigh there
- Here a neigh there a neigh Everywhere a neigh neigh Old
- MacDonald had a farm E-I-E-I-O" > doc04.txt
- echo "Old MACDONALD had a farm E-I-E-I-O And on his farm he had a
- lamb E-I-E-I-O With a baa baa here And a baa baa there Here a
- baa there a baa Everywhere a baa baa Old MacDonald had a farm
- E-I-E-I-O" > doc05.txt
- hdfs dfs -mkdir /Q7_dir
- hdfs dfs -put doc*.txt /Q7_dir
- hdfs dfs -ls /Q7_dir
- [CODE]
- val Q7Data=sc.wholeTextFiles("hdfs://127.0.0.1:9000/Q7_dir/")
- val invIndex = Q7Data.map{case (fname,content) =>
- val contSplited=content.toLowerCase.split("\\s+").groupBy(x=>x).mapValues(x=>x.length)
- val result=contSplited.map(x=>(x._1,
- (fname.takeRight(9))))
- result
- }.flatMap(x=>x).groupByKey().sortByKey(true)
- invIndex.foreach(println)
- [截圖]
- https://imgur.com/a/gHN2VB5.jpg
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement