微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

Spark Streaming,无法访问流数据

如何解决Spark Streaming,无法访问流数据

我正在尝试使用 Spark 运行 Twitter 流。我正在关注本教程: https://github.com/jleetutorial/python-spark-streaming/blob/master/1_start/First%20Twitter%20App.ipynb

socket 文件也运行良好,推文在 TweetRead.py 中加载得很好,正如教程中所说,但最终的条形图没有加载到我的笔记本中。这是一个非常常见的错误,还没有找到修复方法。通常的错误是找不到表“tweets”。

然而,我只是想阅读正在加载的推文,但即使这样也不能很好地执行。有人能告诉我这段代码有什么问题吗?

import re

def remove_URL(text):
    url = re.compile(r"https?://\S+|www\.\S+")
    return url.sub(r"",text)

def remove_html(text):
    html = re.compile(r"<.*?>")
    return html.sub(r"",text)

def remove_emoji(string):
    emoji_pattern = re.compile(
        "["
        u"\U0001F600-\U0001F64F"  # emoticons
        u"\U0001F300-\U0001F5FF"  # symbols & pictographs
        u"\U0001F680-\U0001F6FF"  # transport & map symbols
        u"\U0001F1E0-\U0001F1FF"  # flags (iOS)
        u"\U00002702-\U000027B0"
        u"\U000024C2-\U0001F251"
        "]+",flags=re.UNICODE,)
    return emoji_pattern.sub(r"",string)

import string

def remove_punct(text):
    table = str.maketrans("","",string.punctuation)
    return text.translate(table)

from nltk.corpus import stopwords

stop = set(stopwords.words("english"))

def remove_stopwords(text):
    text = [word.lower() for word in text.split() if word.lower() not in stop]

    return " ".join(text)

# Formatting the loading of tweets
# Use Parenthesis for multiple lines or use \.
( lines.map( lambda text: text.trim())
 .map(lambda x: remove_URL(x))
 .map(lambda x: remove_html(x))
 .map(lambda x: remove_emoji(x))
 .map(lambda x: remove_punct(x))
 .map(lambda x: print(x))
 .pprint() )

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。