📄 tierimpl.java
字号:
/* * File: TierImpl.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.MetaTime;import mpi.eudico.server.corpora.clom.Tag;import mpi.eudico.server.corpora.clom.Tier;import mpi.eudico.server.corpora.clom.TierSharedInfo;import mpi.eudico.server.corpora.clom.TierUnsharedInfo;import mpi.eudico.server.corpora.clom.TimeOrder;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 mpi.eudico.server.corpora.util.ACMEditableObject;import mpi.eudico.server.corpora.util.DataTreeNode;import java.util.ArrayList;import java.util.Collections;import java.util.HashMap;import java.util.Hashtable;import java.util.Iterator;import java.util.ListIterator;import java.util.Locale;import java.util.TreeSet;import java.util.Vector;/** * <h2>History</h2 * <ul> * <li>4-May-1999 Hennie Brugman, Albert Russel * <li>MK:2002/06/21 commented and using setMetaData() * <li>MK:2002/06/21 added getter for Participant and Locale (using hash...) * </ul> * * <h2>Proposed changes</h2> * <ul> * <li>MK:2002/06/21 participant and locale should get a proper member variable * in order to avoid dynamic downcast. * <li>MK:2002/06/21 participant getter/setter in interface Tier * </ul> * * @version Aug 2005 Identity removed * @verion Dec 2006 getter and setter for "Annotator" added */public class TierImpl implements Tier { /** * The Tier's TierSharedInfo part, being the part that can be shared * with other Tiers. */ protected TierSharedInfo sharedInfo; /** * The Tier's UnsharedInfo part, being the part that is unique for * each Tier. */ protected TierUnsharedInfo unsharedInfo; /** * The Tier's list of Tags. It is implemented as a SortedSet, because Tags are * naturally sorted on begin times. */ protected TreeSet tagList; /** * <p>MK:02/06/19<br>The parent of a tier is always a Transcription (is a DataTreeNode) * The too general declaration leeds to downcasts everytime parent is used, which is dangerous! * Preparing for tight declaration. * </p> * */ protected DataTreeNode parent; // back reference, used for deletion of Tiers /** Holds value of property DOCUMENT ME! */ protected TreeSet annotations; /** * see method for documentation * */ protected Hashtable tierMetadata; /** Holds value of property DOCUMENT ME! */ protected Tier parentTier; private LinguisticType linguisticType; /** * <p>MK:02/06/19<br>Added a (complete) Constructor for timealigned tiers. * TierSharedInfo is created. * Locale is set to English. * Linguistic type is created and set to time-aligned. * Constraints not yet created. * You should only add Alignable Annotations to this tier. * </p> * @param name the name of 'this' tier * @param participant the participant of 'this' tier MK:02/06/21 added * @param parent the parent Transcription * */ public TierImpl(String name, String participant, Transcription parent, LinguisticType theType) { //MK:02/06/19 calling the original constructor this(null, parent); //MK:02/06/19 initialise TSI for the name of this tier this.sharedInfo = new TierSharedInfoImpl(name, null, this); // init participant if (participant == null) { this.setMetadata("PARTICIPANT", ""); } else { this.setMetadata("PARTICIPANT", participant); } //MK:02/06/21 init Locale this.setMetadata("DEFAULT_LOCALE", new Locale("EN", "US")); //register 'this' tier with the parent transcription // if (parent != null) { // since viewermanager2 (ab)uses an empty tier // parent.addTier(this); // } //set the LT this.setLinguisticType(theType); } /** * <p>MK:02/06/19<br>Added a (complete) Constructor for not-timealigned tiers. * You should only add not-timealigned annotations to this tier. * </p> * @param parenttier the parenttier * @param name name of this tier * @param participant the participant of 'this' tier * @param parent the parent transcription * @param theType the linguistic type for 'this' tier */ public TierImpl(Tier parenttier, String name, String participant, Transcription parent, LinguisticType theType) { this(name, participant, parent, theType); //reset the LT // HB, 12 jul 02: replaced hard-coded creation of new LT for each Tier instance by theType // argument to constructor. This supports setting different types for child tiers, and re-use // of LTs within Transcription. // register the parent tier. this.setParentTier(parenttier); } /** * <p>MK:02/06/12<br> WARNING: This constructor is incomplete. * It does not reflect the changes introduced * by the shared Info concept. You have to initialise the name of the time * by yourself, using a shared info, which I have to describe elsewhere. * * </p> * @param theName IS IGNORED * * */ public TierImpl(String theName, DataTreeNode theParent) { parent = theParent; tagList = new TreeSet(); annotations = new TreeSet(); tierMetadata = new Hashtable(); } /** * DOCUMENT ME! * * @param operation DOCUMENT ME! * @param modification DOCUMENT ME! */ public void modified(int operation, Object modification) { handleModification(this, operation, modification); } /** * DOCUMENT ME! * * @param source DOCUMENT ME! * @param operation DOCUMENT ME! * @param modification DOCUMENT ME! */ public void handleModification(ACMEditableObject source, int operation, Object modification) { if (parent != null) { ((Transcription) parent).handleModification(source, operation, modification); } } /** * Factory method that creates a new annotation of the proper type and meeting the * relevant Constraints, and adds it to the tier. The new annotation will not have * an initial value, this has to be set afterwards. * Arguments: beginTime and endTime can be either different or equal. The latter is * the case for, for example, creation of new RefAnnotations. */ public Annotation createAnnotation(long beginTime, long endTime) { Annotation annotation = null; TimeOrder timeOrder = ((TranscriptionImpl) parent).getTimeOrder(); if (!isTimeAlignable() && (beginTime == endTime)) { // then contains RefAnnotations Annotation referedAnnot = ((TierImpl) getParentTier()).getAnnotationAtTime(beginTime); if ((referedAnnot != null) && (getAnnotationAtTime(beginTime) == null)) { annotation = new RefAnnotation(referedAnnot, this); } } else { // contains AlignableAnnotations if (endTime > beginTime) { Constraint c = getLinguisticType().getConstraints(); if (c != null) { Vector slots = c.getTimeSlotsForNewAnnotation(beginTime, endTime, this); if (slots.size() == 2) { // HS 17-may-04: check the hasGraphicsRef. value on the linguistic type if (getLinguisticType().hasGraphicReferences()) { annotation = new SVGAlignableAnnotation((TimeSlot) (slots.elementAt( 0)), (TimeSlot) (slots.elementAt(1)), this); } else { annotation = new AlignableAnnotation((TimeSlot) (slots.elementAt( 0)), (TimeSlot) (slots.elementAt(1)), this); } } } else { // default. TimeSlot bts = new TimeSlotImpl(beginTime, timeOrder); timeOrder.insertTimeSlot(bts); TimeSlot ets = new TimeSlotImpl(endTime, timeOrder); timeOrder.insertTimeSlot(ets); annotation = getLinguisticType().hasGraphicReferences() ? new SVGAlignableAnnotation(bts, ets, this) : new AlignableAnnotation(bts, ets, this); } } } if (annotation != null) { addAnnotation(annotation); modified(ACMEditEvent.ADD_ANNOTATION_HERE, annotation); } return annotation; } /** * This override is necessary to check equality of Tiers from database * records and already instantiated Tier objects. GestureTiers are considered * equal if their database tier_ids are equal. Used for: HashMap.containsKey. */ // public abstract boolean equals(Object obj); // Tier interface methods public String getName() { return sharedInfo.getTierName(); } /** * Returns a group of Tier attributes that can be shared among * Transcriptions. * * @return the TierSharedInfo attribute group */ public TierSharedInfo getTierSharedInfo() { return sharedInfo; } /** * Return a group of Tier attributes that is unique for the * Tier's Transcription. * * @return the TierUnsharedInfo attribute group */ public TierUnsharedInfo getTierUnsharedInfo() { return unsharedInfo; } /** * Adds a Tag to the Tier. Where the Tag is inserted is determined by * the Tag's compareTo method. The 'compareTo' method uses the MetaTime that is * associated with this Tier's Transcription to find the correct ordering. * Therefore the Tag has to be added to the MetaTime first. */ public void addTag(Tag theTag) { positionMetaTimeFor(theTag); // first position MetaTime properly ((Transcription) parent).getMetaTime().insertTag(theTag); tagList.add(theTag); } /** * Defines the time scale of the annotations on this Tier. The basic time * units of the Tier's Tags are milliseconds. TimeScale gives a multiplication * factor that e.g. can be used when creating Tags. * Example: PAL video frames last 40 msec. If the original video annotations * on the Tier use frame counts, the time scale is 40.0. * By default, a time scale of 1.0 is returned. */ public double getTimeScale() { return 1.0; } private void positionMetaTimeFor(Tag theTag) { MetaTime mt = ((Transcription) parent).getMetaTime(); if (theTag.isTimeAligned()) { // else: just insert at current position Tag t = null; if (mt.hasNext()) { t = (Tag) mt.next(); } else if (mt.nextIndex() == mt.size()) { // at end of MetaTime if (mt.size() > 0) { t = (Tag) mt.previous(); } }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -