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

📄 notimegapwithinparent.java

📁 编辑视频文件
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
            Annotation ann = (Annotation) childIter.next();            if (ann.getTier() == theTier) {                enclosedAnnots.add(ann);            }        }        if (enclosedAnnots.size() > 0) {            AlignableAnnotation prev = null;            AlignableAnnotation next = null;            int index = enclosedAnnots.indexOf(a);            if (index > 0) {                prev = (AlignableAnnotation) (enclosedAnnots.get(index - 1));            }            // july 2006: added a test (index > -1); if "a" is not in the vector            // it is incorrect to just take the first child annotation as "next"                        if ((index > -1) && (index < (enclosedAnnots.size() - 1))) {                next = (AlignableAnnotation) (enclosedAnnots.get(index + 1));            }            // reconnect            if (prev != null) {                //    prev.setEnd(a.getEnd());                if (prev.isMarkedDeleted()) {                    // don't bother to reconnect an annotation that has been marked deleted                    return;                }                Vector endingAtTs = ((TranscriptionImpl) (theTier.getParent())).getAnnotsEndingAtTimeSlot(prev.getEnd(),                        theTier, true);                for (int i = 0; i < endingAtTs.size(); i++) {                    ((AlignableAnnotation) endingAtTs.elementAt(i)).setEnd(a.getEnd());                }            } else if (next != null) {                //    next.setBegin(a.getBegin());                if (next.isMarkedDeleted()) {                    //don't bother to reconnect an annotation that has been marked deleted??                    // sometimes this is needed? revise..                    //return;                }                Vector beginningAtTs = ((TranscriptionImpl) (theTier.getParent())).getAnnotsBeginningAtTimeSlot(next.getBegin(),                        theTier, true);                for (int i = 0; i < beginningAtTs.size(); i++) {                    ((AlignableAnnotation) beginningAtTs.elementAt(i)).setBegin(a.getBegin());                }            }        }    }    /**     * Recursively sets the begin time slot of the proper annotation on the specified tier; if the annotation is not time aligned,     * it finds the first preceding annotation on that tier with a time aligned begin slot and changes that slot, if it is     * a chile of the specified parent annotation.     * @param nextT the tier     * @param parentAA the parent annotation on the parent tier     * @param ets the new begin slot     * @param the time to start searching for an annotation     */    private void setAlignableBeginSlot(TierImpl nextT,        AlignableAnnotation parentAA, TimeSlot ets, long end) {        if (parentAA == null) {            return;        }        if (nextT.getLinguisticType().getConstraints().getStereoType() == Constraint.INCLUDED_IN) {            return; // test        }        AlignableAnnotation nextAA = (AlignableAnnotation) nextT.getAnnotationAtTime(end);        Vector childT = nextT.getChildTiers();        TierImpl ch;        if (nextAA != null) {            if (nextAA.getBegin().isTimeAligned()) {                if (parentAA.getParentListeners().contains(nextAA)) {                    for (int i = 0; i < childT.size(); i++) {                        ch = (TierImpl) childT.get(i);                        if (ch.isTimeAlignable()) {                            setAlignableBeginSlot(ch, nextAA, ets, end);                        }                    }                    nextAA.setBegin(ets);                }            } else {                // find the first preceding aligned begin time slot/annotation, but don't pass the parent's begin slot                boolean found = false;                Vector annos;                while (!found) {                    annos = nextT.getAnnotsEndingAtTimeSlot(nextAA.getBegin());                    for (int j = 0; j < annos.size(); j++) {                        nextAA = (AlignableAnnotation) annos.get(j);                        if ((nextAA.getBegin().isTimeAligned() ||                                (parentAA.getBegin() == nextAA.getBegin())) &&                                parentAA.getParentListeners().contains(nextAA)) {                            for (int i = 0; i < childT.size(); i++) {                                ch = (TierImpl) childT.get(i);                                if (ch.isTimeAlignable()) {                                    setAlignableBeginSlot(ch, nextAA, ets, end);                                }                            }                            nextAA.setBegin(ets);                            found = true;                        }                    }                    if (annos.size() == 0) {                        break; // error                    }                }            }        } else {            // find a child of parent            Vector ba = nextT.getAnnotsBeginningAtTimeSlot(parentAA.getBegin());            for (int j = 0; j < ba.size(); j++) {                nextAA = (AlignableAnnotation) ba.get(j);                for (int i = 0; i < childT.size(); i++) {                    ch = (TierImpl) childT.get(i);                    if (ch.isTimeAlignable()) {                        setAlignableBeginSlot(ch, nextAA, ets, end);                    }                }                nextAA.setBegin(ets);            }        }    }    /**     * Recursively sets the end time slot of the specified annotation if it is time aligned and reconnects the next annotation     * to that new slot (if it has the same parent). If it is not time aligned it finds the first following annotation     * that has a time aligned end slot.     * @param nextT the tier     * @param parentAA the parent annotation on the parent tier     * @param bts the (new) begin time slot     * @param ets the (new) end time slot     * @param begin the begin time for a new annotation     * @param end the end time for a new annotation     */    private void setAlignableEndSlot(TierImpl nextT,        AlignableAnnotation parentAA, TimeSlot bts, TimeSlot ets, long begin,        long end) {        if (parentAA == null) {            return;        }        if (nextT.getLinguisticType().getConstraints().getStereoType() == Constraint.INCLUDED_IN) {            return; // test        }        AlignableAnnotation nextAA = (AlignableAnnotation) nextT.getAnnotationAtTime(begin);        Vector childT = nextT.getChildTiers();        TierImpl ch;        if (nextAA != null) {            TimeSlot oldEndTS;            if (nextAA.getBegin().getTime() != begin) { // true for any unaligned begin slot                oldEndTS = nextAA.getEnd();                if (nextAA.getEnd().isTimeAligned() ||                        (nextAA.getEnd() == parentAA.getEnd())) {                    for (int i = 0; i < childT.size(); i++) {                        ch = (TierImpl) childT.get(i);                        if (ch.isTimeAlignable()) {                            setAlignableEndSlot(ch, nextAA, bts, ets, begin, end);                        }                    }                    nextAA.setEnd(bts);                    // reconnect the following annotation                    if ((oldEndTS != ets) || (oldEndTS.getTime() < end)) { // && ??                        Vector vv = nextT.getAnnotsBeginningAtTimeSlot(oldEndTS);                        for (int j = 0; j < vv.size(); j++) {                            nextAA = (AlignableAnnotation) vv.get(j);                            // if (parentAA.getParentListeners().contains(nextAA)) {                            nextAA.setBegin(bts);                            //}                        }                    }                } else {                    // find first following aligned annotation/slot                    boolean found = false;                    Vector annos;                    while (!found) {                        annos = nextT.getAnnotsBeginningAtTimeSlot(nextAA.getEnd());                        for (int j = 0; j < annos.size(); j++) {                            nextAA = (AlignableAnnotation) annos.get(j);                            oldEndTS = nextAA.getEnd();                            if (nextAA.getEnd().isTimeAligned()) {                                for (int i = 0; i < childT.size(); i++) {                                    ch = (TierImpl) childT.get(i);                                    if (ch.isTimeAlignable()) {                                        setAlignableEndSlot(ch, nextAA, bts,                                            ets, begin, end);                                    }                                }                                nextAA.setEnd(bts);                                found = true;                                //reconnect the following annotation                                if ((oldEndTS != ets) ||                                        (oldEndTS.getTime() < end)) { // && ??                                    Vector vv = nextT.getAnnotsBeginningAtTimeSlot(oldEndTS);                                    for (int k = 0; k < vv.size(); k++) {                                        nextAA = (AlignableAnnotation) vv.get(k);                                        //if (parentAA.getParentListeners().contains(nextAA)) {                                        nextAA.setBegin(bts);                                        // }                                    }                                }                            }                        }                        if (annos.size() == 0) { // end of (sub) chain                            break; // error                        }                    }                }            } else {                // if the begin time happens to coincide with an existing dep. begin timeslot, replace begin                TimeSlot oldBeginTS = nextAA.getBegin();                for (int i = 0; i < childT.size(); i++) {                    ch = (TierImpl) childT.get(i);                    if (ch.isTimeAlignable()) {                        setAlignableEndSlot(ch, nextAA, bts, ets, begin, end);                    }                }                nextAA.setBegin(bts);                // reconnect the previous annotation..                Vector vv = nextT.getAnnotsEndingAtTimeSlot(oldBeginTS);                for (int k = 0; k < vv.size(); k++) {                    nextAA = (AlignableAnnotation) vv.get(k);                    nextAA.setEnd(bts);                }            }        }        /* else {            // find annotation beginning at parent's end, reconnect            Vector ba = nextT.getAnnotsBeginningAtTimeSlot(parentAA.getEnd());            for (int j = 0; j < ba.size();  j++) {                nextAA = (AlignableAnnotation) ba.get(j);                for (int i = 0; i < childT.size(); i++) {                    ch = (TierImpl) childT.get(i);                    if (ch.isTimeAlignable()) {                        setAlignableEndSlot(ch, nextAA, bts, ets, begin, end);                    }                }                nextAA.setBegin(bts);            }        }        */    }    /**     * Finds the next annotation with an alignable end slot, under the same parent annotation.     * @param tier the tier the annotations are on     * @param fromAnn the starting point for the search to the right     * @return the first aligned annotation     */    /*    private AlignableAnnotation getNextAlignedAnnotation(TierImpl tier, AlignableAnnotation fromAnn) {        if (tier == null || fromAnn == null) {            return null;        }        AlignableAnnotation resAnn = null;        AlignableAnnotation loopAnn = fromAnn;        Vector anns = null;        outerloop:        while (true) {            anns = tier.getAnnotsBeginningAtTimeSlot(loopAnn.getEnd());            for (int i = 0; i < anns.size(); i++) {                loopAnn = (AlignableAnnotation) anns.get(i);                if (loopAnn.getParentAnnotation() != fromAnn.getParentAnnotation()) {                    break outerloop;                }                if (loopAnn.getEnd().isTimeAligned()) {                    resAnn = loopAnn;                    break outerloop;                }            }            resAnn = loopAnn;// save last ref in this vector            if (anns.size() == 0) {                break;            }        }        return resAnn;    }    */    /**     * Finds the first annotation in the chain with an alignable end slot, under the same parent annotation.     * @param tier the tier the annotations are on     * @param fromAnn the starting point for the search to the left     * @return the first aligned annotation     */    private AlignableAnnotation getFirstAlignedAnnotation(TierImpl tier,        AlignableAnnotation fromAnn) {        if ((tier == null) || (fromAnn == null)) {            return null;        }        AlignableAnnotation resAnn = null;        AlignableAnnotation loopAnn = fromAnn;        Vector anns = null;outerloop:         while (true) {            anns = tier.getAnnotsEndingAtTimeSlot(loopAnn.getBegin());            for (int i = 0; i < anns.size(); i++) {                loopAnn = (AlignableAnnotation) anns.get(i);                if (loopAnn.getParentAnnotation() != fromAnn.getParentAnnotation()) {                    break outerloop;                }                if (loopAnn.getBegin().isTimeAligned()) {                    resAnn = loopAnn;                    break outerloop;                }            }            resAnn = loopAnn; // save last ref in this vector            if (anns.size() == 0) {                break;            }        }        return resAnn;    }}

⌨️ 快捷键说明

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