Example #1
0
        /// <summary>
        /// Transliterates the <c>inputString</c> according to specified language identifier for the source.
        /// </summary>
        /// <param name="inputString">The input string, to be transliterated</param>
        /// <param name="id_of_source">The identifier of the source string</param>
        /// <param name="inverse">Should the transliteration be in opposite direction?</param>
        /// <returns>Transliterated text</returns>
        /// <exception cref="System.ArgumentOutOfRangeException">id_of_source - Transliteration definition not found for [" + id_of_source + "]</exception>
        public static String transliterate(this String inputString, String id_of_source = "sr_cyr", Boolean inverse = false)
        {
            String output = inputString;

            transliterationPairSet pairSet = ruleSet.transliteration.GetTransliterationPairSet(id_of_source);

            if (pairSet == null)
            {
                throw new ArgumentOutOfRangeException(nameof(id_of_source), "Transliteration definition not found for [" + id_of_source + "]");
            }
            if (inverse)
            {
                output = pairSet.ConvertFromBtoA(inputString);
            }
            else
            {
                output = pairSet.ConvertFromAtoB(inputString);
            }
            return(output);
        }
Example #2
0
        protected void tryLoading()
        {
            String _psPath = appManager.Application.folder_resources.findFile(transFilename, SearchOption.AllDirectories);

            if (_psPath.isNullOrEmpty())
            {
                String msg = "Transliteration file should be at: [build output]\\resources\\transliteration\\";
                throw new ArgumentException("There is no file for transliteration pair set at: [" + transFilename + "] -- have you installed NuGet package: imbNLP.Transliteration ? Did you made the transliteration definition file? " + msg);
            }

            if (File.Exists(_psPath))
            {
                pairSet = new transliterationPairSet();

                String specs = File.ReadAllText(_psPath);
                pairSet.LoadFromString(specs);
            }
            else
            {
                throw new ArgumentException("There is no file for transliteration pair set at: [" + _psPath + "] -- have you installed NuGet package: imbNLP.Transliteration ? Did you made the transliteration definition file?");
            }
        }
Example #3
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;
            }
        }