📄 tokenizecommand.java
字号:
/* * File: TokenizeCommand.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.client.annotator.commands;import mpi.eudico.client.annotator.ElanLocale;import mpi.eudico.client.annotator.gui.IndeterminateProgressMonitor;import mpi.eudico.client.annotator.util.AnnotationDataRecord;import mpi.eudico.client.annotator.util.AnnotationRecreator;import mpi.eudico.server.corpora.clom.Annotation;import mpi.eudico.server.corpora.clom.Transcription;import mpi.eudico.server.corpora.clomimpl.abstr.AbstractAnnotation;import mpi.eudico.server.corpora.clomimpl.abstr.TierImpl;import mpi.eudico.server.corpora.clomimpl.abstr.TranscriptionImpl;import mpi.eudico.server.corpora.clomimpl.type.Constraint;import java.awt.Cursor;import java.util.ArrayList;import java.util.Iterator;import java.util.StringTokenizer;import java.util.Vector;import java.util.logging.Logger;/** * A Command that tokenizes the contents of the annotations a source tier * new annotations on a destination tier. * * @author Han Sloetjes */public class TokenizeCommand implements UndoableCommand { /** Holds value of property DOCUMENT ME! */ private static final Logger LOG = Logger.getLogger(TokenizeCommand.class.getName()); private String commandName; // store state private TranscriptionImpl transcription; private TierImpl sourceTier; private TierImpl destTier; private String delimiter; private boolean preserve; private boolean createEmpty; // store for undo /** backup data of existing annotations on the destination tier */ private ArrayList existAnnotations; /** store the data of the newly created annotations */ private ArrayList newAnnotationsNodes; // store for redo /** a list of source annotations that have been tokenized */ private ArrayList completedTokenizations; /** * Creates a new TokenizeCommand instance. * * @param name the name of the command */ public TokenizeCommand(String name) { commandName = name; } /** * Undo the changes made by this command. */ public void undo() { if ((transcription == null) || (sourceTier == null) || (destTier == null)) { return; } int curPropMode = 0; curPropMode = transcription.getTimeChangePropagationMode(); if (curPropMode != Transcription.NORMAL) { transcription.setTimeChangePropagationMode(Transcription.NORMAL); } transcription.setNotifying(false); setWaitCursor(true); // delete created annotations if (completedTokenizations.size() > 0) { AnnotationDataRecord srcRecord; AbstractAnnotation srcAnn; AbstractAnnotation destAnn; Vector childrenOnDest; for (int i = 0; i < completedTokenizations.size(); i++) { srcRecord = (AnnotationDataRecord) completedTokenizations.get(i); srcAnn = (AbstractAnnotation) sourceTier.getAnnotationAtTime(srcRecord.getBeginTime()); childrenOnDest = srcAnn.getChildrenOnTier(destTier); for (int j = 0; j < childrenOnDest.size(); j++) { destAnn = (AbstractAnnotation) childrenOnDest.get(j); destTier.removeAnnotation(destAnn); } } } // recreate annotations that have been overwritten if (!preserve && (existAnnotations.size() > 0)) { AnnotationRecreator.createAnnotationsSequentially(transcription, existAnnotations); } transcription.setNotifying(true); setWaitCursor(false); // restore the time propagation mode transcription.setTimeChangePropagationMode(curPropMode); } /** * Redo the changes made by this command. */ public void redo() { if ((transcription == null) || (sourceTier == null) || (destTier == null)) { return; } int curPropMode = 0; curPropMode = transcription.getTimeChangePropagationMode(); if (curPropMode != Transcription.NORMAL) { transcription.setTimeChangePropagationMode(Transcription.NORMAL); } transcription.setNotifying(false); setWaitCursor(true); if (completedTokenizations.size() > 0) { if (!preserve) { AnnotationDataRecord srcRecord; AbstractAnnotation srcAnn; AbstractAnnotation destAnn; Vector childrenOnDest; for (int i = 0; i < completedTokenizations.size(); i++) { srcRecord = (AnnotationDataRecord) completedTokenizations.get(i); srcAnn = (AbstractAnnotation) sourceTier.getAnnotationAtTime(srcRecord.getBeginTime()); childrenOnDest = srcAnn.getChildrenOnTier(destTier); for (int j = 0; j < childrenOnDest.size(); j++) { destAnn = (AbstractAnnotation) childrenOnDest.get(j); destTier.removeAnnotation(destAnn); } } } if (newAnnotationsNodes.size() > 0) { AnnotationRecreator.createAnnotationsSequentiallyDepthless(transcription, newAnnotationsNodes); //AnnotationRecreator.createAnnotationsSequentially(transcription, newAnnotationsNodes); } } transcription.setNotifying(true); setWaitCursor(false); // restore the time propagation mode transcription.setTimeChangePropagationMode(curPropMode); } /** * <b>Note: </b>it is assumed the types and order of the arguments are * correct. * * @param receiver the TranscriptionImpl * @param arguments the arguments: <ul><li>arg[0] = the name of the source * tier (String)<li> <li>arg[1] = the name of the destination tier (String) * </li> <li>arg[2] = the token delimiter(s) (String)</li> <li>arg[3] = * a flag denoting whether or not to preserve existing annotations * on the destination tier (Boolean)</li> <li>arg[4] = a flag denoting * whether or not to create new annotations for empty source annotations * (Boolean)</li> </ul> */ public void execute(Object receiver, Object[] arguments) { transcription = (TranscriptionImpl) receiver; String sourceName = (String) arguments[0]; String destName = (String) arguments[1]; delimiter = (String) arguments[2]; //can be null preserve = ((Boolean) arguments[3]).booleanValue(); createEmpty = ((Boolean) arguments[4]).booleanValue();
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -