/// ------------------------------------------------------------------------------------ public FLExTextExporter(string outputFilePath, string title, TierCollection tierCollection, string wsTranscriptionId, string wsFreeTranslationId, string mediaFilePath, string sourceFilePath) { _outputFilePath = outputFilePath; _title = title; _tierCollection = (tierCollection ?? new TierCollection()); _wsTranscriptionId = wsTranscriptionId; _wsFreeTranslationId = wsFreeTranslationId; _mediaFileGuid = Guid.NewGuid().ToString(); _mediaFilePath = mediaFilePath; if (!string.IsNullOrEmpty(sourceFilePath)) { _sourceFileGuid = Guid.NewGuid().ToString(); _sourceFilePath = sourceFilePath; } _currentSegment = 1; var textTier = _tierCollection.GetTranscriptionTier(); if (textTier != null) { _segmentCount = _tierCollection.GetTranscriptionTier().Segments.Count(); } }
public static void Export(string referencePrefix, string mediaFileName, string outputFilePath, TierCollection tiers) { const string ktimeFormat = "00.00###"; using (var stream = File.CreateText(outputFilePath)) { int count = tiers.GetTimeTier().Segments.Count; var timeSegments = tiers.GetTimeTier().Segments; var transcriptionSegments = tiers.GetTranscriptionTier(true).Segments; var freeTranslationSegments = tiers.GetFreeTranslationTier(true).Segments; for (int i = 0; i < count; i++) { stream.WriteLine("\\ref " + referencePrefix + "_" + (1 + i).ToString("0000")); var begin = timeSegments[i].TimeRange.StartSeconds.ToString(ktimeFormat); var end = timeSegments[i].TimeRange.EndSeconds.ToString(ktimeFormat); stream.WriteLine("\\begin " + begin); stream.WriteLine("\\end " + end); stream.WriteLine("\\media " + mediaFileName + " " + begin + " " + end); stream.WriteLine("\\t " + transcriptionSegments[i].Text); stream.WriteLine("\\f " + freeTranslationSegments[i].Text); stream.WriteLine(); } } }
public void GetTranscriptionTier_TierExists_ReturnsIt() { var tier = _collection.GetTranscriptionTier(); Assert.AreEqual(TextTier.ElanTranscriptionTierId, tier.Id); Assert.AreEqual(TierType.Transcription, tier.TierType); }
public static void Export(string outputFilePath, TierCollection tiers) { using (var stream = File.CreateText(outputFilePath)) { stream.WriteLine("-- " + LocalizationManager.GetString("SessionsView.Transcription.TierDisplayNames.Transcription", "Transcription") + " --"); stream.WriteLine(); foreach (var segment in tiers.GetTranscriptionTier().Segments) { stream.WriteLine(segment.Text); } stream.WriteLine(); stream.WriteLine(); stream.WriteLine("-- " + LocalizationManager.GetString("SessionsView.Transcription.TierDisplayNames.FreeTranslation", "Free Translation") + " --"); stream.WriteLine(); foreach (var segment in tiers.GetFreeTranslationTier().Segments) { stream.WriteLine(segment.Text); } } }
/// ------------------------------------------------------------------------------------ public IEnumerable <XElement> CreateParagraphElements() { var transcriptionTier = _tierCollection.GetTranscriptionTier(); // TODO: This will need refactoring when display name is localizable. var translationTier = _tierCollection.GetDependentTextTiers() .FirstOrDefault(t => t.DisplayName.ToLower() == TextTier.FreeTranslationTierDisplayName.ToLower()); var segmentList = transcriptionTier.Segments.ToArray(); var timeTier = _tierCollection.GetTimeTier(); var timeSegmentList = timeTier.Segments.ToArray(); for (int i = 0; i < segmentList.Length; i++) { // _worker will be null during tests. if (_worker != null) { _worker.ReportProgress(i + 1); } int startTime = (int)Math.Round(timeSegmentList[i].Start * 1000); int endTime = (int)Math.Round(timeSegmentList[i].End * 1000); if (translationTier != null) { AnnotationSegment freeTranslationSegment; translationTier.TryGetSegment(i, out freeTranslationSegment); yield return(CreateSingleParagraphElement(segmentList[i].Text, (freeTranslationSegment != null ? freeTranslationSegment.Text : null), startTime.ToString(CultureInfo.InvariantCulture), endTime.ToString(CultureInfo.InvariantCulture) )); } } }
public static void Export(string outputFilePath, TierCollection tiers) { const string ktimeFormat = "hh\\:mm\\:ss\\.ff"; //ISO 8601 and what ELAN import expects using (var stream = File.CreateText(outputFilePath)) { int count = tiers.GetTimeTier().Segments.Count; var timeSegments = tiers.GetTimeTier().Segments; var transcriptionSegments = tiers.GetTranscriptionTier(true).Segments; var freeTranslationSegments = tiers.GetFreeTranslationTier(true).Segments; for (int i = 0; i < count; i++) { stream.Write(i + 1 + ","); stream.Write(timeSegments[i].TimeRange.Start.ToString(ktimeFormat)); stream.Write(","); stream.Write(timeSegments[i].TimeRange.End.ToString(ktimeFormat) + ","); stream.Write(Escape(transcriptionSegments[i].Text)); stream.Write(","); stream.Write(Escape(freeTranslationSegments[i].Text)); stream.WriteLine(); } } }