@SuppressWarnings("fallthrough")
    public Segments segmentation(int method)
    {
        Segments smnt = new Segments(_tokens);

        addMissingSingles();

        int maxsc, id, bestid=-1, bias=0, c, pos, bestval, temp=0, next=-1;
        int[] maxScore = new int[super.size()];
        int[] nextid   = new int[super.size()];
        for(int i=0;i<nextid.length;i++){
            nextid[i]=-1;
        }

        switch(method){
        case SEGMENTATION_WEIGHTED_BIAS100:
            bias+=50;
        case SEGMENTATION_WEIGHTED_BIAS50:
            bias+=30;
        case SEGMENTATION_WEIGHTED_BIAS20:
            bias+=10;
        case SEGMENTATION_WEIGHTED_BIAS10:
            bias+=10;
        case SEGMENTATION_WEIGHTED:
            bestid=-1;
            for(int i=_tokens.length;i>=0;i--){
                bestid=-1;maxsc=0;
                for(int j=i+1;j<=_tokens.length;j++){
                    id=_map[i][j];
                    if(id>=0 && maxScore[id]+1>maxsc) {
                        bestid=id;
                        maxsc=maxScore[id]+1;
                    }
                }
                if(maxsc>0){
                    maxsc--;
                }
                for(int j=0;j<i;j++){
                    id=_map[j][i];
                    if(id>=0){
                        nextid[id] = bestid;
                        c = conn(id);
                        if(i-j<=1){
                            maxScore[id] = maxsc;
                        }
                        else if(bias>0){
                            maxScore[id] = maxsc + ((100+(i-j-2)*bias)*c)/100;
                        }
                        else{
                            maxScore[id] = maxsc + c;
                        }
                    }
                }
            }
            id = bestid;
            while(id!=-1){
                smnt.add(super.get(id));
                id=nextid[id];
            }
            break;
        case SEGMENTATION_LEFTMOST_LONGEST:
        case SEGMENTATION_LEFTMOST_WEIGHTED:
            pos = 0;
            while(pos<_tokens.length){
                bestid = -1; bestval = -1;
                for(int i=pos+1;i<=_tokens.length;i++){
                    id = _map[pos][i];
                    if(id>=0 &&
                       (method==SEGMENTATION_LEFTMOST_LONGEST ||
                        (temp=(len(id)>1)? conn(id) :0)>bestval) ){
                        bestid = id;
                        bestval = temp;
                        next = i;
                    }
                }
                smnt.add(super.get(bestid));
                pos=next;
            }
            break;
        case SEGMENTATION_RIGHTMOST_LONGEST:
        case SEGMENTATION_RIGHTMOST_WEIGHTED:
            pos = _tokens.length;
            while(pos>0){
                bestid = -1; bestval = -1;
                for(int i=pos-1;i>=0;i--){
                    id = _map[i][pos];
                    if(id>=0 &&
                       (method==SEGMENTATION_RIGHTMOST_LONGEST ||
                        (temp=(len(id)>1)? conn(id) :0)>bestval) ){
                        bestid = id;
                        bestval = temp;
                        next = i;
                    }
                }
                smnt.addFirst(super.get(bestid));
                pos=next;
            }
            smnt.reMap();
            break;
        case SEGMENTATION_LONGEST_WEIGHTED:
        case SEGMENTATION_LONGEST_LEFTMOST:
        case SEGMENTATION_LONGEST_RIGHTMOST:
        case SEGMENTATION_WEIGHTED_LONGEST:
        case SEGMENTATION_WEIGHTED_LEFTMOST:
        case SEGMENTATION_WEIGHTED_RIGHTMOST:
            buildSegmentationRecursive(method,smnt,0,_tokens.length);
            break;
        }

        return smnt;
    }
Contains the segmentation() method.

@author  Peter Boros
fsa/src/main/java/com/yahoo/fsa/segmenter/Segments.java