一、以下是测试数据:
"CITING","CITED" 3858241,956203 3858241,1324234 3858241,3398406 3858241,3557384 3858241,3634889 3858242,1515701 3858242,3319261 3858242,3668705 3858242,3707004 3858243,2949611 3858243,3146465 3858243,3156927 3858243,3221341 3858243,3574238 3858243,3681785 3858243,3684611 3858244,14040 3858244,17445 3858245,17445
注:第一列是专利号,第二列是引用的专利号。
二、Hadoop 代码如下:
import java.io.IOException; import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.conf.Configured; import org.apache.hadoop.fs.Path; import org.apache.hadoop.io.Text; import org.apache.hadoop.mapreduce.Job; import org.apache.hadoop.mapreduce.Mapper; import org.apache.hadoop.mapreduce.Reducer; import org.apache.hadoop.mapreduce.lib.input.FileInputFormat; import org.apache.hadoop.mapreduce.lib.input.KeyValueLineRecordReader; import org.apache.hadoop.mapreduce.lib.input.KeyValueTextInputFormat; import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat; import org.apache.hadoop.mapreduce.lib.output.TextOutputFormat; import org.apache.hadoop.util.Tool; import org.apache.hadoop.util.ToolRunner; public class PatentCitations extends Configured implements Tool { public static class PatentCitationsMapper extends Mapper<Text, Text, Text, Text> { @Override protected void map(Text key, Text value, Context context) throws IOException, InterruptedException { context.write(value, key); } } public static class PatentCitationsReduces extends Reducer<Text, Text, Text, Text> { private static Text staticVal = new Text(); @Override protected void reduce(Text key, Iterable<Text> values,Context context) throws IOException, InterruptedException { StringBuilder sb = new StringBuilder(); for (Text value : values) { if (sb.length() > 0) { sb.append(","); } sb.append(value.toString()); } staticVal.set(sb.toString()); context.write(key,staticVal); } } @Override public int run(String[] args) throws Exception { Configuration conf = getConf(); conf.set(KeyValueLineRecordReader.KEY_VALUE_SEPERATOR, ","); Job job = new Job(getConf()); job.setJarByClass(getClass()); job.setJobName("patentcitations"); job.setInputFormatClass(KeyValueTextInputFormat.class); job.setOutputFormatClass(TextOutputFormat.class); job.setOutputKeyClass(Text.class); job.setOutputValueClass(Text.class); job.setMapperClass(PatentCitationsMapper.class); job.setReducerClass(PatentCitationsReduces.class); FileInputFormat.setInputPaths(job, new Path("/patent/test/input/file1.txt")); FileOutputFormat.setOutputPath(job, new Path("/patent/test/output")); //FileInputFormat.setInputPaths(job, new Path(args[0])); //FileOutputFormat.setOutputPath(job, new Path(args[1])); boolean success = job.waitForCompletion(true); return success ? 0: 1; } public static void main(String[] args) throws Exception{ int result = ToolRunner.run(new PatentCitations(), args); System.exit(result); } }
三、执行结果如下:
"CITED" "CITING" 1324234 3858241 14040 3858244 1515701 3858242 17445 3858245,3858244 2949611 3858243 3146465 3858243 3156927 3858243 3221341 3858243 3319261 3858242 3398406 3858241 3557384 3858241 3574238 3858243 3634889 3858241 3668705 3858242 3681785 3858243 3684611 3858243 3707004 3858242 956203 3858241
注:17445 分别被 3858245,3858244 所引用。
相关推荐
hadoop流量统计程序hadoop流量统计程序hadoop流量统计程序hadoop流量统计程序
Hadoop统计单词出现次数.rar
完整的词频统计MapReduce版本。基于Hadoop2.2.0,包含一个十万单词左右的测试文件。请参照 http://blog.csdn.net/zythy/article/details/17888439 获取详细解说。
该文件可以帮助我们练习Hadoop的统计功能。
基于hadoop的词频统计,通过空格作为词频切分,简单统计了哈姆雷特节选的词频数量。
Hadoop按日期统计访问次数代码实现,以及包含测试用的数据
hadoop词频统计完整版!!!!!!!包含代码以及详细步骤。................................................................................................
Hadoop中单词统计案例运行的代码
Hadoop 分析统计学生考试成绩1
在hadoop平台上,用mapreduce编程实现大数据的词频统计
hadoop统计服务器kpi
Hadoop课程实验和报告——每年申请美国专利的国家数统计
对于基站数据,统计用户数,统计用户拨打电话的次数
基于Hadoop2.2.0的词频统计的例子。包含一个大概十万以上单词的测试数据文件。重写了Partitioner和Combiner,供学习之用。 访问博文 http://blog.csdn.net/zythy/article/details/17852579 以查看详细讲解。
mapreduce在hadoop实现词统计和列式统计,mrwordcount工程是统计hadoop文件中的词数,mrflowcount工程是统hadoop文件中的列表
在windows环境下开发hadoop时,需要配置HADOOP_HOME环境变量,变量值D:\hadoop-common-2.7.3-bin-master,并在Path追加%HADOOP_HOME%\bin,有可能出现如下错误: org.apache.hadoop.io.nativeio.NativeIO$Windows....
简单词频统计,带有注释,方便大家入门hadoop!具体的大家请自己看
3.3 读和写 3.3.1 InputFormat 3.3.2 OutputFormat 3.4 小结第二部分 实战 第4章 编写MapReduce基础程序 4.1 获得专利数据集 4.1.1 专利引用数据 4.1.2 专利描述数据 4.2 构建MapReduce 程序的基础模板 4.3...
第一次实现hadoop上的程序,内含jar包和用例,算迈出大数据的第一步吧。。