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

📄 acm22transcriptionstore.java

📁 编辑视频文件
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/* * File:     ACM22TranscriptionStore.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.dobes;import mpi.eudico.server.corpora.clom.Annotation;import mpi.eudico.server.corpora.clom.EncoderInfo;import mpi.eudico.server.corpora.clom.Tier;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.clom.TranscriptionStore;import mpi.eudico.server.corpora.clomimpl.abstr.AlignableAnnotation;import mpi.eudico.server.corpora.clomimpl.abstr.Parser;import mpi.eudico.server.corpora.clomimpl.abstr.ParserFactory;import mpi.eudico.server.corpora.clomimpl.abstr.RefAnnotation;import mpi.eudico.server.corpora.clomimpl.abstr.SVGAlignableAnnotation;import mpi.eudico.server.corpora.clomimpl.abstr.TierImpl;import mpi.eudico.server.corpora.clomimpl.abstr.TimeOrderImpl;import mpi.eudico.server.corpora.clomimpl.abstr.TimeSlotComparator;import mpi.eudico.server.corpora.clomimpl.abstr.TimeSlotImpl;import mpi.eudico.server.corpora.clomimpl.abstr.TranscriptionImpl;import mpi.eudico.server.corpora.clomimpl.chat.CHATEncoder;import mpi.eudico.server.corpora.clomimpl.shoebox.ShoeboxEncoder;import mpi.eudico.server.corpora.clomimpl.type.Constraint;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.util.ArrayList;import java.util.Collections;import java.util.HashMap;import java.util.Iterator;import java.util.Locale;import java.util.Vector;import java.util.logging.Logger;/** * A TranscriptionStore that corresponds to EAF v2.2.<br> * Version 2.2 extends v2.1 by adding support for Controlled Vocabularies. * * @see EAF21TranscriptionStore * * @author Hennie Brugman * @author Han Sloetjes * @version jun 2004 * @version Aug 2005 Identity removed */public class ACM22TranscriptionStore implements TranscriptionStore {    /** Holds value of property DOCUMENT ME! */    private static final Logger LOG = Logger.getLogger(ACM22TranscriptionStore.class.getName());    // we want the XML to be saved to a file    // HS 19-11-2002: "private final" changed to "public" to enable automatic    // backup (if fileToWirteXMLinto is not null, then the transcription will    // be written to that file    /** Holds value of property DOCUMENT ME! */    public java.io.File fileToWriteXMLinto = null;    private boolean debug = false;    /**     * Creates a new ACM22TranscriptionStore instance     */    public ACM22TranscriptionStore() {        super();        //debug = true;    }    /*    // File lacks println: here we add it.    // TO DO: put this somewhere in mpi.alt    public PrintWriter addPrintln(File f) {        try {            java.io.FileWriter fileWriter1 = new java.io.FileWriter(f);            return new PrintWriter(fileWriter1, true);        } catch (IOException ioe) {            // return null is all we say.        }        return null;    }    */    /**     * Requests to save the specified Transcription to a file.<br>     * The path to the file is taken from the Transcription.     *     * @param theTranscription the Transcription to save     * @param encoderInfo additional encoder information     * @param tierOrder the preferred ordering of the tiers     * @param format the document / file format     */    public void storeTranscription(Transcription theTranscription,        EncoderInfo encoderInfo, Vector tierOrder, int format) {        if (theTranscription instanceof TranscriptionImpl) {            String pathName = ((TranscriptionImpl) theTranscription).getPathName();            if (!pathName.substring(pathName.length() - 4, pathName.length() -                        3).equals(".")) {                pathName += ".eaf";            } else { //always give it extension eaf                pathName = pathName.substring(0, pathName.length() - 3);                pathName = pathName + "eaf";            }            storeTranscriptionIn(theTranscription, encoderInfo, tierOrder,                pathName, format);        }    }    /**     * Requests to save the specified Transcription to a file.<br>     * The path to the file is specified by the given pathName.     *     * @param theTranscription the Transcription to save     * @param tierOrder the preferred ordering of the tiers     * @param pathName the path to the file to use for storage     */    public void storeTranscription(Transcription theTranscription,        EncoderInfo encoderInfo, Vector tierOrder, String pathName, int format) {        if (theTranscription instanceof TranscriptionImpl) {            //String pathName = ((DobesTranscription) theTranscription).getPathName();            if (!pathName.substring(pathName.length() - 4, pathName.length() -                        3).equals(".")) {                pathName += ".eaf";            } else { //always give it extension eaf                pathName = pathName.substring(0, pathName.length() - 3);                pathName = pathName + "eaf";            }            storeTranscriptionIn(theTranscription, encoderInfo, tierOrder,                pathName, format);        }    }    /**     * Writes to the file specified by given path, unless the field     * <code>fileToWriteXMLinto</code> is not null.     *     * @param theTranscription the Transcription to save (not null)     * @param tierOrder the preferred ordering of the tiers     * @param path the path to the file to use for storage     */    public void storeTranscriptionIn(Transcription theTranscription,        EncoderInfo encoderInfo, Vector tierOrder, String path, int format) {        switch (format) {        case TranscriptionStore.EAF:            if (this.fileToWriteXMLinto != null) {                path = fileToWriteXMLinto.getAbsolutePath();            }            new EAF22Encoder().encodeAndSave(theTranscription, null, tierOrder,                path);            break;        case TranscriptionStore.CHAT:            new CHATEncoder().encodeAndSave(theTranscription, encoderInfo,                tierOrder, path);            break;        case TranscriptionStore.SHOEBOX:            new ShoeboxEncoder(path).encodeAndSave(theTranscription,                encoderInfo, tierOrder, path);            break;        default:            break;        }    }    /**     * Creates a template file using the given path, unless the field     * <code>fileToWriteXMLinto</code> is not null.     *     * @param theTranscription the Transcription to use for the template (not null)     * @param tierOrder the preferred ordering of the tiers     * @param path the path to the file to use for storage     */    public void storeTranscriptionAsTemplateIn(Transcription theTranscription,        Vector tierOrder, String path) {        if (this.fileToWriteXMLinto != null) {            path = fileToWriteXMLinto.getAbsolutePath();        }        new EAF22Encoder().encodeAsTemplateAndSave(theTranscription, tierOrder,            path);    }    /**     * Loads the Transcription from an eaf file.     *     * @param theTranscription DOCUMENT ME!     */    public void loadTranscription(Transcription theTranscription) {        //	System.out.println("EAFTranscriptionStore.loadTranscription called");        TranscriptionImpl attisTr = (TranscriptionImpl) theTranscription;        String trPathName = attisTr.getPathName();        String lowerPathName = trPathName.toLowerCase();        Parser parser = null;        if (lowerPathName.endsWith("cha")) {            parser = ParserFactory.getParser(ParserFactory.CHAT);        } else if (lowerPathName.endsWith("txt")) { // Shoebox            parser = ParserFactory.getParser(ParserFactory.SHOEBOX);        } else if (lowerPathName.endsWith("trs")) { // Transcriber            parser = ParserFactory.getParser(ParserFactory.TRANSCRIBER);        } else if (lowerPathName.endsWith("imdi")) { // CGN            parser = ParserFactory.getParser(ParserFactory.CGN);        } else {            parser = ParserFactory.getParser(ParserFactory.EAF22);        }        long beginTime = System.currentTimeMillis();        // NOTE: media file is not used by either Elan 1.4.1 or Elan 2.0        // Instead MediaDescriptors are introduced. Mediafile is temporarily maintained        // for compatibility of EAF 2.1 with Elan 1.4.1        // set media transcription's media file        String mediaFileName = parser.getMediaFile(trPathName);        if (debug) {            System.out.println("Parsing eaf took: " +                (System.currentTimeMillis() - beginTime) + " ms");            beginTime = System.currentTimeMillis();        }        if ((mediaFileName != null) && (mediaFileName.startsWith("file:"))) {            mediaFileName = mediaFileName.substring(5);        }        attisTr.setMainMediaFile(mediaFileName);        // make media descriptors available in transcription        ArrayList mediaDescriptors = parser.getMediaDescriptors(trPathName);        attisTr.setMediaDescriptors(new Vector(mediaDescriptors));        String svgFile = parser.getSVGFile(trPathName);        if (svgFile != null) {            if (!svgFile.startsWith("file:")) {                svgFile = "file:" + mediaFileName;            }            attisTr.setSVGFile(svgFile);        }        // set author        String author = parser.getAuthor(trPathName);        if (attisTr.getAuthor().equals("")) {            attisTr.setAuthor(author);        }        if (debug) {            System.out.println("Extracting header took: " +                (System.currentTimeMillis() - beginTime) + " ms");            beginTime = System.currentTimeMillis();        }        // make linguistic types available in transcription        ArrayList linguisticTypes = parser.getLinguisticTypes(trPathName);        ArrayList typesCopy = new ArrayList(linguisticTypes.size());        for (int i = 0; i < linguisticTypes.size(); i++) {            //           typesCopy.add(i, linguisticTypes.get(i));            LingTypeRecord ltr = (LingTypeRecord) linguisticTypes.get(i);            LinguisticType lt = new LinguisticType(ltr.getLingTypeId());            boolean timeAlignable = true;            if (ltr.getTimeAlignable().equals("false")) {                timeAlignable = false;            }            lt.setTimeAlignable(timeAlignable);            boolean graphicReferences = false;            if (ltr.getGraphicReferences().equals("true")) {                graphicReferences = true;            }            lt.setGraphicReferences(graphicReferences);            String stereotype = ltr.getStereoType();            Constraint c = null;            if (stereotype != null) {                stereotype = stereotype.replace('_', ' '); // for backwards compatibility                if (stereotype.equals(                            Constraint.stereoTypes[Constraint.TIME_SUBDIVISION])) {                    c = new TimeSubdivision();                } else if (stereotype.equals(                            Constraint.stereoTypes[Constraint.SYMBOLIC_SUBDIVISION])) {                    c = new SymbolicSubdivision();                } else if (stereotype.equals(                            Constraint.stereoTypes[Constraint.SYMBOLIC_ASSOCIATION])) {                    c = new SymbolicAssociation();                }            }            if (c != null) {                lt.addConstraint(c);            }            lt.setControlledVocabularyName(ltr.getControlledVocabulary());            typesCopy.add(lt);        }        attisTr.setLinguisticTypes(new Vector(typesCopy));        if (debug) {            System.out.println("Creating linguistic types took: " +                (System.currentTimeMillis() - beginTime) + " ms");            beginTime = System.currentTimeMillis();        }        //attisTr.setLinguisticTypes(linguisticTypes);        TimeOrder timeOrder = attisTr.getTimeOrder();        // populate TimeOrder with TimeSlots        ArrayList order = parser.getTimeOrder(trPathName);        HashMap slots = parser.getTimeSlots(trPathName);        HashMap timeSlothash = new HashMap(); // temporarily stores map from id to TimeSlot object        Iterator orderedIter = order.iterator();        TimeSlot ts = null;        String tsKey = null;        long time;        ArrayList tempSlots = new ArrayList(order.size());        int index = 0;        // jan 2006: sort the timeslots before adding them all to the TimeOrder object        // (for performance reasons)        while (orderedIter.hasNext()) {            tsKey = (String) orderedIter.next();            time = Long.parseLong((String) slots.get(tsKey));            if (time != TimeSlot.TIME_UNALIGNED) {                ts = new TimeSlotImpl(time, timeOrder);            } else {                ts = new TimeSlotImpl(timeOrder);            }            ts.setIndex(index++);            //timeOrder.insertTimeSlot(ts);            tempSlots.add(ts);            timeSlothash.put(tsKey, ts);        }        Collections.sort(tempSlots, new TimeSlotComparator());

⌨️ 快捷键说明

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