Vitajte na [www.pocitac.win] Pripojiť k domovskej stránke Obľúbené stránky

Domáce Hardware Siete Programovanie Softvér Otázka Systémy

Ako sa stavia prevrátené index MapReduce

MapReduce je paralelný programovací model vyvinutý v Google pre veľké súbory dát . Spracováva dáta v blokoch , skôr než v sekvenčnom poradí . V tom , že sa spolieha na mape párových vstupných funkcií ( klávesy ) , a hodnoty , ktoré potom stavajú cez zníženie funkcie - teda jeho meno - aby údaje zrozumiteľnejšie . Miesto poskytuje funkciu mapy s kľúčom a hodnotou , prevrátený Obsah dvojíc slov a dokumentov hľadaného textu . Môžete použiť obrátený indexy v MapReduce vytvoriť index pre vyhľadávanie pomocou kľúčových slov , napríklad. Pokyny dovolená 1

zadajte nasledujúci kód pre mapu funkcie :

public static class InvertedIndexerMapper rozširuje MapReduceBaseimplements Mapper { private static konečnej Text slovo = new text ( ) ; private static konečnej Text location = new Text ( ) ;

public void mapa ( LongWritable kľúč , Text val , výstup OutputCollector , Reporter reportér ) throws IOException { FileSplit FileSplit = ( FileSplit ) reporter.getInputSplit ( ) ; String filename = fileSplit.getPath ( ) getName ( ) ; location.set ( filename) ;

String linka - val.toString ( ) ; . StringTokenizer ITR = new StringTokenizer ( line.Je toLowerCase ( ) ) , zatiaľ čo ( itr.hasMoreTokens ( ) ) { word.set ( itr.nextToken ( ) ) ; output.collect ( slovo , umiestnenie ) ; } } }
2

Zadajte nasledujúce kód pre zníženie funkcie :

public static class InvertedIndexerReducer rozširuje MapReduceBaseimplements Reducer { public void znížiť (Text kľúče , hodnoty Iterator , OutputCollector výstupu , reporter reportér ) throws IOException { boolean prvej = true ; StringBuilder toReturn = new StringBuilder ( ) ; while ( values.hasNext ( ) ) { if ( prvý ) toReturn.append ( " , " ) ; ! prvú = false ; toReturn . append ( . values.next ( ) toString ( ) ) ; } output.collect ( kľúč , nové Text ( toReturn.toString ( ) ) ) ; } }
3

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 ( ) ; } }

Najnovšie články

Copyright © počítačové znalosti Všetky práva vyhradené