📄 annotationrecreator.java
字号:
// 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()); // ?? 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 { //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*/; //an = tier.getAnnotationAtTime(begin); if ((prevAnn != null) && !prevAnn.getTier().getName().equals(annData.getTierName())) { // 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.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 (ra != null) { ra.setValue(annData.getValue()); } else { LOG.severe( "Reference annotation could not be recreated: " + annData.getValue() + " bt: " + annData.getBeginTime()); } } } } } /** * Creates a number of annotations in a sequence without creating child * annotations. <br> * Should handle the recreation of sequences of unaligned annotations on * either Time-Subdivision or Symbolic Subdivision tiers correctly.<br> * Depthless means that annotations are only created on one level, no * information on child annotations is to be expected (like a tree without * branches). The arraylist does not contain DefaultMutableTreeNode * objects but Lists of AnnotationDataRecord objects instead; this * prevents the unnecessary creation of DefaultMutableTreeNode objects, * as well as unnecessary checks on the existence of child annotations. * Useful for tokenizations. * * @param trans the Transcription to work on * @param annotationsRecords an ArrayList containing ArrayLists of * AnnotationDataRecord objects for each annotation to recreate, * all 'siblings' grouped in one list * * @see #createAnnotationsSequentially(Transcription, ArrayList) */ public static void createAnnotationsSequentiallyDepthless( Transcription trans, ArrayList annotationsRecords) { if ((trans == null) || (annotationsRecords == null) || (annotationsRecords.size() == 0)) { return; } ArrayList siblingList = null; for (int i = 0; i < annotationsRecords.size(); i++) { siblingList = (ArrayList) annotationsRecords.get(i); createSiblingAnnotations(trans, siblingList); } } /** * Creates a number of unaligned child annotations that share the same * parent annotation and without further child annotations (one level). * * @param trans the transcription * @param siblings the list containing the information necessary to * recreate the child annotations */ static void createSiblingAnnotations(Transcription trans, ArrayList siblings) { if ((trans == null) || (siblings == null) || (siblings.size() == 0)) { return; } Annotation prevAnn = null; AlignableAnnotation aa = null; RefAnnotation ra = null; Annotation an = null; AnnotationDataRecord annData = null; TierImpl tier = null; long begin; int linStereoType = -1; for (int i = 0; i < siblings.size(); i++) { aa = null; //reset an = null; ra = null; annData = (AnnotationDataRecord) siblings.get(i); // only get the tier once... if (tier == null) { tier = (TierImpl) trans.getTierWithId(annData.getTierName()); } if (tier == null) { LOG.severe("Cannot recreate annotations: tier does not exist."); return; } if (tier.isTimeAlignable()) { if (annData.isBeginTimeAligned()) { // only the first annotation aa = (AlignableAnnotation) tier.createAnnotation(annData.getBeginTime(), annData.getEndTime()); prevAnn = aa; } else { 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 { aa = (AlignableAnnotation) tier.createAnnotationAfter(prevAnn); prevAnn = aa; } } if (aa != null) { aa.setValue(annData.getValue()); // ?? check for alignment ?? 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 { // 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) { 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.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 (ra != null) { ra.setValue(annData.getValue()); } else { LOG.severe( "Reference annotation could not be recreated: " + annData.getValue() + " bt: " + annData.getBeginTime()); } } } } } /** * Creates SVGAnnotationDataRecord objects of every SVGAlignableAnnotation * referencing a graphical object, on every tier of the specified LinguisticType.<br> * Annotations that do not reference a graphical object (yet) are being * skipped! * * @param transcription the Transcription * @param type the LinguisticType * * @return an ArrayList of SVGAnnotationDataRecord objects or null */ public static ArrayList storeGraphicsData(Transcription transcription, LinguisticType type) { if ((transcription == null) || (type == null)) { return null; } ArrayList storedGraphics = new ArrayList(); Vector tiers = null; tiers = transcription.getTiersWithLinguisticType(type.getLinguisticTypeName()); ArrayList temp; TierImpl curTier; for (int i = 0; i < tiers.size(); i++) { curTier = (TierImpl) tiers.get(i); temp = AnnotationRecreator.storeGraphicsData(transcription, curTier); if (temp != null) { storedGraphics.addAll(temp); } } return storedGraphics; } /** * Creates SVGAnnotationDataRecord objects of every SVGAlignableAnnotation * referencing a graphical object on the specified tier.<br> * Annotations that do not reference a graphical object (yet) are being * skipped! * * @param transcription the Transcription * @param tier the Tier * * @return an ArrayList of SVGAnnotationDataRecord objects or null */ public static ArrayList storeGraphicsData(Transcription transcription, TierImpl tier) { if ((transcription == null) || (tier == null)) { return null; } ArrayList dataRecords = new ArrayList(); if (!tier.isTimeAlignable()) { return dataRecords; } Vector annos = tier.getAnnotations(); Annotation aa; SVGAlignableAnnotation svgAa; for (int i = 0; i < annos.size(); i++) { aa = (Annotation) annos.get(i); if (aa instanceof SVGAlignableAnnotation) { svgAa = (SVGAlignableAnnotation) aa; // only store it if there actually is a Shape if (svgAa.getShape() != null) { dataRecords.add(new SVGAnnotationDataRecord(svgAa)); } } } return dataRecords; } /** * Restores graphical objects to SVGAlignableAnnotations.<br> * The Annotations themselves are not (re)created; it is assumed (and * checked) that they exist. * * @param transcription the Transcription * @param graphicsDataRecords an Arraylist containing * SVGAnnotationDataRecords */ public static void restoreGraphicsData(Transcription transcription, ArrayList graphicsDataRecords) { if ((transcription == null) || (graphicsDataRecords == null)) { return; } TierImpl curTier; String tierName; Annotation aa; SVGAlignableAnnotation svgAa; SVGAnnotationDataRecord record; for (int i = 0; i < graphicsDataRecords.size(); i++) { record = (SVGAnnotationDataRecord) graphicsDataRecords.get(i); tierName = record.getTierName(); curTier = (TierImpl) transcription.getTierWithId(tierName); aa = curTier.getAnnotationAtTime(record.getBeginTime()); if (aa instanceof SVGAlignableAnnotation) { svgAa = (SVGAlignableAnnotation) aa; svgAa.setShape(record.getShape()); svgAa.setSVGElementID(record.getSvgElementId()); } } }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -