List of usage examples for com.mongodb.client MongoCursor next
@Override TResult next();
From source file:StatisticsGathering.StatisticsCalculator.java
public ArrayList<HashMap<String, Integer>> wordRepresentativesForTrend(Trend trend, double intervalWidth, ArrayList<Tuple<Date, Integer[]>> stats) { ArrayList<HashMap<String, Integer>> representativeWords = new ArrayList<HashMap<String, Integer>>(); long trendStartTime = trend.getStartTime().getTime(); int interval = 1; Double[] scores;/*from w w w. ja va2 s. c o m*/ MongoCursor tweetCursor = tweetCollection.getCursorByTrend(trend.getTermList()); ArrayList<Tweet> tweetList = new ArrayList<>(); while (tweetCursor.hasNext()) { org.bson.Document docTweet = (org.bson.Document) tweetCursor.next(); if (trendStartTime + interval * intervalWidth > ((Date) docTweet.get("date")).getTime()) { scores = getScores(docTweet); if (getMaxScoreIndex(scores) == getMaxIndex(stats.get(interval - 1).second())) tweetList.add(new Tweet(docTweet)); } else //if else runs, we have reached the end of the interval { //here call slave representativeWords.add(getTF(tweetList)); tweetList = new ArrayList<>(); //make new tweetList for the next interval } } return representativeWords; }
From source file:StatisticsGathering.StatisticsCalculator.java
ArrayList<Tuple<Date, Integer[]>> calculateStatsFor(Trend trend, long width, Date startTime) { ArrayList<Tuple<Date, Integer[]>> list = new ArrayList<>(); MongoCursor tweetCursor; Integer[] sentimentsCount = new Integer[] { 0, 0, 0, 0, 0, 0 }; tweetCursor = tweetCollection.getCursorByTrend(trend.getTermList()); int interval = 1; while (tweetCursor.hasNext()) { Double scores[];//from w w w.jav a 2s . co m org.bson.Document currentTweet = (org.bson.Document) tweetCursor.next(); scores = getScores(currentTweet); Date currentDate = (Date) currentTweet.get("date"); while (startTime.getTime() + interval * width < currentDate.getTime()) { list.add(new Tuple<Date, Integer[]>(new Date(startTime.getTime() + (interval - 1) * width), sentimentsCount)); for (int i = 0; i < 6; i++) sentimentsCount[i] = 0; interval++; } ++sentimentsCount[getMaxScoreIndex(scores)]; } return list; }
From source file:swm.project.findsimilarities.FindMovieSimilarities.java
private void findDistancesForActors() { PrintWriter pw = null;/* ww w . j a va 2 s .c om*/ try { pw = new PrintWriter("datafiles//ActorSimilarities.csv"); } catch (FileNotFoundException ex) { Logger.getLogger(FindMovieSimilarities.class.getName()).log(Level.SEVERE, null, ex); } MongoCollection<Document> movieActorsCollection = db.getCollection(Consts.MOVIE_ACTORS_DATA); FindIterable<Document> movieActorsAll = movieActorsCollection.find(); MongoCursor movieActorCursorX = movieActorsAll.iterator(); while (movieActorCursorX.hasNext()) { Document dX = (Document) movieActorCursorX.next(); int idX = (int) dX.get("_id"); List<String> actorsX = (List<String>) dX.get(Consts.MOVIE_ACTORS_DATA); MongoCursor movieActorCursorY = movieActorsAll.iterator(); while (movieActorCursorY.hasNext()) { Document dY = (Document) movieActorCursorY.next(); int idY = (int) dY.get("_id"); List<String> actorsY = (List<String>) dY.get(Consts.MOVIE_ACTORS_DATA); double simActors = Operations.findJaccardDistance(actorsX, actorsY); simActs[idX - 1][idY - 1] = simActors; //System.out.print(simActors+","); pw.print(simActors + ","); } // System.out.println(""); pw.println(); } }
From source file:swm.project.findsimilarities.FindMovieSimilarities.java
private void findDistancesForDirectors() { PrintWriter pw = null;/*ww w.j av a2 s .c om*/ try { pw = new PrintWriter("datafiles//DirectorSimilarities.csv"); } catch (FileNotFoundException ex) { Logger.getLogger(FindMovieSimilarities.class.getName()).log(Level.SEVERE, null, ex); } MongoCollection<Document> movieDirectorsCollection = db.getCollection(Consts.MOVIE_DIRECTORS_DATA); FindIterable<Document> movieDirectorsAll = movieDirectorsCollection.find(); MongoCursor movieDirectorsCursorX = movieDirectorsAll.iterator(); while (movieDirectorsCursorX.hasNext()) { Document dX = (Document) movieDirectorsCursorX.next(); int idX = (int) dX.get("_id"); List<String> directorsX = (List<String>) dX.get(Consts.MOVIE_DIRECTORS_DATA); MongoCursor movieDirectorsCursorY = movieDirectorsAll.iterator(); while (movieDirectorsCursorY.hasNext()) { Document dY = (Document) movieDirectorsCursorY.next(); int idY = (int) dY.get("_id"); List<String> directorsY = (List<String>) dY.get(Consts.MOVIE_DIRECTORS_DATA); double simDirectors = Operations.findJaccardDistance(directorsX, directorsY); simDirects[idX - 1][idY - 1] = simDirectors; //System.out.print(simDirectors+","); pw.print(simDirectors + ","); } // System.out.println(""); pw.println(); } }
From source file:swm.project.findsimilarities.FindMovieSimilarities.java
private void findDistancesForGenre() { PrintWriter pw = null;/*from w w w. java2 s. c om*/ try { pw = new PrintWriter("datafiles//GenreSimilarities.csv"); } catch (FileNotFoundException ex) { Logger.getLogger(FindMovieSimilarities.class.getName()).log(Level.SEVERE, null, ex); } MongoCollection<Document> movieGenreCollection = db.getCollection(Consts.MOVIE_GENRE_DATA); FindIterable<Document> movieGenreAll = movieGenreCollection.find(); MongoCursor movieGenreCursorX = movieGenreAll.iterator(); while (movieGenreCursorX.hasNext()) { Document dX = (Document) movieGenreCursorX.next(); int idX = (int) dX.get("_id"); String genreX = (String) dX.get(Consts.MOVIE_GENRE_DATA); MongoCursor movieGenreCursorY = movieGenreAll.iterator(); while (movieGenreCursorY.hasNext()) { Document dY = (Document) movieGenreCursorY.next(); int idY = (int) dY.get("_id"); String genreY = (String) dY.get(Consts.MOVIE_GENRE_DATA); double similarGenres = Operations.findBinaryJaccardDistance(genreX, genreY); simGenres[idX - 1][idY - 1] = similarGenres; //System.out.print(similarGenres+","); pw.print(similarGenres + ","); } // System.out.println(""); pw.println(); } }
From source file:swm.project.findsimilarities.FindMovieSimilarities.java
private void findDistancesForDates() { PrintWriter pw = null;/* w w w . ja va 2s . c om*/ try { pw = new PrintWriter("datafiles//DateSimilarities.csv"); } catch (FileNotFoundException ex) { Logger.getLogger(FindMovieSimilarities.class.getName()).log(Level.SEVERE, null, ex); } MongoCollection<Document> movieDateCollection = db.getCollection(Consts.MOVIE_DATE_DATA); FindIterable<Document> movieDateAll = movieDateCollection.find(); MongoCursor movieDateCursorX = movieDateAll.iterator(); while (movieDateCursorX.hasNext()) { Document dX = (Document) movieDateCursorX.next(); int idX = (int) dX.get("_id"); int dateX = (int) dX.get(Consts.MOVIE_DATE_DATA); MongoCursor movieDateCursorY = movieDateAll.iterator(); while (movieDateCursorY.hasNext()) { Document dY = (Document) movieDateCursorY.next(); int idY = (int) dY.get("_id"); int dateY = (int) dY.get(Consts.MOVIE_DATE_DATA); double similarDates = Operations.findSimilarDates(dateX, dateY); simDates[idX - 1][idY - 1] = similarDates; //System.out.print(similarDates+","); pw.print(similarDates + ","); } // System.out.println(""); pw.println(); } pw.close(); }
From source file:swm.project.findsimilarities.FindUserSimilarities.java
private void findDistancesForGender() { PrintWriter pw = null;/*from w ww . j a v a 2s. co m*/ try { pw = new PrintWriter("datafiles//GenderSimilarities.csv"); } catch (FileNotFoundException ex) { Logger.getLogger(FindMovieSimilarities.class.getName()).log(Level.SEVERE, null, ex); } MongoCollection<Document> userGenderCollection = db.getCollection(Consts.USER_GENDER); FindIterable<Document> userGenderAll = userGenderCollection.find(); MongoCursor userGenderCursorX = userGenderAll.iterator(); while (userGenderCursorX.hasNext()) { Document dX = (Document) userGenderCursorX.next(); int idX = (int) dX.get("_id"); String genderX = (String) dX.get(Consts.USER_GENDER); MongoCursor userGenderCursorY = userGenderAll.iterator(); while (userGenderCursorY.hasNext()) { Document dY = (Document) userGenderCursorY.next(); int idY = (int) dY.get("_id"); String genderY = (String) dY.get(Consts.USER_GENDER); int simGenders = Operations.findSimilar(genderX, genderY); simGender[idX - 1][idY - 1] = simGenders; System.out.print(simGenders + ","); pw.print(simGenders + ","); } // System.out.println(""); pw.println(); } pw.close(); }
From source file:swm.project.findsimilarities.FindUserSimilarities.java
private void findDistancesForOccupation() { PrintWriter pw = null;// w w w .j a v a 2 s .c o m try { pw = new PrintWriter("datafiles//OccupationSimilarities.csv"); } catch (FileNotFoundException ex) { Logger.getLogger(FindMovieSimilarities.class.getName()).log(Level.SEVERE, null, ex); } MongoCollection<Document> userOccupationCollection = db.getCollection(Consts.USER_OCCUPATION); FindIterable<Document> userOccupationAll = userOccupationCollection.find(); MongoCursor userOccupationCursorX = userOccupationAll.iterator(); while (userOccupationCursorX.hasNext()) { Document dX = (Document) userOccupationCursorX.next(); int idX = (int) dX.get("_id"); String occupationX = (String) dX.get(Consts.USER_OCCUPATION); MongoCursor userOccupationCursorY = userOccupationAll.iterator(); while (userOccupationCursorY.hasNext()) { Document dY = (Document) userOccupationCursorY.next(); int idY = (int) dY.get("_id"); String occupationY = (String) dY.get(Consts.USER_OCCUPATION); int simOccupations = Operations.findSimilar(occupationX, occupationY); simOccupation[idX - 1][idY - 1] = simOccupations; System.out.print(simOccupations + ","); pw.print(simOccupations + ","); } // System.out.println(""); pw.println(); } pw.close(); }
From source file:swm.project.findsimilarities.FindUserSimilarities.java
private void findDistancesForAge() { PrintWriter pw = null;//from w ww . j av a2 s . c om try { pw = new PrintWriter("datafiles//AgeSimilarities.csv"); } catch (FileNotFoundException ex) { Logger.getLogger(FindMovieSimilarities.class.getName()).log(Level.SEVERE, null, ex); } MongoCollection<Document> userAgeCollection = db.getCollection(Consts.USER_AGE); FindIterable<Document> userAgeAll = userAgeCollection.find(); MongoCursor userAgeCursorX = userAgeAll.iterator(); while (userAgeCursorX.hasNext()) { Document dX = (Document) userAgeCursorX.next(); int idX = (int) dX.get("_id"); int ageX = (Integer) dX.get(Consts.USER_AGE); MongoCursor userAgeCursorY = userAgeAll.iterator(); while (userAgeCursorY.hasNext()) { Document dY = (Document) userAgeCursorY.next(); int idY = (int) dY.get("_id"); int ageY = (Integer) dY.get(Consts.USER_AGE); double simAges = Operations.findSimilarAges(ageX, ageY); simAge[idX - 1][idY - 1] = simAges; //System.out.print(simAges+","); pw.print(simAges + ","); } // System.out.println(""); pw.println(); } pw.close(); }
From source file:swm.project.loadDataToDb.GetDataFromDb.java
/** * /*ww w . ja v a 2 s . c o m*/ * @return * returns : HashMap<Integer, HashMap<Integer, Integer>> * i.e. HashMap<userid, HashMap<movieId, rating>> */ public HashMap<Integer, HashMap<Integer, Integer>> getAllUserRatings() { MongoCollection<Document> collection; collection = db.getCollection(Consts.UDATA); HashMap<Integer, HashMap<Integer, Integer>> userRatings = new HashMap<>(); FindIterable<Document> userRatingData = collection.find(); MongoCursor<Document> userRatingCursor = userRatingData.iterator(); while (userRatingCursor.hasNext()) { Document ratingFields = userRatingCursor.next(); int userId = (int) ratingFields.get("userid"); int movieId = (int) ratingFields.get("itemid"); int rating = (int) ratingFields.get("rating"); if (userRatings.containsKey(userId)) { HashMap<Integer, Integer> itemRatings = userRatings.get(userId); itemRatings.put(movieId, rating); } else { HashMap<Integer, Integer> itemRatings = new HashMap<Integer, Integer>(); itemRatings.put(movieId, rating); userRatings.put(userId, itemRatings); } } return userRatings; }