Example usage for com.mongodb.client MongoCursor hasNext

List of usage examples for com.mongodb.client MongoCursor hasNext

Introduction

In this page you can find the example usage for com.mongodb.client MongoCursor hasNext.

Prototype

@Override
    boolean hasNext();

Source Link

Usage

From source file:StatisticsGathering.StatisticsCalculator.java

public ArrayList<HashMap<String, Integer>> representativesByTrendForEachEmotion(Trend trend) {

    ArrayList<Tweet>[] tweetLists = new ArrayList[6];
    ArrayList<HashMap<String, Integer>> tfPerEmotion = new ArrayList<>();

    for (int i = 0; i < 6; i++)
        tweetLists[i] = new ArrayList<Tweet>();

    MongoCursor tweetCursor = tweetCollection.getCursorByTrend(trend.getTermList());

    while (tweetCursor.hasNext()) {

        org.bson.Document doc = (org.bson.Document) tweetCursor.next();
        Double scores[] = getScores(doc);

        tweetLists[getMaxScoreIndex(scores)].add(new Tweet(doc));
    }// w w w.  j  a  v  a 2 s.  c  om

    for (int i = 0; i < 6; i++)
        tfPerEmotion.add(getTF(tweetLists[i]));

    return tfPerEmotion;
}

From source file:StatisticsGathering.StatisticsCalculator.java

public void calculateTrendEmotions(MongoCursor trendCursor) {
    while (trendCursor.hasNext()) {

        Trend trend = new Trend((org.bson.Document) trendCursor.next());
        long intervalWidth = findIntervalWidth(trend);
        ArrayList<Tuple<Date, Integer[]>> stats = calculateStatsFor(trend, intervalWidth, trend.getStartTime());
        ArrayList<HashMap<String, Integer>> representativeWords = wordRepresentativesForTrend(trend,
                intervalWidth, stats);//from   w ww. j  a v  a 2s. co m
        ArrayList<HashMap<String, Integer>> data = representativesByTrendForEachEmotion(trend);

    }
    //We will return data
}

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 ww.  j a  v a  2s .  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  . ja  va  2 s .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;//from   w  w w .  ja  va2  s.c o  m
    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;//from w  ww.j  a  va 2  s.  com
    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;//  w  ww.  j  av a2  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 ww.  ja va2s  .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 va  2  s .c  om*/
    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;//  ww  w. j  a va2 s.c om
    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();
}