    001    package calhoun.analysis.crf.io;
    002
    003    import java.io.BufferedReader;
    004    import java.io.IOException;
    005
    006    public class Interval21HiddenSequenceTranslator extends IntInput {
    007            private static final long serialVersionUID = 4413724139445660883L;
    008
    009            @Override
    010            public int[] readSequence(BufferedReader r) throws IOException {
    011                    int[] states = super.readSequence(r);
    012                    // Weird boundary conditions here
    013                    int swap;
    014                    int ctr = 0;
    015                    // HEY!
    016                    for(int i=0; i<states.length-1; i++) {
    017                            swap = 0;
    018                            // ig-e
    019                            if (states[i]==0 && states[i+1]>=1 && states[i+1]<=3) {
    020                                    swap = 13;
    021                            // e-i
    022                            } else if (states[i]>=1 && states[i]<=3 && states[i+1]>=4 && states[i+1]<=6) {
    023                                    swap = 14;
    024                            // i-e
    025                            } else if (states[i]>=4 && states[i]<=6 && states[i+1]>=1 && states[i+1]<=3) {
    026                                    swap = 15;
    027                            // e-ig
    028                            } else if (states[i]>=1 && states[i]<=3 && states[i+1]==0) {
    029                                    swap = 16;
    030                            // ig-em
    031                            } else if (states[i]==0 && states[i+1]>=7 && states[i+1]<=9) {
    032                                    swap = 17;
    033                            // em-im
    034                            } else if (states[i]>=7 && states[i]<=9 && states[i+1]>=10 && states[i+1]<=12) {
    035                                    swap = 18;
    036                            // im-em
    037                            } else if (states[i]>=10 && states[i]<=12 && states[i+1]>=7 && states[i+1]<=9) {
    038                                    swap = 19;
    039                            // em-ig
    040                            } else if (states[i]>=7 && states[i]<=9 && states[i+1]==0) {
    041                                    swap = 20;
    042                            }
    043                            if (swap != 0) {
    044                                    if (i != states.length-1 && states[i+2] == states[i+1]) {
    045                                            states[i+1] = swap;
    046                                            states[i+2] = swap;
    047                                    } else if (i == states.length-1) {
    048                                            states[i+1] = swap;
    049                                    }
    050
    051                                    ctr++;
    052                            }
    053                    }
    054                    //System.out.println("made " + ctr + " changes, where length is " + states.length);
    055                    return states;
    056            }
    057
    058    }