| 1 | |
| 2 | 原本 |
| 3 | |
| 4 | {{{ |
| 5 | #!java |
| 6 | public static class wordindexM extends |
| 7 | Mapper<LongWritable, Text, Text, Text> { |
| 8 | public void map(LongWritable key, Text value, |
| 9 | OutputCollector<Text, Text> output, Reporter reporter) |
| 10 | throws IOException { |
| 11 | |
| 12 | FileSplit fileSplit = (FileSplit) reporter.getInputSplit(); |
| 13 | |
| 14 | String line = value.toString(); |
| 15 | StringTokenizer st = new StringTokenizer(line.toLowerCase()); |
| 16 | while (st.hasMoreTokens()) { |
| 17 | String word = st.nextToken(); |
| 18 | output.collect(new Text(word), new Text(fileSplit.getPath() |
| 19 | .getName() |
| 20 | + ":" + line)); |
| 21 | } |
| 22 | } |
| 23 | } |
| 24 | }}} |
12 | | 待解 |
| 36 | |
| 37 | * 已解決 |
| 38 | |
| 39 | {{{ |
| 40 | #!java |
| 41 | public static class wordindexM extends |
| 42 | Mapper<LongWritable, Text, Text, Text> { |
| 43 | public void map(LongWritable key, Text value, |
| 44 | OutputCollector<Text, Text> output, Reporter reporter) |
| 45 | throws IOException { |
| 46 | |
| 47 | FileSplit fileSplit = (FileSplit) reporter.getInputSplit(); |
| 48 | Text map_key = new Text(); |
| 49 | Text map_value = new Text(); |
| 50 | String line = value.toString(); |
| 51 | StringTokenizer st = new StringTokenizer(line.toLowerCase()); |
| 52 | while (st.hasMoreTokens()) { |
| 53 | String word = st.nextToken(); |
| 54 | map_key.set(word); |
| 55 | map_value.set(fileSplit.getPath().getName() + ":" + line); |
| 56 | output.collect(map_key,map_value); |
| 57 | } |
| 58 | } |
| 59 | } |
| 60 | }}} |