/// <summary>
        /// Prepares resource file for querying and loads the grammar tag converter specification
        /// </summary>
        /// <param name="resourceFilePath">The text resource file path</param>
        /// <param name="grammSpecFilename">The Excel file with the grammar tag converter</param>
        /// <param name="output">The output.</param>
        protected void Setup(string resourceFilePath, string grammSpecFilename, ILogBuilder output = null)
        {
            if (resourceFilePath.isNullOrEmpty())
            {
                imbACE.Services.terminal.aceTerminalInput.askYesNo("Resource file path is empty (textResourceResolverBase.Setup)!");
                throw new ArgumentNullException(nameof(resourceFilePath));
                return;
            }

            if (grammSpecFilename.isNullOrEmpty())
            {
                imbACE.Services.terminal.aceTerminalInput.askYesNo("Grammar conversion specification file path is empty (textResourceResolverBase.Setup)!");
                throw new ArgumentNullException(nameof(grammSpecFilename));
                return;
            }

            resourceFileOperater = new fileTextOperater(resourceFilePath, true);

            grammTagConverter = new resourceConverterForGramaticTags();

            if (grammSpecFilename.EndsWith(".xlsx"))
            {
                if (output != null)
                {
                    output.log("Grammar conversion specification loading from Excel file");
                }

                grammTagConverter.LoadSpecificationExcelFile(grammSpecFilename, output);
            }
            else if (grammSpecFilename.EndsWith(".csv"))
            {
                string filebase = Path.GetFileNameWithoutExtension(grammSpecFilename);
                string filepath = Path.GetDirectoryName(grammSpecFilename);

                if (output != null)
                {
                    output.log("Grammar conversion specification loading from CSV files");
                }

                string gramSpecFileFormat      = filepath + Path.DirectorySeparatorChar + filebase + "_format.csv";
                string gramSpecFileTranslation = filepath + Path.DirectorySeparatorChar + filebase + "_translation.csv";

                grammTagConverter.LoadSpecificationCSV(gramSpecFileFormat, gramSpecFileTranslation, output);
            }
            else
            {
                if (output != null)
                {
                    output.log("Grammar conversion file format not recognized from the filepath! [" + grammSpecFilename + "]");
                }
                else
                {
                    throw new ArgumentOutOfRangeException("File format not recognized for " + nameof(textResourceResolverBase) + " Setup call.", nameof(grammSpecFilename));
                }
            }
        }
Пример #2
0
        /// <summary>
        /// Setups the specified resource file path.
        /// </summary>
        /// <param name="resourceFilePath">The resource file path.</param>
        /// <param name="grammSpecFilename">The gramm spec filename.</param>
        /// <param name="output">The output.</param>
        /// <exception cref="ArgumentNullException">
        /// resourceFilePath
        /// or
        /// grammSpecFilename
        /// </exception>
        /// <exception cref="ArgumentOutOfRangeException">File format not recognized for " + nameof(textResourceResolverBase) + " Setup call. - grammSpecFilename</exception>
        public void Setup(string resourceFilePath, string grammSpecFilename, String spellAlternatorFilename, ILogBuilder output = null, textResourceIndexResolveMode __mode = textResourceIndexResolveMode.resolveOnQuery)
        {
            if (resourceFilePath.isNullOrEmpty())
            {
                imbACE.Services.terminal.aceTerminalInput.askYesNo("Resource file path is empty (textResourceIndexBase.Setup)!");
                throw new ArgumentNullException(nameof(resourceFilePath));
                return;
            }

            if (grammSpecFilename.isNullOrEmpty())
            {
                imbACE.Services.terminal.aceTerminalInput.askYesNo("Grammar conversion specification file path is empty (textResourceIndexBase.Setup)!");
                throw new ArgumentNullException(nameof(grammSpecFilename));
                return;
            }

            mode = __mode;

            // <---------------------------------------------- [

            grammTagConverter = new resourceConverterForGramaticTags();

            if (grammSpecFilename.EndsWith(".xlsx"))
            {
                if (output != null)
                {
                    output.log("Grammar conversion specification loading from Excel file");
                }

                grammTagConverter.LoadSpecificationExcelFile(grammSpecFilename, output);
            }
            else if (grammSpecFilename.EndsWith(".csv"))
            {
                string filebase = Path.GetFileNameWithoutExtension(grammSpecFilename);
                string filepath = Path.GetDirectoryName(grammSpecFilename);

                if (output != null)
                {
                    output.log("Grammar conversion specification loading from CSV files");
                }

                string gramSpecFileFormat      = filepath + Path.DirectorySeparatorChar + filebase + "_format.csv";
                string gramSpecFileTranslation = filepath + Path.DirectorySeparatorChar + filebase + "_translation.csv";

                grammTagConverter.LoadSpecificationCSV(gramSpecFileFormat, gramSpecFileTranslation, output);
            }
            else
            {
                if (output != null)
                {
                    output.log("Grammar conversion file format not recognized from the filepath! [" + grammSpecFilename + "]");
                }
                else
                {
                    throw new ArgumentOutOfRangeException("File format not recognized for " + nameof(textResourceResolverBase) + " Setup call.", nameof(grammSpecFilename));
                }
            }

            resourcePath = resourceFilePath;

            if (!spellAlternatorFilename.isNullOrEmpty())
            {
                var alternator = new transliterationPairSet();
                var altDef     = File.ReadAllText(spellAlternatorFilename);
                alternator.LoadFromString(altDef);
                spellAlternator = alternator;
            }

            if (mode != textResourceIndexResolveMode.loadAndResolveOnQuery)
            {
                LoadLexicResource(output, resourceFilePath);
            }
            else
            {
                mode = textResourceIndexResolveMode.resolveOnQuery;
            }
        }