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

📄 tiercopier.java

📁 编辑视频文件
💻 JAVA
📖 第 1 页 / 共 4 页
字号:
                    if ((prevAnn != null) &&                            !prevAnn.getTier().getName().equals((String) tierMapping.get(                                    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.warning(                            "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.warning(                            "Reference annotation could not be recreated: " +                            annData.getValue() + " bt: " +                            annData.getBeginTime());                    }                }            }        }        // end second run        return annotation;    }    /**     * Creates a number of related annotations (siblings) in one run. Not to be     * used on root tiers.     *     * @param trans the transcription     * @param group a group of annotations that belong together and should end     *        up under the same (higher level) parent     * @param tierMapping mappings of old tier name to new tier names     */    public void createAnnotationsSequentially(Transcription trans,        ArrayList group, HashMap tierMapping) {        if ((trans == null) || (group == null) || (group.size() == 0) ||                (tierMapping == null)) {            return;        }        DefaultMutableTreeNode node;        AnnotationDataRecord annData = null;        String tierName = null;        TierImpl tier = null;        LinguisticType linType = null;        int linStereoType = -1;        Annotation an = null;        long[] timeBounds = new long[] { 0, 0 };        node = (DefaultMutableTreeNode) group.get(0);        annData = (AnnotationDataRecord) node.getUserObject();        tierName = (String) tierMapping.get(annData.getTierName());        tier = (TierImpl) trans.getTierWithId(tierName);        if ((tier == null) || (tier.getParentTier() == null)) {            LOG.warning(                "Cannot recreate annotations: tier copy or it's parent does not exist: " +                tierName);            return;        }        linType = tier.getLinguisticType();        if (linType.getConstraints() != null) {            linStereoType = linType.getConstraints().getStereoType();        }        AnnotationDataRecord annData2 = (AnnotationDataRecord) ((DefaultMutableTreeNode) group.get(group.size() -                1)).getUserObject();        Vector overlap = ((TierImpl) tier.getParentTier()).getOverlappingAnnotations(annData.getBeginTime(),                annData2.getEndTime());        if (overlap.size() > 0) {            for (int i = 0; i < overlap.size(); i++) {                an = (Annotation) overlap.get(i);                if (tier.getOverlappingAnnotations(an.getBeginTimeBoundary(),                            an.getEndTimeBoundary()).size() == 0) {                    timeBounds[0] = an.getBeginTimeBoundary();                    timeBounds[1] = an.getEndTimeBoundary();                    break;                }            }            if ((timeBounds[0] == 0) && (timeBounds[1] == 0)) {                return;            }        } else {            return; // no overlap, no annotation        }        // time subdivision, symbolic subdivision and symbolic association could/should be treated in         // their own way, or better each 'transition type' should be handled differently        if ((linStereoType == Constraint.TIME_SUBDIVISION) ||                (linStereoType == Constraint.INCLUDED_IN)) {            DefaultMutableTreeNode pNode = new DefaultMutableTreeNode("p");            for (int i = 0; i < group.size(); i++) {                node = (DefaultMutableTreeNode) group.get(i);                annData = (AnnotationDataRecord) node.getUserObject();                // transition time-sub -> time-sub check aligned annotations only                if (!((annData.getBeginTime() > timeBounds[1]) ||                        (annData.getEndTime() < timeBounds[0]))) {                    //group.remove(i);                    pNode.add(node);                }            }            createTimeSubAnnotationsSkipRoot(trans, pNode, tierMapping);        } else if (linStereoType == Constraint.SYMBOLIC_SUBDIVISION) {            DefaultMutableTreeNode pNode = new DefaultMutableTreeNode("p");            for (int i = 0; i < group.size(); i++) {                node = (DefaultMutableTreeNode) group.get(i);                pNode.add(node);            }            adjustTimes(pNode, timeBounds[0], timeBounds[1]);            createSymSubAnnotationsSkipRoot(trans, pNode, tierMapping);        } else if (linStereoType == Constraint.SYMBOLIC_ASSOCIATION) {            DefaultMutableTreeNode pNode = new DefaultMutableTreeNode("p");            for (int i = 0; i < group.size(); i++) {                node = (DefaultMutableTreeNode) group.get(i);                pNode.add(node);            }            adjustTimes(pNode, timeBounds[0], timeBounds[1]);            createSymAssAnnotationsSkipRoot(trans, pNode, tierMapping);        }    }    /**     * Creates a number of sibling annotations; the root node is just a     * container node. It is assumed that the annotations are created on a     * time subdivision tier.     *     * @param trans the transcription     * @param pNode the container node     * @param tierMapping mappings of old tier name to new tier names     */    private void createTimeSubAnnotationsSkipRoot(Transcription trans,        DefaultMutableTreeNode pNode, HashMap tierMapping) {        DefaultMutableTreeNode node;        AnnotationDataRecord annData = null;        String tierName = null;        TierImpl tier = null;        AlignableAnnotation aa = null;        RefAnnotation ra = null;        Annotation an = null;        Annotation prevAnn = null;        long begin;        long mid;        long end;        int linStereoType = -1;        long[] timeBounds = new long[] { 0, 0 };        // first recreate aligned annotations        Enumeration en = pNode.breadthFirstEnumeration();        en.nextElement(); // skip root        while (en.hasMoreElements()) {            node = (DefaultMutableTreeNode) en.nextElement();            annData = (AnnotationDataRecord) node.getUserObject();            if (annData.isBeginTimeAligned()) {                //createAnnotationFromTree(trans, node, tierMapping);                tierName = (String) tierMapping.get(annData.getTierName());                tier = (TierImpl) trans.getTierWithId(tierName);                if (tier == null) {                    LOG.warning(                        "Cannot recreate annotations: tier copy does not exist: " +                        tierName);                    return;                }                begin = annData.getBeginTime();                end = annData.getEndTime();                Vector overlap = ((TierImpl) tier.getParentTier()).getOverlappingAnnotations(begin,                        end);                if (overlap.size() > 0) {                    an = (Annotation) overlap.get(0);                    timeBounds[0] = an.getBeginTimeBoundary();                    timeBounds[1] = an.getEndTimeBoundary();                }                if ((timeBounds[0] == 0) && (timeBounds[1] == 0)) {                    continue;                }                // correct to fit in the parentbounds                if (begin < timeBounds[0]) {                    begin = timeBounds[0];                }                if (end > timeBounds[1]) {                    end = timeBounds[1];                }                aa = (AlignableAnnotation) tier.createAnnotation(begin, end);                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.warning("Alignable annotation could not be recreated: " +                        annData.getValue() + " bt: " + annData.getBeginTime() +                        " et: " + annData.getEndTime());                }            }        }        // next recreate the rest        en = pNode.breadthFirstEnumeration();        en.nextElement(); // skip root        while (en.hasMoreElements()) {            aa = null; //reset            an = null;            ra = null;            node = (DefaultMutableTreeNode) en.nextElement();            annData = (AnnotationDataRecord) node.getUserObject();            if (annData.isBeginTimeAligned()) {                // we already had this one                continue;            }            tierName = (String) tierMapping.get(annData.getTierName());            tier = (TierImpl) trans.getTierWithId(tierName);            if (tier == null) {                LOG.warning("Cannot recreate annotations: tier does not exist.");                continue;            }            if (tier.isTimeAlignable()) {                if (!annData.isBeginTimeAligned()) {                    if ((prevAnn != null) &&                            (!prevAnn.getTier().getName().equals(tierName) ||                            (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 {                            // time subdivision of a time subdivision...                            aa = (AlignableAnnotation) tier.createAnnotation(begin,                                    annData.getEndTime());                            prevAnn = aa;                        }                    } else {                        aa = (AlignableAnnotation) tier.createAnnotationAfter(prevAnn);                        prevAnn = aa;                    }                    if (aa != null) {                        aa.setValue(annData.getValue());

⌨️ 快捷键说明

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