📄 tiercopier.java
字号:
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.warning( "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*/; // correct to fit in the parentbounds if ((begin < timeBounds[0]) && (annData.getEndTime() > timeBounds[0])) { begin = timeBounds[0]; } //an = tier.getAnnotationAtTime(begin); 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()); System.out.println("Begin: " + begin); } } else if (linStereoType == Constraint.SYMBOLIC_ASSOCIATION) { begin = annData.getBeginTime() /*+ 1*/; if ((begin < timeBounds[0]) && (annData.getEndTime() > timeBounds[0])) { begin = timeBounds[0]; } 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; } /** * Suitable for recreation of annotations on root tiers. Almost identical * to AnnotationRecreator.createRootAnnotationFromTree(), but assumes * that the root annotation is created on a toplevel tier (no parent). * * @param trans the transcription * @param root the rootnode * @param tierMapping mappings of old tier name to new tier names * * @return the 'root' annotation */ public AbstractAnnotation createRootAnnotationFromTree( Transcription trans, DefaultMutableTreeNode root, HashMap tierMapping) { if ((trans == null) || (root == null) || (tierMapping == null)) { return null; } AbstractAnnotation annotation = null; DefaultMutableTreeNode node; AnnotationDataRecord annData = null; String tierName = null; TierImpl tier = null; AlignableAnnotation aa = null; RefAnnotation ra = null; Annotation an = null; long begin; long end; int linStereoType = -1; annData = (AnnotationDataRecord) root.getUserObject(); 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); } Enumeration en = root.breadthFirstEnumeration(); while (en.hasMoreElements()) { aa = null; //reset 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()) { 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.warning( "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(); 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((String) tierMapping.get( 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.warning( "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);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -