📄 alignableannotation.java
字号:
/* * File: AlignableAnnotation.java * Project: MPI Linguistic Application * Date: 02 May 2007 * * Copyright (C) 2001-2007 Max Planck Institute for Psycholinguistics * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */package mpi.eudico.server.corpora.clomimpl.abstr;import mpi.eudico.server.corpora.clom.Annotation;import mpi.eudico.server.corpora.clom.Tier;import mpi.eudico.server.corpora.clom.TimeSlot;import mpi.eudico.server.corpora.clom.Transcription;import mpi.eudico.server.corpora.clomimpl.type.Constraint;import mpi.eudico.server.corpora.clomimpl.type.LinguisticType;import mpi.eudico.server.corpora.util.ACMEditEvent;import java.util.ArrayList;import java.util.Enumeration;import java.util.EventObject;import java.util.TreeSet;import java.util.Vector;/** * DOCUMENT ME! $Id: AlignableAnnotation.java,v 1.12 2005/02/16 12:56:41 hasloe * Exp $ * * @author $Author: hasloe $ * @version $Revision: 1.18 $ */public class AlignableAnnotation extends AbstractAnnotation { /** Holds value of property DOCUMENT ME! */ TimeSlot beginTime; /** Holds value of property DOCUMENT ME! */ TimeSlot endTime; /** * Creates a new AlignableAnnotation instance * * @param bts DOCUMENT ME! * @param ets DOCUMENT ME! * @param theTier DOCUMENT ME! */ public AlignableAnnotation(TimeSlot bts, TimeSlot ets, Tier theTier) { super(); beginTime = bts; endTime = ets; this.setTier(theTier); // NOTE: this code assumes that parent Annotation already exists. // When reading in a document, this assumption does not always hold. // Therefore, when initially reading in a document, registerWithParent() // has to be called after all AlignableAnnotations are constructed. registerWithParent(); } /** * Registers this AlignableAnnotation as a ParentAnnotationListener with * the parent annotation. (Is the counterpart of * RefAnnotation.addReference). */ public void registerWithParent() { if (hasParentAnnotation()) { Annotation p = getParentAnnotation(); if (p != null) { p.addParentAnnotationListener(this); } } } /** * DOCUMENT ME! * * @return DOCUMENT ME! */ public TimeSlot getBegin() { return beginTime; } /** * DOCUMENT ME! * * @param theBegin DOCUMENT ME! */ public void setBegin(TimeSlot theBegin) { beginTime = theBegin; } /** * DOCUMENT ME! * * @return DOCUMENT ME! */ public TimeSlot getEnd() { return endTime; } /** * DOCUMENT ME! * * @param theEnd DOCUMENT ME! */ public void setEnd(TimeSlot theEnd) { endTime = theEnd; } /** * DOCUMENT ME! * * @param beginTime DOCUMENT ME! * @param endTime DOCUMENT ME! */ public void updateTimeInterval(long beginTime, long endTime) { long oldBegin = getBegin().getTime(); long oldEnd = getEnd().getTime(); // HS feb 2005: first check times in relation to the parent annotation's // begin and end time AlignableAnnotation parent = null; if (this.hasParentAnnotation()) { parent = (AlignableAnnotation) this.getParentAnnotation(); if ((beginTime >= parent.getEnd().getTime()) || (endTime <= parent.getBegin().getTime())) { return; } if (endTime >= parent.getEnd().getTime()) { endTime = parent.getEnd().getTime(); // July 06: See comments at setBegin below. // this all needs to be revised... // setEnd(parent.getEnd()); } if (beginTime <= parent.getBegin().getTime()) { beginTime = parent.getBegin().getTime(); // July 06: to ensure that the annotations will be given the right time slot reference and // overlapping annotations to be cleaned up, set the begin slot here. // This doesn't work with the end slot though (due to the way overlapping annotations are // forced out of the interval and later detached from the tier (see alsp TierImpl) setBegin(parent.getBegin()); } } TreeSet connectedAnnots = new TreeSet(); TreeSet connectedTimeSlots = new TreeSet(); (((TranscriptionImpl) ((TierImpl) getTier()).getParent())).getConnectedAnnots(connectedAnnots, connectedTimeSlots, getBegin()); Vector connectedAnnotVector = new Vector(connectedAnnots); TimeSlot[] graphEndpoints = ((TierImpl) getTier()).getGraphEndpoints(connectedAnnotVector); if (!((getBegin() == graphEndpoints[0]) && hasParentAnnotation()) && !((parent != null) && (getBegin() == parent.getBegin()))) { getBegin().setTime(beginTime); } if (!((getEnd() == graphEndpoints[1]) && hasParentAnnotation()) && !((parent != null) && (getEnd() == parent.getEnd()))) { getEnd().setTime(endTime); } // HB, 27-feb-02: correct potential time overlaps if ((((TranscriptionImpl) (((TierImpl) getTier()).getParent())).getTimeChangePropagationMode() == Transcription.BULLDOZER) && (!hasParentAnnotation())) { ((TierImpl) getTier()).correctOverlapsByPushing(this, oldBegin, oldEnd); } else if ((((TranscriptionImpl) (((TierImpl) getTier()).getParent())).getTimeChangePropagationMode() == Transcription.SHIFT) && (!hasParentAnnotation())) { Vector fixedSlots = new Vector(connectedTimeSlots); ((TranscriptionImpl) (((TierImpl) getTier()).getParent())).correctOverlapsByShifting(this, fixedSlots, oldBegin, oldEnd); ((TierImpl) getTier()).correctTimeOverlaps(this); } else { ((TierImpl) getTier()).correctTimeOverlaps(this); } // HB, 10 apr 03, notify child annotations about time change notifyParentListeners(); // HS jan 2005, (partially) unaligned children cannot mark themselves as // deleted, take care of this here and now cleanUpUnalignedChildAnnotations(); ((TranscriptionImpl) (((TierImpl) getTier()).getParent())).pruneAnnotations(this.getTier()); // HS jan 05: preliminary fix for the case one annotation has been moved beyond another // on the same tier. The order of the annotations in the TreeSet has become inconsistent boolean consistent = checkAnnotationOrderConsistency((TierImpl) this.getTier()); if (!consistent) { // reuse the previously stored time slots resortAnnotationsAndSlots(connectedTimeSlots); } // end preliminary fix modified(ACMEditEvent.CHANGE_ANNOTATION_TIME, this); } /** * DOCUMENT ME! * * @return DOCUMENT ME! */ public long getBeginTimeBoundary() { long beginBoundary = 0; if (beginTime.isTimeAligned()) { beginBoundary = beginTime.getTime(); } else { // oct 04: the if part added for performance reasons if (((TimeSlotImpl) beginTime).getProposedTime() >= 0) { beginBoundary = ((TimeSlotImpl) beginTime).getProposedTime(); } else { beginBoundary = ((TierImpl) getTier()).proposeTimeFor(beginTime); } } return beginBoundary; } /** * DOCUMENT ME! * * @return DOCUMENT ME! */ public long getEndTimeBoundary() { long endBoundary = getBeginTimeBoundary(); // media end time would be better // long endBoundary = Long.MAX_VALUE; if (endTime.isTimeAligned()) { endBoundary = endTime.getTime(); } else { // // endBoundary = ((TranscriptionImpl) (((TierImpl) getTier()).getParent())).getTimeOrder() // .proposeTimeFor(endTime); // endBoundary = ((TierImpl) getTier()).proposeTimeFor(endTime); // oct 04: the if part added for performance reasons if (((TimeSlotImpl) endTime).getProposedTime() >= 0) { endBoundary = ((TimeSlotImpl) endTime).getProposedTime(); } else { endBoundary = ((TierImpl) getTier()).proposeTimeFor(endTime); } } return endBoundary; } /** * Returns the begin time if the begintime slot is time aligned or a new * proposed time when the slot is unaligned. Note: oct 04 addition * related to performance of unaligned slots.. temporary? * * @return the begin time boundary */ public long calculateBeginTime() { if (beginTime.isTimeAligned()) { return beginTime.getTime(); } else { return ((TierImpl) getTier()).proposeTimeFor(beginTime); } } /** * Returns the end time if the endtime slot is time aligned or a new * proposed time when the slot is unaligned. NOte: oct 04 addition * related to performance of unaligned slots.. temporary? * * @return the end time boundary */ public long calculateEndTime() { if (endTime.isTimeAligned()) { return endTime.getTime(); } else { return ((TierImpl) getTier()).proposeTimeFor(endTime); } } /* // Comparable interface method public int compareTo(Object obj) { return beginTime.compareTo(((AlignableAnnotation) obj).getBegin()); } */ // ParentAnnotationListener implementation public void parentAnnotationChanged(EventObject e) { if (e.getSource() instanceof AlignableAnnotation) { if (((Annotation) e.getSource()).isMarkedDeleted()) { ((AlignableAnnotation) e.getSource()).removeParentAnnotationListener(this); markDeleted(true); } else { // HB, 7 may 03, adjust to parent time alignment changes // force times within parent's time interval long parentBegin = ((AlignableAnnotation) e.getSource()).getBegin() .getTime(); long parentEnd = ((AlignableAnnotation) e.getSource()).getEnd() .getTime(); if (beginTime.isTimeAligned()) { if (beginTime.getTime() < parentBegin) {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -