-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPatent3.java
More file actions
98 lines (70 loc) · 2.78 KB
/
Copy pathPatent3.java
File metadata and controls
98 lines (70 loc) · 2.78 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
package com.Rajesh.mapreduce;
import java.io.*;
import java.util.*;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.*;
import org.apache.hadoop.mapreduce.*;
import org.apache.hadoop.conf.*;
import org.apache.hadoop.mapreduce.lib.input.MultipleInputs;
import org.apache.hadoop.mapreduce.lib.input.TextInputFormat;
import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;
public class Patent3 {
public static class PatentMap extends Mapper<LongWritable,Text, IntWritable, Text> {
public void map(LongWritable key, Text value, Context context) throws IOException, InterruptedException {
String[] column = value.toString().split(",");
String patent = column[0] ;
try {
int asignee = Integer.parseInt(column[6]) ;
context.write(new IntWritable(asignee), new Text("PAT" +"\t" + patent));
}
catch (NumberFormatException e) {
System.out.println("Number Format Exception" + e);
}
}
}
public static class AsigneeMap extends Mapper<LongWritable,Text, IntWritable, Text> {
public void map(LongWritable key, Text value, Context context) throws IOException, InterruptedException {
String[] column = value.toString().split(",");
String coname = column[1];
try {
int asignee = Integer.parseInt(column[0]) ;
context.write(new IntWritable(asignee), new Text("ASN"+ "\t" + coname));
}
catch (NumberFormatException e) {
System.out.println("Number Format Exception" + e);
}
}
}
public static class MyReducer extends Reducer<IntWritable, Text, Text, Text> {
public void reduce(IntWritable key, Iterable<Text> values, Context context) throws IOException, InterruptedException {
Text coname = new Text() ;
ArrayList<String> patents = new ArrayList<String>() ;
for (Text value : values) {
String [] column = value.toString().split("\t") ;
if (column[0].equals("PAT")) {
patents.add(column[1]);
} else {
coname.set(column[1]);
}
}
for (String patent : patents) {
context.write(new Text(patent), coname);
}
}
}
public static void main(String[] args) throws IOException, ClassNotFoundException, InterruptedException{
Configuration conf = new Configuration();
Job job = new Job(conf, "Patent3");
job.setJarByClass(Patent3.class);
job.setReducerClass(MyReducer.class) ;
// job.setNumReduceTasks(0);
job.setMapOutputKeyClass(IntWritable.class);
job.setMapOutputValueClass(Text.class);
job.setOutputKeyClass(Text.class);
job.setOutputValueClass(Text.class);
MultipleInputs.addInputPath(job, new Path(args[0]), TextInputFormat.class, PatentMap.class);
MultipleInputs.addInputPath(job, new Path(args[1]), TextInputFormat.class, AsigneeMap.class);
FileOutputFormat.setOutputPath(job, new Path(args[2]));
job.waitForCompletion(true);
}
}