import sys
reload(sys)
sys.setdefaultencoding('utf-8') from os import path
import jieba
from pyspark import SparkContext
from pyspark.sql import SQLContext
#from operator import add sc = SparkContext("local[1]" , "wordCount")
sc.setLogLevel("ERROR")
sqc = SQLContext(sc) thisDir = path.dirname(__file__) def wordCut(strings):
strings = strings.strip()
returnList = []
for r in jieba.cut(strings):
returnList.append(r)
return returnList fileName = 'words.txt'
file_in = sc.textFile(path.join(thisDir,fileName)) linesNum = file_in.count()
print '[INFO]number of lines in file %s : %d' % (fileName , linesNum) charsNum = file_in.map(lambda x : len(x)).reduce(lambda x,y : x+y)
print '[INFO]number of charts in file %s : %d' % (fileName , charsNum) words = file_in.flatMap(lambda line : wordCut(line))
termBigger3 = words.filter(lambda word : len(word) > 3)
print '[INFO]number of words bigger than 3 in file %s : %d' % (fileName , termBigger3.count()) wordCount = words.map(lambda w : (w,1)).reduceByKey(lambda x,y:x+y)
sqc.createDataFrame(wordCount,['word','count']).sort('count',ascending = False).show(20)

【spark】jieba + wordcount的更多相关文章

  1. 【Spark】部署流程的深度了解

    文章目录 Spark核心组件 Driver Executor Spark通用运行流程图 Standalone模式运行机制 Client模式流程图 Cluster模式流程图 On-Yarn模式运行机制 ...

  2. 【Spark】Spark任务调度相关知识

    文章目录 准备知识 DAG 概述 shuffle 概述 SortShuffleManager 普通机制 bypass机制 Spark任务调度 流程 准备知识 要弄清楚Spark的任务调度流程,就必须要 ...

  3. 【Spark】Sparkstreaming-性能调优

    Sparkstreaming-性能调优 Spark Master at spark://node-01:7077 sparkstreaming 线程 数量_百度搜索 streaming中partiti ...

  4. 【Spark】Sparkstreaming-共享变量-缓存RDD-到底是什么情况?

    Sparkstreaming-共享变量-缓存RDD-到底是什么情况? sparkstreaming 多个 rdd_百度搜索 Spark Streaming中空RDD处理及流处理程序优雅的停止 - xu ...

  5. 【Spark】SparkStreaming-Kafka-Redis-集成-基础参考资料

    SparkStreaming-Kafka-Redis-集成-基础参考资料 Overview - Spark 2.2.0 Documentation Spark Streaming + Kafka In ...

  6. 【Spark】提交Spark任务-ClassNotFoundException-错误处理

    提交Spark任务-ClassNotFoundException-错误处理 Overview - Spark 2.2.0 Documentation Spark Streaming - Spark 2 ...

  7. 【Spark】Spark-Redis连接池

    Spark-Redis连接池 jedispool returnresource 遭废弃 用 什么替代_百度知道 spark-stream 访问 Redis数据库示例 - 阿里云 [Redis]Java ...

  8. 【Spark】SparkStreaming-CPU资源设置的蹊跷

    SparkStreaming-CPU资源设置的蹊跷. Spark streaming network_wordcount.py does not print result - Stack Overfl ...

  9. 【Spark】SparkStreaming-流处理-规则动态更新-解决方案

    SparkStreaming-流处理-规则动态更新-解决方案 image2017-10-27_11-10-53.png (1067×738) elasticsearch-head Elasticsea ...

随机推荐

  1. composer概念学习

    composer的中文文档地址 Composer是什么 Composer 是 PHP 的一个依赖管理工具.它允许你申明项目所依赖的代码库,它会在你的项目中为你安装他们. Composer 不是一个包管 ...

  2. TP v5中Request取值方式变化

    到目前为止的5.0.7版本中,route里相关参数不会再压入$_GET与$_REQUEST变量中,比如 index.php/user/blog/id/123 里我们想用 $_GET['id']是取不到 ...

  3. Java通过ssh连接到Linxu和Windos服务器远程启动Tomcat

    一.Linxu服务器远程启动tomcat 1.首先确保linxu服务器上的tomcat jdk等必要软件正确安装,并且可以正常启动. 2.编写Java SSH工具类. 相关jar包: <depe ...

  4. MacBook如何用Parallels Desktop安装windows7/8

    虽然MacBook真的很好用,不过在天朝的国情下,有很多软件还是仅支持IE和windows系统下才有.所以有必要为自己的MacBook装一个windows版本的系统,之前试过用Boot Camp来建立 ...

  5. an error has occurred while trying to access the log file. logging may not function properly

    I had this issure a couple of days ago  when  open my vs2012 on windows8,by google i find the soluth ...

  6. [算法]从一道题引出variable-precision SWAR算法

    苏君君出了一道题,是牛客网上面的: 输入一个int型整数,输出该数二进制表示中1的个数.其中负数用补码表示. 其实这道题并不难,大家很容易想到的解法是转成字符串的思路,即如下所示: public st ...

  7. python django查询12306火车票

    逢年过节,想坐个高铁票,都得上12306去买票,但用过的都会发现,它会把临近站点的也筛出来了.但有时我们压根就不会考虑买到临近站点的. 另一方面,在购票高峰期,有可能你要的出发站到目的站都没有票了,这 ...

  8. 【html5】html5 本地存储

    最近一直在学习 html5,为了后期的移动项目进行知识储备.html5 相对于 html4 新增加了一些有趣的标签.属性和方法,今天主要介绍下 html5 的本地存储. 在客户端存储数据 html5 ...

  9. ajax 多个参数问题,如何既能表单序列化获取,又能加参数,加全部代码

      $.param({'address':address,'delivity':delivity,'payment':payment}) + '&' + $('#card_form').ser ...

  10. JS不同浏览器图片载入处理

    //不同浏览器图片加载判断 p.loadImgVerify = function(oimg,fn){ //载入发起请求 加入JS单线程队列事件(当状态满足时候执行些事件) if (qp_shared. ...