Esempio n. 1
0
        private void buttonUserDict_Click(object sender, EventArgs e)
        {
            string s = GetSelectedText();

            if (s != null)
            {
                s = s.Trim();
            }
            if (string.IsNullOrEmpty(s))
            {
                return;
            }
            EdictEntry entry = new EdictEntry(s, "", new string[] {}, null, 0);

            TopMost = false;
            if (FormDictionaryEdit.instance.MyShow(entry) == System.Windows.Forms.DialogResult.OK)
            {
                List <string> usr = new List <string>(Edict.instance.LoadDictText("user.txt"));
                usr.Add(string.Format("{0} [{1}]/{2}", entry.key, entry.reading, ((entry.pos != null && entry.pos.Length > 0) ? "(" + string.Join(", ", entry.pos) + ") " : "") + string.Join("/", entry.meaning)));
                string usr_new = string.Join(Environment.NewLine, usr.ToArray());
                Edict.instance.ReloadUserDictionary(usr_new);
                Edict.instance.SaveDictText("user.txt", usr_new);
            }
            TopMost = Global.isTopMost();
        }
Esempio n. 2
0
                                                      "suf",   "v1",     "vi",     "vs",     "vs-i",  "vs-s", "vk",  "vt", "vz",  "adj-ta", "copula" }; // ,"v5*"

        private static void ParseMeaning(string meaning, EdictEntry entry)
        {
            if (meaning.EndsWith("(P)/"))
            {
                entry.priority = 2;
                meaning        = meaning.Substring(0, meaning.Length - 4);
            }
            bool uk = false;

            string[] res = meaning.Split(new char[] { '/' }, StringSplitOptions.RemoveEmptyEntries);
            for (int i = 0; i < res.Length; ++i)
            {
                string rr  = res[i].Trim();
                string buf = "";
                string tmp = GetAnnotation(ref rr);
                while (tmp != null)
                {
                    bool isPOS = false;
                    foreach (string pos in tmp.Split(','))
                    {
                        if (pos.StartsWith("v5") || Array.IndexOf(pos_list, pos) >= 0)
                        {
                            entry.AddPOS(pos);
                            isPOS = true;
                        }
                    }
                    if (!isPOS)
                    {
                        if (tmp == "uk")
                        {
                            uk = true;
                        }
                        else
                        {
                            if (tmp.Length > 7 || (tmp.Length >= 1 && tmp[0] >= '0' && tmp[0] <= '9'))
                            {
                                buf += "(" + tmp + ") ";
                            }
                            if (tmp.Length > 7)
                            {
                                break;
                            }
                        }
                    }
                    tmp = GetAnnotation(ref rr);
                }
                res[i] = buf + rr;
            }
            if (uk)
            {
                entry.priority += 1;
            }
            entry.meaning = res;

            /*if (entry.pos.Length > 0 && entry.meaning.Length > 0)
             * {
             *  entry.meaning[entry.meaning.Length - 1] += " [" + string.Join(", ", entry.pos) + "]";
             * }*/
        }
Esempio n. 3
0
 public EdictEntry[] LoadDictUsingCache(string name, Encoding encoding, out EdictEntry[] rdict)
 {
     try
     {
         string file_name  = GetRealFilename(name);
         string cache_name = file_name + ".cache.txt";
         if (File.GetLastWriteTime(file_name) >= File.GetLastWriteTime(cache_name))
         {
             throw new Exception();
         }
         var sr = new StreamReader(new FileStream(cache_name, FileMode.Open, FileAccess.Read), Encoding.UTF8);
         try
         {
             int          n   = int.Parse(sr.ReadLine());
             EdictEntry[] res = new EdictEntry[n];
             for (int i = 0; i < n; ++i)
             {
                 res[i] = new EdictEntry();
                 res[i].LoadFrom(sr);
             }
             rdict = new EdictEntry[n];
             int ctr = 0;
             foreach (string s in sr.ReadLine().Split(','))
             {
                 rdict[ctr++] = res[int.Parse(s)];
             }
             if (ctr != n)
             {
                 //MessageBox.Show("Debug: size of dict and rdict do not match");
                 throw new Exception();
             }
             return(res);
         }
         finally
         {
             sr.Close();
         }
     }
     catch (Exception)
     {
         EdictEntry[] res = LoadDict(LoadDictText(name, encoding));
         rdict = (EdictEntry[])res.Clone();
         int[] nums = new int[res.Length];
         for (int i = 0; i < nums.Length; ++i)
         {
             nums[i] = i;
         }
         Array.Sort(rdict, nums, new EdictEntry.ByReading());
         try
         {
             SaveDictToCache(res, nums, name);
         }
         catch (Exception)
         { }
         return(res);
     }
 }
Esempio n. 4
0
 private void gridUserDict_CellClick(object sender, DataGridViewCellEventArgs e)
 {
     if (e.ColumnIndex == 3)
     {
         var        row   = gridUserDict.Rows[e.RowIndex];
         EdictEntry entry = new EdictEntry(row.Cells[0].Value.ToString(), row.Cells[1].Value.ToString(), row.Cells[2].Value.ToString().Split('/'), null, 0);
         if (FormDictionaryEdit.instance.MyShow(entry) == System.Windows.Forms.DialogResult.OK)
         {
             row.SetValues(entry.key, entry.reading, string.Join("/", entry.meaning));
         }
     }
 }
Esempio n. 5
0
        public DialogResult MyShow(EdictEntry entry)
        {
            SetTextBoxes(entry);
            textBoxWord.Text = entry.key;
            listBox1.Items.Clear();
            var res = ShowDialog();

            entry.key     = textBoxWord.Text;
            entry.reading = textBoxReading.Text;
            entry.meaning = textBoxMeaning.Text.Split('/');
            return(res);
        }
Esempio n. 6
0
        public static int Comparer(EdictEntry a, EdictEntry b)
        {
            int res = a.key.CompareTo(b.key);

            if (res == 0)
            {
                res = b.priority.CompareTo(a.priority);
            }
            if (res == 0)
            {
                res = a.id.CompareTo(b.id);
            }
            return(res);
        }
Esempio n. 7
0
 private EdictEntry[] LoadDict(string[] ss)
 {
     try
     {
         EdictEntry[] res = new EdictEntry[ss.Length - 1];
         for (int i = 1; i < ss.Length; ++i)
         {
             string   s    = ss[i];
             string[] part = s.Split(new char[] { '/' }, 2);
             string   head = part[0];
             int      p0   = head.IndexOf('[');
             int      p1   = -1;
             if (p0 >= 0)
             {
                 p1 = head.IndexOf(']', p0);
             }
             string key, reading;
             if (p0 >= 0 && p1 >= 0)
             {
                 key     = head.Substring(0, p0).TrimEnd();
                 reading = head.Substring(p0 + 1, p1 - (p0 + 1));
             }
             else
             {
                 key     = head.Trim();
                 reading = key;
             }
             EdictEntry entry = new EdictEntry(key, reading);
             if (part.Length >= 2)
             {
                 ParseMeaning(part[1], entry);
             }
             else
             {
                 ParseMeaning("", entry);
             }
             res[i - 1] = entry;
         }
         Array.Sort(res, EdictEntry.Comparer);
         return(res);
     }
     catch (Exception)
     {
         return(null);
     }
 }
Esempio n. 8
0
        private EdictEntry[] SearchExact(string key, string pos, bool second, bool byReading)
        {
            var entries = new List <EdictEntry>();

            if (!Ready)
            {
                return(entries.ToArray());
            }
            if (key.Length == 0 || key.Length == 1 && !Translation.isKanji(key[0]))
            {
                return(entries.ToArray());
            }
            int x;

            if (!byReading)
            {
                if (user != null)
                {
                    x = BinarySearch(user, key);
                    while (x < user.Length && user[x].key == key)
                    {
                        EdictEntry entry = user[x];
                        if (!second && entry.meaning.Length > 0)
                        {
                            char ch = entry.meaning[0][0];
                            if (ch == '=')
                            {
                                return(SearchExact(key, pos, true, true));
                            }
                            else if (char.GetUnicodeCategory(ch) == System.Globalization.UnicodeCategory.OtherLetter)
                            {
                                key = entry.meaning[0];
                                return(SearchExact(key, pos, true, false));
                            }
                            else
                            {
                                entries.Add(entry);
                            }
                        }
                        else
                        {
                            entries.Add(entry);
                        }
                        ++x;
                    }
                    if (entries.Count > 0)
                    {
                        return(entries.ToArray());
                    }
                }
                x = BinarySearch(dict, key);
                while (x < dict.Length && dict[x].key == key)
                {
                    EdictEntry entry = dict[x];
                    if (pos == null || entry.isPOS(pos))
                    {
                        entries.Add(entry);
                    }
                    ++x;
                }
                if (entries.Count > 0)
                {
                    return(entries.ToArray());
                }
            }
            if (key.ToCharArray().All(Translation.isKatakana))
            {
                key = Translation.KatakanaToHiragana(key);
            }
            if (key.ToCharArray().All(Translation.isHiragana))
            {
                x = BinarySearchByReading(rdict, key);
                string reading = Translation.KatakanaToHiragana(rdict[x].reading);
                while (x < rdict.Length && reading == key)
                {
                    EdictEntry entry = rdict[x];
                    if (pos == null || entry.isPOS(pos))
                    {
                        if (second || key.Length > 3 || key.Length > 2 && entry.priority >= 1 || entry.priority >= 3)
                        {
                            entries.Add(entry);
                        }
                    }
                    ++x;
                    if (x < rdict.Length)
                    {
                        reading = Translation.KatakanaToHiragana(rdict[x].reading);
                    }
                }
            }
            return(entries.ToArray());
        }
Esempio n. 9
0
 private void DictSearchAddItem(HashSet <EdictEntry> added, List <string> res, EdictEntry entry)
 {
     if (!added.Add(entry))
     {
         return;
     }
     if (entry.meaning.Length == 0)
     {
         return;
     }
     res.Add(entry.key);
     res.Add(string.Join(", ", entry.pos));
     res.Add(Translation.formatReading(entry.key, entry.reading, Global.options.furiganaRomaji));
     res.Add(Translation.formatMeaning(string.Join("; ", entry.meaning)));
 }
Esempio n. 10
0
 private void SetTextBoxes(EdictEntry entry)
 {
     textBoxReading.Text = entry.reading;
     textBoxMeaning.Text = ((entry.pos != null && entry.pos.Length > 0) ? "(" + string.Join(", ", entry.pos) + ") " : "") + string.Join("/", entry.meaning);
 }