/// ------------------------------------------------------------------------------------ public AnnotationSegment CreateSingleSegment(string[] labelInfo) { var seg = new AnnotationSegment(null); if (labelInfo.Length >= 3) { seg.Text = labelInfo[2]; } float value; if (float.TryParse(labelInfo[0].Trim(), out value)) { seg.Start = value; } if (labelInfo.Length > 1 && float.TryParse(labelInfo[1].Trim(), out value)) { seg.End = value; } else { seg.End = seg.Start; } return(seg); }
/// ------------------------------------------------------------------------------------ public BoundaryModificationResult ChangeSegmentsEndBoundary(AnnotationSegment segment, float newEndBoundary) { // New boundary must be at least a minimal amount greater than the segment's start boundary. if (!GetIsAcceptableSegmentLength(segment.Start, newEndBoundary)) { return(BoundaryModificationResult.SegmentWillBeTooShort); } var segIndex = GetIndexOfSegment(segment); if (segIndex < 0) { return(BoundaryModificationResult.SegmentNotFound); } var nextSegment = (segIndex < Segments.Count - 1 ? Segments[segIndex + 1] : null); if (nextSegment != null) { if (!GetIsAcceptableSegmentLength(newEndBoundary, nextSegment.End)) { return(BoundaryModificationResult.NextSegmentWillBeTooShort); } RenameAnnotationSegmentFile(nextSegment, newEndBoundary, nextSegment.End); nextSegment.Start = newEndBoundary; } RenameAnnotationSegmentFile(Segments[segIndex], Segments[segIndex].Start, newEndBoundary); Segments[segIndex].End = newEndBoundary; return(BoundaryModificationResult.Success); }
/// ------------------------------------------------------------------------------------ public AnnotationSegment AddSegment(float start, float stop) { var segment = new AnnotationSegment(this, start, stop); Segments.Add(segment); return(segment); }
/// ------------------------------------------------------------------------------------ public AnnotationSegment AddSegment(string text) { var segment = new AnnotationSegment(this, text ?? string.Empty); Segments.Add(segment); return(segment); }
/// ------------------------------------------------------------------------------------ public BoundaryModificationResult InsertSegmentBoundary(float newBoundary, Func <AnnotationSegment, bool, bool, bool> allowDeletionOfOralAnnotations = null) { float newSegStart = 0f; var segBeingSplit = Segments.FirstOrDefault( seg => seg.TimeRange.Contains(TimeSpan.FromSeconds(newBoundary), true)); if (segBeingSplit == null) { if (Segments.GetLast() != null) { newSegStart = Segments.GetLast().End; } if (!GetIsAcceptableSegmentLength(newSegStart, newBoundary)) { return(BoundaryModificationResult.SegmentWillBeTooShort); } AddSegment(newSegStart, newBoundary); return(BoundaryModificationResult.Success); } if (!GetIsAcceptableSegmentLength(segBeingSplit.Start, newBoundary)) { return(BoundaryModificationResult.SegmentWillBeTooShort); } if (!GetIsAcceptableSegmentLength(newBoundary, segBeingSplit.End)) { return(BoundaryModificationResult.NextSegmentWillBeTooShort); } if (segBeingSplit.TimeRange.EndSeconds > newBoundary) { var hasCarefulSpeech = segBeingSplit.GetHasOralAnnotation(OralAnnotationType.CarefulSpeech); var hasOralTranslation = segBeingSplit.GetHasOralAnnotation(OralAnnotationType.Translation); if ((hasCarefulSpeech || hasOralTranslation) && (allowDeletionOfOralAnnotations == null || !allowDeletionOfOralAnnotations(segBeingSplit, hasCarefulSpeech, hasOralTranslation))) { return(BoundaryModificationResult.BlockedByOralAnnotations); } } float newSegEnd = segBeingSplit.End; segBeingSplit.End = newBoundary; var newSegment = new AnnotationSegment(segBeingSplit.Tier, newBoundary, newSegEnd); Segments.Insert(GetIndexOfSegment(segBeingSplit) + 1, newSegment); return(BoundaryModificationResult.Success); }
/// ------------------------------------------------------------------------------------ public virtual bool TryGetSegment(int index, out AnnotationSegment segment) { segment = null; if (index < 0 || index >= Segments.Count) { return(false); } segment = Segments[index]; return(true); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Creates an annotation element in the transcription tier for the specified segment /// and returns the id of the annotation added. /// </summary> /// ------------------------------------------------------------------------------------ public string CreateTranscriptionAnnotationElement(AnnotationSegment seg) { var timeSlotRef1 = GetOrCreateTimeOrderElementAndReturnId(seg.Start); var timeSlotRef2 = GetOrCreateTimeOrderElementAndReturnId(seg.End); var annotationId = GetNextAvailableAnnotationIdAndIncrement(); GetOrCreateTranscriptionTierElement().Add(new XElement("ANNOTATION", new XElement("ALIGNABLE_ANNOTATION", new XAttribute("ANNOTATION_ID", annotationId), new XAttribute("TIME_SLOT_REF1", timeSlotRef1), new XAttribute("TIME_SLOT_REF2", timeSlotRef2), new XElement("ANNOTATION_VALUE", XmlUtils.SanitizeString(seg.Text))))); return(annotationId); }
/// ------------------------------------------------------------------------------------ public int GetIndexOfSegment(AnnotationSegment segment) { if (segment == null) { return(-1); } for (int i = 0; i < Segments.Count; i++) { if (Segments[i].TimeRange == segment.TimeRange) { return(i); } } return(-1); }
/// ------------------------------------------------------------------------------------ public void RenameAnnotationSegmentFile(AnnotationSegment oldSegment, float newStart, float newEnd) { try { var oldSegmentFilePath = Path.Combine(SegmentFileFolder, ComputeFileNameForCarefulSpeechSegment(oldSegment)); if (File.Exists(oldSegmentFilePath)) { if (BackupOralAnnotationSegmentFileAction != null) { BackupOralAnnotationSegmentFileAction(oldSegmentFilePath, false); } File.Move(oldSegmentFilePath, Path.Combine(SegmentFileFolder, ComputeFileNameForCarefulSpeechSegment(newStart, newEnd))); } } catch { } try { var oldSegmentFilePath = Path.Combine(SegmentFileFolder, ComputeFileNameForOralTranslationSegment(oldSegment)); if (File.Exists(oldSegmentFilePath)) { if (BackupOralAnnotationSegmentFileAction != null) { BackupOralAnnotationSegmentFileAction(oldSegmentFilePath, false); } File.Move(oldSegmentFilePath, Path.Combine(SegmentFileFolder, ComputeFileNameForOralTranslationSegment(newStart, newEnd))); } } catch { } }
/// ------------------------------------------------------------------------------------ public void DeleteAnnotationSegmentFile(AnnotationSegment segment) { try { var path = GetFullPathToCarefulSpeechFile(segment); if (File.Exists(path)) { if (BackupOralAnnotationSegmentFileAction != null) { BackupOralAnnotationSegmentFileAction(path, true); } else { File.Delete(path); } } } catch { } try { var path = GetFullPathToOralTranslationFile(segment); if (File.Exists(path)) { if (BackupOralAnnotationSegmentFileAction != null) { BackupOralAnnotationSegmentFileAction(path, true); } else { File.Delete(path); } } } catch { } }
/// ------------------------------------------------------------------------------------ private bool SegmentIsIgnored(AnnotationSegment transcriptionSegment) { return(transcriptionSegment.Text == kIgnoreSegment || transcriptionSegment.Text == "%junk%" /*old indicator*/); }
/// ------------------------------------------------------------------------------------ public string GetFullPathToOralTranslationFile(AnnotationSegment segment) { return(Path.Combine(SegmentFileFolder, ComputeFileNameForOralTranslationSegment(segment))); }
/// ------------------------------------------------------------------------------------ public string GetFullPathToCarefulSpeechFile(AnnotationSegment segment) { return(Path.Combine(SegmentFileFolder, ComputeFileNameForCarefulSpeechSegment(segment))); }
/// ------------------------------------------------------------------------------------ public bool RemoveSegment(AnnotationSegment segment) { return(RemoveSegment(GetIndexOfSegment(segment))); }
/// ------------------------------------------------------------------------------------ public static string ComputeFileNameForOralTranslationSegment(AnnotationSegment segment) { return(ComputeFileNameForOralTranslationSegment(segment.TimeRange)); }
/// ------------------------------------------------------------------------------------ public static string ComputeFileNameForCarefulSpeechSegment(AnnotationSegment segment) { return(ComputeFileNameForCarefulSpeechSegment(segment.TimeRange)); }