📄 copytiercommand.java
字号:
case Constraint.TIME_SUBDIVISION: transitionType = TierCopier.SYMSUB_TO_TIMESUB; break; case Constraint.SYMBOLIC_SUBDIVISION: transitionType = TierCopier.SAME; break; case Constraint.SYMBOLIC_ASSOCIATION: transitionType = TierCopier.SYMSUB_TO_ASSOC; break; case Constraint.INCLUDED_IN: transitionType = TierCopier.SYMSUB_TO_INCLUDED_IN; } break; case Constraint.SYMBOLIC_ASSOCIATION: switch (destStereo) { case -1: transitionType = TierCopier.ANY_TO_ROOT; break; case Constraint.TIME_SUBDIVISION: transitionType = TierCopier.ASSOC_TO_TIMESUB; break; case Constraint.SYMBOLIC_SUBDIVISION: transitionType = TierCopier.ASSOC_TO_SYMSUB; break; case Constraint.SYMBOLIC_ASSOCIATION: transitionType = TierCopier.SAME; break; case Constraint.INCLUDED_IN: transitionType = TierCopier.ASSOC_TO_INCLUDED_IN; } break; case Constraint.INCLUDED_IN: switch (destStereo) { case -1: transitionType = TierCopier.ANY_TO_ROOT; break; case Constraint.TIME_SUBDIVISION: transitionType = TierCopier.INCLUDED_IN_TO_TIMESUB; break; case Constraint.SYMBOLIC_SUBDIVISION: transitionType = TierCopier.INCLUDED_IN_TO_SYMSUB; break; case Constraint.SYMBOLIC_ASSOCIATION: transitionType = TierCopier.ASSOC_TO_INCLUDED_IN; break; case Constraint.INCLUDED_IN: transitionType = TierCopier.SAME; } } if ((parent != null) && (parent != tier)) { int stereo = destType.getConstraints().getStereoType(); if (((transitionType == TierCopier.SAME) && ((stereo == Constraint.TIME_SUBDIVISION) || (stereo == Constraint.SYMBOLIC_SUBDIVISION))) || ((transitionType != TierCopier.ANY_TO_ROOT) && (transitionType != TierCopier.ROOT_TO_ASSOC) && (transitionType != TierCopier.ROOT_TO_SYMSUB) && (transitionType != TierCopier.ROOT_TO_TIMESUB) && (transitionType != TierCopier.ROOT_TO_INCLUDED_IN))) { groupWiseCopying = true; } } //System.out.println("group copying: " + groupWiseCopying); } /** * Create copies of the tier(s) involved. A unique name is generated * and 'proper' Linguistic Types are applied to the new tiers. */ private void copyTiers() { progressUpdate(10, "Copying tier(s)"); Vector depTiers = tier.getDependentTiers(); if (!includeDepTiers) { depTiers = new Vector(); } DefaultMutableTreeNode rootNode = new DefaultMutableTreeNode(tier); DefaultMutableTreeNode[] nodes = new DefaultMutableTreeNode[depTiers.size()]; HashMap nodeMap = new HashMap(); for (int i = 0; i < depTiers.size(); i++) { TierImpl ti = (TierImpl) depTiers.get(i); nodes[i] = new DefaultMutableTreeNode(ti); nodeMap.put(ti, nodes[i]); } for (int i = 0; i < depTiers.size(); i++) { TierImpl ti = (TierImpl) depTiers.get(i); if (ti.getParentTier() == tier) { rootNode.add(nodes[i]); } else { DefaultMutableTreeNode dn = (DefaultMutableTreeNode) nodeMap.get(ti.getParentTier()); if (dn != null) { dn.add(nodes[i]); } } } // a subtree has been made, now create copies oldNameToNewName = new HashMap(); newTiers = new ArrayList(); DefaultMutableTreeNode dn; TierImpl to; TierImpl tn; TierImpl pt; LinguisticType curType; Enumeration en = rootNode.breadthFirstEnumeration(); while (en.hasMoreElements()) { dn = (DefaultMutableTreeNode) en.nextElement(); to = (TierImpl) dn.getUserObject(); String newName = getUniqueName(to.getName()); oldNameToNewName.put(to.getName(), newName); LinguisticType nextType = to.getLinguisticType(); if (to == tier) { nextType = destType; } else { // only check the transition types that imply a change of type for dep tiers. curType = to.getLinguisticType(); int stereo = -1; if (curType.getConstraints() != null) { stereo = curType.getConstraints().getStereoType(); } switch (transitionType) { case TierCopier.ROOT_TO_SYMSUB: case TierCopier.ROOT_TO_ASSOC: case TierCopier.TIMESUB_TO_SYMSUB: case TierCopier.TIMESUB_TO_ASSOC: case TierCopier.INCLUDED_IN_TO_SYMSUB: case TierCopier.INCLUDED_IN_TO_ASSOC: if (stereo == Constraint.TIME_SUBDIVISION) { // same type as the tier that is reparented. in case of // ROOT_TO_ASSOC Symbolic Subdivision would be better nextType = destType; } break; case TierCopier.SYMSUB_TO_ASSOC: if (stereo != Constraint.SYMBOLIC_ASSOCIATION) { nextType = destType; } } } pt = null; if (dn.getParent() != null) { String oldParentName = ((TierImpl) ((DefaultMutableTreeNode) dn.getParent()).getUserObject()).getName(); String newPName = (String) oldNameToNewName.get(oldParentName); pt = (TierImpl) transcription.getTierWithId(newPName); } else { // the tier to reparent if (to == tier) { pt = parent; } } if (pt != null) { tn = new TierImpl(pt, newName, to.getParticipant(), transcription, nextType); } else { tn = new TierImpl(newName, to.getParticipant(), transcription, nextType); } tn.setDefaultLocale(to.getDefaultLocale()); tn.setAnnotator(to.getAnnotator()); newTiers.add(tn); transcription.addTier(tn); //System.out.println("OT: " + to.getName() + " LT: " + // to.getLinguisticType().getLinguisticTypeName()); //System.out.println("NT: " + tn.getName() + " LT: " + // tn.getLinguisticType().getLinguisticTypeName()); } progressUpdate(20, "Tier(s) copied"); } /** * Store information on the annotations of the tier to reparent (and * depending tiers). */ private void storeAnnotations() { progressUpdate(20, "Copying annotations..."); int progForThis = 30; // (100 - 20 - 20) / 2 annotationsNodes = new ArrayList(); Vector annos = tier.getAnnotations(); float perAnn = 0f; if (annos.size() > 0) { perAnn = progForThis / (float) annos.size(); } int count = 0; Iterator anIter = annos.iterator(); AbstractAnnotation ann; if (!groupWiseCopying) { while (anIter.hasNext()) { ann = (AbstractAnnotation) anIter.next(); if (includeDepTiers) { annotationsNodes.add(AnnotationRecreator.createTreeForAnnotation( ann)); } else { annotationsNodes.add(AnnotationRecreator.createNodeForAnnotation( ann)); } count++; progressUpdate((int) (20 + (count * perAnn)), null); } } else { ArrayList group = new ArrayList(); TierImpl rootTier = tier.getRootTier(); Annotation curParent = null; while (anIter.hasNext()) { ann = (AbstractAnnotation) anIter.next(); if (curParent == null) { // add to first group if (includeDepTiers) { group.add(AnnotationRecreator.createTreeForAnnotation( ann)); } else { group.add(AnnotationRecreator.createNodeForAnnotation( ann)); } curParent = rootTier.getAnnotationAtTime(ann.getBeginTimeBoundary()); } else if (rootTier.getAnnotationAtTime( ann.getBeginTimeBoundary()) == curParent) { // add to current group if (includeDepTiers) { group.add(AnnotationRecreator.createTreeForAnnotation( ann)); } else { group.add(AnnotationRecreator.createNodeForAnnotation( ann)); } } else { annotationsNodes.add(group); // finish group group = new ArrayList(); curParent = rootTier.getAnnotationAtTime(ann.getBeginTimeBoundary()); // add to new group if (includeDepTiers) { group.add(AnnotationRecreator.createTreeForAnnotation( ann)); } else { group.add(AnnotationRecreator.createNodeForAnnotation( ann)); } } count++; progressUpdate((int) (20 + (count * perAnn)), null); } // add the last group... if (group.size() > 0) { annotationsNodes.add(group); } } } /** * Creates copies of the annotation: success might depend on the new * LinguisticType and on the annotations on the (new) parent tier. */ private void createCopiesOfAnnotations() { progressUpdate(60, "Creating new annotations..."); int progForThis = 30; // (100 - 20 - 20) / 2 int curPropMode = 0; curPropMode = transcription.getTimeChangePropagationMode(); if (curPropMode != Transcription.NORMAL) { transcription.setTimeChangePropagationMode(Transcription.NORMAL); } if (annotationsNodes.size() > 0) { float perAnn = progForThis / (float) annotationsNodes.size(); int count = 0; transcription.setNotifying(false); TierCopier copier = new TierCopier(); DefaultMutableTreeNode node; if (parent != null) { // int stereo = destType.getConstraints().getStereoType(); if (groupWiseCopying) { // annotationNodes contains ArrayLists ArrayList group; for (int i = 0; i < annotationsNodes.size(); i++) { group = (ArrayList) annotationsNodes.get(i); copier.createAnnotationsSequentially(transcription, group, oldNameToNewName); count++; progressUpdate((int) (50 + (count * perAnn)), null); } } else { for (int i = 0; i < annotationsNodes.size(); i++) { node = (DefaultMutableTreeNode) annotationsNodes.get(i); copier.createAnnotationFromTree(transcription, node, oldNameToNewName); count++; progressUpdate((int) (50 + (count * perAnn)), null); } } } else { for (int i = 0; i < annotationsNodes.size(); i++) { node = (DefaultMutableTreeNode) annotationsNodes.get(i); copier.createRootAnnotationFromTree(transcription, node, oldNameToNewName); count++; progressUpdate((int) (50 + (count * perAnn)), null); } } transcription.setNotifying(true); } // restore the time propagation mode transcription.setTimeChangePropagationMode(curPropMode); } /** * Store datarecords for the new annotations for undo/redo */ private void storeCopiedAnnotations() { progressUpdate(80, "Storing information for undo/redo..."); int progForThis = 20; // leftover String newName = (String) oldNameToNewName.get(tierName); TierImpl tierCopy = null; for (int i = 0; i < newTiers.size(); i++) { TierImpl t = (TierImpl) newTiers.get(i); if (t.getName().equals(newName)) { tierCopy = t; break; } } if (tierCopy != null) { copiedAnnotationsNodes = new ArrayList(tierCopy.getAnnotations() .size()); Vector annos = tierCopy.getAnnotations(); Iterator anIter = annos.iterator(); AbstractAnnotation ann; float perAnn = progForThis / (float) annotationsNodes.size(); int count = 0; while (anIter.hasNext()) { ann = (AbstractAnnotation) anIter.next(); copiedAnnotationsNodes.add(AnnotationRecreator.createTreeForAnnotation( ann)); count++; progressUpdate((int) (80 + (count * perAnn)), null); } } } /** * Creates a unique name for a copy of an existing tier. * * @param name the name of the original tier * * @return the name for a copy, unique within the transcription */ private String getUniqueName(String name) { String nName = name + "-cp"; if (transcription.getTierWithId(nName) != null) { for (int i = 1; i < 50; i++) { nName = nName + "-" + i; if (transcription.getTierWithId(nName) == null) { return nName; } } } return nName; } }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -