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


Java Tweet类代码示例

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


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

示例1: processTweet

import org.springframework.social.twitter.api.Tweet; //导入依赖的package包/类
private void processTweet(Tweet tweet) {
        String lang = tweet.getLanguageCode();
        //String text = tweet.getText();
        // filter non-English tweets:
        if (!"en".equals(lang)) {
            return;
        }

        //Set<String> hashTags = hashTagsFromTweet(text);

        // filter tweets without hashtags:
//        if (hashTags.isEmpty()) {
//            return;
//        }

        log.info("\n Tweet: " + tweet.getText() + "\n");

        dataService.saveTweet(tweet);

    }
 
开发者ID:thinksky-sourcecode,项目名称:microservices-prototype,代码行数:21,代码来源:TweetProcessor.java

示例2: news

import org.springframework.social.twitter.api.Tweet; //导入依赖的package包/类
@GET
@Produces(MediaType.APPLICATION_JSON)
@Path("/news")
public Map<Tweet, String> news() throws InvalidInputException {
    List<Trend> someTrends = trendSearch.getTrends(1);

    Map<Tweet, String> allClassification = new HashMap<>();

    for (Trend iterator : someTrends) {
        List<Tweet> tweets = twitterScrape.scrape(iterator.getName());

        for (Tweet iteratorTweet : tweets) {
            if (iteratorTweet.getLanguageCode().equals("en") == true) {
                String classification = new Request().classify(iteratorTweet);

                allClassification.put(iteratorTweet, classification);
            }
        }
    }
    return allClassification;
}
 
开发者ID:cipriancus,项目名称:FakeTwitterDetection,代码行数:22,代码来源:RestApi.java

示例3: tweets

import org.springframework.social.twitter.api.Tweet; //导入依赖的package包/类
@Bean
CommandLineRunner tweets(Logger logger, TwitterTemplate twitterTemplate, JdbcTemplate jdbcTemplate) {
    return args -> {
        String screenName = "hintjens";
        int pageSize = 200;
        List<Tweet> userTimeline = twitterTemplate.timelineOperations()
                .getUserTimeline(screenName, pageSize);
        long maxId;
        while (userTimeline.size() != 0 ) {
            maxId = userTimeline.stream()
                    .map(Tweet::getId)
                    .reduce((tweet, tweet2) -> tweet < tweet2 ? tweet : tweet2)
                    .orElse(0L);
            userTimeline = twitterTemplate.timelineOperations()
                    .getUserTimeline(screenName, pageSize, 0L, maxId - 1);
            addAllTweets(jdbcTemplate, userTimeline);
            logger.info("added " + userTimeline.size() + " records.");
        }
    };
}
 
开发者ID:joshlong,项目名称:hintjens-tweets,代码行数:21,代码来源:HintjensApplication.java

示例4: save

import org.springframework.social.twitter.api.Tweet; //导入依赖的package包/类
private TweetEntity save(final Tweet tweetEntity, final UserEntity user) {
	TweetEntity tweet = new TweetEntity();
	tweet.setCreatedAt(tweetEntity.getCreatedAt());
	tweet.setLanguageCode(tweetEntity.getLanguageCode());
	tweet.setSource(tweetEntity.getSource());
	tweet.setText(tweetEntity.getText());
	tweet.setUser(user);

	if (tweetRepository != null) {
		tweet = tweetRepository.save(tweet);
		System.out.println(tweetEntity.getText());
		return tweet;
	}

	return null;
}
 
开发者ID:ivanvs,项目名称:elasticsearch-spring-demo,代码行数:17,代码来源:TweetService.java

示例5: searchTwitter

import org.springframework.social.twitter.api.Tweet; //导入依赖的package包/类
@GetMapping(path = "tweet")
public String searchTwitter(Model model, @RequestParam String search) {
	
	int count = 200;
	
    SearchResults results = twitterTemplate.searchOperations().search(
    	    new SearchParameters(search)
    	        .resultType(SearchParameters.ResultType.RECENT)
    	        .count(count));
    
    List<Tweet> tweets = results.getTweets();        
    model.addAttribute("tweets", tweets);
    model.addAttribute("count", count);
    model.addAttribute("search", search);
    
    return "search";
}
 
开发者ID:RawSanj,项目名称:spring-twitter-stream,代码行数:18,代码来源:SearchController.java

示例6: storeUserTimelinePiece

import org.springframework.social.twitter.api.Tweet; //导入依赖的package包/类
@Transactional
public TimelineMusic storeUserTimelinePiece(User user) {
    if (user == null) {
        return null;
    }

    SocialAuthentication auth = userDao.getTwitterAuthentication(user);

    if (auth == null) {
        return null;
    }

    Twitter twitter = provider.getApi(auth.getToken(), auth.getSecret());
    List<Tweet> tweets = twitter.timelineOperations().getUserTimeline(200);

    TimelineMusic meta = getUserTimelinePiece(tweets);
    meta.setTwitterHandle(twitter.userOperations().getScreenName());
    meta.setUser(user);

    meta = pieceDao.persist(meta);
    return meta;
}
 
开发者ID:Glamdring,项目名称:computoser,代码行数:23,代码来源:TimelineToMusicService.java

示例7: getTempo

import org.springframework.social.twitter.api.Tweet; //导入依赖的package包/类
/**
 * Gets the tempo, depending on the rate of tweeting
 *
 * @param tweets
 * @return tempo
 */
private Tempo getTempo(List<Tweet> tweets, TimelineMusic meta) {
    long totalSpacingInMillis = 0;
    Tweet previousTweet = null;
    for (Tweet tweet : tweets) {
       if (previousTweet != null) {
           totalSpacingInMillis += Math.abs(previousTweet.getCreatedAt().getTime() - tweet.getCreatedAt().getTime());
       }
       previousTweet = tweet;
    }

    double averageSpacing = totalSpacingInMillis / (tweets.size() - 1);
    meta.setAverageSpacing(averageSpacing);

    if (averageSpacing > 3 * DateTimeConstants.MILLIS_PER_DAY) { //once every three days
        return Tempo.VERY_SLOW;
    } else if (averageSpacing > 1.5 * DateTimeConstants.MILLIS_PER_DAY) { // more than once every 1.5 days
        return Tempo.SLOW;
    } else if (averageSpacing > 16 * DateTimeConstants.MILLIS_PER_HOUR) { // more than once every 16 hours
        return Tempo.MEDIUM;
    } else if (averageSpacing > 4 * DateTimeConstants.MILLIS_PER_HOUR) { // more than once every 4 hours
        return Tempo.FAST;
    } else {
        return Tempo.VERY_FAST;
    }
}
 
开发者ID:Glamdring,项目名称:computoser,代码行数:32,代码来源:TimelineToMusicService.java

示例8: getScale

import org.springframework.social.twitter.api.Tweet; //导入依赖的package包/类
/**
 * Sentiment determines major or minor scale (or lydian/dorian ~= neutral)
 * Average length of tweets determines pentatonic or heptatonic
 *
 * @param tweets
 * @return scale
 */
private Scale getScale(List<Tweet> tweets, TimelineMusic meta) {
    Set<String> documents = new HashSet<>();
    for (Tweet tweet : tweets) {
        documents.add(tweet.getText());
    }
    SentimentResult sentiment = sentimentAnalyzer.getSentiment(documents, meta);

    double totalLength = 0;
    for (String document : documents) {
        totalLength += document.length();
    }
    double averageLength = totalLength / documents.size();

    meta.setSentiment(sentiment);
    meta.setAverageLength(averageLength);

    if (sentiment == SentimentResult.POSITIVE) {
        return averageLength < 40 ? Scale.MAJOR_PENTATONIC : Scale.MAJOR;
    } else if (sentiment == SentimentResult.NEGATIVE) {
        return averageLength < 40 ? Scale.MINOR_PENTATONIC : Scale.MINOR;
    }
    // choose rarer scales for neutral tweets
    return Chance.test(50) ? Scale.LYDIAN : Scale.DORIAN;
}
 
开发者ID:Glamdring,项目名称:computoser,代码行数:32,代码来源:TimelineToMusicService.java

示例9: run

import org.springframework.social.twitter.api.Tweet; //导入依赖的package包/类
@Override
public void run() {
    while (true) {
        try {
            Tweet tweet = queue.take();
            processTweet(tweet);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
}
 
开发者ID:thinksky-sourcecode,项目名称:microservices-prototype,代码行数:12,代码来源:TweetProcessor.java

示例10: getUserTimeline

import org.springframework.social.twitter.api.Tweet; //导入依赖的package包/类
/**
* 
* @param twitterUser
* @return
*/
public List <Tweet> getUserTimeline(String twitterUser) {
    TimelineOperations timelineOps = twitter.timelineOperations();
    List<Tweet> tweets = timelineOps.getUserTimeline("@" + twitterUser);

    return tweets;
}
 
开发者ID:tspannhw,项目名称:hive,代码行数:12,代码来源:TwitterService.java

示例11: scrape

import org.springframework.social.twitter.api.Tweet; //导入依赖的package包/类
public List<Tweet> scrape(String term) throws InvalidInputException{
    if(term == null || term.length()==0)
        throw new InvalidInputException();

    List<Tweet> tweetList = twitterTemplate.searchOperations().search(term).getTweets();

    tweetList.forEach(tweetEntity -> {
        twitter.entity.Tweet tweet = new twitter.entity.Tweet();
        tweet.setText(tweetEntity.getText());
        tweetService.save(tweet);
    });
    return tweetList;
}
 
开发者ID:cipriancus,项目名称:FakeTwitterDetection,代码行数:14,代码来源:TwitterScrape.java

示例12: classify

import org.springframework.social.twitter.api.Tweet; //导入依赖的package包/类
public String classify(Tweet tweet) {
    MultiValueMap<String, String> allArguments= new LinkedMultiValueMap<>();

    allArguments.add("Date", tweet.getCreatedAt().toString());
    allArguments.add("Tweet_Text", tweet.getText());
    allArguments.add("Tweet_Id", tweet.getIdStr());
    allArguments.add("User_Id", Long.toString(tweet.getFromUserId()));
    allArguments.add("User_Name", tweet.getUser().getName());
    allArguments.add("User_Screen_Name", tweet.getUser().getScreenName());
    allArguments.add("Retweets", Integer.toString(tweet.getRetweetCount()));
    allArguments.add("Favorites", Integer.toString(tweet.getFavoriteCount()));

    HttpHeaders headers = new HttpHeaders();
    headers.setContentType(MediaType.APPLICATION_FORM_URLENCODED);

    HttpEntity<MultiValueMap<String, String>> request = new HttpEntity<MultiValueMap<String, String>>(allArguments, headers);

    ResponseEntity<String> response = restTemplate.postForEntity( requestURL, request , String.class );

    return response.getBody();
}
 
开发者ID:cipriancus,项目名称:FakeTwitterDetection,代码行数:22,代码来源:Request.java

示例13: search

import org.springframework.social.twitter.api.Tweet; //导入依赖的package包/类
@GET
@Produces(MediaType.APPLICATION_JSON)
@Path("/tweets/{tweetTerm}")
public List<Tweet> search(@PathParam("tweetTerm") String tweetTerm) {
    List<Tweet> tweetList = null;
    try {
        tweetList = twitterScrape.scrape(tweetTerm);
    } catch (InvalidInputException e) {
        e.printStackTrace();
    }
    return tweetList;
}
 
开发者ID:cipriancus,项目名称:FakeTwitterDetection,代码行数:13,代码来源:RestApi.java

示例14: trendSearchAndScrapeWithSentiment_tweetIsNull_ShouldThrowException

import org.springframework.social.twitter.api.Tweet; //导入依赖的package包/类
@Test(expected = InvalidInputException.class)
public final void trendSearchAndScrapeWithSentiment_tweetIsNull_ShouldThrowException() throws InvalidInputException {
    List<Trend> trends = trendSearch.getTrends(WORLD_WOEID).subList(0, 10);
    assertNotNull(trends);
    for (Trend trend : trends) {
        List<Tweet> tweets = twitterScrape.scrape(trend.getName()).subList(0, 10);
        assertNotNull(tweets);

        for (Tweet tweet : tweets) {
            int sentiment = sentimentAnalysis.calculateSentiment(null);
        }

    }
}
 
开发者ID:cipriancus,项目名称:FakeTwitterDetection,代码行数:15,代码来源:TrendScrapeSentimentIntegrationTest.java

示例15: trendSearchAndScrape

import org.springframework.social.twitter.api.Tweet; //导入依赖的package包/类
@Test
public final void trendSearchAndScrape() throws InvalidInputException {
    List<Trend> trends = trendSearch.getTrends(WORLD_WOEID).subList(0, 5);//get some trends
    assertNotNull(trends);
    for (Trend trend : trends) {
        List<Tweet> tweets = twitterScrape.scrape(trend.getName()).subList(0, 5);
        assertNotNull(tweets);
    }
}
 
开发者ID:cipriancus,项目名称:FakeTwitterDetection,代码行数:10,代码来源:TrendScrapeIntegrationTest.java


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