Guest User

Untitled

a guest
Dec 10th, 2018
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.12 KB | None | 0 0
  1. package info.moaikids.mapred.map;
  2.  
  3. import info.moaikids.chunker.Chunker;
  4. import info.moaikids.chunker.KuromojiChunker;
  5.  
  6. import java.io.IOException;
  7.  
  8. import org.apache.hadoop.io.IntWritable;
  9. import org.apache.hadoop.io.LongWritable;
  10. import org.apache.hadoop.io.Text;
  11. import org.apache.hadoop.mapreduce.Mapper;
  12.  
  13. public class Figure38Mapper extends
  14. Mapper<LongWritable, Text, Text, IntWritable> {
  15. Chunker chunker = new KuromojiChunker();
  16. static final IntWritable ONE = new IntWritable(1);
  17.  
  18. @Override
  19. protected void setup(Context context) throws IOException,
  20. InterruptedException {
  21. super.setup(context);
  22. }
  23.  
  24. @Override
  25. protected void map(LongWritable key, Text value, Context context)
  26. throws IOException, InterruptedException {
  27.  
  28. for (String line : value.toString().split("。|\n")) {
  29. line = line.replaceAll(" ", "").trim();
  30. String[] chunks = chunker.chunking(line);
  31. if (chunks.length > 1) {
  32. for (int i = 0; i < chunks.length; i++) {
  33. for (int j = 0; j < chunks.length; j++) {
  34. if (i >= j) {
  35. continue;
  36. }
  37. context.write(new Text(chunks[i] + " " + chunks[j]),
  38. ONE);
  39. }
  40. }
  41. }
  42. }
  43. }
  44.  
  45. }
Add Comment
Please, Sign In to add comment