tierimpl.java
来自「编辑视频文件」· Java 代码 · 共 1,749 行 · 第 1/5 页
JAVA
1,749 行
Iterator annIter = connectedAnnotVector.iterator(); while (annIter.hasNext()) { AlignableAnnotation ann = (AlignableAnnotation) annIter.next(); if (!ann.hasParentAnnotation()) { // assume there is only one root annot in a graph endpoints[0] = ann.getBegin(); endpoints[1] = ann.getEnd(); break; } } return endpoints; } /** * Returns the timeslots where the 'subchain' containing theSlot connects to * either an aligned timeslot or an unaligned slot shared with a parent annotation. * * @param theSlot * @return */ public TimeSlot[] getEndpointsOfSubchain(TimeSlot theSlot, boolean stopAtAlignedSlot) { TimeSlot[] endpoints = new TimeSlot[2]; endpoints[0] = getBeginSlotOfChain(theSlot, stopAtAlignedSlot); endpoints[1] = getEndSlotOfChain(theSlot, stopAtAlignedSlot); return endpoints; } /** * Starting at theSlot, find the last time slot of annotations connected * to it in the same 'chain' on this tier. * * @param theSlot * @return */ public TimeSlot getEndSlotOfChain(TimeSlot theSlot, boolean stopAtAlignedSlot) { TimeSlot endSlot = theSlot; if (((getParentTier() != null) && (((TierImpl) getParentTier()).getAnnotationsUsingTimeSlot( endSlot).size() > 0))) { return endSlot; } Vector annotsFromSlot = getAnnotsBeginningAtTimeSlot(theSlot); if (annotsFromSlot.size() > 0) { AlignableAnnotation nextAnnot = (AlignableAnnotation) annotsFromSlot.firstElement(); TimeSlot nextSlot = nextAnnot.getEnd(); if ((nextSlot.isTimeAligned() && stopAtAlignedSlot) || ((getParentTier() != null) && (((TierImpl) getParentTier()).getAnnotationsUsingTimeSlot( nextSlot).size() > 0))) { // end found, stop endSlot = nextSlot; } else { endSlot = getEndSlotOfChain(nextSlot, stopAtAlignedSlot); } } return endSlot; } /** * Starting at theSlot, find the first time slot of annotations connected * to it in the same 'chain' on this tier. * * @param theSlot * @return */ public TimeSlot getBeginSlotOfChain(TimeSlot theSlot, boolean stopAtAlignedSlot) { TimeSlot beginSlot = theSlot; if (((getParentTier() != null) && (((TierImpl) getParentTier()).getAnnotationsUsingTimeSlot( beginSlot).size() > 0))) { return beginSlot; } Vector annotsToSlot = getAnnotsEndingAtTimeSlot(theSlot); if (annotsToSlot.size() > 0) { AlignableAnnotation prevAnnot = (AlignableAnnotation) annotsToSlot.firstElement(); TimeSlot prevSlot = prevAnnot.getBegin(); if ((prevSlot.isTimeAligned() && stopAtAlignedSlot) || ((getParentTier() != null) && (((TierImpl) getParentTier()).getAnnotationsUsingTimeSlot( prevSlot).size() > 0))) { // end found, stop beginSlot = prevSlot; } else { beginSlot = getBeginSlotOfChain(prevSlot, stopAtAlignedSlot); } } return beginSlot; } private Vector inGraphOrder(Vector overlappingAnnots, TimeSlot graphBegin) { TimeSlot aBegin = graphBegin; TimeSlot aEnd = graphBegin; Vector annsForTS = null; AlignableAnnotation currentA = null; Vector result = new Vector(); while (aEnd != null) { annsForTS = this.getAnnotsBeginningAtTimeSlot(aBegin); if ((annsForTS != null) && (annsForTS.size() > 0)) { currentA = (AlignableAnnotation) annsForTS.firstElement(); aEnd = currentA.getEnd(); if (overlappingAnnots.contains(currentA)) { result.add(currentA); } aBegin = aEnd; } else { aEnd = null; } } // and add remaining to result Iterator remainingIter = overlappingAnnots.iterator(); while (remainingIter.hasNext()) { AlignableAnnotation remA = (AlignableAnnotation) remainingIter.next(); if (!result.contains(remA)) { result.add(remA); } } return result; } private void forceOutOfFixedInterval(AlignableAnnotation aa, AlignableAnnotation fixedAnnotation) { TimeSlot begin = aa.getBegin(); TimeSlot end = aa.getEnd(); TimeSlot fixedSlot1 = fixedAnnotation.getBegin(); TimeSlot fixedSlot2 = fixedAnnotation.getEnd(); if (aa.getTier() == this) { boolean beginInFixedInterval = false; boolean endInFixedInterval = false; TreeSet connAnnots = new TreeSet(); TreeSet connTimeSlots = new TreeSet(); ((TranscriptionImpl) parent).getConnectedAnnots(connAnnots, connTimeSlots, begin); if ((begin.isAfter(fixedSlot1) && fixedSlot2.isAfter(begin)) || (begin.getTime() == fixedSlot1.getTime())) { beginInFixedInterval = true; } if ((end.isAfter(fixedSlot1) && fixedSlot2.isAfter(end)) || (end.getTime() == fixedSlot1.getTime())) { endInFixedInterval = true; } if (beginInFixedInterval && !endInFixedInterval) { // only begin in fixed interval // force all connected timeslot to after fixedSlot2 shiftAfterTimeSlot(fixedSlot2, connTimeSlots); } else { // all other cases // force all connected timeslots to before fixedSlot1 shiftBeforeTimeSlot(fixedSlot1, connTimeSlots); } } else { // handle annotations on Included_In tiers here Constraint cc = ((TierImpl) aa.getTier()).getLinguisticType() .getConstraints(); if ((cc != null) && (cc.getStereoType() == Constraint.INCLUDED_IN)) { if ((begin.getTime() >= fixedAnnotation.getBeginTimeBoundary()) && (begin.getTime() < fixedAnnotation.getEndTimeBoundary())) { begin.setTime(fixedAnnotation.getEndTimeBoundary()); if (end.getTime() < fixedAnnotation.getEndTimeBoundary()) { end.setTime(fixedAnnotation.getEndTimeBoundary()); } } else if ((begin.getTime() < fixedAnnotation.getBeginTimeBoundary()) && (end.getTime() > fixedAnnotation.getBeginTimeBoundary())) { end.setTime(fixedAnnotation.getBeginTimeBoundary()); } else if ((begin.getTime() < fixedAnnotation.getBeginTimeBoundary()) && (end.getTime() >= fixedAnnotation.getEndTimeBoundary())) { // shift to front end.setTime(fixedAnnotation.getBeginTimeBoundary()); } // update existing Time_Subdivision and Included_In child tiers forceChildAnnotationsOfAlignable(aa); } else if ((cc != null) && (cc.getStereoType() == Constraint.TIME_SUBDIVISION)) { if (aa.getBegin().isTimeAligned() && aa.getEnd().isTimeAligned() && (aa.getBegin().getTime() > fixedAnnotation.getBegin() .getTime()) && (aa.getEnd().getTime() < fixedAnnotation.getEnd() .getTime())) { aa.markDeleted(true); } else if (aa.getBegin().isTimeAligned() && (aa.getBegin().getTime() <= fixedAnnotation.getEnd() .getTime()) && (aa.getBegin().getTime() > fixedAnnotation.getBegin() .getTime()) && (aa.getEnd().getTime() >= fixedAnnotation.getEnd() .getTime())) { // reconnect at the right side, the counterpart on the left side is handled elsewhere? aa.setBegin(fixedAnnotation.getEnd()); forceChildAnnotationsOfAlignable(aa); } } } } private void shiftAfterTimeSlot(TimeSlot fixedSlot, TreeSet connTimeSlots) { TimeSlot lastShiftedSlot = null; Iterator tsIter = connTimeSlots.iterator(); while (tsIter.hasNext()) { TimeSlot ts = (TimeSlot) tsIter.next(); if (fixedSlot.isAfter(ts)) { if (ts.isTimeAligned()) { ts.setTime(fixedSlot.getTime()); lastShiftedSlot = ts; } else { // keep with last shifted time slot ((TranscriptionImpl) parent).getTimeOrder().removeTimeSlot(ts); ((TranscriptionImpl) parent).getTimeOrder().insertTimeSlot(ts, lastShiftedSlot, null); // July 2006: keep unaligned slot in the right order lastShiftedSlot = ts; } } } } private void shiftBeforeTimeSlot(TimeSlot fixedSlot, TreeSet connTimeSlots) { TimeSlot lastShiftedSlot = null; Iterator tsIter = connTimeSlots.iterator(); while (tsIter.hasNext()) { TimeSlot ts = (TimeSlot) tsIter.next(); if (ts.isAfter(fixedSlot)) { if (ts.isTimeAligned()) { ts.setTime(fixedSlot.getTime()); lastShiftedSlot = ts; } else { // keep with last shifted time slot ((TranscriptionImpl) parent).getTimeOrder().removeTimeSlot(ts); ((TranscriptionImpl) parent).getTimeOrder().insertTimeSlot(ts, lastShiftedSlot, null); } } } } /* private void forceInsideFixedInterval(AlignableAnnotation aa, AlignableAnnotation fixedAnnotation) { TimeSlot begin = aa.getBegin(); TimeSlot end = aa.getEnd(); TimeSlot fixedSlot1 = fixedAnnotation.getBegin(); TimeSlot fixedSlot2 = fixedAnnotation.getEnd(); if (fixedSlot1.isAfter(begin)) { if (begin.isTimeAligned() && (begin != fixedSlot1)) { begin.setTime(fixedSlot1.getTime()); } else { ((TranscriptionImpl) parent).getTimeOrder().removeTimeSlot(begin); ((TranscriptionImpl) parent).getTimeOrder().insertTimeSlot(begin, fixedSlot1, null); } } if (fixedSlot1.isAfter(end)) { if (end.isTimeAligned() && (end != fixedSlot2)) { end.setTime(fixedSlot1.getTime()); } else { ((TranscriptionImpl) parent).getTimeOrder().removeTimeSlot(end); ((TranscriptionImpl) parent).getTimeOrder().insertTimeSlot(end, begin, null); } } if (begin.isAfter(fixedSlot2)) { if (begin.isTimeAligned() && (begin != fixedSlot1)) { begin.setTime(fixedSlot2.getTime()); } else { ((TranscriptionImpl) parent).getTimeOrder().removeTimeSlot(begin); ((TranscriptionImpl) parent).getTimeOrder().insertTimeSlot(begin, null, fixedSlot2); } } if (end.isAfter(fixedSlot2)) { if (end.isTimeAligned() && (end != fixedSlot2)) { end.setTime(fixedSlot2.getTime()); } else { ((TranscriptionImpl) parent).getTimeOrder().removeTimeSlot(end); ((TranscriptionImpl) parent).getTimeOrder().insertTimeSlot(end, begin, null); } } } */ private void forceInsideFixedInterval(TimeSlot[] graphEndpoints, AlignableAnnotation fixedAnnotation) { TimeSlot annBegin = graphEndpoints[0]; TimeSlot annEnd = graphEndpoints[0]; Vector annotsForTS = null; AlignableAnnotation currentAnn = null; while (annEnd != null) { annotsForTS = this.getAnnotsBeginningAtTimeSlot(annBegin); if ((annotsForTS != null) && (annotsForTS.size() > 0)) { currentAnn = (AlignableAnnotation) annotsForTS.firstElement(); annEnd = currentAnn.getEnd(); if (annEnd.isTimeAligned() && (annEnd.getTime() < fixedAnnotation.getBegin().getTime())) { annEnd.setTime(fixedAnnotation.getBegin().getTime()); } if (!annEnd.isTimeAligned() && fixedAnnotation.getBegin().isAfter(annEnd)) { ((TranscriptionImpl) parent).getTimeOrder().removeTimeSlot(annEnd); ((TranscriptionImpl) parent).getTimeOrder().insertTimeSlot(annEnd, fixedAnnotation.getBegin(), null); } annBegin = annEnd; } else { annEnd = null;
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?