📄 transcriptionimpl.java
字号:
/** * DOCUMENT ME! * * @return DOCUMENT ME! */ public String getPathName() { return fileName; } /** * DOCUMENT ME! * * @param theFileName DOCUMENT ME! */ public void setPathName(String theFileName) { if (theFileName.startsWith("file:")) { theFileName = theFileName.substring(5); } fileName = theFileName; url = pathToURLString(fileName); } /** * Load the Annotations into the Tiers. * * @param identity DOCUMENT ME! */ public void loadAnnotations() { if (!isLoaded()) { (new ACM24TranscriptionStore()).loadTranscription(this, null); } } /** * DOCUMENT ME! * * @param pathName DOCUMENT ME! */ public void setMainMediaFile(String pathName) { // HS feb 05: // let the auto detected media file name precede if (mediafileName == null) { this.mediafileName = pathName; //mediaObject = createMediaObject(mediafileName); } } /** * Sets the path to an svg file containing the information of graphical annotations (2D). * This assumes that there is only one such file. This might need to be changed for cases of * graphical annotations on multiple videos, but it might also stay the same. * 2006-11 HS: create a LinkedFileDescriptor for the svg file if it isn't already there. This replaces * the implicit association based on file name and location. * * @param fileName the path to an .svg file */ public void setSVGFile(String fileName) { if (fileName == null) { removeSVGFile(); return; } String svgURL = fileName; // check if there is already a linked file descriptor for this file if (!svgURL.startsWith("file:")) { svgURL = pathToURLString(svgURL); } svgFile = svgURL; LinkedFileDescriptor lfd; for (int i = 0; i < linkedFileDescriptors.size(); i++) { lfd = (LinkedFileDescriptor) linkedFileDescriptors.get(i); if (lfd.linkURL.equals(svgURL)) { return; } } // create a new one lfd = new LinkedFileDescriptor(svgURL, LinkedFileDescriptor.SVG_TYPE); linkedFileDescriptors.add(lfd); MediaDescriptor mmd; // create association based on file name for (int i = 0; i < mediaDescriptors.size(); i++) { mmd = (MediaDescriptor) mediaDescriptors.get(i); if (mmd.mediaURL.substring(0, mmd.mediaURL.lastIndexOf('.')).equals(svgURL.substring( 0, svgURL.lastIndexOf('.')))) { if (mmd.mimeType.equals(MediaDescriptor.MPG_MIME_TYPE) || mmd.mimeType.equals(MediaDescriptor.QUICKTIME_MIME_TYPE) || mmd.mimeType.equals(MediaDescriptor.GENERIC_VIDEO_TYPE)) { lfd.associatedWith = mmd.mediaURL; break; } } } if (lfd.associatedWith == null) { // associate with the first video for (int i = 0; i < mediaDescriptors.size(); i++) { mmd = (MediaDescriptor) mediaDescriptors.get(i); if (mmd.mimeType.equals(MediaDescriptor.MPG_MIME_TYPE) || mmd.mimeType.equals(MediaDescriptor.QUICKTIME_MIME_TYPE) || mmd.mimeType.equals(MediaDescriptor.GENERIC_VIDEO_TYPE)) { lfd.associatedWith = mmd.mediaURL; break; } } } } /** * DOCUMENT ME! * * @return DOCUMENT ME! */ public String getSVGFile() { return svgFile; } /** * Removes the LinkedFileDescriptor that corresponds to the current svgFile. */ private void removeSVGFile() { if (svgFile != null) { LinkedFileDescriptor lfd; for (int i = 0; i < linkedFileDescriptors.size(); i++) { lfd = (LinkedFileDescriptor) linkedFileDescriptors.get(i); if (lfd.linkURL.equals(svgFile)) { linkedFileDescriptors.remove(i); // rename the .svg file String svgFileString = svgFile.substring(5); File svgFile = new File(svgFileString); if (svgFile.exists()) { File renamed = new File(svgFileString + "_old"); try { svgFile.renameTo(renamed); } catch (Exception exc) { } } break; } } svgFile = null; } } /******** support for controlled vocabularies ******/ /** * Sets the collection of ControlledVocabularies known to this Transcription. * * @param controlledVocabs the CV's for this transcription */ public void setControlledVocabularies(Vector controlledVocabs) { if (controlledVocabs != null) { controlledVocabularies = controlledVocabs; } //called at parse/construction time, don't call modified } /** * Returns the collection of controlled vocabularies known to this Transcription. * If there are no CV's an empty Vector is returned. * * @return the list of associated cv's */ public Vector getControlledVocabularies() { return controlledVocabularies; } /** * Returns the ControlledVocabulary with the specified name if it exists * in the Transcription or null otherwise. * * @param name the name of the cv * * @return the CV with the specified name or <code>null</code> */ public ControlledVocabulary getControlledVocabulary(String name) { if (name == null) { return null; } ControlledVocabulary conVoc = null; for (int i = 0; i < controlledVocabularies.size(); i++) { conVoc = (ControlledVocabulary) controlledVocabularies.get(i); if (conVoc.getName().equalsIgnoreCase(name)) { break; } else { conVoc = null; } } return conVoc; } /** * Adds the specified CV to the list of cv's if it is not already in the list * and if there is not already a cv with the same name in the list. * * @param cv the ControlledVocabulary to add */ public void addControlledVocabulary(ControlledVocabulary cv) { if (cv == null) { return; } ControlledVocabulary conVoc; for (int i = 0; i < controlledVocabularies.size(); i++) { conVoc = (ControlledVocabulary) controlledVocabularies.get(i); if ((conVoc == cv) || conVoc.getName().equalsIgnoreCase(cv.getName())) { return; } } controlledVocabularies.add(cv); // register as a listener for modifications // A.K. was never used -> removed //cv.setACMEditableObject(this); if (isLoaded) { modified(ACMEditEvent.CHANGE_CONTROLLED_VOCABULARY, cv); } } /** * Removes the specified CV from the list.<br> * Any LinguisticTypes that reference the specified ControlledVocabulary will * have their refernce set to <code>null</code>. * * @param cv the CV to remove from the list */ public void removeControlledVocabulary(ControlledVocabulary cv) { if (cv == null) { return; } Vector types = getLinguisticTypesWithCV(cv.getName()); for (int i = 0; i < types.size(); i++) { ((LinguisticType) types.get(i)).setControlledVocabularyName(null); } controlledVocabularies.remove(cv); modified(ACMEditEvent.CHANGE_CONTROLLED_VOCABULARY, cv); } /** * Updates the name and description of the specified CV and updates the Linguistic * Types referencing this CV, if any.<br> The contents of a ControlledVocabulary is changed * directly in an editor; the CV class insures it's integrity. THe ditor class * should call setChanged on the Transcription object.<br><br> * Pending: The moment updating existing annotation values is offered as an option, * this implementation has to been changed. * * @param cv the cv that has been changed or is to be changed. * @param name the new name of the cv * @param description the description for the cv */ public void changeControlledVocabulary(ControlledVocabulary cv, String name, String description /*, Vector entries*/) { boolean newChange = false; String oldName = cv.getName(); String oldDescription = cv.getDescription(); // doublecheck on the name ControlledVocabulary conVoc; for (int i = 0; i < controlledVocabularies.size(); i++) { conVoc = (ControlledVocabulary) controlledVocabularies.get(i); if ((conVoc != cv) && conVoc.getName().equalsIgnoreCase(name)) { return; } } if (!oldName.equals(name)) { newChange = true; Vector types = getLinguisticTypesWithCV(oldName); for (int i = 0; i < types.size(); i++) { ((LinguisticType) types.get(i)).setControlledVocabularyName(name); } cv.setName(name); } if (!oldDescription.equals(description)) { cv.setDescription(description); newChange = true; } if (newChange) { modified(ACMEditEvent.CHANGE_CONTROLLED_VOCABULARY, cv); } } /** * Finds the LinguisticTypes that hold a reference to the CV with * the specified name and returns them in a Vector. * * @param name the identifier of the ControlledVocabulary * @return a list of linguistic types */ public Vector getLinguisticTypesWithCV(String name) { Vector matchingTypes = new Vector(); LinguisticType lt; String cvName; for (int i = 0; i < linguisticTypes.size(); i++) { lt = (LinguisticType) linguisticTypes.get(i); cvName = lt.getControlledVocabylaryName(); if ((cvName != null) && cvName.equalsIgnoreCase(name)) { matchingTypes.add(lt); } } return matchingTypes; } /** * Finds the tiers with a linguistic type that references the Controlled Vocabulary * with the specified name. * * @see #getLinguisticTypes(String) * * @param name the identifier of the ControlledVocabulary * * @return a list of all tiers using the specified ControlledVocabulary */ public Vector getTiersWithCV(String name) { Vector matchingTiers = new Vector(); if ((name == null) || (name.length() == 0)) { return matchingTiers; } Vector types = getLinguisticTypesWithCV(name); if (types.size() > 0) { Vector tv; LinguisticType type; for (int i = 0; i < types.size(); i++) { type = (LinguisticType) types.get(i); tv = getTiersWithLinguisticType(type.getLinguisticTypeName()); if (tv.size() > 0) { matchingTiers.addAll(tv); } } } return matchingTiers; } /** * DOCUMENT ME! * * @return DOCUMENT ME! */ public boolean allRootAnnotsUnaligned() { // used when importing unaligned files from for example Shoebox or CHAT Vector topTiers = getTopTiers(); Iterator tierIter = topTiers.iterator(); while (tierIter.hasNext()) { TierImpl t = (TierImpl) tierIter.next(); Vector annots = t.getAnnotations(); Iterator aIter = annots.iterator(); while (aIter.hasNext()) { AlignableAnnotation a = (AlignableAnnotation) aIter.next(); if (a.getBegin().isTimeAligned() || a.getEnd().isTimeAligned()) { return false; } } } return true; } /** * DOCUMENT ME! */ public void alignRootAnnots() { Vector rootTimeSlots = new Vector(); // collect timeslots of root annotations Vector topTiers = getTopTiers(); Iterator tierIter = topTiers.iterator(); while (tierIter.hasNext()) { TierImpl t = (TierImpl) tierIter.next(); Vector annots = t.getAnnotations(); Iterator aIter = annots.iterator(); while (aIter.hasNext()) { AlignableAnnotation a = (AlignableAnnotation) aIter.next(); rootTimeSlots.add(a.getBegin()); rootTimeSlots.add(a.getEnd()); } } // align at regular intervals. Assume that slots belong to one // annotation pairwise int cnt = 0; Object[] tsArray = rootTimeSlots.toArray();
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -