List of usage examples for twitter4j Status getUserMentionEntities
UserMentionEntity[] getUserMentionEntities();
From source file:org.nsoft.openbus.model.Mensagem.java
License:Open Source License
private static JSONObject createAddtions(Status s) throws JSONException { JSONObject json = new JSONObject(); Vector<String> metions = new Vector<String>(); UserMentionEntity[] in_metions = s.getUserMentionEntities(); if (in_metions != null) { for (UserMentionEntity metion : in_metions) { metions.add(metion.getName()); }/*from w w w .ja v a 2 s . c om*/ } URLEntity[] urls = s.getURLEntities(); Vector<String> image_files = new Vector<String>(); MediaEntity[] in_medias = s.getMediaEntities(); if (in_medias != null) { for (MediaEntity media : in_medias) { image_files.add(media.getMediaURL().toString()); } } json.put("metions", metions); json.put("image_files", metions); json.put("inReplyId", s.getInReplyToStatusId()); return json; }
From source file:org.sociotech.communitymashup.source.twitter.TwitterSourceService.java
License:Open Source License
/** * Creates a content for the given tweet, adds it to the data set and sets * the author.//from w w w.j av a 2 s . c o m * * @param author * Person corresponding to the twitter user which authored the * tweet * @param tweet * The tweet * @return The Content created from the tweet, null in error case. */ private Content createContentFromTweet(Person author, Status tweet) { if (tweet == null) { return null; } String tweetText = tweet.getText(); if (tweetText == null || tweetText.isEmpty()) { return null; } String ident = tweet.getId() + ""; if (this.getContentWithSourceIdent(ident) != null) { // status already created return null; } Content tweetContent = factory.createContent(); tweetContent.setStringValue(tweetText); tweetContent.setName(createTitleFromTwitterText(tweetText)); tweetContent = (Content) this.add(tweetContent, ident); if (tweetContent == null) { return null; } tweetContent.metaTag(TwitterTags.TWITTER); tweetContent.setCreated(tweet.getCreatedAt()); if (author != null) { tweetContent.setAuthor(author); } // and tag the status HashtagEntity[] hashtags = tweet.getHashtagEntities(); tagIOwithHashtags(tweetContent, hashtags); UserMentionEntity[] mentionedUsers = tweet.getUserMentionEntities(); if (mentionedUsers != null && mentionedUsers.length > 0 && source.isPropertyTrue(TwitterProperties.ADD_MENTIONED_PEOPLE_PROPERTY)) { for (int i = 0; i < mentionedUsers.length; i++) { Person mentionedPerson = getPersonForTwitterUserId(mentionedUsers[i].getId()); if (mentionedPerson == null) { continue; } tweetContent.addContributor(mentionedPerson); } } URLEntity[] urlEntities = tweet.getURLEntities(); if (urlEntities != null && urlEntities.length > 0 && source.isPropertyTrue(TwitterProperties.ADD_URL_ENTITIES_PROPERTY)) { for (int i = 0; i < urlEntities.length; i++) { String url = urlEntities[i].getURL(); if (url != null) { // attach url as website tweetContent.addWebSite(url); } } } // no more available // String language = tweet.getIsoLanguageCode(); // if(language != null && !language.isEmpty()) // { // // set in content // tweetContent.setLocale(language); // // set as meta tag // tweetContent.metaTag(language); // } // TODO check media entities // MediaEntity[] mediaEntities = twitterStatus.getMediaEntities(); // add location GeoLocation tweetLocation = tweet.getGeoLocation(); Place place = tweet.getPlace(); if (tweetLocation != null || place != null) { Location location = factory.createLocation(); if (place != null) { location.setStreet(place.getStreetAddress()); location.setCountry(place.getCountry()); location.setStringValue(place.getFullName()); } if (tweetLocation != null) { location.setLatitude(tweetLocation.getLatitude() + ""); location.setLongitude(tweetLocation.getLongitude() + ""); } location = (Location) this.add(location, "tloc_" + tweet.getId()); if (location != null) { location.metaTag(TwitterTags.TWITTER); tweetContent.extend(location); if (place != null) { location.metaTag(place.getCountryCode()); location.metaTag(place.getPlaceType()); } } } return tweetContent; }
From source file:org.tweetalib.android.model.TwitterStatus.java
License:Apache License
public TwitterStatus(Status status) { User statusUser = status.getUser();//from w ww.jav a 2 s . c o m mCreatedAt = status.getCreatedAt(); mId = status.getId(); if (status.getInReplyToStatusId() != -1) { mInReplyToStatusId = status.getInReplyToStatusId(); } if (status.getInReplyToUserId() != -1) { mInReplyToUserId = status.getInReplyToUserId(); } mInReplyToUserScreenName = status.getInReplyToScreenName(); mIsFavorited = status.isFavorited(); mIsRetweet = status.isRetweet(); mIsRetweetedByMe = status.isRetweetedByMe(); mSource = TwitterUtil.stripMarkup(status.getSource()); if (statusUser != null) { mUserId = statusUser.getId(); mUserName = statusUser.getName(); mUserScreenName = statusUser.getScreenName(); } mMediaEntity = TwitterMediaEntity.createMediaEntity(status); boolean useDefaultAuthor = true; if (mIsRetweet) { if (status.getRetweetedStatus() != null && status.getRetweetedStatus().getUser() != null) { SetProfileImagesFromUser(new TwitterUser(status.getRetweetedStatus().getUser())); } mOriginalRetweetId = status.getRetweetedStatus().getId(); // You'd think this check wasn't necessary, but apparently not... UserMentionEntity[] userMentions = status.getUserMentionEntities(); if (userMentions != null && userMentions.length > 0) { useDefaultAuthor = false; UserMentionEntity authorMentionEntity = status.getUserMentionEntities()[0]; mAuthorId = authorMentionEntity.getId(); mAuthorName = authorMentionEntity.getName(); mAuthorScreenName = authorMentionEntity.getScreenName(); Status retweetedStatus = status.getRetweetedStatus(); mStatus = retweetedStatus.getText(); setStatusMarkup(retweetedStatus); mRetweetCount = retweetedStatus.getRetweetCount(); mUserMentions = TwitterUtil.getUserMentions(retweetedStatus.getUserMentionEntities()); mIsRetweetedByMe = retweetedStatus.isRetweetedByMe(); } } else { if (statusUser != null) { SetProfileImagesFromUser(new TwitterUser(statusUser)); } } if (useDefaultAuthor) { if (statusUser != null) { mAuthorId = statusUser.getId(); } mStatus = status.getText(); setStatusMarkup(status); mRetweetCount = status.getRetweetCount(); mUserMentions = TwitterUtil.getUserMentions(status.getUserMentionEntities()); } /* * if (status.getId() == 171546910249852928L) { mStatus = * "<a href=\"http://a.com\">@chrismlacy</a> You've been working on Tweet Lanes for ages. Is it done yet?" * ; mStatusMarkup = * "<a href=\"http://a.com\">@chrismlacy</a> You've been working on Tweet Lanes for ages. Is it done yet?" * ; mAuthorScreenName = "emmarclarke"; mStatusMarkup = mStatus; } else * if (status.getId() == 171444098698457089L) { mStatus = * "<a href=\"http://a.com\">@chrismlacy</a> How's that app of yours coming along?" * ; mStatusMarkup = * "<a href=\"http://a.com\">@chrismlacy</a> How's that app of yours coming along?" * ; mStatusMarkup = mStatus; } */ }
From source file:org.xmlsh.twitter.util.TwitterWriter.java
License:BSD License
public void write(Status t) throws XMLStreamException { startElement("tweet"); attribute("id", t.getId()); // write("annotations",t.getAnnotations()); write("created-at", t.getCreatedAt()); write("from-user", sanitizeID(t.getUser().getId()), sanitizeUser(t.getUser().getName())); write("geo-location", t.getGeoLocation()); write("hash-tags", t.getHashtagEntities()); write("iso-language-code", t.getUser().getLang()); write("location", t.getUser().getLocation()); write("media", t.getMediaEntities()); write("place", t.getPlace()); write("profile-image-url", sanitizeUser(t.getUser().getProfileImageURL())); write("source", t.getSource()); write("text", t.getText()); write("to-user", sanitizeID(t.getInReplyToUserId()), sanitizeUser(t.getInReplyToScreenName())); write("url-entities", t.getURLEntities()); write("user-mention-entities", t.getUserMentionEntities()); endElement();/*from w w w.java 2s . c o m*/ }
From source file:org.xmlsh.twitter.util.TwitterWriter.java
License:BSD License
public void write(String localName, Status status) throws XMLStreamException { if (status != null) { startElement(localName);/*w w w .j av a2 s . c o m*/ attribute("id", status.getId()); // write("annotations",t.getAnnotations()); write("created-at", status.getCreatedAt()); write("user", status.getUser()); write("geo-location", status.getGeoLocation()); write("hash-tags", status.getHashtagEntities()); write("media", status.getMediaEntities()); write("place", status.getPlace()); write("source", status.getSource()); write("text", status.getText()); write("url-entities", status.getURLEntities()); write("user-mention-entities", status.getUserMentionEntities()); endElement(); } }
From source file:Principal.Tracker_Twitter.java
License:Minecraft Mod Public
public void guardarResultados_Twitter(List<ObjetoBuscar> lista, BD base, int contadorBase, int TokenIndice) throws NoSuchAlgorithmException, KeyManagementException { int nuevoContadorBase = 0; if (contadorBase >= lista.size()) { System.out.println("Termino en:" + contadorBase); } else {/*from www . j a v a 2 s . com*/ System.out.println("---------------------------------------------------------------------:P"); TrustManager[] trustAllCerts = { new X509TrustManager() { public X509Certificate[] getAcceptedIssuers() { return null; } public void checkClientTrusted(X509Certificate[] certs, String authType) { } public void checkServerTrusted(X509Certificate[] certs, String authType) { } } }; SSLContext sc = SSLContext.getInstance("SSL"); sc.init(null, trustAllCerts, new SecureRandom()); HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory()); HostnameVerifier allHostsValid = new HostnameVerifier() { public boolean verify(String hostname, SSLSession session) { return true; } }; HttpsURLConnection.setDefaultHostnameVerifier(allHostsValid); System.out.println("Token : " + TokenIndice); System.out.println(consumerKey[TokenIndice]); try { ConfigurationBuilder cb = new ConfigurationBuilder(); cb.setOAuthConsumerKey(consumerKey[TokenIndice]); cb.setOAuthConsumerSecret(this.consumerSecret[TokenIndice]); cb.setOAuthAccessToken(this.token[TokenIndice]); cb.setOAuthAccessTokenSecret(this.tokenSecret[TokenIndice]); Twitter unauthenticatedTwitter = new TwitterFactory(cb.build()).getInstance(); for (int numtTweets = contadorBase; numtTweets < contadorBase + 5; numtTweets++) { if (((ObjetoBuscar) lista.get(numtTweets)).getUrl().equals("") || ((ObjetoBuscar) lista.get(numtTweets)).getUrl() == null) { } else { System.out.println("Usuario: " + ((ObjetoBuscar) lista.get(numtTweets)).getUrl()); String usuariosinArroba = ((ObjetoBuscar) lista.get(numtTweets)).getUrl().replace("@", ""); System.out.println("" + usuariosinArroba); try { User usuario = unauthenticatedTwitter.showUser(usuariosinArroba); List<Status> ret = unauthenticatedTwitter.getRetweetsOfMe(); List<Status> favoritos = unauthenticatedTwitter.getFavorites(); Paging paging = new Paging(1, 1000); ResponseList<Status> statuses = unauthenticatedTwitter.getUserTimeline(usuario.getId(), paging); System.out.println("Followers: " + usuario.getFollowersCount()); System.out.println("Yo sigo: " + usuario.getFriendsCount()); List<String> listaTweets = new ArrayList(); List<Long> ListaRettewts = new ArrayList(); List<Integer> ListaFavoritos = new ArrayList(); List<Integer> ListaMenciones = new ArrayList(); List<Date> ListaFecha = new ArrayList(); List<Long> ListaIds = new ArrayList(); for (Status sta : statuses) { ListaIds.add(Long.valueOf(sta.getId())); listaTweets.add(sta.getText()); ListaRettewts.add(Long.valueOf(Long.parseLong(sta.getRetweetCount() + ""))); ListaMenciones.add(Integer.valueOf(sta.getUserMentionEntities().length)); ListaFecha.add(sta.getCreatedAt()); ListaFavoritos.add(Integer.valueOf(sta.getFavoriteCount())); } for (int i = 0; i < listaTweets.size(); i++) { base.guardarTrackTwitter_Log((Long) ListaIds.get(i), ((ObjetoBuscar) lista.get(numtTweets)).getUrl(), (String) listaTweets.get(i), (Date) ListaFecha.get(i), (Long) ListaRettewts.get(i), ((Integer) ListaFavoritos.get(i)).intValue(), ((Integer) ListaMenciones.get(i)).intValue()); } } catch (Exception e) { System.err.println("Entro al Try por :" + e); } nuevoContadorBase = numtTweets; } } System.out.println("Numero de Contador Base:" + nuevoContadorBase); guardarResultados_Twitter(lista, base, nuevoContadorBase + 1, TokenIndice + 1); } catch (NumberFormatException e) { System.err.println("Fallo por :" + e); } } }
From source file:testtweet.TweetUsingTwitter4jExample.java
/** * @param args the command line arguments *//*from w w w. ja v a2 s. c om*/ public static void main(String[] args) throws IOException, TwitterException { //Instantiate a re-usable and thread-safe factory TwitterFactory twitterFactory = new TwitterFactory(Data.getConf().build()); //Instantiate a new Twitter instance Twitter twitter = twitterFactory.getInstance(); /* //setup OAuth Consumer Credentials twitter.setOAuthConsumer(consumerKey, consumerSecret); //setup OAuth Access Token twitter.setOAuthAccessToken(new AccessToken(accessToken, accessTokenSecret)); */ //Instantiate and initialize a new twitter status update StatusUpdate statusUpdate = new StatusUpdate( //your tweet or status message "Twitter API #Hacked"); //attach any media, if you want to /* statusUpdate.setMedia( //title of media "http://h1b-work-visa-usa.blogspot.com" , new URL("http://lh6.ggpht.com/-NiYLR6SkOmc/Uen_M8CpB7I/AAAAAAAAEQ8/tO7fufmK0Zg/h-1b%252520transfer%252520jobs%25255B4%25255D.png?imgmax=800").openStream()); */ //tweet or update status Status status = twitter.updateStatus(statusUpdate); //response from twitter server System.out.println("status.toString() = " + status.toString()); System.out.println("status.getInReplyToScreenName() = " + status.getInReplyToScreenName()); System.out.println("status.getSource() = " + status.getSource()); System.out.println("status.getText() = " + status.getText()); System.out.println("status.getContributors() = " + Arrays.toString(status.getContributors())); System.out.println("status.getCreatedAt() = " + status.getCreatedAt()); System.out.println("status.getCurrentUserRetweetId() = " + status.getCurrentUserRetweetId()); System.out.println("status.getGeoLocation() = " + status.getGeoLocation()); System.out.println("status.getId() = " + status.getId()); System.out.println("status.getInReplyToStatusId() = " + status.getInReplyToStatusId()); System.out.println("status.getInReplyToUserId() = " + status.getInReplyToUserId()); System.out.println("status.getPlace() = " + status.getPlace()); System.out.println("status.getRetweetCount() = " + status.getRetweetCount()); System.out.println("status.getRetweetedStatus() = " + status.getRetweetedStatus()); System.out.println("status.getUser() = " + status.getUser()); System.out.println("status.getAccessLevel() = " + status.getAccessLevel()); System.out.println("status.getHashtagEntities() = " + Arrays.toString(status.getHashtagEntities())); System.out.println("status.getMediaEntities() = " + Arrays.toString(status.getMediaEntities())); if (status.getRateLimitStatus() != null) { System.out .println("status.getRateLimitStatus().getLimit() = " + status.getRateLimitStatus().getLimit()); System.out.println( "status.getRateLimitStatus().getRemaining() = " + status.getRateLimitStatus().getRemaining()); System.out.println("status.getRateLimitStatus().getResetTimeInSeconds() = " + status.getRateLimitStatus().getResetTimeInSeconds()); System.out.println("status.getRateLimitStatus().getSecondsUntilReset() = " + status.getRateLimitStatus().getSecondsUntilReset()); System.out.println("status.getRateLimitStatus().getRemainingHits() = " + status.getRateLimitStatus().getRemaining()); } System.out.println("status.getURLEntities() = " + Arrays.toString(status.getURLEntities())); System.out.println("status.getUserMentionEntities() = " + Arrays.toString(status.getUserMentionEntities())); }
From source file:twitterapidemo.TwitterAPIDemo.java
License:Apache License
public static void main(String[] args) throws IOException, TwitterException { //TwitterAPIDemo twitterApiDemo = new TwitterAPIDemo(); ConfigurationBuilder builder = new ConfigurationBuilder(); builder.setOAuthConsumerKey(consumerKey); builder.setOAuthConsumerSecret(consumerSecret); Configuration configuration = builder.build(); TwitterFactory twitterFactory = new TwitterFactory(configuration); Twitter twitter = twitterFactory.getInstance(); twitter.setOAuthAccessToken(new AccessToken(accessToken, accessTokenSecret)); Scanner sc = new Scanner(System.in); System.out.println(/*from w w w. ja v a 2 s .c o m*/ "Enter your choice:\n1. To post tweet\n2.To search tweets\n3. Recent top 3 trends and number of posts of each trending topic"); int choice = sc.nextInt(); switch (choice) { case 1: System.out.println("What's happening: "); String post = sc.next(); StatusUpdate statusUpdate = new StatusUpdate(post + "-Posted by TwitterAPI"); Status status = twitter.updateStatus(statusUpdate); System.out.println("status.toString() = " + status.toString()); System.out.println("status.getInReplyToScreenName() = " + status.getInReplyToScreenName()); System.out.println("status.getSource() = " + status.getSource()); System.out.println("status.getText() = " + status.getText()); System.out.println("status.getContributors() = " + Arrays.toString(status.getContributors())); System.out.println("status.getCreatedAt() = " + status.getCreatedAt()); System.out.println("status.getCurrentUserRetweetId() = " + status.getCurrentUserRetweetId()); System.out.println("status.getGeoLocation() = " + status.getGeoLocation()); System.out.println("status.getId() = " + status.getId()); System.out.println("status.getInReplyToStatusId() = " + status.getInReplyToStatusId()); System.out.println("status.getInReplyToUserId() = " + status.getInReplyToUserId()); System.out.println("status.getPlace() = " + status.getPlace()); System.out.println("status.getRetweetCount() = " + status.getRetweetCount()); System.out.println("status.getRetweetedStatus() = " + status.getRetweetedStatus()); System.out.println("status.getUser() = " + status.getUser()); System.out.println("status.getAccessLevel() = " + status.getAccessLevel()); System.out.println("status.getHashtagEntities() = " + Arrays.toString(status.getHashtagEntities())); System.out.println("status.getMediaEntities() = " + Arrays.toString(status.getMediaEntities())); if (status.getRateLimitStatus() != null) { System.out.println( "status.getRateLimitStatus().getLimit() = " + status.getRateLimitStatus().getLimit()); System.out.println("status.getRateLimitStatus().getRemaining() = " + status.getRateLimitStatus().getRemaining()); System.out.println("status.getRateLimitStatus().getResetTimeInSeconds() = " + status.getRateLimitStatus().getResetTimeInSeconds()); System.out.println("status.getRateLimitStatus().getSecondsUntilReset() = " + status.getRateLimitStatus().getSecondsUntilReset()); } System.out.println("status.getURLEntities() = " + Arrays.toString(status.getURLEntities())); System.out.println( "status.getUserMentionEntities() = " + Arrays.toString(status.getUserMentionEntities())); break; case 2: System.out.println("Enter keyword"); String keyword = sc.next(); try { Query query = new Query(keyword); QueryResult result; do { result = twitter.search(query); List<Status> tweets = result.getTweets(); for (Status tweet : tweets) { System.out.println(tweet.getCreatedAt() + ":\t@" + tweet.getUser().getScreenName() + " - " + tweet.getText()); } } while ((query = result.nextQuery()) != null); System.exit(0); } catch (TwitterException te) { System.out.println("Failed to search tweets: " + te.getMessage()); System.exit(-1); break; } case 3: //WOEID for India = 23424848 Trends trends = twitter.getPlaceTrends(23424848); int count = 0; for (Trend trend : trends.getTrends()) { if (count < 3) { Query query = new Query(trend.getName()); QueryResult result; int numberofpost = 0; do { result = twitter.search(query); List<Status> tweets = result.getTweets(); for (Status tweet : tweets) { numberofpost++; } } while ((query = result.nextQuery()) != null); System.out .println("Number of post for the topic '" + trend.getName() + "' is: " + numberofpost); count++; } else break; } break; default: System.out.println("Invalid input"); } }
From source file:twittermongodbapp.SaveTweets.java
static public void saveTweets(DB db, twitter4j.Twitter twitter) throws TwitterException { DBCollection collection = db.getCollection("collection2"); DBCollection savedCollection = db.getCollection("savedCollection"); DBCollection ConnectionCollection = db.getCollection(" ConnectionCollection"); BasicDBObject document0 = new BasicDBObject(); savedCollection.remove(document0);/*ww w . j a v a2 s .c om*/ ConnectionCollection.remove(document0); Status savedTweet; //Read Tweets from Database System.out.println("Saved tweets: "); DBCursor cursor = collection.find(); List<String> allUsers = new ArrayList<>(); int count = 1; while (cursor.hasNext()) { DBObject obj = cursor.next(); savedTweet = TwitterObjectFactory.createStatus(obj.toString()); String name = savedTweet.getUser().getScreenName(); String date = savedTweet.getCreatedAt().toString(); boolean exist = false; BasicDBObject document = new BasicDBObject("User", name); BasicDBObject searchDocument = new BasicDBObject("User", name); DBObject theObj = null; if (!allUsers.contains(name)) { allUsers.add(name); } else { exist = true; DBCursor cursor2 = savedCollection.find(searchDocument); if (cursor2.hasNext()) { theObj = cursor2.next(); } } // BasicDBList allHashtags = new BasicDBList(); List<String> allHashtags = new ArrayList<>(); List<String> allsortURLS = new ArrayList<>(); List<String> allcompleteURLS = new ArrayList<>(); //BasicDBList allURLS = new BasicDBList(); List<String> allmentionedUsers = new ArrayList<>(); List<String> allTweets = new ArrayList<>(); if (exist) { allHashtags = (ArrayList) theObj.get("Hashtags"); } HashtagEntity[] hashtagsEntities = savedTweet.getHashtagEntities(); for (HashtagEntity hashtagsEntitie : hashtagsEntities) { if (!allHashtags.contains(hashtagsEntitie.getText())) { allHashtags.add(hashtagsEntitie.getText()); } saveConnection(date, name, new BasicDBObject("hashtag", hashtagsEntitie.getText()), 1, count, ConnectionCollection); count++; } document.append("Hashtags", allHashtags); if (exist) { allsortURLS = (ArrayList) theObj.get("sortUrls"); allcompleteURLS = (ArrayList) theObj.get("completeUrls"); } URLEntity[] urlEntities = savedTweet.getURLEntities(); if (savedTweet.getURLEntities().length > 0) { for (int i = 0; i < savedTweet.getURLEntities().length; i++) { if (urlEntities[i].getStart() < urlEntities[i].getEnd()) { BasicDBObject document1 = new BasicDBObject("url", urlEntities[i].getURL()); String completeURL = urlEntities[i].getExpandedURL(); document1.append("completeURL", completeURL); if (!allsortURLS.contains(document1)) { allsortURLS.add(urlEntities[i].getURL()); allcompleteURLS.add(urlEntities[i].getExpandedURL()); } saveConnection(date, name, document1, 2, count, ConnectionCollection); count++; } } } document.append("sortUrls", allsortURLS); document.append("completeUrls", allsortURLS); if (exist) { allmentionedUsers = (ArrayList) theObj.get("Mentions"); } UserMentionEntity[] mentionEntities = savedTweet.getUserMentionEntities(); for (UserMentionEntity mentionEntitie : mentionEntities) { BasicDBObject document2 = new BasicDBObject("mentioned_user", mentionEntitie.getText()); if (!allmentionedUsers.contains(mentionEntitie.getText())) { allmentionedUsers.add(mentionEntitie.getText()); } saveConnection(date, name, document2, 3, count, ConnectionCollection); count++; } document.append("Mentions", allmentionedUsers); if (exist) { allTweets = (ArrayList) theObj.get("Tweets"); } String tweetText = " "; if (savedTweet.isRetweet()) { tweetText = savedTweet.getRetweetedStatus().getText(); } else { tweetText = savedTweet.getText(); } BasicDBObject document2 = new BasicDBObject("Tweet", tweetText); if (!allTweets.contains(tweetText)) { allTweets.add(tweetText); } saveConnection(date, name, document2, 4, count, ConnectionCollection); count++; document.append("Tweets", allTweets); if (exist) { savedCollection.remove(searchDocument); } savedCollection.insert(document); } JaccardSimilarity js = new JaccardSimilarity(); List<Map<List<String>, List<Float>>> list = new ArrayList<>();//This is the final list you need Map<List<String>, List<Float>> map1 = new HashMap<>();//This is one instance of the map you want to store in the above map List<String> usersNames = new ArrayList<>(); List<Float> usersResults = new ArrayList<>(); BasicDBObject doc1; BasicDBObject doc2; DBCursor cursor1; DBCursor cursor2; DBObject obj1; DBObject obj2; List<String> tl1 = new ArrayList(); List<String> tl2 = new ArrayList(); float countSimilarity = 0; for (int i = 0; i < allUsers.size(); i++) { for (int j = i + 1; j < allUsers.size(); j++) { //System.out.println(i+" "+j); System.out.print(allUsers.get(i) + " " + allUsers.get(j) + " "); usersNames.add(allUsers.get(i)); usersNames.add(allUsers.get(j)); doc1 = new BasicDBObject("User", allUsers.get(i)); doc2 = new BasicDBObject("User", allUsers.get(j)); cursor1 = savedCollection.find(doc1); cursor2 = savedCollection.find(doc2); if (cursor1.hasNext() && cursor2.hasNext()) { obj1 = cursor1.next(); obj2 = cursor2.next(); tl1 = (ArrayList) obj1.get("Hashtags"); tl2 = (ArrayList) obj2.get("Hashtags"); countSimilarity = countSimilarity + js.findSimilarity(tl1, tl2); usersResults.add(js.findSimilarity(tl1, tl2)); System.out.print(js.findSimilarity(tl1, tl2) + " "); tl1 = (ArrayList) obj1.get("Mentions"); tl2 = (ArrayList) obj2.get("Mentions"); countSimilarity = countSimilarity + js.findSimilarity(tl1, tl2); usersResults.add(js.findSimilarity(tl1, tl2)); System.out.print(js.findSimilarity(tl1, tl2) + " "); tl1 = (ArrayList) obj1.get("Tweets"); tl2 = (ArrayList) obj2.get("Tweets"); countSimilarity = countSimilarity + js.findSimilarity(tl1, tl2); usersResults.add(js.findSimilarity(tl1, tl2)); System.out.print(js.findSimilarity(tl1, tl2) + " "); tl1 = (ArrayList) obj1.get("sortUrls"); tl2 = (ArrayList) obj2.get("sortUrls"); countSimilarity = countSimilarity + js.findSimilarity(tl1, tl2); usersResults.add(js.findSimilarity(tl1, tl2)); System.out.print(js.findSimilarity(tl1, tl2) + " "); usersResults.add((float) (countSimilarity / 4)); System.out.print((float) (countSimilarity / 4) + " "); System.out.println(); countSimilarity = 0; } } map1.put(usersNames, usersResults); } list.add(map1); //System.out.println(savedCollection.count()); /* // Read every Element Example DBCursor cursor2 = savedCollection.find(searchDocument); if (cursor2.hasNext()) { theObj = cursor2.next(); //String l = ( String) cursor2.one().get("exist").toString(); } BasicDBList list = new BasicDBList(); list = (BasicDBList) theObj.get("Hashtags"); BasicDBList l2 = new BasicDBList(); for (int i = 0; i < list.size(); i++) { BasicDBObject bj = (BasicDBObject) list.get(i); System.out.println(bj.getString("hashtag")); } DBCursor cursor2 = savedCollection.find(); List<String> list = new ArrayList(); while (cursor2.hasNext()) { BasicDBObject document2 = (BasicDBObject) cursor2.next(); String bj = (String) document2.get("User"); System.out.println(bj); for (int i = 0; i < list.size(); i++) { // String bj = (String) list.get(i); // System.out.println(bj.getString("hashtag")); System.out.println(bj); } */ }
From source file:TwitterStats.Facade.Twitter.java
public Map<String, Integer> getMenciones(String user, int estudio) throws TwitterException { ResponseList res;//from ww w .ja va 2 s .co m List<Status> lista = new ArrayList<>(); Map<String, Integer> menciones = new HashMap<>(); for (int i = 1; i <= estudio / 200; i++) { res = twitter.getUserTimeline(user, new Paging(i, 200)); lista.addAll(res); } for (Status status : lista) { UserMentionEntity[] men = status.getUserMentionEntities(); for (int i = 0; i < men.length; i++) { String mencion = men[i].getText(); if (menciones.containsKey(mencion)) { menciones.put(mencion, menciones.get(mencion) + 1); } else { menciones.put(mencion, 1); } } } return sortByValue(menciones); }