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

📄 exportresulttableaseaf.java

📁 编辑视频文件
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/* * File:     ExportResultTableAsEAF.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.export;import mpi.eudico.client.annotator.ElanLocale;import mpi.eudico.client.annotator.Preferences;import mpi.eudico.client.annotator.grid.AnnotationTable;import mpi.eudico.client.annotator.grid.GridViewerTableModel;import mpi.eudico.client.annotator.search.result.model.ElanMatch;import mpi.eudico.client.annotator.search.result.viewer.EAFResultViewerTableModel;import mpi.eudico.client.annotator.util.AnnotationRecreator;import mpi.eudico.client.annotator.util.ClientLogger;import mpi.eudico.client.annotator.util.ElanFileFilter;import mpi.eudico.client.annotator.util.FileExtension;import mpi.eudico.client.util.TierTree;import mpi.eudico.server.corpora.clom.Annotation;import mpi.eudico.server.corpora.clom.AnnotationCore;import mpi.eudico.server.corpora.clom.TranscriptionStore;import mpi.eudico.server.corpora.clomimpl.abstr.AlignableAnnotation;import mpi.eudico.server.corpora.clomimpl.abstr.LinkedFileDescriptor;import mpi.eudico.server.corpora.clomimpl.abstr.MediaDescriptor;import mpi.eudico.server.corpora.clomimpl.abstr.TierImpl;import mpi.eudico.server.corpora.clomimpl.abstr.TranscriptionImpl;import mpi.eudico.server.corpora.clomimpl.dobes.ACM24TranscriptionStore;import mpi.eudico.server.corpora.clomimpl.type.Constraint;import mpi.eudico.server.corpora.clomimpl.type.IncludedIn;import mpi.eudico.server.corpora.clomimpl.type.LinguisticType;import mpi.eudico.server.corpora.clomimpl.type.SymbolicAssociation;import mpi.eudico.server.corpora.clomimpl.type.SymbolicSubdivision;import mpi.eudico.server.corpora.clomimpl.type.TimeSubdivision;import mpi.util.CVEntry;import mpi.util.ControlledVocabulary;import java.io.File;import java.util.ArrayList;import java.util.Enumeration;import java.util.Vector;import javax.swing.JFileChooser;import javax.swing.JOptionPane;import javax.swing.ProgressMonitor;import javax.swing.filechooser.FileFilter;import javax.swing.tree.DefaultMutableTreeNode;/** * Export the annotations in the search result table with their context (the annotation block the annotations * is part of) to a new eaf file. */public class ExportResultTableAsEAF implements ClientLogger {    private ProgressMonitor monitor;    /**     * Creates new instance.     */    public ExportResultTableAsEAF() {        super();    }    /**     * Prompts for a file name, extracts the tiers (and thus types and cv's) that need to be copied     * and copies the toplevel parent annotations of all annotations in the annotation table.     *     * @param table the search result table     */    public void exportTableAsEAF(final AnnotationTable table) {        if ((table == null) || (table.getRowCount() == 0)) {            // warn?            return;        }        final String fileName = promptForFileName();        if (fileName == null) {            return;        }        monitor = new ProgressMonitor(null,                ElanLocale.getString("SaveDialog.Message.Title"), "", 0, 100);        monitor.setMillisToDecideToPopup(10);        monitor.setMillisToPopup(10);        new Thread() {                public void run() {                    try {                        Thread.sleep(50);                    } catch (Exception e) {                        e.printStackTrace();                    }                    TranscriptionImpl transcription = null;                    ///GridViewerTableModel dataModel = (GridViewerTableModel) table.getModel();                    EAFResultViewerTableModel dataModel = (EAFResultViewerTableModel) table.getModel();                    AnnotationCore anc = null;                    Annotation ann = null;                    AlignableAnnotation aa = null;                    // first get the transcription                    anc = dataModel.getAnnotationCore(0);                    if (anc instanceof Annotation) {                        ann = (Annotation) anc;                        transcription = (TranscriptionImpl) ann.getTier()                                                               .getParent();                    }                    if (transcription == null) {                        //warn message                        LOG.warning(                            "Could not retrieve the transcription, no results exported");                        progressUpdate(null, 100);                        return;                    }                    progressUpdate(null, 10);                    if (isCancelled()) {                        return;                    }                    ArrayList topAnnos = new ArrayList();                    ArrayList topTiers = new ArrayList();                    int annColumn = -1;                    Object val;                    ElanMatch match;                    for (int i = 0; i < dataModel.getColumnCount(); i++) {                        if (dataModel.getColumnName(i).equals(GridViewerTableModel.ANNOTATION)) {                            annColumn = i;                            break;                        }                    }                    if (annColumn < 0) {                        LOG.warning(                            "Could not find the matches column in the table");                        progressUpdate(null, 100);                        return;                    }                    for (int i = 0; i < dataModel.getRowCount(); i++) {                        val = dataModel.getValueAt(i, annColumn);                        if (val instanceof ElanMatch) {                            match = (ElanMatch) val;                            //System.out.println("" + i + " " + match.getValue());                            // only process toplevel matches; their children will all be checked                            if (match.getParent() != null) {                                continue;                            }                            ann = match.getAnnotation();                            aa = rootAnnotationOf(ann);                            if ((aa != null) && !topAnnos.contains(aa)) {                                topAnnos.add(aa);                            }                            if ((aa != null) &&                                    !topTiers.contains(aa.getTier())) {                                topTiers.add(aa.getTier());                            }                            // process children                            extractSubMatches(match, topAnnos, topTiers);                        } else {                            anc = dataModel.getAnnotationCore(i);                            //System.out.println("" + i + " " + anc.getClass());                            if (anc instanceof Annotation) {                                ann = (Annotation) anc;                                aa = rootAnnotationOf(ann);                                if ((aa != null) && !topAnnos.contains(aa)) {                                    topAnnos.add(aa);                                }                                if (!topTiers.contains(aa.getTier())) {                                    topTiers.add(aa.getTier());                                }                            }                        }                    }                    // now create a new transcription, either with only the tiers, types and cv's in use by                    // the annotations or all tiers, types and cv's?                    TranscriptionImpl nextTrans = new TranscriptionImpl();                    nextTrans.setNotifying(false);                    progressUpdate(null, 15);                    if (isCancelled()) {                        return;                    }                    copyDescriptors(transcription, nextTrans);                    if (isCancelled()) {                        return;                    }                    copyTiersTypesCvs(transcription, nextTrans, topTiers);                    if (isCancelled()) {                        return;                    }                    copyAnnotations(transcription, nextTrans, topAnnos);                    progressUpdate(null, 90);                    if (isCancelled()) {                        return;                    }                    ACM24TranscriptionStore store = new ACM24TranscriptionStore();                    store.storeTranscription(nextTrans, null, new Vector(),                        fileName, TranscriptionStore.EAF);                    progressUpdate(null, 100);                }            }.start();    }    /**     * Recursively extract annotations from sub matches.     * @param match the (sub)match     * @param topAnnos the list of toplevel annotations in the matches     * @param topTiers the list of involved toplevel tiers     */    private void extractSubMatches(ElanMatch match, ArrayList topAnnos,        ArrayList topTiers) {        ElanMatch chMatch;        Annotation ann;        for (int j = 0; j < match.getChildCount(); j++) {            chMatch = (ElanMatch) match.getChildAt(j);            ann = chMatch.getAnnotation();            ann = rootAnnotationOf(ann);            if ((ann != null) && !topAnnos.contains(ann)) {                topAnnos.add(ann);            }            if ((ann != null) && !topTiers.contains(ann.getTier())) {                topTiers.add(ann.getTier());            }            // recursive extraction            if (!chMatch.isLeaf()) {                extractSubMatches(chMatch, topAnnos, topTiers);            }        }    }    /**     * Copies media and linked files descriptors.     * @param transcription source transcription     * @param nextTrans destination transcription     */    private void copyDescriptors(TranscriptionImpl transcription,        TranscriptionImpl nextTrans) {        if ((transcription == null) || (nextTrans == null)) {            return;        }        Vector mds = transcription.getMediaDescriptors();        Vector cmds = new Vector(mds.size());        MediaDescriptor md;        for (int i = 0; i < mds.size(); i++) {            md = (MediaDescriptor) mds.get(i);            cmds.add((MediaDescriptor) md.clone());        }        nextTrans.setMediaDescriptors(cmds);        // copy/clone linked files descriptors        Vector lfds = transcription.getLinkedFileDescriptors();        Vector clfds = new Vector(lfds.size());        LinkedFileDescriptor lfd;        for (int i = 0; i < lfds.size(); i++) {            lfd = (LinkedFileDescriptor) lfds.get(i);            clfds.add((LinkedFileDescriptor) lfd.clone());        }        nextTrans.setLinkedFileDescriptors(clfds);        progressUpdate(null, 20);    }    /**     * Copies tiers, linguistic types and cv's.     * @param transcription source transcription     * @param nextTrans destination transcription     * @param topTiers a list of top level tiers, all depending tiers will also be copied     */    private void copyTiersTypesCvs(TranscriptionImpl transcription,        TranscriptionImpl nextTrans, ArrayList topTiers) {

⌨️ 快捷键说明

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