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

📄 annotationrecreator.java

📁 编辑视频文件
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
            node = (DefaultMutableTreeNode) en.nextElement();            annData = (AnnotationDataRecord) node.getUserObject();            tier = (TierImpl) trans.getTierWithId(annData.getTierName());            if (tier == null) {                LOG.severe("Cannot recreate annotations: tier does not exist.");                continue;            }            if (tier.isTimeAlignable()) {                if (annData.isBeginTimeAligned()) {                    begin = annData.getBeginTime();                    end = annData.getEndTime();                    // this sucks... sometimes an annotation can have the same begin and 'virtual'                    // end time on a time-subdivision tier                    if (!annData.isEndTimeAligned() && (end == begin)) {                        end++;                    }                    aa = (AlignableAnnotation) tier.createAnnotation(begin, end);                    if (node == root) {                        annotation = aa;                    }                    if (aa != null) {                        aa.setValue(annData.getValue());                        if (aa instanceof SVGAlignableAnnotation &&                                annData instanceof SVGAnnotationDataRecord) {                            SVGAnnotationDataRecord svgRec = (SVGAnnotationDataRecord) annData;                            if (svgRec.getShape() != null) {                                ((SVGAlignableAnnotation) aa).setShape(svgRec.getShape());                            }                            if (svgRec.getSvgElementId() != null) {                                ((SVGAlignableAnnotation) aa).setSVGElementID(svgRec.getSvgElementId());                            }                        }                    } else {                        LOG.severe(                            "Alignable annotation could not be recreated: " +                            annData.getValue() + " bt: " +                            annData.getBeginTime() + " et: " +                            annData.getEndTime());                    }                }            } else {                // non-alignable in second run            }        }        // second run        en = root.breadthFirstEnumeration();        // for re-creation of unaligned annotation on Alignable (Time-Subdivision) tiers        Annotation prevAnn = null;        while (en.hasMoreElements()) {            aa = null; //reset            an = null;            ra = null;            node = (DefaultMutableTreeNode) en.nextElement();            annData = (AnnotationDataRecord) node.getUserObject();            tier = (TierImpl) trans.getTierWithId(annData.getTierName());            if (tier == null) {                LOG.severe("Cannot recreate annotations: tier does not exist.");                continue;            }            if (tier.isTimeAlignable()) {                if (!annData.isBeginTimeAligned()) {                    if ((prevAnn != null) &&                            (!prevAnn.getTier().getName().equals(annData.getTierName()) ||                            (prevAnn.getEndTimeBoundary() <= annData.getBeginTime()))) {                        // reset previous annotation field                        prevAnn = null;                    }                    if (prevAnn == null) {                        begin = annData.getBeginTime();                        end = annData.getEndTime();                        an = tier.getAnnotationAtTime( /*annData.getEndTime() - 1*/                                begin /*< end ? begin + 1 : begin*/);                        if (an != null) {                            aa = (AlignableAnnotation) tier.createAnnotationAfter(an);                            prevAnn = aa;                        } else {                            // time subdivision of a time subdivision...                            aa = (AlignableAnnotation) tier.createAnnotation(begin,                                    end);                            prevAnn = aa;                        }                    } else {                        aa = (AlignableAnnotation) tier.createAnnotationAfter(prevAnn);                        prevAnn = aa;                    }                    if (node == root) {                        annotation = aa;                    }                    if (aa != null) {                        aa.setValue(annData.getValue());                        // ?? shapes with unaligned annotations ??                        if (aa instanceof SVGAlignableAnnotation &&                                annData instanceof SVGAnnotationDataRecord) {                            SVGAnnotationDataRecord svgRec = (SVGAnnotationDataRecord) annData;                            if (svgRec.getShape() != null) {                                ((SVGAlignableAnnotation) aa).setShape(svgRec.getShape());                            }                            if (svgRec.getSvgElementId() != null) {                                ((SVGAlignableAnnotation) aa).setSVGElementID(svgRec.getSvgElementId());                            }                        }                    } else {                        LOG.severe(                            "Alignable annotation could not be recreated: " +                            annData.getValue() + " bt: " +                            annData.getBeginTime());                    }                } else {                    //reset the prevAnn object when an aligned annotation is encountered                    prevAnn = null;                }            } else {                // ref annotations                linStereoType = tier.getLinguisticType().getConstraints()                                    .getStereoType();                if (linStereoType == Constraint.SYMBOLIC_SUBDIVISION) {                    begin = annData.getBeginTime() /*+ 1*/;                    //an = tier.getAnnotationAtTime(begin);                    if ((prevAnn != null) &&                            !prevAnn.getTier().getName().equals(annData.getTierName())) {                        // reset previous annotation field                        prevAnn = null;                    }                    if ((prevAnn != null) &&                            (prevAnn.getEndTimeBoundary() < (begin + 1))) {                        prevAnn = null;                    }                    if (prevAnn == null) {                        an = tier.getAnnotationAtTime(begin);                        if (an != null) {                            if (an.getBeginTimeBoundary() == begin) {                                // the first annotation                                ra = (RefAnnotation) tier.createAnnotationBefore(an);                            } else {                                ra = (RefAnnotation) tier.createAnnotationAfter(an);                            }                        } else {                            ra = (RefAnnotation) tier.createAnnotation(begin,                                    begin);                        }                        prevAnn = ra;                    } else {                        ra = (RefAnnotation) tier.createAnnotationAfter(prevAnn);                        prevAnn = ra;                    }                    if (node == root) {                        annotation = ra;                    }                    if (ra != null) {                        ra.setValue(annData.getValue());                    } else {                        LOG.severe(                            "Reference annotation could not be recreated: " +                            annData.getValue() + " bt: " +                            annData.getBeginTime());                    }                } else if (linStereoType == Constraint.SYMBOLIC_ASSOCIATION) {                    begin = annData.getBeginTime() /*+ 1*/;                    an = tier.getAnnotationAtTime(begin);                    if (an == null) {                        ra = (RefAnnotation) tier.createAnnotation(begin, begin);                    }                    if (node == root) {                        annotation = ra;                    }                    if (ra != null) {                        ra.setValue(annData.getValue());                    } else {                        LOG.severe(                            "Reference annotation could not be recreated: " +                            annData.getValue() + " bt: " +                            annData.getBeginTime());                    }                }            }        }        // end second run        return annotation;    }    /**     * Creates a number of annotations with child-annotations in a sequence. <br>     * Should handle the recreation of sequences of unaligned annotations on     * either Time-Subdivision or Symbolic Subdivision tiers correctly.<br>     * When annotations are only to be recreated on one tier (one level, no     * child annotations) createAnnotationsSequentiallyDepthless can be used     * instead.     *     * @param trans the Transcription to work on     * @param annotationsNodes an ArrayList containing a DefaultMutableTreeNode     *        for each annotation to recreate     *     * @see #createAnnotationsSequentiallyDepthless(Transcription, ArrayList)     */    public static void createAnnotationsSequentially(Transcription trans,        ArrayList annotationsNodes) {        if ((trans == null) || (annotationsNodes == null) ||                (annotationsNodes.size() == 0)) {            return;        }        DefaultMutableTreeNode node;        DefaultMutableTreeNode parentNode;        AnnotationDataRecord annData = null;        TierImpl tier = null;        LinguisticType linType = null;        // first recreate aligned annotations        for (int i = 0; i < annotationsNodes.size(); i++) {            node = (DefaultMutableTreeNode) annotationsNodes.get(i);            annData = (AnnotationDataRecord) node.getUserObject();            if (annData.isBeginTimeAligned()) {                AnnotationRecreator.createAnnotationFromTree(trans, node);            }        }        // next recreate the rest        for (int i = 0; i < annotationsNodes.size(); i++) {            node = (DefaultMutableTreeNode) annotationsNodes.get(i);            annData = (AnnotationDataRecord) node.getUserObject();            if (annData.isBeginTimeAligned()) {                // we already had this one                continue;            }            tier = (TierImpl) trans.getTierWithId(annData.getTierName());            if (tier == null) {                LOG.severe("Cannot recreate annotations: tier does not exist.");                continue;            }            linType = tier.getLinguisticType();            if ((linType.getConstraints() != null) &&                    (linType.getConstraints().getStereoType() == Constraint.SYMBOLIC_ASSOCIATION)) {                AnnotationRecreator.createAnnotationFromTree(trans, node);                continue;            }            // tier is of a subdivision type...            // count the number of unaligned annotations we have to create under a             // single parent annotation, horizontally....            TierImpl parentTier = (TierImpl) tier.getParentTier();            AbstractAnnotation parentAnn = (AbstractAnnotation) parentTier.getAnnotationAtTime(annData.getBeginTime());            if (parentAnn == null) {                LOG.severe(                    "Cannot recreate annotations: parent annotation does not exist.");                continue;            }            parentNode = new DefaultMutableTreeNode("parent");            parentNode.add(node);            for (; i < annotationsNodes.size(); i++) {                node = (DefaultMutableTreeNode) annotationsNodes.get(i);                annData = (AnnotationDataRecord) node.getUserObject();                if ((parentTier.getAnnotationAtTime(annData.getBeginTime()) == parentAnn) &&                        !annData.isBeginTimeAligned()) {                    parentNode.add(node);                    if (i == (annotationsNodes.size() - 1)) {                        AnnotationRecreator.createChildAnnotationsSkipRoot(trans,                            parentNode);                    }                } else {                    AnnotationRecreator.createChildAnnotationsSkipRoot(trans,                        parentNode);                    i--;                    break;                }            }        }    }    /**     * Creates a number of unaligned child annotations that share the same     * parent  annotation.     *     * @param trans the transcription     * @param parentNode the parent node containing the nodes with the     *        information necessary to recreate the child annotations     */    static void createChildAnnotationsSkipRoot(Transcription trans,        DefaultMutableTreeNode parentNode) {        if ((trans == null) || (parentNode == null) ||                (parentNode.getChildCount() == 0)) {            return;        }        Annotation prevAnn = null;        DefaultMutableTreeNode node;        AlignableAnnotation aa = null;        RefAnnotation ra = null;        Annotation an = null;        AnnotationDataRecord annData = null;        TierImpl tier = null;        long begin;        int linStereoType = -1;        Enumeration en = parentNode.breadthFirstEnumeration();        // skip the empty root        en.nextElement();        while (en.hasMoreElements()) {            aa = null; //reset            an = null;            ra = null;            node = (DefaultMutableTreeNode) en.nextElement();            annData = (AnnotationDataRecord) node.getUserObject();            tier = (TierImpl) trans.getTierWithId(annData.getTierName());            if (tier == null) {                LOG.severe("Cannot recreate annotations: tier does not exist.");                continue;            }            if (tier.isTimeAlignable()) {                if (!annData.isBeginTimeAligned()) {                    if ((prevAnn != null) &&                            (!prevAnn.getTier().getName().equals(annData.getTierName()) ||                            (prevAnn.getEndTimeBoundary() <= annData.getBeginTime()))) {                        // reset previous annotation field                        prevAnn = null;                    }                    if (prevAnn == null) {                        begin = annData.getBeginTime();                        an = tier.getAnnotationAtTime( /*annData.getEndTime() - 1*/                                begin /*< end ? begin + 1 : begin*/);                        if (an != null) {                            aa = (AlignableAnnotation) tier.createAnnotationAfter(an);                            prevAnn = aa;                        } else {

⌨️ 快捷键说明

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