List of usage examples for twitter4j Status getHashtagEntities
HashtagEntity[] getHashtagEntities();
From source file:uk.co.flax.ukmp.twitter.TweetUpdateThread.java
License:Apache License
private Tweet buildTweetFromStatus(Status status) { String text = status.getText(); Tweet tweet = new Tweet(); tweet.setId("" + status.getId()); tweet.setText(text);// w ww .ja va 2 s. c o m tweet.setUserScreenName(status.getUser().getScreenName()); tweet.setUserName(status.getUser().getName()); tweet.setCreated(status.getCreatedAt()); if (status.getPlace() != null) { tweet.setPlaceName(status.getPlace().getFullName()); tweet.setCountry(status.getPlace().getCountry()); } tweet.setRetweetCount(status.getRetweetCount()); tweet.setFavouriteCount(status.getFavoriteCount()); tweet.setParty(partyListIds.get(status.getUser().getId())); if (status.getUserMentionEntities() != null) { List<String> screenNames = new ArrayList<>(status.getUserMentionEntities().length); List<String> fullNames = new ArrayList<>(status.getUserMentionEntities().length); for (UserMentionEntity ent : status.getUserMentionEntities()) { screenNames.add(ent.getScreenName()); if (StringUtils.isNotBlank(ent.getName())) { fullNames.add(ent.getName()); } } tweet.setMentionScreenNames(screenNames); tweet.setMentionFullNames(fullNames); } if (status.getHashtagEntities().length > 0) { List<String> hashtags = new ArrayList<>(status.getHashtagEntities().length); for (HashtagEntity ht : status.getHashtagEntities()) { hashtags.add(ht.getText()); } tweet.setHashtags(hashtags); } // Call the entity extraction service Map<String, List<String>> entities = entityExtraction.getEntities(text); if (entities != null && !entities.isEmpty()) { Map<String, Object> tweetEntities = new HashMap<String, Object>(); entities.keySet().forEach(type -> tweetEntities.put(type, entities.get(type))); tweet.setEntities(tweetEntities); } return tweet; }