Esempio n. 1
0
        /// <summary>
        /// Generate Language Profile from Text File
        /// <para />
        /// usage: --genprofile-text -l [language code] [text file path]
        /// </summary>
        private void generateProfileFromText()
        {
            if (arglist.Count != 1)
            {
                System.Console.WriteLine("Need to specify text file path");
                return;
            }
            string file = arglist[0];

            if (!System.IO.File.Exists(file))
            {
                System.Console.WriteLine("Need to specify existing text file path");
                return;
            }

            string lang = get("lang");

            if (lang == null)
            {
                System.Console.WriteLine("Need to specify langage code(-l)");
                return;
            }

            LangProfile profile = GenProfile.loadFromText(lang, file);

            profile.omitLessFreq();

            using (var os = System.IO.File.CreateText(lang))
            {
                os.Write(JsonConvert.SerializeObject(profile));
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Generate Language Profile from Wikipedia Abstract Database File
        /// <para />
        /// usage: --genprofile -d [abstracts directory] [language names]
        /// </summary>
        public void generateProfile()
        {
            string directory = get("directory");

            foreach (string lang in arglist)
            {
                string file = searchFile(directory, lang + "wiki-.*-abstract\\.xml.*");
                if (file == null)
                {
                    System.Console.WriteLine("Not Found abstract xml : lang = " + lang);
                    continue;
                }

                LangProfile profile = GenProfile.loadFromWikipediaAbstract(lang, file);
                profile.omitLessFreq();

                string profile_path = get("directory") + "/profiles/" + lang;
                using (var os = System.IO.File.CreateText(profile_path))
                {
                    os.Write(JsonConvert.SerializeObject(profile));
                }
            }
        }