Web Intelligence and Big Data
by Dr. Gautam Shroff

这门课是关于大数据处理,本周是第一次编程作业,要求使用Map-Reduce对文本数据进行统计。使用的工具为轻量级的mincemeat。
需要注意的是,使用正则式来匹配单词。做完之后先按照姓名和频率排序,即双重排序,然后写入文件。做作业时因为有两分钟的时间限制,要即时进行搜索。
作业要求如下:
Download data files bundled as a .zip file from hw3data.zip
Each file in this archive contains entries that look like:

journals/cl/SantoNR90:::Michele Di Santo::Libero Nigro::Wilma Russo:::Programmer-Defined Control Abstractions in Modula-2.

that represent bibliographic information about publications, formatted as follows:

paper-id:::author1::author2::…. ::authorN:::title

Your task is to compute how many times every term occurs across titles, for each author.

For example, the author Alberto Pettorossi the following terms occur in titles with the indicated cumulative frequencies (across all his papers): program:3, transformation:2, transforming:2, using:2, programs:2, and logic:2.

Remember that an author might have written multiple papers, which might be listed in multiple files. Further notice that ‘terms’ must exclude common stop-words, such as prepositions etc. For the purpose of this assignment, the stop-words that need to be omitted are listed in the script stopwords.py. In addition, single letter words, such as "a" can be ignored; also hyphens can be ignored (i.e. deleted). Lastly, periods, commas, etc. need to be ignored; in other words, only alphabets and numbers can be part of a title term: Thus, “program” and “program.” should both be counted as the term ‘program’, and "map-reduce" should be taken as 'map reduce'. Note: You do not need to do stemming, i.e. "algorithm" and "algorithms" can be treated as separate terms.

The assignment is to write a parallel map-reduce program for the above task using either octo.py, or mincemeat.py, each of which is a lightweight map-reduce implementation written in Python.

These are available from http://code.google.com/p/octopy/ and mincemeat.py-zipfile respectively.

I strongly recommend mincemeat.py which is much faster than Octo,py even though the latter was covered first in the lecture video as an example. Both are very similar.

Once you have computed the output, i.e. the terms-frequencies per author, go attempt Homework 3 where you will be asked questions that can be simply answered using your computed output, such as the top terms that occur for some particular author.


输入范例如下:
conf/fc/KravitzG99:::David W. Kravitz::David M. Goldschlag:::Conditional Access Concepts and Principles.
conf/fc/Moskowitz01:::Scott Moskowitz:::A Solution to the Napster Phenomenon: Why Value Cannot Be Created Absent the Transfer of Subjective Data.
conf/fc/BellareNPS01:::Mihir Bellare::Chanathip Namprempre::David Pointcheval::Michael Semanko:::The Power of RSA Inversion Oracles and the Security of Chaum's RSA-Based Blind Signature Scheme.
conf/fc/Kocher98:::Paul C. Kocher:::On Certificate Revocation and Validation.
conf/ep/BertiDM98:::Laure Berti::Jean-Luc Damoiseaux::Elisabeth Murisasco:::Combining the Power of Query Languages and Search Engines for On-line Document and Information Retrieval : The QIRi@D Environment.
conf/ep/LouS98:::Qun Lou::Peter Stucki:::Funfamentals of 3D Halftoning.
conf/ep/Mather98:::Laura A. Mather:::A Linear Algebra Approach to Language Identification.
conf/ep/BallimCLV98:::Afzal Ballim::Giovanni Coray::A. Linden::Christine Vanoirbeek:::The Use of Automatic Alignment on Structured Multilingual Documents.
conf/ep/ErdenechimegMN98:::Myatav Erdenechimeg::Richard Moore::Yumbayar Namsrai:::On the Specification of the Display of Documents in Multi-lingual Computing.
conf/ep/VercoustreP98:::Anne-Marie Vercoustre::François Paradis:::Reuse of Linked Documents through Virtual Document Prescriptions.
conf/ep/CruzBMW98:::Isabel F. Cruz::Slava Borisov::Michael A. Marks::Timothy R. Webb:::Measuring Structural Similarity Among Web Documents: Preliminary Results.
conf/er/Hohenstein89:::Uwe Hohenstein:::Automatic Transformation of an Entity-Relationship Query Language into SQL.
conf/er/NakanishiHT01:::Yoshihiro Nakanishi::Tatsuo Hirose::Katsumi Tanaka:::Modeling and Structuring Multiple Perspective Video for Browsing.
conf/er/Sciore91:::Edward Sciore:::Abbreviation Techniques in Entity-Relationship Query Languages.
conf/er/Chen79:::Peter P. Chen:::Recent Literature on the Entity-Relationship Approach.


进行处理时,需要开两个客户端。使用的命令分别是:

python mincemeat.py -p pwd localhost
python hw3.py
hw3.py的code为:
import glob
import mincemeat
import operator all_filepaths = glob.glob('hw3data/*') def file_contents(filename):
f = open(filename)
try:
return f.read()
finally:
f.close() datasource = dict((filename,file_contents(filename)) for filename in all_filepaths) def my_mapper(key,value):
from stopwords import allStopWords
import re
for line in value.splitlines():
allThree=line.split(':::')
for author in allThree[1].split('::'):
for word in re.sub(r'([^\s\t0-9a-zA-Z-])+', '',allThree[2]).split():
tmpWord=word.strip().lower()
if len(tmpWord)<=1 or tmpWord in allStopWords:
continue
yield (author,tmpWord),1 def my_reducer(key,value):
result=sum(value)
return result s = mincemeat.Server()
s.datasource = datasource
s.mapfn = my_mapper
s.reducefn = my_reducer results = s.run_server(password="pwd")
print results resList=[(x[0],x[1],results[x]) for x in results.keys()]
sorted_results = sorted(resList, key=operator.itemgetter(0,2)) with open('output.txt','w') as f:
for (a,b,c) in sorted_results:
f.write(a+' *** '+b+' *** '+str(c)+'\n')

输出的结果范例如下:

Stephen L. Bloom *** scalar *** 1
Stephen L. Bloom *** concatenation *** 1
Stephen L. Bloom *** point *** 1
Stephen L. Bloom *** varieties *** 1
Stephen L. Bloom *** observation *** 1
Stephen L. Bloom *** equivalence *** 1
Stephen L. Bloom *** axioms *** 1
Stephen L. Bloom *** languages *** 1
Stephen L. Bloom *** logical *** 1
Stephen L. Bloom *** algebras *** 1
Stephen L. Bloom *** equations *** 1
Stephen L. Bloom *** number *** 1
Stephen L. Bloom *** vector *** 1
Stephen L. Bloom *** polynomial *** 1
Stephen L. Bloom *** solving *** 1
Stephen L. Bloom *** equational *** 1
Stephen L. Bloom *** axiomatizing *** 1
Stephen L. Bloom *** characterization *** 1
Stephen L. Bloom *** regular *** 2
Stephen L. Bloom *** sets *** 2
Stephen L. Bloom *** iteration *** 3
Stephen L. Lieman *** unacceptable *** 1
Stephen L. Lieman *** correcting *** 1
Stephen L. Lieman *** never *** 1
Stephen L. Lieman *** powerful *** 1
Stephen L. Lieman *** accept *** 1

网络智能和大数据公开课Homework3 Map-Reduce编程的更多相关文章

  1. 大文本 通过 hadoop spark map reduce 获取 特征列 的 属性值 计算速度

    大文本 通过 hadoop spark map reduce   获取 特征列  的 属性值  计算速度

  2. 大数据学习(4)MapReduce编程Helloworld:WordCount

    Maven依赖: <dependency> <groupId>jdk.tools</groupId> <artifactId>jdk.tools< ...

  3. 大数据之路week02--day03 Map集合、Collections工具类的用法

    1.Map(掌握) (1)将键映射到值的对象.一个映射不能包含重复的键:每个键最多只能映射到一个值. (2)Map和Collection的区别? A: Map 存储的是键值对形式的元素,键唯一,值可以 ...

  4. 【学习笔记】大数据技术原理与应用(MOOC视频、厦门大学林子雨)

    1 大数据概述 大数据特性:4v volume velocity variety value 即大量化.快速化.多样化.价值密度低 数据量大:大数据摩尔定律 快速化:从数据的生成到消耗,时间窗口小,可 ...

  5. 年度钜献,108个大数据文档PDF开放下载

    1.大数据的开放式创新——吴甘沙 相关阅读:[PPT]吴甘沙:让不同领域的数据真正流动.融合起来,才能释放大数据的价值 下载:大数据的开放式创新——吴甘沙.pdf 2.微软严治庆——让大数据为每个人服 ...

  6. 【Energy Big Data】能源互联网和电力大数据

    背景 今年的政府工作报告突出了互联网在经济结构转型中的重要地位,报告明白指出:要制定"互联网+"行动计划,推动移动互联网.云计算.大数据.物联网等与现代制造业结合,促进电子商务.工 ...

  7. 杂项:大数据 (巨量数据集合(IT行业术语))

    ylbtech-杂项:大数据 (巨量数据集合(IT行业术语)) 大数据(big data),指无法在一定时间范围内用常规软件工具进行捕捉.管理和处理的数据集合,是需要新处理模式才能具有更强的决策力.洞 ...

  8. 大数据框架:Spark vs Hadoop vs Storm

    大数据时代,TB级甚至PB级数据已经超过单机尺度的数据处理,分布式处理系统应运而生. 知识预热 「专治不明觉厉」之“大数据”: 大数据生态圈及其技术栈: 关于大数据的四大特征(4V) 海量的数据规模( ...

  9. Java转大数据开发全套视频资料

    大数据在近两年可算是特别火,有很多人都想去学大数据,有java转大数据的,零基础学习大数据的.但是大数据真的好学吗. 我们先来了解一下什么是大数据. 大数据是指无法在一定时间内用常规软件工具对其内容进 ...

随机推荐

  1. 1247 排排站 USACO(查分+hash)

    /* 暴力查分 n*n */ #include<cstdio> #include<cstring> #include<iostream> #define maxn ...

  2. codevs 1183 泥泞的道路 (二分+SPFA+差分约束)

    /* 二分答案(注意精度) 对于每一个答案 有(s1+s2+s3...)/(t1+t2+t3...)>=ans 时符合条件 这时ans有变大的空间 对于上述不等式如果枚举每一条路显得太暴力 化简 ...

  3. 本文实例汇总了C#中@的用法,对C#程序设计来说有不错的借鉴价值。

    具体如下: 一 字符串中的用法 1.学过C#的人都知道C# 中字符串常量可以以@ 开头声名,这样的优点是转义序列“不”被处理,按“原样”输出,即我们不需要对转义字符加上 \ (反斜扛),就可以轻松co ...

  4. Django runserver show client ip

    get path of basehttp.py $ python >>> import site >>> site.getsitepackages() ['/usr ...

  5. Android界面刷新方法

    Android提供了Invalidate方法实现界面刷新,但是Invalidate不能直接在线程中调用,因为他是违背了单线程模型:Android UI操作并不是线程安全的,并且这些操作必须在UI线程中 ...

  6. C# Wpf异步修改UI,多线程修改UI(二)

    1.使用定时器异步修改 这是相对比较简单的方法 在Wpf中定时器使用DiapatcherTimer,不使用Timer原因: 在一个应用程序中,Timer会重复生成time事件,而DispatcherT ...

  7. List、Set、Map的使用

    1.List(接口) List接口的特点: a.List接口可以存放任意数据,且在接口中,数据可以重复. b.List中提供了高效的插入和移除多个元素的方法. List常用的子类 a.ArrayLis ...

  8. PHP 数据库 ODBC

    PHP 数据库 ODBC ODBC 是一种应用程序编程接口(Application Programming Interface,API),使我们有能力连接到某个数据源(比如一个 MS Access 数 ...

  9. ActiveX相关

    ActiveX 1.创建ActiveXhttp://blog.csdn.net/fww330666557/article/details/6533118 继承IObjectSafety接口http:/ ...

  10. Spring事务管理中@Transactional的参数配置

    Spring作为低侵入的Java EE框架之一,能够很好地与其他框架进行整合,其中Spring与Hibernate的整合实现的事务管理是常用的一种功能. 所谓事务,就必须具备ACID特性,即原子性.一 ...