List of usage examples for twitter4j Place getGeometryCoordinates
GeoLocation[][] getGeometryCoordinates();
From source file:br.com.porcelli.hornetq.integration.twitter.support.TweetMessageConverterSupport.java
License:Apache License
public static ServerMessage buildMessage(final String queueName, final Status status) { final ServerMessage msg = new ServerMessageImpl(status.getId(), InternalTwitterConstants.INITIAL_MESSAGE_BUFFER_SIZE); msg.setAddress(new SimpleString(queueName)); msg.setDurable(true);// www . j av a2s . com msg.putStringProperty(TwitterConstants.KEY_MSG_TYPE, MessageType.TWEET.toString()); msg.putStringProperty(TwitterConstants.KEY_CREATED_AT, read(status.getCreatedAt())); msg.putStringProperty(TwitterConstants.KEY_ID, read(status.getId())); msg.putStringProperty(TwitterConstants.KEY_TEXT, read(status.getText())); msg.putStringProperty(TwitterConstants.KEY_SOURCE, read(status.getSource())); msg.putStringProperty(TwitterConstants.KEY_TRUNCATED, read(status.isTruncated())); msg.putStringProperty(TwitterConstants.KEY_IN_REPLY_TO_STATUS_ID, read(status.getInReplyToStatusId())); msg.putStringProperty(TwitterConstants.KEY_IN_REPLY_TO_USER_ID, read(status.getInReplyToUserId())); msg.putStringProperty(TwitterConstants.KEY_IN_REPLY_TO_SCREEN_NAME, read(status.getInReplyToScreenName())); msg.putStringProperty(TwitterConstants.KEY_RETWEET, read(status.isRetweet())); msg.putStringProperty(TwitterConstants.KEY_FAVORITED, read(status.isFavorited())); msg.putStringProperty(TwitterConstants.KEY_ENTITIES_URLS_JSON, read(status.getURLEntities())); msg.putStringProperty(TwitterConstants.KEY_ENTITIES_HASHTAGS_JSON, read(status.getHashtagEntities())); msg.putStringProperty(TwitterConstants.KEY_ENTITIES_MENTIONS_JSON, read(status.getUserMentionEntities())); msg.putStringProperty(TwitterConstants.KEY_CONTRIBUTORS_JSON, read(status.getContributors())); if (status.getUser() != null) { buildUserData("", status.getUser(), msg); } GeoLocation gl; if ((gl = status.getGeoLocation()) != null) { msg.putStringProperty(TwitterConstants.KEY_GEO_LATITUDE, read(gl.getLatitude())); msg.putStringProperty(TwitterConstants.KEY_GEO_LONGITUDE, read(gl.getLongitude())); } Place place; if ((place = status.getPlace()) != null) { msg.putStringProperty(TwitterConstants.KEY_PLACE_ID, read(place.getId())); msg.putStringProperty(TwitterConstants.KEY_PLACE_URL, read(place.getURL())); msg.putStringProperty(TwitterConstants.KEY_PLACE_NAME, read(place.getName())); msg.putStringProperty(TwitterConstants.KEY_PLACE_FULL_NAME, read(place.getFullName())); msg.putStringProperty(TwitterConstants.KEY_PLACE_COUNTRY_CODE, read(place.getCountryCode())); msg.putStringProperty(TwitterConstants.KEY_PLACE_COUNTRY, read(place.getCountry())); msg.putStringProperty(TwitterConstants.KEY_PLACE_STREET_ADDRESS, read(place.getStreetAddress())); msg.putStringProperty(TwitterConstants.KEY_PLACE_TYPE, read(place.getPlaceType())); msg.putStringProperty(TwitterConstants.KEY_PLACE_GEO_TYPE, read(place.getGeometryType())); msg.putStringProperty(TwitterConstants.KEY_PLACE_BOUNDING_BOX_TYPE, read(place.getBoundingBoxType())); msg.putStringProperty(TwitterConstants.KEY_PLACE_BOUNDING_BOX_COORDINATES_JSON, read(place.getBoundingBoxCoordinates().toString())); msg.putStringProperty(TwitterConstants.KEY_PLACE_BOUNDING_BOX_GEOMETRY_COORDINATES_JSON, read(place.getGeometryCoordinates().toString())); } msg.putStringProperty(TwitterConstants.KEY_RAW_JSON, status.toString()); return msg; }
From source file:edu.cmu.cs.lti.discoursedb.io.twitter.converter.TwitterConverterService.java
License:Open Source License
/** * Maps a Tweet represented as a Twitter4J Status object to DiscourseDB * /*w w w . j a v a 2 s .co m*/ * @param discourseName the name of the discourse * @param datasetName the dataset identifier * @param tweet the Tweet to store in DiscourseDB */ public void mapTweet(String discourseName, String datasetName, Status tweet, PemsStationMetaData pemsMetaData) { if (tweet == null) { return; } Assert.hasText(discourseName, "The discourse name has to be specified and cannot be empty."); Assert.hasText(datasetName, "The dataset name has to be specified and cannot be empty."); if (dataSourceService.dataSourceExists(String.valueOf(tweet.getId()), TweetSourceMapping.ID_TO_CONTRIBUTION, datasetName)) { log.trace("Tweet with id " + tweet.getId() + " already exists in database. Skipping"); return; } log.trace("Mapping Tweet " + tweet.getId()); Discourse discourse = discourseService.createOrGetDiscourse(discourseName); twitter4j.User tUser = tweet.getUser(); User user = null; if (!userService.findUserByDiscourseAndUsername(discourse, tUser.getScreenName()).isPresent()) { user = userService.createOrGetUser(discourse, tUser.getScreenName()); user.setRealname(tUser.getName()); user.setEmail(tUser.getEmail()); user.setLocation(tUser.getLocation()); user.setLanguage(tUser.getLang()); user.setStartTime(tweet.getUser().getCreatedAt()); AnnotationInstance userInfo = annoService.createTypedAnnotation("twitter_user_info"); annoService.addFeature(userInfo, annoService.createTypedFeature(String.valueOf(tUser.getFavouritesCount()), "favorites_count")); annoService.addFeature(userInfo, annoService.createTypedFeature(String.valueOf(tUser.getFollowersCount()), "followers_count")); annoService.addFeature(userInfo, annoService.createTypedFeature(String.valueOf(tUser.getFriendsCount()), "friends_count")); annoService.addFeature(userInfo, annoService.createTypedFeature(String.valueOf(tUser.getStatusesCount()), "statuses_count")); annoService.addFeature(userInfo, annoService.createTypedFeature(String.valueOf(tUser.getListedCount()), "listed_count")); if (tUser.getDescription() != null) { annoService.addFeature(userInfo, annoService.createTypedFeature(String.valueOf(tUser.getDescription()), "description")); } annoService.addAnnotation(user, userInfo); } Contribution curContrib = contributionService.createTypedContribution(ContributionTypes.TWEET); DataSourceInstance contribSource = dataSourceService.createIfNotExists(new DataSourceInstance( String.valueOf(tweet.getId()), TweetSourceMapping.ID_TO_CONTRIBUTION, datasetName)); curContrib.setStartTime(tweet.getCreatedAt()); dataSourceService.addSource(curContrib, contribSource); AnnotationInstance tweetInfo = annoService.createTypedAnnotation("twitter_tweet_info"); if (tweet.getSource() != null) { annoService.addFeature(tweetInfo, annoService.createTypedFeature(tweet.getSource(), "tweet_source")); } annoService.addFeature(tweetInfo, annoService.createTypedFeature(String.valueOf(tweet.getFavoriteCount()), "favorites_count")); if (tweet.getHashtagEntities() != null) { for (HashtagEntity hashtag : tweet.getHashtagEntities()) { annoService.addFeature(tweetInfo, annoService.createTypedFeature(hashtag.getText(), "hashtag")); } } if (tweet.getMediaEntities() != null) { for (MediaEntity media : tweet.getMediaEntities()) { //NOTE: additional info is available for MediaEntities annoService.addFeature(tweetInfo, annoService.createTypedFeature(media.getMediaURL(), "media_url")); } } //TODO this should be represented as a relation if the related tweet is part of the dataset if (tweet.getInReplyToStatusId() > 0) { annoService.addFeature(tweetInfo, annoService .createTypedFeature(String.valueOf(tweet.getInReplyToStatusId()), "in_reply_to_status_id")); } //TODO this should be represented as a relation if the related tweet is part of the dataset if (tweet.getInReplyToScreenName() != null) { annoService.addFeature(tweetInfo, annoService.createTypedFeature(tweet.getInReplyToScreenName(), "in_reply_to_screen_name")); } annoService.addAnnotation(curContrib, tweetInfo); GeoLocation geo = tweet.getGeoLocation(); if (geo != null) { AnnotationInstance coord = annoService.createTypedAnnotation("twitter_tweet_geo_location"); annoService.addFeature(coord, annoService.createTypedFeature(String.valueOf(geo.getLongitude()), "long")); annoService.addFeature(coord, annoService.createTypedFeature(String.valueOf(geo.getLatitude()), "lat")); annoService.addAnnotation(curContrib, coord); } Place place = tweet.getPlace(); if (place != null) { AnnotationInstance placeAnno = annoService.createTypedAnnotation("twitter_tweet_place"); annoService.addFeature(placeAnno, annoService.createTypedFeature(String.valueOf(place.getPlaceType()), "place_type")); if (place.getGeometryType() != null) { annoService.addFeature(placeAnno, annoService.createTypedFeature(String.valueOf(place.getGeometryType()), "geo_type")); } annoService.addFeature(placeAnno, annoService .createTypedFeature(String.valueOf(place.getBoundingBoxType()), "bounding_box_type")); annoService.addFeature(placeAnno, annoService.createTypedFeature(String.valueOf(place.getFullName()), "place_name")); if (place.getStreetAddress() != null) { annoService.addFeature(placeAnno, annoService.createTypedFeature(String.valueOf(place.getStreetAddress()), "street_address")); } annoService.addFeature(placeAnno, annoService.createTypedFeature(String.valueOf(place.getCountry()), "country")); if (place.getBoundingBoxCoordinates() != null) { annoService.addFeature(placeAnno, annoService.createTypedFeature( convertGeoLocationArray(place.getBoundingBoxCoordinates()), "bounding_box_lat_lon_array")); } if (place.getGeometryCoordinates() != null) { annoService.addFeature(placeAnno, annoService.createTypedFeature( convertGeoLocationArray(place.getGeometryCoordinates()), "geometry_lat_lon_array")); } annoService.addAnnotation(curContrib, placeAnno); } Content curContent = contentService.createContent(); curContent.setText(tweet.getText()); curContent.setAuthor(user); curContent.setStartTime(tweet.getCreatedAt()); curContrib.setCurrentRevision(curContent); curContrib.setFirstRevision(curContent); DataSourceInstance contentSource = dataSourceService.createIfNotExists(new DataSourceInstance( String.valueOf(tweet.getId()), TweetSourceMapping.ID_TO_CONTENT, datasetName)); dataSourceService.addSource(curContent, contentSource); if (pemsMetaData != null) { log.warn("PEMS station meta data mapping not implemented yet"); //TODO map pems meta data if available } }