Exemplo n.º 1
0
        /// ------------------------------------------------------------------------------------
        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);
        }
Exemplo n.º 2
0
        /// ------------------------------------------------------------------------------------
        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);
        }
Exemplo n.º 3
0
        /// ------------------------------------------------------------------------------------
        public AnnotationSegment AddSegment(float start, float stop)
        {
            var segment = new AnnotationSegment(this, start, stop);

            Segments.Add(segment);
            return(segment);
        }
Exemplo n.º 4
0
        /// ------------------------------------------------------------------------------------
        public AnnotationSegment AddSegment(string text)
        {
            var segment = new AnnotationSegment(this, text ?? string.Empty);

            Segments.Add(segment);
            return(segment);
        }
Exemplo n.º 5
0
        /// ------------------------------------------------------------------------------------
        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);
        }
Exemplo n.º 6
0
        /// ------------------------------------------------------------------------------------
        public virtual bool TryGetSegment(int index, out AnnotationSegment segment)
        {
            segment = null;

            if (index < 0 || index >= Segments.Count)
            {
                return(false);
            }

            segment = Segments[index];
            return(true);
        }
Exemplo n.º 7
0
        /// ------------------------------------------------------------------------------------
        /// <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);
        }
Exemplo n.º 8
0
        /// ------------------------------------------------------------------------------------
        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);
        }
Exemplo n.º 9
0
        /// ------------------------------------------------------------------------------------
        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 { }
        }
Exemplo n.º 10
0
        /// ------------------------------------------------------------------------------------
        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 { }
        }
Exemplo n.º 11
0
 /// ------------------------------------------------------------------------------------
 private bool SegmentIsIgnored(AnnotationSegment transcriptionSegment)
 {
     return(transcriptionSegment.Text == kIgnoreSegment ||
            transcriptionSegment.Text == "%junk%" /*old indicator*/);
 }
Exemplo n.º 12
0
 /// ------------------------------------------------------------------------------------
 public string GetFullPathToOralTranslationFile(AnnotationSegment segment)
 {
     return(Path.Combine(SegmentFileFolder, ComputeFileNameForOralTranslationSegment(segment)));
 }
Exemplo n.º 13
0
 /// ------------------------------------------------------------------------------------
 public string GetFullPathToCarefulSpeechFile(AnnotationSegment segment)
 {
     return(Path.Combine(SegmentFileFolder, ComputeFileNameForCarefulSpeechSegment(segment)));
 }
Exemplo n.º 14
0
 /// ------------------------------------------------------------------------------------
 public bool RemoveSegment(AnnotationSegment segment)
 {
     return(RemoveSegment(GetIndexOfSegment(segment)));
 }
Exemplo n.º 15
0
 /// ------------------------------------------------------------------------------------
 public static string ComputeFileNameForOralTranslationSegment(AnnotationSegment segment)
 {
     return(ComputeFileNameForOralTranslationSegment(segment.TimeRange));
 }
Exemplo n.º 16
0
 /// ------------------------------------------------------------------------------------
 public static string ComputeFileNameForCarefulSpeechSegment(AnnotationSegment segment)
 {
     return(ComputeFileNameForCarefulSpeechSegment(segment.TimeRange));
 }