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

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

            string lang = Get("lang");

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

            FileStream os = null;

            try
            {
                LangProfile profile = GenProfile.LoadFromText(lang, file);
                profile.OmitLessFreq();

                string profile_path = lang;
                File.WriteAllText(profile_path, JsonSerializer.Serialize(profile));
            }
            catch (NotSupportedException e)
            {
                Debug.WriteLine(e);
            }
            catch (IOException e)
            {
                Debug.WriteLine(e);
            }
            catch (LangDetectException e)
            {
                Debug.WriteLine(e);
            }
            finally
            {
                try
                {
                    if (os != null)
                    {
                        os.Close();
                    }
                }
                catch (IOException e) { }
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Generate Language Profile from Wikipedia Abstract Database File
        /// <pre>
        /// usage: --genprofile -d [abstracts directory] [language names]
        /// </pre>
        /// </summary>
        public void GenerateProfile()
        {
            string directory = Get("directory");

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

                FileStream os = null;
                try
                {
                    LangProfile profile = GenProfile.LoadFromWikipediaAbstract(lang, file);
                    profile.OmitLessFreq();

                    string profile_path = Get("directory") + "/profiles/" + lang;
                    File.WriteAllText(profile_path, JsonSerializer.Serialize(profile));
                }
                catch (NotSupportedException e)
                {
                    Debug.WriteLine(e);
                }
                catch (IOException e)
                {
                    Debug.WriteLine(e);
                }
                catch (LangDetectException e)
                {
                    Debug.WriteLine(e);
                }
                finally
                {
                    try
                    {
                        if (os != null)
                        {
                            os.Close();
                        }
                    }
                    catch (IOException e) { }
                }
            }
        }