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

📄 tokenizecommand.java

📁 编辑视频文件
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
        sourceTier = (TierImpl) transcription.getTierWithId(sourceName);        destTier = (TierImpl) transcription.getTierWithId(destName);        if ((transcription == null) || (sourceTier == null) ||                (destTier == null)) {            LOG.severe(                "Error in retrieving the transcription or one of the tiers.");            return;        }        // create a blocking progress monitor and start tokenizing        existAnnotations = new ArrayList();        newAnnotationsNodes = new ArrayList();        completedTokenizations = new ArrayList();        int curPropMode = 0;        curPropMode = transcription.getTimeChangePropagationMode();        if (curPropMode != Transcription.NORMAL) {            transcription.setTimeChangePropagationMode(Transcription.NORMAL);        }        new TokenizeThread().start();        // restore the time propagation mode        transcription.setTimeChangePropagationMode(curPropMode);    }    /**     * Returns the name of the command.     *     * @return the name of the command     */    public String getName() {        return commandName;    }    /**     * Changes the cursor to either a 'busy' cursor or the default cursor.     *     * @param showWaitCursor when <code>true</code> show the 'busy' cursor     */    private void setWaitCursor(boolean showWaitCursor) {        if (showWaitCursor) {            ELANCommandFactory.getRootFrame(transcription).getRootPane()                              .setCursor(Cursor.getPredefinedCursor(                    Cursor.WAIT_CURSOR));        } else {            ELANCommandFactory.getRootFrame(transcription).getRootPane()                              .setCursor(Cursor.getDefaultCursor());        }    }    ///////////////////////////////////////////    // inner class: execution thread    ///////////////////////////////////////////    /**     * Class that handles the tokenization in a separate thread.     * @author Han Sloetjes     */    private class TokenizeThread extends Thread {        /**         * Before using this inner class we must ensure none of the relevant fields         * (transcription, sourcetier and destination tier) are null!         */        TokenizeThread() {        }        /**         * DOCUMENT ME!         */        public void run() {            final IndeterminateProgressMonitor monitor = new IndeterminateProgressMonitor(ELANCommandFactory.getRootFrame(                        transcription), true,                    ElanLocale.getString("TokenizeDialog.Message.Tokenizing"),                    true, ElanLocale.getString("Button.Cancel"));            // if we are blocking (modal) call show from a separate thread            new Thread(new Runnable() {                    public void run() {                        monitor.show();                    }                }).start();            Vector sourceAnnos = sourceTier.getAnnotations();            if (sourceAnnos.size() <= 0) {                monitor.close();                return;            }            TokenizeCommand.this.transcription.setNotifying(false);            //start iterating over source annotations            int stereotype = destTier.getLinguisticType().getConstraints()                                     .getStereoType();            StringTokenizer tokenizer;            String nextToken;            Iterator annIt = sourceAnnos.iterator();            AbstractAnnotation srcAnn;            String srcValue;            AbstractAnnotation destAnn;            Annotation prevAnn;            Vector childrenOnDest;            ArrayList newAnnos = new ArrayList();            ArrayList siblings;            while (annIt.hasNext()) {                srcAnn = (AbstractAnnotation) annIt.next();                childrenOnDest = srcAnn.getChildrenOnTier(destTier);                if ((childrenOnDest.size() > 0) && !preserve) {                    // store old annotations                    Iterator childIt = childrenOnDest.iterator();                    while (childIt.hasNext()) {                        destAnn = (AbstractAnnotation) childIt.next();                        existAnnotations.add(AnnotationRecreator.createTreeForAnnotation(                                destAnn));                    }                    // next remove them                    childIt = childrenOnDest.iterator();                    while (childIt.hasNext()) {                        destTier.removeAnnotation((AbstractAnnotation) childIt.next());                    }                }                // if existing anns need to be preserved, do nothing                if ((childrenOnDest.size() == 0) || !preserve) {                    srcValue = srcAnn.getValue();                    if (delimiter != null) {                        tokenizer = new StringTokenizer(srcValue, delimiter);                    } else {                        tokenizer = new StringTokenizer(srcValue);                    }                    newAnnos.clear();                    if (tokenizer.countTokens() == 0) {                        // if the source annotation is empty and the create destination                        // for empty source is selected create one empty annotation                        if (createEmpty) {                            Annotation ann;                            if (stereotype == Constraint.SYMBOLIC_SUBDIVISION) {                                long time = (long) (srcAnn.getBeginTimeBoundary() +                                    srcAnn.getEndTimeBoundary()) / 2;                                ann = destTier.createAnnotation(time, time);                            } else {                                ann = destTier.createAnnotation(srcAnn.getBeginTimeBoundary(),                                        srcAnn.getEndTimeBoundary());                            }                            if (ann != null) {                                newAnnos.add(ann);                            }                        }                    } else {                        prevAnn = null;                        while (tokenizer.hasMoreTokens()) {                            nextToken = tokenizer.nextToken();                            if (prevAnn == null) {                                if (stereotype == Constraint.SYMBOLIC_SUBDIVISION) {                                    long time = (long) (srcAnn.getBeginTimeBoundary() +                                        srcAnn.getEndTimeBoundary()) / 2;                                    prevAnn = destTier.createAnnotation(time,                                            time);                                } else {                                    prevAnn = destTier.createAnnotation(srcAnn.getBeginTimeBoundary(),                                            srcAnn.getEndTimeBoundary());                                }                            } else {                                prevAnn = destTier.createAnnotationAfter(prevAnn);                            }                            prevAnn.setValue(nextToken);                            newAnnos.add(prevAnn);                        }                    }                    // now create datarecords of the created annotations...                    if (newAnnos.size() > 0) {                        siblings = new ArrayList(newAnnos.size());                        for (int i = 0; i < newAnnos.size(); i++) {                            //newAnnotationsNodes.add(new DefaultMutableTreeNode(                            //	new AnnotationDataRecord((Annotation)newAnnos.get(i))));                            siblings.add(new AnnotationDataRecord(                                    (Annotation) newAnnos.get(i)));                        }                        newAnnotationsNodes.add(siblings);                    }                    completedTokenizations.add(new AnnotationDataRecord(srcAnn));                }                // after completion of a whole source annotation, check the cancelled value of the monitor                if (monitor.isCancelled()) {                    //monitor.close();                    //return;                    break;                }            }            TokenizeCommand.this.transcription.setNotifying(true);            monitor.close();        }    }}

⌨️ 快捷键说明

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