当前位置: 首页>>代码示例>>Java>>正文


Java HashTagEntity类代码示例

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


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

示例1: importer

import org.springframework.social.twitter.api.HashTagEntity; //导入依赖的package包/类
@Bean
CommandLineRunner importer(UserRepository userRepository,
                           TweetRepository tweetRepository,
                           TagRepository tagRepository,
                           Neo4jTemplate neo4jTemplate,
                           TwitterTemplate twitterTemplate) {
    return args -> {

        // reset db
        neo4jTemplate.query("MATCH (n) OPTIONAL MATCH (n)-[r]-() DELETE n,r", null);

        // search for tweets matching query ('@SpringBoot')
        SearchResults results = twitterTemplate.searchOperations().search("@SpringBoot", 200);

        results.getTweets().stream().map(source -> {

            User user = userRepository.save(new User(source.getUser()));

            Tweet tweet = new Tweet(source.getId(), user, source.getText());

            source.getEntities().getMentions().forEach((MentionEntity m) -> tweet.addMention(
                    userRepository.save(new User(m.getId(), m.getName(), m.getScreenName()))));

            source.getEntities().getHashTags().forEach((HashTagEntity t) -> tweet.addTag(tagRepository.save(new Tag(t.getText()))));

            return tweetRepository.save(tweet);

        }).forEach(System.out::println);

        userRepository.suggestFriends("starbuxman").forEach(System.out::println);
    };
}
 
开发者ID:joshlong,项目名称:graphconnect-2014,代码行数:33,代码来源:Application.java

示例2: addAllTweets

import org.springframework.social.twitter.api.HashTagEntity; //导入依赖的package包/类
private void addAllTweets(JdbcTemplate template, List<Tweet> tweets) {
    List<Object[]> list = tweets.stream().map(tweet -> new Object[]{tweet.getText(),
            tweet.getFromUser(),
            tweet.getCreatedAt(),
            tweet.getId(),
            tweet.getProfileImageUrl(),
            tweet.getIdStr(),
            tweet.getLanguageCode(),
            tweet.getUser().getName(),
            tweet.getInReplyToStatusId(),
            tweet.getInReplyToUserId(),
            tweet.getInReplyToScreenName(),
            tweet.getToUserId(),
            tweet.getEntities().getHashTags()
                    .stream()
                    .map(HashTagEntity::getText)
                    .collect(Collectors.joining(" ")),
            tweet.getRetweetCount(),
            tweet.getRetweetedStatus() != null ? tweet.getRetweetedStatus().getId() : null,
            tweet.getUnmodifiedText(),
            tweet.getSource()})
            .collect(Collectors.toList());

    template.batchUpdate("insert into tweets(" +
            "text, " +
            "from_user, " +
            "created_at, " +
            "tweet_id, " +
            "profile_image_url," +
            "id_string," +
            "language_code, " +
            "username," +
            "in_reply_to_status_id , " +
            "in_reply_to_user_id," +
            "in_reply_to_screename," +
            "to_user_id," +
            "hashtags," +
            "retweeted_count," +
            "retweeted_status_id," +
            "unmodified_text," +
            "source" +
            ") values ( ?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)", list);
}
 
开发者ID:joshlong,项目名称:hintjens-tweets,代码行数:44,代码来源:HintjensApplication.java

示例3: streamTweetEvent

import org.springframework.social.twitter.api.HashTagEntity; //导入依赖的package包/类
public void streamTweetEvent(List<SseEmitter> emitters) throws InterruptedException{

    	List<StreamListener> listeners = new ArrayList<StreamListener>();
    	
    	StreamListener streamListener = new StreamListener() {
			@Override
			public void onWarning(StreamWarningEvent warningEvent) {
			}

			@Override
			public void onTweet(Tweet tweet) {
				//log.info("User '{}', Tweeted : {}, from ; {}", tweet.getUser().getName() , tweet.getText(), tweet.getUser().getLocation());
				Integer connectedUsers =  emitters.size();
				
				//log.info("Streaming to :" + connectedUsers +" connected Users");
				
				if (connectedUsers!=0) {
					for (SseEmitter emiter : emitters) {
						try {
							emiter.send(SseEmitter.event().name("streamLocation").data(tweet.getUser().getLocation()));
							
							StringBuilder hashTag = new StringBuilder();
							
							List<HashTagEntity> hashTags = tweet.getEntities().getHashTags();
							for (HashTagEntity hash : hashTags) {
								hashTag.append("#"+hash.getText() + " ");
							}
							//System.out.println(hashTag);
							emiter.send(SseEmitter.event().name("streamHashtags").data(hashTag));
						} catch (IOException e) {
							System.out.println("User Disconnected from the Stream");
							//e.printStackTrace();
						}
					}
				}else{
					//Close Stream when all Users are disconnected.
					userStream.close();
					log.info("Zero Connected Users - Closing Stream");
				}
				
			}

			@Override
			public void onLimit(int numberOfLimitedTweets) {
			}

			@Override
			public void onDelete(StreamDeleteEvent deleteEvent) {
			}
		};
		//Start Stream when a User is connected
		if (emitters.size()==1) {
			listeners.add(streamListener);
			userStream = twitter.streamingOperations().sample(listeners);
		}
		
//		Stream from a specific Location:
//		Float west=-122.75f;
//		Float south=36.8f;
//		Float east=-121.75f;
//		Float north = 37.8f;
//
//		FilterStreamParameters filterStreamParameters = new FilterStreamParameters();
//		filterStreamParameters.addLocation(west, south, east, north);
		//Stream userStream = twitter.streamingOperations().filter(filterStreamParameters, listeners);
	
	}
 
开发者ID:RawSanj,项目名称:spring-twitter-stream,代码行数:68,代码来源:StreamTweetEventService.java


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