📄 tierimpl.java
字号:
} else { return currentAnnotation; } } /** * DOCUMENT ME! * * @param theAnnotation DOCUMENT ME! * * @return DOCUMENT ME! */ public Annotation getAnnotationAfter(Annotation theAnnotation) { Annotation nextAnnotation = null; Annotation currentAnnotation = null; Iterator iter = annotations.iterator(); while (iter.hasNext()) { currentAnnotation = (Annotation) iter.next(); if (currentAnnotation.equals(theAnnotation)) { if (iter.hasNext()) { nextAnnotation = (Annotation) iter.next(); } break; } } return nextAnnotation; } /** * DOCUMENT ME! * * @param time DOCUMENT ME! * * @return DOCUMENT ME! */ public Annotation getAnnotationAfter(long time) { Annotation currentAnnotation = null; Annotation resultAnnotation = null; Iterator iter = annotations.iterator(); while (iter.hasNext()) { currentAnnotation = (Annotation) iter.next(); if (currentAnnotation.getEndTimeBoundary() > time) { resultAnnotation = currentAnnotation; break; } } return resultAnnotation; } /** * Corrects overlapping time intervals using the following algorithm: * - get all begin and end TimeSlots in order of the Tier's Annotations * - get fixed TimeSlots from fixedAnnotation * - get first and second time value * - compare: if first smaller than second make second first * - if first bigger than second correct by making them equal, keeping the fixed * one fixed. Assumed is that exactly one of the pair is fixed !!!!! * - go on to the next second value * - not aligned TimeSlots are ignored */ /* public void correctTimeOverlaps(AlignableAnnotation fixedAnnotation) { System.out.println(""); System.out.println("before correction:"); ((TranscriptionImpl) parent).getTimeOrder().printTimeOrder(); Vector tiersTimeSlots = new Vector(); // add all aligned TimeSlots in Annotation order Iterator annotIter = annotations.iterator(); while (annotIter.hasNext()) { AlignableAnnotation ann = (AlignableAnnotation) annotIter.next(); if (ann.getBegin().isTimeAligned()) { tiersTimeSlots.add(ann.getBegin()); } if (ann.getEnd().isTimeAligned()) { tiersTimeSlots.add(ann.getEnd()); } } Iterator slotIter = tiersTimeSlots.iterator(); TimeSlot slot1 = null; TimeSlot slot2 = null; if (slotIter.hasNext()) { slot1 = (TimeSlot) slotIter.next(); } while (slotIter.hasNext()) { slot2 = (TimeSlot) slotIter.next(); if (slot1.getTime() <= slot2.getTime()) { // correct order slot1 = slot2; } else { // incorrect order if ( (slot1.equals(fixedAnnotation.getBegin())) || (slot1.equals(fixedAnnotation.getEnd())) ) { // slot1 fixed // adapt slot2 slot2.setTime(slot1.getTime()); } else { // slot2 fixed slot1.setTime(slot2.getTime()); } } } // delete any completely overlapped Annotations. Tests: for aligned timeslots, // check if begintime is equal to end time, for unaligned slots, check if there is // a non zero time gap left (getTimeBegin/EndBoundary not equal). System.out.println(""); System.out.println("after correction:"); ((TranscriptionImpl) parent).getTimeOrder().printTimeOrder(); markAnnotationsForDeletion(); //MK:02/06/12 quick fix //MK:02/06/17 removed guard in order to find the cause of the problem // if (parent instanceof TranscriptionImpl) { ((TranscriptionImpl) parent).pruneAnnotations(); // prunes all tiers // } } */ public void correctTimeOverlaps(AlignableAnnotation fixedAnnotation) { TimeSlot fixedSlot1 = fixedAnnotation.getBegin(); TimeSlot fixedSlot2 = fixedAnnotation.getEnd(); if (!fixedSlot1.isTimeAligned()) { return; } if (!fixedSlot2.isTimeAligned()) { return; } // get annotations that are connected to fixedAnnotation by one graph TreeSet connectedAnnots = new TreeSet(); TreeSet connectedTimeSlots = new TreeSet(); //((TranscriptionImpl) parent).getConnectedAnnots(connectedAnnots, // connectedTimeSlots, fixedSlot1); ((TranscriptionImpl) parent).getConnectedAnnots(connectedAnnots, connectedTimeSlots, fixedAnnotation); Vector connectedAnnotVector = new Vector(connectedAnnots); //Vector connectedTimeSlotVector = new Vector(connectedTimeSlots); // the annotation TreeSet sometimes contains duplicate elements (although it is a Set), probably // due to oddities in the compareTo method in AbstractAnnotation ArrayList correctedAnnos = new ArrayList(connectedAnnotVector.size()); // find 'begin' and 'end' timeslot of connected graph TimeSlot[] graphEndpoints = getGraphEndpoints(connectedAnnotVector); // get all overlapping annotations on this tier and their alignable children TreeSet overlappingAnnots = new TreeSet(); // oct 04 old implementation //Iterator annotIter = getOverlappingAnnotations(fixedSlot1.getTime(), fixedSlot2.getTime()).iterator(); // oct 04 old 2 implementation //Iterator annotIter = getOverlappingAnnotations(fixedSlot1.getTime(), // fixedSlot2.getTime(), true).iterator(); // aug 05 include extremes, to solve problems on time subdivision tiers (new annotation // over existing annotations, starting at begin time of parent annotation Iterator annotIter = getOverlappingAnnotationsIncludeExtremes(fixedSlot1, fixedSlot2).iterator(); while (annotIter.hasNext()) { AlignableAnnotation ann = (AlignableAnnotation) annotIter.next(); if (ann != fixedAnnotation) { overlappingAnnots.add(ann); } // then add ann's alignable children. // Note HS July 2006: in the process of propagation of changes as a result of the addition of a new // annotation, getChildAnnotationsOf returns (graph based) overlapping annotations rather then child annotations Vector children = ((TranscriptionImpl) parent).getChildAnnotationsOf(ann); if (children.size() > 0) { Iterator childIter = children.iterator(); while (childIter.hasNext()) { Annotation child = (Annotation) childIter.next(); if (child instanceof AlignableAnnotation) { //AlignableAnnotation a = (AlignableAnnotation) child; overlappingAnnots.add((AlignableAnnotation) child); } } } } Vector overlappingAnnotVector = new Vector(overlappingAnnots); // put overlappingAnnots in Vector, in order given by graph, starting at graphBegin // then add remaining annots to result, in original order overlappingAnnotVector = inGraphOrder(overlappingAnnotVector, graphEndpoints[0]); boolean forcedInside = false; // now correct each overlapping annotation Iterator overlappingAnnotIter = overlappingAnnotVector.iterator(); while (overlappingAnnotIter.hasNext()) { AlignableAnnotation aa = (AlignableAnnotation) overlappingAnnotIter.next(); if (correctedAnnos.contains(aa)) { continue; } else { correctedAnnos.add(aa); } Constraint cc = ((TierImpl) aa.getTier()).getLinguisticType() .getConstraints(); // 3 different cases: // - an annotation not connected to aa's graph overlaps aa // - the fixedAnnotation is the root annotation of aa's graph // - the fixedAnnotation is a dependent annotation in aa's graph if ((cc != null) && (cc.getStereoType() == Constraint.INCLUDED_IN)) { if (fixedAnnotation.isAncestorOf(aa)) { forceAnnotationInInterval(aa, fixedAnnotation); } else { forceOutOfFixedInterval(aa, fixedAnnotation); } } else if (!connectedAnnotVector.contains(aa)) { // other annotation overlaps aa if (aa.getTier() == fixedAnnotation.getTier()) { forceOutOfFixedInterval(aa, fixedAnnotation); // update children first forceChildAnnotationsOfAlignable(aa); } } // special case for included in? else if (!fixedAnnotation.hasParentAnnotation()) { // fixed annot is root of graph // this only needs to be called once, works only on this tier?? if (!forcedInside) { forceInsideFixedInterval(graphEndpoints, fixedAnnotation); forcedInside = true; } if ((cc != null) && (cc.getStereoType() == Constraint.TIME_SUBDIVISION)) { forceTSInsideFixedInterval(aa, graphEndpoints, fixedAnnotation); } } else { // fixedAnnotation is dependent member of graph if (aa.getTier() == fixedAnnotation.getTier()) { forceAnnotChainOutOfFixedInterval(graphEndpoints, fixedSlot1, fixedSlot2); if (aa.getBegin().isTimeAligned() && (aa.getBegin().getTime() < aa.getEnd().getTime())) { // update children if ((aa.getBegin().getTime() < fixedSlot1.getTime()) && (aa.getEnd().getTime() > fixedSlot1.getTime())) { forceChildChainOutOfInterval(aa, graphEndpoints, fixedSlot1, fixedSlot2, true); } else if ((aa.getBegin().getTime() <= fixedSlot2.getTime()) && (aa.getEnd().getTime() > fixedSlot2.getTime())) { forceChildChainOutOfInterval(aa, graphEndpoints, fixedSlot1, fixedSlot2, false); } } } } } // special iteration for connected Include_In descendant annotations Iterator connAnnotIter = connectedAnnotVector.iterator(); while (connAnnotIter.hasNext()) { AlignableAnnotation aa = (AlignableAnnotation) connAnnotIter.next(); if (correctedAnnos.contains(aa)) { continue; } else { correctedAnnos.add(aa); } if (overlappingAnnotVector.contains(aa) || (aa == fixedAnnotation)) { continue; } if (!((TierImpl) aa.getTier()).hasAncestor(this)) { continue; } Constraint cc = ((TierImpl) aa.getTier()).getLinguisticType() .getConstraints(); if ((cc != null) && (cc.getStereoType() == Constraint.INCLUDED_IN)) { if (fixedAnnotation.isAncestorOf(aa)) { forceAnnotationInInterval(aa, fixedAnnotation); } else { forceOutOfFixedInterval(aa, fixedAnnotation); } overlappingAnnotVector.add(aa); // eventually mark for deletion } else if ((cc != null) && (cc.getStereoType() == Constraint.TIME_SUBDIVISION)) { // special case to handle the event of a time subdivision annotation's time has been modified if (!fixedAnnotation.isAncestorOf(aa)) { forceOutOfFixedInterval(aa, fixedAnnotation); overlappingAnnotVector.add(aa); // eventually mark for deletion } } } // HB, 12-8-04, reposition unaligned slots // start at graph begin, find next annot on this tier following the graph, until graph end. // correct order for each (partially) unaligned annotation repositionUnalignedSlots(graphEndpoints[0]); if (overlappingAnnotVector.size() > 0) { // delete any completely overlapped Annotations. Tests: for aligned timeslots, // check if begintime is equal to end time, for unaligned slots, check if there is // a non zero time gap left (getTimeBegin/EndBoundary not equal). //markAnnotationsForDeletion(new Vector(overlappingAnnots)); markAnnotationsForDeletion(overlappingAnnotVector); ((TranscriptionImpl) parent).pruneAnnotations(this); // prunes tiers that possibly are changed } } /** * DOCUMENT ME! * * @param connectedAnnotVector DOCUMENT ME! * * @return DOCUMENT ME! */ public TimeSlot[] getGraphEndpoints(Vector connectedAnnotVector) { TimeSlot[] endpoints = new TimeSlot[2];
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -