📄 transcriptionmerger.java
字号:
AnnotationRecreator.createAnnotationFromTree(destTranscription, recordNode); progressUpdate(tierStartProgress + (ppa * i), busy); } LOG.info("Added " + numAnn + " annotations to " + tier.getName()); } progressUpdate(tierStartProgress + (tierNum * progressPerIndepTier), "Done merging tier: " + tier.getName()); LOG.info("Done merging tier: " + tier.getName()); tierNum++; } } progressUpdate(100 - LOAD_PERCENTAGE, "Saving transcription..."); // save the new transcription ACM24TranscriptionStore transcriptionStore = new ACM24TranscriptionStore(); transcriptionStore.storeTranscription(destTranscription, null, new Vector(), destinationFile.getAbsolutePath(), TranscriptionStore.EAF); LOG.info("Transcription saved to: " + destinationFile.getAbsolutePath()); progressComplete("Completed merging transcription..."); } catch (Exception rex) { progressInterrupt("Error while merging: " + rex.getMessage()); if (mergeThread != null) { mergeThread.interrupt(); } } } /** * Adds the tiers in the specified Vector to the destination transcription, * after performing some checks. If Linguistic types and/or CV's should * be copied these are copied first. * * @param tiersToAdd a list of tiers to add to the destination */ private void addTiersTypesAndCVs(Vector tiersToAdd) { if ((tiersToAdd == null) || (destTranscription == null) || (transcription2 == null)) { LOG.warning("Transcription or tiers null"); return; } Hashtable renamedCVS = new Hashtable(); Hashtable renamedTypes = new Hashtable(); ArrayList typesToAdd = new ArrayList(); ArrayList cvsToAdd = new ArrayList(); TierImpl t; TierImpl t2; LinguisticType lt; LinguisticType lt2 = null; String typeName; Vector destTypes; ControlledVocabulary cv; ControlledVocabulary cv2 = null; for (int i = 0; i < tiersToAdd.size(); i++) { t = (TierImpl) tiersToAdd.get(i); lt = t.getLinguisticType(); if (!typesToAdd.contains(lt)) { typesToAdd.add(lt); } typeName = lt.getLinguisticTypeName(); if (lt.isUsingControlledVocabulary()) { cv = transcription2.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 = destTranscription.getControlledVocabulary(cv.getName()); if (cv2 == null) { destTranscription.addControlledVocabulary(cv); LOG.info("Added Controlled Vocabulary: " + cv.getName()); } else if (!cv.equals(cv2)) { // rename String newCVName = cv.getName() + "-copy"; renamedCVS = new Hashtable(); LOG.info("Renamed Controlled Vocabulary: " + cv.getName() + " to " + newCVName); renamedCVS.put(cv.getName(), cv); cv.setName(newCVName); destTranscription.addControlledVocabulary(cv); LOG.info("Added Controlled Vocabulary: " + cv.getName()); } } // end cv's 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()); } destTypes = destTranscription.getLinguisticTypes(); if (!destTypes.contains(lt)) { lt2 = null; boolean typeNameExists = false; for (int j = 0; j < destTypes.size(); j++) { lt2 = (LinguisticType) destTypes.get(j); if (lt.getLinguisticTypeName().equals(lt2.getLinguisticTypeName())) { typeNameExists = true; break; } } if (!typeNameExists) { destTranscription.addLinguisticType(lt); LOG.info("Added Linguistic Type: " + lt.getLinguisticTypeName()); } else { // if they are equal the existing will be used by its name if (!lt.equals(lt2)) { String newLTName = lt.getLinguisticTypeName() + "-copy"; renamedTypes = new Hashtable(); LOG.info("Renamed Linguistic Type: " + lt.getLinguisticTypeName() + " to " + newLTName); renamedTypes.put(lt.getLinguisticTypeName(), lt); lt.setLinguisticTypeName(newLTName); destTranscription.addLinguisticType(lt); LOG.info("Added Linguistic Type: " + lt.getLinguisticTypeName()); } } } } //end linguistic types // create new tiers on the destination transcription for (int i = 0; i < tiersToAdd.size(); i++) { t = (TierImpl) tiersToAdd.get(i); t2 = (TierImpl) t.getParentTier(); String parentTierName = null; if (t2 != null) { parentTierName = t2.getName(); } TierImpl newTier = null; if (parentTierName == null) { newTier = new TierImpl(t.getName(), t.getParticipant(), destTranscription, null); } else { t2 = (TierImpl) destTranscription.getTierWithId(parentTierName); if (t2 != null) { newTier = new TierImpl(t2, t.getName(), t.getParticipant(), destTranscription, 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(); destTypes = destTranscription.getLinguisticTypes(); if (destTypes.contains(lt)) { newTier.setLinguisticType(lt); // transcription does not perform any checks.. if (destTranscription.getTierWithId(newTier.getName()) == null) { destTranscription.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 add/create tiers } /** * Notifies any listeners of a progress update. * * @param percent the new progress percentage, [0 - 100] * @param message a descriptive message */ private void progressUpdate(int percent, String message) { if (listeners != null) { for (int i = 0; i < listeners.size(); i++) { ((ProgressListener) listeners.get(i)).progressUpdated(this, percent, message); } } } /** * Notifies any listeners that the process has completed. * * @param message a descriptive message */ private void progressComplete(String message) { if (listeners != null) { for (int i = 0; i < listeners.size(); i++) { ((ProgressListener) listeners.get(i)).progressCompleted(this, message); } } } /** * Notifies any listeners that the process has been interrupted. * * @param message a descriptive message */ private void progressInterrupt(String message) { if (listeners != null) { for (int i = 0; i < listeners.size(); i++) { ((ProgressListener) listeners.get(i)).progressInterrupted(this, message); } } } /** * Adds a ProgressListener to the list of ProgressListeners. * * @param pl the new ProgressListener */ public synchronized void addProgressListener(ProgressListener pl) { if (listeners == null) { listeners = new ArrayList(2); } listeners.add(pl); } /** * Removes the specified ProgressListener from the list of listeners. * * @param pl the ProgressListener to remove */ public synchronized void removeProgressListener(ProgressListener pl) { if ((pl != null) && (listeners != null)) { listeners.remove(pl); } } /** * A thread that directs the main steps in the merging process. Merging is * done in a separate thread in order to be able to update ui elements * that visualize the progress of the process. * * @author HS * @version 1.0, april 2005 */ class MergeThread extends Thread { /** * Creates a new MergeThread instance. */ public MergeThread() { super(); } /** * Creates a new MergeThread instance. * * @param name the name of the thread */ public MergeThread(String name) { super(name); } /** * The actual action of this thread. */ public void run() { TranscriptionMerger.this.firstTranscription(); TranscriptionMerger.this.secondTranscription(); TranscriptionMerger.this.mergeTranscriptions(); } /** * Interrupts the current merging process. */ public void interrupt() { TranscriptionMerger.LOG.warning("Merge thread interrupted."); TranscriptionMerger.this.progressInterrupt("Merging interrupted..."); super.interrupt(); } }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -