Wikipedia 5 http download wikimedia orgjawikilatest jawikilatestinterwiki sql














































- Slides: 46
Wikipediaの配布データ 5
ダウンロードサイト • http: //download. wikimedia. org/jawiki/latest/ jawiki-latest-interwiki. sql. gz jawiki-latest-pages-meta-current. xml. bz 2 6
jawiki-latest-pages-meta-current. xml • 全ページ内容が記述されているXMLファイル • 6. 5 GB • page要素がWikipedia 1ページ分の情報 <mediawiki> <siteinfo>ヘッダー情報</siteinfo> <page>ページ内容 1</page> <page>ページ内容 2</page> <page>ページ内容 3</page> ・ <page>ページ内容n</page> </mediawiki> ページ要素 1, 880, 711個 7
page要素 <page> <title>Hadoop</title> <id>1805248</id> <revision> <id>34222653</id> <timestamp>2010 -09 -28 T 14: 57: 34 Z</timestamp> <contributor> <username>Tire works</username> <id>456732</id> </contributor> <minor/> <comment>バージョンを更新。</comment> <text xml: space="preserve"> 記事本文…… </text> </revidion> </page> title要素 ページタイトル id要素 ページID text要素 記事本文 Wiki形式の 生データ 8
Hadoopとは 10
平均点算出Mapper 総称型で入出力デー タの型を定義 valueが 入力ファイル 1行分 public class Score. Average. Mapper extends Mapper<Long. Writable, Text, Int. Writable> { protected void map(Long. Writable key, Text value, Context context) throws IOException , Interrupted. Exception { String[] columns = value. to. String(). split("t"); int class. N = Integer. parse. Int(columns[0]); int score = Integer. parse. Int(columns[2]); context. write(new Int. Writable(class. N), new Int. Writable(score)); }; } keyが組 valueが点数 として出力 23
平均点算出Reducer keyが組 key(組)と結びついている value(点数)が Iterableとして取得できる public class Score. Average. Reducer extends Reducer<Int. Writable, Double. Writable> { protected void reduce(Int. Writable key, Iterable<Int. Writable> values, Context context)throws IOException , Interrupted. Exception { int sum = 0; int students = 0; for (Int. Writable score : values) { sum += score. get(); students++; } context. write(key, new Double. Writable((double)sum / (double)students)); }; } keyが組 valueが平均点 として出力 24
Jobオブジェクトの生成 Job job = new Job(get. Conf()); job. set. Jar. By. Class(Score. Average. class); job. set. Mapper. Class(Score. Average. Mapper. class); Mapperクラスの指定 job. set. Reducer. Class(Score. Average. Reducer. class); Reducerクラスの指定 job. set. Map. Output. Key. Class(Int. Writable. class); Mapperクラスの出力keyの型 job. set. Map. Output. Value. Class(Int. Writable. class); Mapperクラスの出力valueの 型 job. set. Output. Key. Class(Int. Writable. class); Reducerクラスの出力keyの型 job. set. Output. Value. Class(Double. Writable. class); Reducerクラスの出力valueの 型 job. set. Input. Format. Class(Text. Input. Format. class); Mapperへのデータの与え方 job. set. Output. Format. Class(Text. Output. Format. class); 出力結果の形式 File. Input. Format. add. Input. Path(job, new Path(args[0])); 入力ファイルのパス File. Output. Format. set. Output. Path(job, new Path(args[1])); 出力ファイルのパス return job. wait. For. Completion(true) ? 0 : 1; 設定内容でMap. Reduceを実行 25
Wikipediaデータへの応用 29
Wikipediaデータへの応用 • 平均点の時と同様に、このMap. Reduceの枠 組みに当てはめて考える jawiki-latest-pagesmeta-current. xml map reduce 30
Media. Wikiとの比較 40
テンプレート • 与えた引数に応じてParserが文字列を出力す る仕組み • {{Lang-en|United States of America}} – Lang-enというテンプレート – 引数は” Lang-en|United States of America” • Parserの出力は • 英語: United States of America 42