⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 shoeboxarray.java

📁 编辑视频文件
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
     */    final public String getLabel(int i) {        return (String) labelList.elementAt(i);    }    /**     * DOCUMENT ME!     *     * @param i DOCUMENT ME!     *     * @return DOCUMENT ME!     */    final public DefaultMutableTreeNode getLabelNode(int i) {        return (DefaultMutableTreeNode) labelNodeList.elementAt(i);    }    /**     * DOCUMENT ME!     *     * @param name DOCUMENT ME!     *     * @return DOCUMENT ME!     */    final public DefaultMutableTreeNode getLabelNode(String name) {        try {            return (DefaultMutableTreeNode) labelNodeList.elementAt(getLabelIndex(                    name));        } catch (ArrayIndexOutOfBoundsException ex) {            return (DefaultMutableTreeNode) labelNodeList.elementAt(0);        }    }    /**     * returns -1 if not found     *     * @param labelincludingtrailingbackslash DOCUMENT ME!     *     * @return DOCUMENT ME!     */    final public int getLabelIndex(String labelincludingtrailingbackslash) {        return labelList.indexOf(labelincludingtrailingbackslash);    }    /**     * DOCUMENT ME!     *     * @return DOCUMENT ME!     */    final public int getNumberOfBlocks() {        return maxIndexBlocks;    }    /**     * DOCUMENT ME!     *     * @return file-dump from Array.     *     * @throws Exception DOCUMENT ME!     */    final public String getShoeboxFile() throws Exception {        String result = getShoeboxHeader() + "\n";        for (int bi = 0; bi < getNumberOfBlocks(); bi++) {            for (int i = 0; i < getNumberOfLabels(); i++) {                String cntnt = shoeboxArray[i][bi];                if ((cntnt == null) || (cntnt.length() == 0)) {                    continue;                }                String label = getLabel(i);                if (i == 0) { // label_ref.equals(label)                    result = result + "\n";                }                result = result + label + "\t" + cntnt.replace('\n', ' ') +                    "\n";            }        }        return result;    }    /**     * DOCUMENT ME!     *     * @throws Exception yepp     */    final public void dump() throws Exception {        for (int bi = 0; bi < getNumberOfBlocks(); bi++) {            for (int i = 0; i < getNumberOfLabels(); i++) {                String cntnt = getCell(i, bi);                if (cntnt == null) {                    cntnt = "#";                }                String label = getLabel(i);                System.out.println(i + "/" + bi + ":\t" + label + "\t" +                    cntnt.replace('\n', ' '));            }        }    }    /**     * DOCUMENT ME!     *     * @throws Exception yepp     */    final public void dump2() throws Exception {        for (int _b = 0; _b < getNumberOfBlocks(); _b++) {            for (int _l = 0; _l < getNumberOfLabels(); _l++) {                String label = getLabel(_l);                String cntnt = getCell(label, _b);                System.out.println(_b + " " + label + " \t" + cntnt);            }        }    }    /**     * should look like sbx     *     * @throws Exception yepp     */    final public void dumpSbx() throws Exception {        for (int bi = 0; bi < getNumberOfBlocks(); bi++) {            for (int i = 0; i < getNumberOfLabels(); i++) {                String cntnt = getCell(i, bi);                if (cntnt == null) {                    cntnt = "#";                }                //               logger.log(Level.FINE, cntnt.replace('\n', ' '));                if (i == (getNumberOfLabels() - 1)) {                    //                   logger.log(Level.FINE, "\n");                } else {                    //                   logger.log(Level.FINE, "\t");                }            }        }    }    private void define_default_labels(String label_ref)        throws Exception {        // define the ordering of the array by storing labels        store_label(label_ref);        //    store_label(label_eudicoparticipant);        store_label(ShoeboxEncoder.elanParticipantLabel);        //    store_label(label_eudicot0);        store_label(ShoeboxEncoder.elanBeginLabel);        //    store_label(label_eudicot1);        store_label(ShoeboxEncoder.elanEndLabel);    }    /**     * Tries to keep a list of markers in the order they appear in the file. Since each block may not     * contain all markers, the result may not always be satisfactory     * @param label the label to add     * @param prevLabel the previous label in the block     */    private void storeLabelInOrder(String label, String prevLabel) {        if ((label == null) || (label.length() == 1) ||                markerOrder.contains(label)) {            return;        }        if (prevLabel == null) {            markerOrder.add(label);        } else {            if (markerOrder.size() == 0) {                markerOrder.add(label);                return;            }            for (int i = 0; i < markerOrder.size(); i++) {                if (prevLabel.equals(markerOrder.get(i))) {                    // insert after                    markerOrder.add(i + 1, label);                    return;                }            }        }    }    /**     * Testing     *     * @param arg DOCUMENT ME!     *     * @throws Exception DOCUMENT ME!     */    public static void main(String[] arg) throws Exception {        ShoeboxArray s = new ShoeboxArray(new File(arg[0]));        s.dump2();    }    /*       Add label only once     */    private void store_label(String label) throws Exception {        if (labelList.contains(label) || (label == null) ||                (label.length() == 1) || typFile.excludeFromImport(label)) {            return;        }        //       logger.log(Level.FINE,        //           getClass().getName() + ": store_label (" + label + ")...");        // rectify the name of the label.        // brute force.        // I could escape it to the XML sequence.        // boolean bad = false;        /* May 2006: doesn't seem to do anything        for (int i = 1; i < label.length(); i++) {            int c = (int) label.charAt(i);            if (!(((c >= 65) && (c <= 90)) || ((c >= 97) && (c <= 122)) ||                    ((c >= 48) && (c <= 57)))) {                // TO DO                // remove all non-ascii characters for labels                //label = label.replace(label.charAt(i), 'x');            }        }        */        labelList.add(label);        labelNodeList.add(new DefaultMutableTreeNode(label));        // skip the rest for WAC        if (readingWAC) {            return;        }        // the file has to be started with the block defining label        // OOF        if ((getNumberOfLabels() == 0) && !label.equals(label_ref)) {            throw new Exception("found '" + label + "', expected '" +                label_ref + "'.");        }        //logger.log(Level.FINE, "good label " + label + " " + labelList.indexOf(label));    }    /**     * preparation and time linking for the last block     */    private final void prepare_or_finish_block() {        //      int pax = getLabelIndex(label_eudicoparticipant);        int elanPax = getLabelIndex(ShoeboxEncoder.elanParticipantLabel);        //      int t0 = getLabelIndex(label_eudicot0);        int elanT0 = getLabelIndex(ShoeboxEncoder.elanBeginLabel);        //      int t1 = getLabelIndex(label_eudicot1);        int elanT1 = getLabelIndex(ShoeboxEncoder.elanEndLabel);        if (!isShoeboxArrayPreparation) {            if (currentIndexBlock >= 0) {                if ((shoeboxArray[elanPax][currentIndexBlock] == null) ||                        (shoeboxArray[elanPax][currentIndexBlock].length() == 0)) {                    shoeboxArray[elanPax][currentIndexBlock] = "unknown";                }                if ((shoeboxArray[elanT0][currentIndexBlock] == null) ||                        (shoeboxArray[elanT0][currentIndexBlock].length() == 0)) {                    Integer II = new Integer(-1);                    shoeboxArray[elanT0][currentIndexBlock] = II.toString();                }                if ((shoeboxArray[elanT1][currentIndexBlock] == null) ||                        (shoeboxArray[elanT1][currentIndexBlock].length() == 0)) {                    Integer II = new Integer(-1);                    shoeboxArray[elanT1][currentIndexBlock] = II.toString();                }                correctLineBreaksIfNeeded(); // if not all interlinear lines break off            }        }        currentIndexBlock += 1;        currentIndexLabel = -1; //reset        //        logger.log(Level.FINE, "     prepare_block()");    }    /**     * sideeffect on variables: currentIndexLabel, currentIndexBlock stores the     * content for this label in Array. if label is \per, store name     * seperately (aditionally) in Vector.     *     * @param label name of tier     * @param block DOCUMENT ME!     * @param content value of tier     *     * @throws Exception DOCUMENT ME!     */    private final void overwriteContent(String label, int block, String content)        throws Exception {        if (isShoeboxArrayPreparation) {            return;        }        shoeboxArray[labelList.indexOf(label)][block] = content; // store in array        shoeboxArrayMaxLength[block] = content.length();    }    /*       sideeffect on variables: currentIndexLabel, currentIndexBlock       stores the content for this label in Array.       if label is \per, store name seperately (aditionally) in Vector.     */    private final void store_label_and_content(String label, String content)        throws Exception {        //logger.log(Level.FINE, "store_label_and_content (" + label + ")(" + content + ")...");        // append to the existing content of the label        // TODO use function...        // substitute old EUDICO style labels with new ELAN style labels        if (label.equals(label_eudicoparticipant)) {            label = ShoeboxEncoder.elanParticipantLabel;        }        if (label.equals(label_eudicot0)) {            label = ShoeboxEncoder.elanBeginLabel;        }        if (label.equals(label_eudicot1)) {            label = ShoeboxEncoder.elanEndLabel;        }        //if (completelyUnaligned && label.equals(ShoeboxEncoder.elanBeginLabel)) {        //	completelyUnaligned = false;        //}        currentIndexLabel = labelList.indexOf(label);        if (isShoeboxArrayPreparation) {            return;        }        // may be a bad label...        if (currentIndexLabel < 0) {            return;        }        if (typFile.excludeFromImport(label)) {            return;        }        // may be a bad day...        // TODO...        if (currentIndexBlock < 0) {            return;        }        if ((currentIndexLabel > 0) && (currentIndexBlock > 0)) {            //System.out.println(" --------- testi a " + currentIndexBlock);            String testi = shoeboxArray[0][currentIndexBlock];            if ((testi == null) || "".equals(testi)) {                shoeboxArray[0][currentIndexBlock] = null;                //                logger.log(Level.FINE,                //                    "  stored [" + 0 + "," + currentIndexBlock +                //                    "] (-----)(null)");            }        }        //debug ("...probing oldContent " + currentIndexLabel +"//" + currentIndexBlock);        String oldContent = shoeboxArray[currentIndexLabel][currentIndexBlock];        //	if (oldContent != null) content = oldContent + "\n" + content;        // HB, 30 jul 02: concatenate content of identical labels within the same block        // using the right number of spaces iso a line break.        // HB, 31 jul 02 ---------------------------------        // Algorithm:         // - if line of interlinear block, increment the corresponding count in 'lineCounts'        // - if oldContent != null, add '\n' at beginning of current line        // - add current line to oldContent        // - if all line counts > 0, then, for all lines in interlinear block        // 	- determine largest line until first newline or end        //	- substitute first \n, or attach to end, the right number of spaces in shoeboxArray        //	- decrement all counts by one        //        // This should work irrespective of the order in which broken tiers occur (so both for tx,        // mb, gl, ps, tx, mb, gl, ps and for tx, tx, mb, mb, gl, gl, ps, ps)        if (interlinearTierMarkers.contains(label)) {            lineCounts.put(label,                new Integer(((Integer) (lineCounts.get(label))).intValue() + 1)); // incr count        }        if (oldContent != null) {            content = oldContent + "\n" + content; // concatenate with a newline by default        }        shoeboxArray[currentIndexLabel][currentIndexBlock] = content; // store in array        correctLineBreaksIfNeeded();        // HB, 31 jul 02, end of block break padding-----------------------        //        logger.log(Level.FINE,        //            "  stored [" + currentIndexLabel + "," + currentIndexBlock + "] (" +        //            label + ")(" + shoeboxArray[currentIndexLabel][currentIndexBlock] +        //            ")");        // set the maximum length of this block        int oldLen = shoeboxArrayMaxLength[currentIndexBlock];        int newLen = content.length();        int max = (oldLen < newLen) ? newLen : oldLen;        shoeboxArrayMaxLength[currentIndexBlock] = max;    }    private void correctLineBreaksIfNeeded() {        // check if we have to correct interlinear structure at block break        boolean correct = true;        Iterator markerIter = interlinearTierMarkers.iterator();        while (markerIter.hasNext()) {            if (((Integer) (lineCounts.get(markerIter.next()))).intValue() == 0) {                correct = false;                break;            }        }        if (correct) {            correctLineBreaks();        }    }    private void correctLineBreaks() {        // find maxLengthInInterlinearBlock        int maxLengthInInterlinearBlock = 0;        Iterator markerIter2 = interlinearTierMarkers.iterator();        while (markerIter2.hasNext()) {            int lblIndex = labelList.indexOf(markerIter2.next());            String c = shoeboxArray[lblIndex][currentIndexBlock];            int l = -1;            if (c != null) {                l = c.indexOf("\n"); // find first newline            }            if ((l < 0) && (c != null)) { // no newline, take length of block                l = c.length();            }            maxLengthInInterlinearBlock = (l < maxLengthInInterlinearBlock)                ? maxLengthInInterlinearBlock : l;        }        // pad each interlinear line with right number of spaces        Iterator markerIter3 = interlinearTierMarkers.iterator();        while (markerIter3.hasNext()) {            int lblIndex = labelList.indexOf(markerIter3.next());            String c = shoeboxArray[lblIndex][currentIndexBlock];            if (c != null) {                boolean nlFound = true;                int l = c.indexOf("\n"); // find first newline                if (l < 0) { // no newline, take length of block                    l = c.length();

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -