📄 mergeutil.java
字号:
//tiersToAdd.clear(); ArrayList sorted = new ArrayList(tiersToSort.size()); Enumeration en = sortedRootNode.breadthFirstEnumeration(); while (en.hasMoreElements()) { DefaultMutableTreeNode node = (DefaultMutableTreeNode) en.nextElement(); if (node.getUserObject() instanceof TierImpl) { sorted.add(node.getUserObject()); } } return sorted; } /** * Adds the tiers that are not yet in the destination transcription, * after performing some checks. If Linguistic types and/or CV's should * be copied/added these are copied/added first. It is assumed that it is * save to add LT's and CV's to the destination Transcription without cloning. * * @param tiersToAdd a list of tiers to add to the destination */ public void addTiersTypesAndCVs(TranscriptionImpl srcTrans, TranscriptionImpl destTrans, ArrayList tiersToAdd) { if (srcTrans == null) { LOG.warning("Source transcription is null."); return; } if (destTrans == null) { LOG.warning("Destination transcription is null"); return; } if ((tiersToAdd == null) || (tiersToAdd.size() == 0)) { LOG.warning("No tiers to add"); return; } // System.out.println("num tiers: " + tiersToAdd.size()); Hashtable renamedCVS = new Hashtable(5); Hashtable renamedTypes = new Hashtable(5); ArrayList typesToAdd = new ArrayList(5); ArrayList cvsToAdd = new ArrayList(5); TierImpl t; TierImpl t2; TierImpl newTier; LinguisticType lt; LinguisticType lt2 = null; String typeName; ControlledVocabulary cv; ControlledVocabulary cv2 = null; for (int i = 0; i < tiersToAdd.size(); i++) { t = (TierImpl) tiersToAdd.get(i); if ((t == null) || (destTrans.getTierWithId(t.getName()) != null)) { // don't do further checks on ling. type and cv continue; } lt = t.getLinguisticType(); if (typesToAdd.contains(lt)) { continue; } typeName = lt.getLinguisticTypeName(); lt2 = destTrans.getLinguisticTypeByName(typeName); if (lt2 != null) { //already there if ((lt.getConstraints() == null) && (lt2.getConstraints() == null)) { continue; } else if ((lt.getConstraints() != null) && (lt2.getConstraints() != null)) { if (lt.getConstraints().getStereoType() == lt.getConstraints() .getStereoType()) { continue; } } // rename and add String nname = typeName + "-cp"; int c = 1; while (destTrans.getLinguisticTypeByName(nname + c) != null) { c++; } nname = nname + c; if (!renamedTypes.containsKey(typeName)) { renamedTypes.put(typeName, nname); } } typesToAdd.add(lt); if (lt.isUsingControlledVocabulary()) { cv = srcTrans.getControlledVocabulary(lt.getControlledVocabylaryName()); if (!cvsToAdd.contains(cv)) { cvsToAdd.add(cv); } } } // add CV's, renaming when necessary for (int i = 0; i < cvsToAdd.size(); i++) { cv = (ControlledVocabulary) cvsToAdd.get(i); cv2 = destTrans.getControlledVocabulary(cv.getName()); if (cv2 == null) { destTrans.addControlledVocabulary(cv); LOG.info("Added Controlled Vocabulary: " + cv.getName()); } else if (!cv.equals(cv2)) { // rename String newCVName = cv.getName() + "-cp"; int c = 1; while (destTrans.getControlledVocabulary(newCVName + c) != null) { c++; } newCVName = newCVName + c; LOG.info("Renamed Controlled Vocabulary: " + cv.getName() + " to " + newCVName); renamedCVS.put(cv.getName(), cv); cv.setName(newCVName); destTrans.addControlledVocabulary(cv); LOG.info("Added Controlled Vocabulary: " + cv.getName()); } } // end cv // add linguistic types for (int i = 0; i < typesToAdd.size(); i++) { lt = (LinguisticType) typesToAdd.get(i); typeName = lt.getLinguisticTypeName(); if (lt.isUsingControlledVocabulary() && renamedCVS.containsKey(lt.getControlledVocabylaryName())) { cv2 = (ControlledVocabulary) renamedCVS.get(lt.getControlledVocabylaryName()); lt.setControlledVocabularyName(cv2.getName()); } if (renamedTypes.containsKey(lt.getLinguisticTypeName())) { String newLTName = (String) renamedTypes.get(lt.getLinguisticTypeName()); LOG.info("Renamed Linguistic Type: " + lt.getLinguisticTypeName() + " to " + newLTName); lt.setLinguisticTypeName(newLTName); } destTrans.addLinguisticType(lt); LOG.info("Added Linguistic Type: " + lt.getLinguisticTypeName()); } // end linguistic types // add tiers if necessary for (int i = 0; i < tiersToAdd.size(); i++) { // System.out.println("i: " + i); t = (TierImpl) tiersToAdd.get(i); if (destTrans.getTierWithId(t.getName()) != null) { continue; } t2 = (TierImpl) t.getParentTier(); String parentTierName = null; if (t2 != null) { parentTierName = t2.getName(); } newTier = null; if (parentTierName == null) { newTier = new TierImpl(t.getName(), t.getParticipant(), destTrans, null); } else { t2 = (TierImpl) destTrans.getTierWithId(parentTierName); if (t2 != null) { newTier = new TierImpl(t2, t.getName(), t.getParticipant(), destTrans, null); } else { LOG.warning("The parent tier: " + parentTierName + " for tier: " + t.getName() + " was not found in the destination transcription"); } } if (newTier != null) { lt = t.getLinguisticType(); lt2 = destTrans.getLinguisticTypeByName(lt.getLinguisticTypeName()); if (lt2 != null) { newTier.setLinguisticType(lt2); destTrans.addTier(newTier); LOG.info("Created and added tier to destination: " + newTier.getName()); } else { LOG.warning("Could not add tier: " + newTier.getName() + " because the Linguistic Type was not found in the destination transcription."); } newTier.setDefaultLocale(t.getDefaultLocale()); newTier.setAnnotator(t.getAnnotator()); } } //end tiers }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -