• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Java TwitterUtils类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中org.apache.spark.streaming.twitter.TwitterUtils的典型用法代码示例。如果您正苦于以下问题:Java TwitterUtils类的具体用法?Java TwitterUtils怎么用?Java TwitterUtils使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



TwitterUtils类属于org.apache.spark.streaming.twitter包,在下文中一共展示了TwitterUtils类的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: run

import org.apache.spark.streaming.twitter.TwitterUtils; //导入依赖的package包/类
private void run(CompositeConfiguration conf) {
    // Spark conf
    SparkConf sparkConf = new SparkConf().setAppName("TwitterSparkCrawler").setMaster(conf.getString("spark.master"))
            .set("spark.serializer", conf.getString("spark.serializer"));
    JavaStreamingContext jssc = new JavaStreamingContext(sparkConf, Durations.seconds(conf.getLong("stream.duration")));

    // Twitter4J
    // IMPORTANT: put keys in twitter4J.properties
    Configuration twitterConf = ConfigurationContext.getInstance();
    Authorization twitterAuth = AuthorizationFactory.getInstance(twitterConf);

    // Create twitter stream
    String[] filters = { "#Car" };
    TwitterUtils.createStream(jssc, twitterAuth, filters).print();
    // Start the computation
    jssc.start();
    jssc.awaitTermination();
}
 
开发者ID:ogidogi,项目名称:laughing-octo-sansa,代码行数:19,代码来源:TwitterSparkCrawler.java


示例2: getTwitterStream

import org.apache.spark.streaming.twitter.TwitterUtils; //导入依赖的package包/类
protected static JavaReceiverInputDStream<Status> getTwitterStream(JavaStreamingContext spark, String consumerKey, String consumerSecret,
		String accessToken, String accessTokenSecret) {
	// Enable Oauth
	ConfigurationBuilder cb = new ConfigurationBuilder();
	cb.setDebugEnabled(true)
	  .setOAuthConsumerKey(consumerKey).setOAuthConsumerSecret(consumerSecret)
	  .setOAuthAccessToken(accessToken).setOAuthAccessTokenSecret(accessTokenSecret);
	TwitterFactory tf = new TwitterFactory(cb.build());
	Twitter twitter = tf.getInstance();
	
	// Create stream
	return TwitterUtils.createStream(spark, twitter.getAuthorization());
}
 
开发者ID:DaniUPC,项目名称:near-image-replica-detection,代码行数:14,代码来源:StreamingReplicaDetector.java


示例3: main

import org.apache.spark.streaming.twitter.TwitterUtils; //导入依赖的package包/类
public static void main(String[] args)
{
    BasicConfigurator.configure();
    SparkConf conf = new SparkConf().setAppName("Twitter Sentiment Analysis");

    if (args.length > 0)
        conf.setMaster(args[0]);
    else
        conf.setMaster("local[2]");

    JavaStreamingContext ssc = new JavaStreamingContext(conf, new Duration(2000));

    /*Map<String, Integer> topicMap = new HashMap<String, Integer>();
    topicMap.put(KAFKA_TOPIC, KAFKA_PARALLELIZATION);

    JavaPairReceiverInputDStream<String, String> messages =
        KafkaUtils.createStream(
            ssc,
            Properties.getString("rts.spark.zkhosts"),
            "twitter.sentimentanalysis.kafka",
            topicMap);

    JavaDStream<String> json = messages.map(
        new Function<Tuple2<String, String>, String>() {
            private static final long serialVersionUID = 42l;
            public String call(Tuple2<String, String> message) {
                return message._2();
            }
        }
    );*/


    JavaPairDStream<Long, String> tweets = TwitterUtils.createStream(ssc).mapToPair(
            new TwitterFilterFunction());

    JavaPairDStream<Long, String> filtered = tweets.filter(
            tweet -> tweet != null
    );

    JavaDStream<Tuple2<Long, String>> tweetsFiltered = filtered.map(
        new TextFilterFunction());

    tweetsFiltered = tweetsFiltered.map(
        new StemmingFunction());

    JavaPairDStream<Tuple2<Long, String>, Float> positiveTweets =
        tweetsFiltered.mapToPair(new PositiveScoreFunction());

    JavaPairDStream<Tuple2<Long, String>, Float> negativeTweets =
        tweetsFiltered.mapToPair(new NegativeScoreFunction());

    JavaPairDStream<Tuple2<Long, String>, Tuple2<Float, Float>> joined =
        positiveTweets.join(negativeTweets);

    JavaDStream<Tuple4<Long, String, Float, Float>> scoredTweets =
        joined.map(tweet -> new Tuple4<Long, String, Float, Float>(
            tweet._1()._1(),
            tweet._1()._2(),
            tweet._2()._1(),
            tweet._2()._2()));

    JavaDStream<Tuple5<Long, String, Float, Float, String>> result =
        scoredTweets.map(new ScoreTweetsFunction());

    //result.print();
    result.dstream().saveAsTextFiles("file:///home/mayconbordin/spark/sentiment", "txt");
    //result.foreachRDD(new FileWriter());
    //result.foreachRDD(new HTTPNotifierFunction());

    ssc.start();
    ssc.awaitTermination();
}
 
开发者ID:mayconbordin,项目名称:erad2016-streamprocessing,代码行数:73,代码来源:SentimentAnalysis.java


示例4: convert

import org.apache.spark.streaming.twitter.TwitterUtils; //导入依赖的package包/类
@Override
public JavaDStream<Tuple> convert(List<JavaDStream<Tuple>> predecessorRdds, POLoad poLoad) throws IOException {
	//        if (predecessors.size()!=0) {
	//            throw new RuntimeException("Should not have predecessors for Load. Got : "+predecessors);
	//        }
	configureLoader(physicalPlan, poLoad, sparkContext.ssc().sc().hadoopConfiguration(),this.pigContext);

	Iterator<PhysicalOperator> top = physicalPlan.iterator();
	boolean isTwitter = false;
	while(top.hasNext()){    		
		String load = top.next().toString();

		if(load.contains("hdfs://")){
			String[] splitted = load.split("hdfs://");       		 
			String url = "hdfs://" + splitted[1];

			if(url.contains("/_twitter")){
				isTwitter = true;        			
			}
			break;

		}

	}

	if(!isTwitter){    	   

		DStream<Tuple2<Text, Tuple>> hadoopRDD= sparkContext.ssc().fileStream(poLoad.getLFile().getFileName(), 
				SparkUtil.getManifest(Text.class), 
				SparkUtil.getManifest(Tuple.class), 
				SparkUtil.getManifest(PigInputFormat.class));

		//hadoopRDD.print();
		/*
		JavaDStream<String> mhadoopRDD = sparkContext.textFileStream(poLoad.getLFile().getFileName());
		
		stringTupleFunction tf = new stringTupleFunction();
		
		JavaDStream<Tuple> lulz = mhadoopRDD.map(tf);
		
		//lulz.print();			
		
		return lulz;
		*/
		
		JavaDStream<Tuple> hdfsTuple = new JavaDStream<Tuple>(hadoopRDD.map(TO_VALUE_FUNCTION,SparkUtil.getManifest(Tuple.class)),SparkUtil.getManifest(Tuple.class));

		hdfsTuple.print();
		
		return hdfsTuple;
		
	}else{

		System.out.println("=====Tweeets-Tweets=======");
		System.setProperty("twitter4j.oauth.consumerKey","mGkece93BmDILkPXXXXX");
		System.setProperty("twitter4j.oauth.consumerSecret","K9RhnuOdZJlxDgxKJXXXXXXXXXXXXXXXXXXXXX");
		System.setProperty("twitter4j.oauth.accessToken","2493987XXXXXXXXXXXXXXXXXXXXXXXXXFPRs0Ho7");
		System.setProperty("twitter4j.oauth.accessTokenSecret","XXXXXXXXXXXXXXXXXXXXikQ0KxfqByVrtzs3jYP");
		//sparkContext.checkpoint("/home/akhld/mobi/temp/pig/twitter/");

		//JavaDStream<Status> dtweets= sparkContext.twitterStream();
		JavaDStream<Status> dtweets = TwitterUtils.createStream(sparkContext);

		System.out.println("=====Tweeets-Tweets=======");

		tweetFunction fnc = new tweetFunction();
		DStream<Tuple> dstatuses = dtweets.dstream().map(fnc,SparkUtil.getManifest(Tuple.class));				

		dstatuses.print();

		JavaDStream<Tuple> tweetTuple = new JavaDStream<Tuple>(dstatuses, SparkUtil.getManifest(Tuple.class));

		return tweetTuple;

	}

}
 
开发者ID:sigmoidanalytics,项目名称:spork-streaming,代码行数:78,代码来源:LoadConverter.java



注:本文中的org.apache.spark.streaming.twitter.TwitterUtils类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java ReceivePackFactory类代码示例发布时间:2022-05-22
下一篇:
Java ExDate类代码示例发布时间:2022-05-22
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap