对两个结果词pyspark

Daniel Chepenko

我正在研究语言模型,并希望计算两个后续单词的数字对。我发现这样的问题的一个例子scala蒙山slicing功能。虽然我没有找到类似的东西pyspark

data.splicing(2).map(lambda (x,y): ((x,y),1).redcueByKey(lambda x,y: x+y)

我想应该是这样的。解决方法可能是一个创建函数,该函数可以找到数组中的下一个单词,但是我想应该有一个内置的解决方案。

用户名

也许这会有所帮助。您可以在此处找到其他拆分方法:是否可以通过Python中的第n个分隔符来拆分字符串?

from itertools import izip

text = "I'm working on language model and want to count the number pairs of two consequent words.\
        I found an examples of such problem on language model and want to count the number pairs"

i = iter(text.split())

rdd = sc.parallelize([" ".join(x) for x in izip(i,i)])

print rdd.map(lambda x: (x, 1)).reduceByKey(lambda x, y: x + y).collect()

[('found an',1),('count the',2),('want to',2),('examples of',1),('model and',2),('on language ',2),('数字对',2),(“我正在工作”,1),('常用词.I',1),('此类问题',1),('两个' ,1)]

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章