private ArrayList<ArrayList<PhrasePositions>> gatherRptGroups(LinkedHashMap<Term,Integer> rptTerms) throws IOException {
  PhrasePositions[] rpp=repeatingPPs(rptTerms);
  ArrayList<ArrayList<PhrasePositions>> res=new ArrayList<>();
  if (!hasMultiTermRpts) {
    for (int i=0; i < rpp.length; i++) {
      PhrasePositions pp=rpp[i];
      if (pp.rptGroup >= 0)       continue;
      int tpPos=tpPos(pp);
      for (int j=i + 1; j < rpp.length; j++) {
        PhrasePositions pp2=rpp[j];
        if (pp2.rptGroup >= 0 || pp2.offset == pp.offset || tpPos(pp2) != tpPos) {
          continue;
        }
        int g=pp.rptGroup;
        if (g < 0) {
          g=res.size();
          pp.rptGroup=g;
          ArrayList<PhrasePositions> rl=new ArrayList<>(2);
          rl.add(pp);
          res.add(rl);
        }
        pp2.rptGroup=g;
        res.get(g).add(pp2);
      }
    }
  }
 else {
    ArrayList<HashSet<PhrasePositions>> tmp=new ArrayList<>();
    ArrayList<FixedBitSet> bb=ppTermsBitSets(rpp,rptTerms);
    unionTermGroups(bb);
    HashMap<Term,Integer> tg=termGroups(rptTerms,bb);
    HashSet<Integer> distinctGroupIDs=new HashSet<>(tg.values());
    for (int i=0; i < distinctGroupIDs.size(); i++) {
      tmp.add(new HashSet<PhrasePositions>());
    }
    for (    PhrasePositions pp : rpp) {
      for (      Term t : pp.terms) {
        if (rptTerms.containsKey(t)) {
          int g=tg.get(t);
          tmp.get(g).add(pp);
          assert pp.rptGroup == -1 || pp.rptGroup == g;
          pp.rptGroup=g;
        }
      }
    }
    for (    HashSet<PhrasePositions> hs : tmp) {
      res.add(new ArrayList<>(hs));
    }
  }
  return res;
}

private ArrayList < ArrayList < PhrasePositions > > gatherRptGroups ( LinkedHashMap < Term , Integer > rptTerms ) throws IOException { PhrasePositions [ ] rpp = repeatingPPs ( rptTerms ) ; ArrayList < ArrayList < PhrasePositions > > res = new ArrayList < > ( ) ; if ( ! hasMultiTermRpts ) { for ( int i = 0 ; i < rpp . length ; i ++ ) { PhrasePositions pp = rpp [ i ] ; if ( pp . rptGroup >= 0 ) continue ; int tpPos = tpPos ( pp ) ; for ( int j = i + 1 ; j < rpp . length ; j ++ ) { PhrasePositions pp2 = rpp [ j ] ; if ( pp2 . rptGroup >= 0 || pp2 . offset == pp . offset || tpPos ( pp2 ) != tpPos ) { continue ; } int g = pp . rptGroup ; if ( g < 0 ) { g = res . size ( ) ; pp . rptGroup = g ; ArrayList < PhrasePositions > rl = new ArrayList < > ( 2 ) ; rl . add ( pp ) ; res . add ( rl ) ; } pp2 . rptGroup = g ; res . get ( g ) . add ( pp2 ) ; } } } else { ArrayList < HashSet < PhrasePositions > > tmp = new ArrayList < > ( ) ; ArrayList < FixedBitSet > bb = ppTermsBitSets ( rpp , rptTerms ) ; unionTermGroups ( bb ) ; HashMap < Term , Integer > tg = termGroups ( rptTerms , bb ) ; HashSet < Integer > distinctGroupIDs = new HashSet < > ( tg . values ( ) ) ; for ( int i = 0 ; i < distinctGroupIDs . size ( ) ; i ++ ) { tmp . add ( new HashSet < PhrasePositions > ( ) ) ; } for ( PhrasePositions pp : rpp ) { for ( Term t : pp . terms ) { if ( rptTerms . containsKey ( t ) ) { int g = tg . get ( t ) ; tmp . get ( g ) . add ( pp ) ; assert pp . rptGroup == - 1 || pp . rptGroup == g ; pp . rptGroup = g ; } } } for ( HashSet < PhrasePositions > hs : tmp ) { res . add ( new ArrayList < > ( hs ) ) ; } } return res ; }
detect repetition groups . done once - for first doc
