Vitajte na [www.pocitac.win] Pripojiť k domovskej stránke Obľúbené stránky
zadajte nasledujúci kód pre mapu funkcie :
public static class InvertedIndexerMapper rozširuje MapReduceBaseimplements Mapper public void mapa ( LongWritable kľúč , Text val , výstup OutputCollector String linka - val.toString ( ) ; . StringTokenizer ITR = new StringTokenizer ( line.Je toLowerCase ( ) ) , zatiaľ čo ( itr.hasMoreTokens ( ) ) { word.set ( itr.nextToken ( ) ) ; output.collect ( slovo , umiestnenie ) ; } } } Zadajte nasledujúce kód pre zníženie funkcie : public static class InvertedIndexerReducer rozširuje MapReduceBaseimplements Reducer Zadajte nasledujúci kód na dokončenie obrátenej index : public static void main ( String [ ] args ) throws IOException { if ( args.length < 2 ) { System.outprintln ( " Použitie : InvertedIndex < ; výstup path > " ) ; System.exit ( 1 ) ; } JobConf conf = new JobConf ( InvertedIndex.class ) ; conf.setJobName ( " InvertedIndex " ) ; conf.setOutputKeyClass ( Text.class ) ; conf.setOutputValueClass ( Text.class ) ; conf.setMapperClass ( InvertedIndexerMapper.class ) ; conf.setReducerClass ( InvertedIndexerReducer.class ) ; FileInputFormat.setInputPaths ( conf , nová cesta ( args [ 0 ] ) ) ; FileOutputFormat.setOutputPath ( conf , nová cesta ( args [ 1 ] ) ) ; try { JobClient.runJob ( conf ) ; } catch ( Exception e ) { e.pringStackTrace ( ) ; } }
2
3