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

📄 tiercopier.java

📁 编辑视频文件
💻 JAVA
📖 第 1 页 / 共 4 页
字号:
                        // ?? 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.info(                            "Alignable annotation could not be recreated: " +                            annData.getValue() + " bt: " +                            annData.getBeginTime());                    }                } else {                    //should nor happen; all annotations should be unaligned in this case                    prevAnn = null;                }            } else {                // ref annotations                linStereoType = tier.getLinguisticType().getConstraints()                                    .getStereoType();                if (linStereoType == Constraint.SYMBOLIC_SUBDIVISION) {                    begin = annData.getBeginTime() /*+ 1*/;                    if (begin < timeBounds[0]) {                        begin = timeBounds[0];                    }                    //an = tier.getAnnotationAtTime(begin);                    if ((prevAnn != null) &&                            !prevAnn.getTier().getName().equals(tierName)) {                        // reset previous annotation field                        prevAnn = null;                    }                    // should not be necessary here                    if ((prevAnn != null) &&                            (prevAnn.getEndTimeBoundary() < (begin + 1))) {                        prevAnn = null;                    }                    if (prevAnn == null) {                        ra = (RefAnnotation) tier.createAnnotation(begin, begin);                        prevAnn = ra;                    } else {                        ra = (RefAnnotation) tier.createAnnotationAfter(prevAnn);                        prevAnn = ra;                    }                    if (ra != null) {                        ra.setValue(annData.getValue());                    } else {                        LOG.info(                            "Reference annotation could not be recreated: " +                            annData.getValue() + " bt: " +                            annData.getBeginTime());                    }                } else if (linStereoType == Constraint.SYMBOLIC_ASSOCIATION) {                    begin = annData.getBeginTime() /*+ 1*/;                    end = annData.getEndTime();                    if (begin < timeBounds[0]) {                        begin = timeBounds[0];                    }                    if (end > timeBounds[1]) {                        end = timeBounds[1];                    }                    mid = (begin + end) / 2;                    an = tier.getAnnotationAtTime(mid);                    if (an == null) {                        ra = (RefAnnotation) tier.createAnnotation(mid, mid);                    }                    if (ra != null) {                        ra.setValue(annData.getValue());                    } else {                        LOG.info(                            "Reference annotation could not be recreated: " +                            annData.getValue() + " bt: " +                            annData.getBeginTime());                    }                }            }        }    }    /**     * Creates a number of sibling annotations; the root node is just a     * container node. It is assumed that the annotations are created on a     * symbolic subdivision tier.     *     * @param trans the transcription     * @param pNode the container node     * @param tierMapping mappings of old tier name to new tier names     */    private void createSymSubAnnotationsSkipRoot(Transcription trans,        DefaultMutableTreeNode pNode, HashMap tierMapping) {        DefaultMutableTreeNode node;        AnnotationDataRecord annData = null;        String tierName = null;        TierImpl tier = null;        RefAnnotation ra = null;        Annotation an = null;        Annotation prevAnn = null;        long begin;        long mid;        int linStereoType = -1;        // first recreate aligned annotations        Enumeration en = pNode.breadthFirstEnumeration();        en.nextElement(); // skip root        while (en.hasMoreElements()) {            an = null; //reset            ra = null;            node = (DefaultMutableTreeNode) en.nextElement();            annData = (AnnotationDataRecord) node.getUserObject();            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()) {                LOG.warning("Tier should not be time alignable");            } 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(tierName)) {                        // reset previous annotation field                        prevAnn = null;                    }                    // should not be necessary here                    if ((prevAnn != null) &&                            (prevAnn.getEndTimeBoundary() < (begin + 1))) {                        prevAnn = null;                    }                    if (prevAnn == null) {                        ra = (RefAnnotation) tier.createAnnotation(begin, begin);                        prevAnn = ra;                    } else {                        ra = (RefAnnotation) tier.createAnnotationAfter(prevAnn);                        prevAnn = ra;                    }                    if (ra != null) {                        ra.setValue(annData.getValue());                    } else {                        LOG.info(                            "Reference annotation could not be recreated: " +                            annData.getValue() + " bt: " +                            annData.getBeginTime());                    }                } else if (linStereoType == Constraint.SYMBOLIC_ASSOCIATION) {                    begin = annData.getBeginTime() /*+ 1*/;                    mid = (begin + annData.getEndTime()) / 2;                    an = tier.getAnnotationAtTime(mid);                    if (an == null) {                        ra = (RefAnnotation) tier.createAnnotation(mid, mid);                    }                    if (ra != null) {                        ra.setValue(annData.getValue());                    } else {                        LOG.info(                            "Reference annotation could not be recreated: " +                            annData.getValue() + " bt: " +                            annData.getBeginTime());                    }                }            }        }    }    /**     * Creates a number of sibling annotations; the root node is just a     * container node. It is assumed that the annotations are created on a     * symbolic association tier.  Incomplete...     *     * @param trans the transcription     * @param pNode the container node     * @param tierMapping mappings of old tier name to new tier names     */    private void createSymAssAnnotationsSkipRoot(Transcription trans,        DefaultMutableTreeNode pNode, HashMap tierMapping) {        DefaultMutableTreeNode node;        AnnotationDataRecord annData = null;        String tierName = null;        TierImpl tier = null;        RefAnnotation ra = null;        Annotation an = null;        Annotation prevAnn = null;        long begin;        long mid;        int linStereoType = -1;        Enumeration en = pNode.breadthFirstEnumeration();        en.nextElement(); // skip root        while (en.hasMoreElements()) {            an = null; //reset            ra = null;            node = (DefaultMutableTreeNode) en.nextElement();            annData = (AnnotationDataRecord) node.getUserObject();            tierName = (String) tierMapping.get(annData.getTierName());            tier = (TierImpl) trans.getTierWithId(tierName);            if (tier == null) {                LOG.warning(                    "Cannot recreate annotations: tier does not exist: " +                    tierName);                continue;            }            if (tier.isTimeAlignable()) {                LOG.warning("Tier should not be time alignable");            } else {                // ref annotations                linStereoType = tier.getLinguisticType().getConstraints()                                    .getStereoType();                if (linStereoType == Constraint.SYMBOLIC_ASSOCIATION) {                    begin = annData.getBeginTime() /*+ 1*/;                    mid = (begin + annData.getEndTime()) / 2;                    an = tier.getAnnotationAtTime(mid);                    if (an == null) {                        ra = (RefAnnotation) tier.createAnnotation(mid, mid);                    }                    if (ra != null) {                        ra.setValue(annData.getValue());                    } else {                        LOG.info(                            "Reference annotation could not be recreated: " +                            annData.getValue() + " bt: " +                            annData.getBeginTime());                    }                } else if (linStereoType == Constraint.SYMBOLIC_SUBDIVISION) {                    begin = annData.getBeginTime() /*+ 1*/;                    //an = tier.getAnnotationAtTime(begin);                    if ((prevAnn != null) &&                            !prevAnn.getTier().getName().equals(tierName)) {                        // reset previous annotation field                        prevAnn = null;                    }                    // should not be necessary here                    if ((prevAnn != null) &&                            (prevAnn.getEndTimeBoundary() < (begin + 1))) {                        prevAnn = null;                    }                    if (prevAnn == null) {                        ra = (RefAnnotation) tier.createAnnotation(begin, begin);                        prevAnn = ra;                    } else {                        ra = (RefAnnotation) tier.createAnnotationAfter(prevAnn);                        prevAnn = ra;                    }                    if (ra != null) {                        ra.setValue(annData.getValue());                    } else {                        LOG.info(                            "Reference annotation could not be recreated: " +                            annData.getValue() + " bt: " +                            annData.getBeginTime());                    }                }            }        }    }    /**     * Calculates (new) begin and endtimes for a series of (unaligned) child     * annotations  using the parent's begin and end times.     *     * @param node the parent node     * @param bt the parents begin time     * @param et the parents end time     */    private void adjustTimes(DefaultMutableTreeNode node, long bt, long et) {        if (node == null) {            return;        }        int numChildren = node.getChildCount();        if (numChildren == 0) {            return;        }        int perAnn = (int) (et - bt) / numChildren;        DefaultMutableTreeNode n = null;        AnnotationDataRecord annData = null;        for (int i = 0; i < numChildren; i++) {            n = (DefaultMutableTreeNode) node.getChildAt(i);            annData = (AnnotationDataRecord) n.getUserObject();            annData.setBeginTime(bt + (i * perAnn));            annData.setEndTime(bt + ((i + 1) * perAnn));            adjustTimes(n, annData.getBeginTime(), annData.getEndTime());        }    }}

⌨️ 快捷键说明

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