⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 annotationsfromoverlapscommand.java

📁 编辑视频文件
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/* * File:     AnnotationsFromOverlapsCommand.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.Constants;import mpi.eudico.client.annotator.util.AnnotationDataRecord;import mpi.eudico.client.annotator.util.ClientLogger;import mpi.eudico.client.annotator.util.ProgressListener;import mpi.eudico.server.corpora.clom.Annotation;import mpi.eudico.server.corpora.clom.Transcription;import mpi.eudico.server.corpora.clomimpl.abstr.AlignableAnnotation;import mpi.eudico.server.corpora.clomimpl.abstr.TierImpl;import mpi.eudico.server.corpora.clomimpl.abstr.TranscriptionImpl;import mpi.eudico.server.corpora.clomimpl.type.LinguisticType;import mpi.util.TimeFormatter;import java.awt.Cursor;import java.util.ArrayList;/** * Undoable Command that calculates overlaps of annotations on 2 tiers and * creates a new annotation for each overlap found. Position and duration of * the new annotation corresponds to begin time and length of the overlap. * Optionally the annotation gets the duration of the overlap as value. * * @author Han Sloetjes * @version 1.0 Jan 2007 */public class AnnotationsFromOverlapsCommand implements UndoableCommand,    ClientLogger {    private ArrayList listeners;    private String commandName;    private TranscriptionImpl transcription;    private TierImpl sourceTier1;    private TierImpl sourceTier2;    private TierImpl destTier;    private boolean addContent = false;    private int timeFormat = 0;    private ArrayList overlaps;    private ArrayList annRecords;    /**     * Constructor.     *     * @param name the name of the command     */    public AnnotationsFromOverlapsCommand(String name) {        commandName = name;    }    /**     * Calculates the overlaps of the annotations on 2 source tiers and creates     * new annotation on the destination tier of the duration of the overlaps     * and optionally adds the duration as the annotations' values.   <br>     * <b>Note: </b>it is assumed the types and order of the arguments are     * correct.     *     * @param receiver the transcription     * @param arguments the arguments: <ul><li>arg[0] = the first source tier     *        (String)</li> <li>arg[1] the second source tier (String)</li>     *        <li>arg[2] the destination tier name (new tier) (String)</li>     *        <li>arg[3] the name of the LinguisticType for the new tier     *        (String)</li> <li>arg[4] whether or not to make the duration of     *        the overlap the value of  each annotation (Boolean)</li>     *        <li>arg[5] the format of the time value  (in case arg[4] is     *        true), a constant for ms, ssms or hhmmssms (Integer)</li> </ul>     */    public void execute(Object receiver, Object[] arguments) {        transcription = (TranscriptionImpl) receiver;        String sourceName1 = (String) arguments[0];        String sourceName2 = (String) arguments[1];        String destName = (String) arguments[2];        String typeName = (String) arguments[3];        Boolean ac = (Boolean) arguments[4];        if (ac != null) {            addContent = ac.booleanValue();        }        Integer tf = (Integer) arguments[5];        if (tf != null) {            timeFormat = tf.intValue();        }        sourceTier1 = (TierImpl) transcription.getTierWithId(sourceName1);        sourceTier2 = (TierImpl) transcription.getTierWithId(sourceName2);        if ((sourceTier1 == null) || (sourceTier2 == null)) {            progressInterrupt("One of the sourcetiers could not be found");            return;        }        if (destName == null) {            destName = "Overlap";            LOG.warning("Name of destination tier is null, changed to Overlap");        }        destTier = (TierImpl) transcription.getTierWithId(destName);        if (destTier != null) {            // it already exists            int count = 1;            String cName = destName + "-";            while (destTier != null) {                cName = cName + count;                destTier = (TierImpl) transcription.getTierWithId(cName);                count++;            }            LOG.warning("Tier " + destName +                " already exists, changed name to " + cName);            destName = cName;        }        LinguisticType type = transcription.getLinguisticTypeByName(typeName);        if (type == null) {            // get the first suitable type            LinguisticType countType;            for (int i = 0; i < transcription.getLinguisticTypes().size();                    i++) {                countType = (LinguisticType) transcription.getLinguisticTypes()                                                          .get(i);                if (countType.getConstraints() == null) {                    LOG.warning("LinguisticType " + typeName +                        " could not be found, using " +                        countType.getLinguisticTypeName() + " instead.");                    type = countType;                    typeName = type.getLinguisticTypeName();                    break;                }            }        }        destTier = new TierImpl(null, destName, null, transcription, type);        transcription.addTier(destTier);        overlaps = new ArrayList();        progressUpdate(8, "Created tier: " + destName);        Thread calcThread = new CalcOverLapsThread(AnnotationsFromOverlapsCommand.class.getName());        try {            calcThread.start();        } catch (Exception exc) {            transcription.setNotifying(true);            LOG.severe("Exception in calculation of overlaps: " +                exc.getMessage());            progressInterrupt("An exception occurred: " + exc.getMessage());        }    }    /**     * Removes the tier.     *     * @see mpi.eudico.client.annotator.commands.UndoableCommand#undo()     */    public void undo() {        if ((transcription != null) && (destTier != null)) {            setWaitCursor(true);            transcription.removeTier(destTier);            setWaitCursor(false);        }    }    /**     * Adds the tier again and the annotations.     *     * @see mpi.eudico.client.annotator.commands.UndoableCommand#redo()     */    public void redo() {        if ((transcription != null) && (destTier != null)) {            int curPropMode = 0;            curPropMode = transcription.getTimeChangePropagationMode();            if (curPropMode != Transcription.NORMAL) {                transcription.setTimeChangePropagationMode(Transcription.NORMAL);            }            setWaitCursor(true);            if (transcription.getTierWithId(destTier.getName()) == null) {                transcription.addTier(destTier);            }            if ((annRecords != null) && (annRecords.size() > 0)) {                transcription.setNotifying(false);                AnnotationDataRecord record;                Annotation ann;                for (int i = 0; i < annRecords.size(); i++) {                    record = (AnnotationDataRecord) annRecords.get(i);                    ann = destTier.createAnnotation(record.getBeginTime(),                            record.getEndTime());                    if ((ann != null) && (record.getValue() != null)) {                        ann.setValue(record.getValue());                    }                }                transcription.setNotifying(true);            }            setWaitCursor(false);            // restore the time propagation mode            transcription.setTimeChangePropagationMode(curPropMode);        }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -