コード例 #1
0
ファイル: FLExTextExporter.cs プロジェクト: vkarthim/saymore
        /// ------------------------------------------------------------------------------------
        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();
            }
        }
コード例 #2
0
        /// ------------------------------------------------------------------------------------
        public AnnotationComponentFile(ProjectElement parentElement,
                                       string pathToAnnotationFile, ComponentFile associatedComponentFile,
                                       List <FileType> fileTypes, IEnumerable <ComponentRole> componentRoles) :
            base(parentElement, pathToAnnotationFile,
                 fileTypes.Single(t => t is AnnotationFileType), null, null, null)
        {
            Tiers = new TierCollection();

            AssociatedComponentFile = associatedComponentFile;
            _componentRoles         = componentRoles;
            InitializeFileInfo();
            Load();

            SmallIcon = ResourceImageCache.ElanIcon;

            var oralAnnotationFilePath = GetSuggestedPathToOralAnnotationFile();

            if (File.Exists(oralAnnotationFilePath))
            {
                OralAnnotationFile = new OralAnnotationComponentFile(parentElement,
                                                                     oralAnnotationFilePath, associatedComponentFile, fileTypes, _componentRoles);
            }
            else
            {
                associatedComponentFile.PostGenerateOralAnnotationFileAction += generated =>
                {
                    OralAnnotationFile = new OralAnnotationComponentFile(parentElement,
                                                                         oralAnnotationFilePath, associatedComponentFile, fileTypes, _componentRoles);
                };
            }
        }
コード例 #3
0
        /// ------------------------------------------------------------------------------------
        public Exception TryLoadAndReturnException()
        {
            var savTiers = Tiers;

            try
            {
                Tiers = TierCollection.LoadFromAnnotationFile(PathToAnnotatedFile);
            }
            catch (Exception e)
            {
                Logger.WriteEvent("Handled Exception in AnnotationComponentFile.TryLoadAndReturnException:\r\n{0}", e.ToString());
                Tiers = savTiers;
                return(e);
            }

            return(null);
        }
コード例 #4
0
        public void Setup()
        {
            var tempMediaPath = MediaFileInfoTests.GetLongerTestAudioFile();

            _tempFolder = new TemporaryFolder("TierCollectionTests");
            var mediaFile = Path.Combine(_tempFolder.Path, "mediaFile.wav");

            File.Move(tempMediaPath, mediaFile);

            _collection = new TierCollection(mediaFile);
            _collection.Clear();
            var timeTier = new TimeTier("timeTier", mediaFile);

            _collection.Add(timeTier);

            var transcriptionTier = new TextTier(TextTier.ElanTranscriptionTierId);

            _collection.Add(transcriptionTier);

            var translationTier = new TextTier(TextTier.ElanTranslationTierId);

            _collection.Add(translationTier);

            var otherTextTier = new TextTier("otherTextTier");

            _collection.Add(otherTextTier);

            timeTier.AddSegment(10f, 20f);
            timeTier.AddSegment(20f, 30f);
            timeTier.AddSegment(30f, 40f);

            transcriptionTier.AddSegment("trans1");
            transcriptionTier.AddSegment("trans2");
            transcriptionTier.AddSegment("trans3");

            translationTier.AddSegment("free1");
            translationTier.AddSegment("free2");
            translationTier.AddSegment(null);

            otherTextTier.AddSegment("other1");
            otherTextTier.AddSegment(null);
            otherTextTier.AddSegment(null);

            Assert.AreEqual(mediaFile, _collection.AnnotatedMediaFile);
            Assert.AreEqual(4, _collection.Count);
        }
コード例 #5
0
ファイル: FLExTextExporter.cs プロジェクト: vkarthim/saymore
        /// ------------------------------------------------------------------------------------
        public static void Save(string outputFilePath, string title, TierCollection tierCollection,
                                string wsTranscriptionId, string wsFreeTranslationId,
                                string mediaFilePath, string sourceFilePath)
        {
            var helper = new FLExTextExporter(outputFilePath, title,
                                              tierCollection, wsTranscriptionId, wsFreeTranslationId, mediaFilePath, sourceFilePath);

            var caption = LocalizationManager.GetString(
                "SessionsView.Transcription.TextAnnotationEditor.ExportingToFLExInterlinear.ProgressDlg.Caption",
                "Exporting to FLEx Interlinear");

            using (var dlg = new ProgressDlg(helper, caption))
            {
                dlg.StartPosition = FormStartPosition.CenterScreen;
                dlg.ShowDialog();
            }
        }
コード例 #6
0
        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);
                }
            }
        }
コード例 #7
0
ファイル: ComponentFile.cs プロジェクト: vkarthim/saymore
        /// ------------------------------------------------------------------------------------
        public bool GenerateOralAnnotationFile(TierCollection tiers, Control parentOfProgressPopup, GenerateOption option)
        {
            bool generated = false;

            // subclass OralAnnotationComponentFile will handle the case of JIT generation
            if (option != GenerateOption.GenerateIfNeeded)
            {
                if (PreGenerateOralAnnotationFileAction != null)
                {
                    PreGenerateOralAnnotationFileAction();
                }

                generated = OralAnnotationFileGenerator.Generate(tiers, parentOfProgressPopup,
                                                                 option == GenerateOption.ClearAndRegenerateOnDemand);
            }

            if (PostGenerateOralAnnotationFileAction != null)
            {
                PostGenerateOralAnnotationFileAction(generated);
            }

            return(generated);
        }
コード例 #8
0
        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();
                }
            }
        }
コード例 #9
0
        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();
                }
            }
        }