Пример #1
0
        private static bool AddImport(JObject wordJO, JObject meanJO, JObject linkJO)
        {
            var wMap = new Dictionary <int, int>();
            var mMap = new Dictionary <int, int>();
            int tmp;
            var w = new DBWord();

            foreach (var jp in wordJO)
            {
                if (words.TryGetValue(w.Letters = jp.Key.ToLower(), out tmp))
                {
                    wMap.Add(w.Id = jp.Value.ToInt(), tmp);
                }
                else
                {
                    db.Insert(w);
                    wMap.Add(jp.Value.ToInt(), w.Id);
                    words.Add(w.Letters, w.Id);
                    eles.Add(w.ToStat());
                    WrongCount += w.wrong + 1;
                }
            }
            var m = new DBMeaning();

            foreach (var jp in meanJO)
            {
                if (means.TryGetValue(m.Meaning = jp.Key, out tmp))
                {
                    mMap.Add(m.Id = jp.Value.ToInt(), tmp);
                }
                else
                {
                    db.Insert(m);
                    mMap.Add(jp.Value.ToInt(), m.Id);
                    means.Add(m.Meaning, m.Id);
                    eles.Add(m.ToStat());
                    WrongCount += m.wrong + 1;
                }
            }
            var t = new DBTranslation();

            foreach (var jp in linkJO)
            {
                t.Wid = wMap[jp.Key.ToInt()];
                foreach (var ji in jp.Value as JArray)
                {
                    t.Mid = mMap[ji.ToInt()];
                    if (!e2c.Contains(t.Wid, t.Mid))
                    {
                        e2c.Add(t.Wid, t.Mid);
                        c2e.Add(t.Mid, t.Wid);
                        db.Insert(t);
                    }
                }
            }
            updTimeAll = updTimeDetail = DateTime.Now.Ticks;
            return(true);
        }
Пример #2
0
        public static void AddWord(string eng, ICollection <string> chi)
        {
            int wid, mid;

            if (!words.TryGetValue(eng, out wid))//add word
            {
                var word = new DBWord()
                {
                    Letters = eng
                };
                db.Insert(word);
                words[eng] = wid = word.Id;
                eles.Add(word.ToStat());
                WrongCount += word.wrong + 1;
            }
            foreach (var str in chi)
            {
                if (!means.TryGetValue(str, out mid))//add meaning
                {
                    var mean = new DBMeaning()
                    {
                        Meaning = str
                    };
                    db.Insert(mean);
                    means[str] = mid = mean.Id;
                    eles.Add(mean.ToStat());
                    WrongCount += mean.wrong + 1;
                }
                if (!e2c.Contains(wid, mid))
                {
                    db.Insert(new DBTranslation()
                    {
                        Wid = wid, Mid = mid
                    });
                    e2c.Add(wid, mid);
                    c2e.Add(mid, wid);
                }
            }
            updTimeAll = updTimeDetail = DateTime.Now.Ticks;
        }
Пример #3
0
 public static void AddWord(string eng, ICollection<string> chi)
 {
     int wid, mid;
     if (!words.TryGetValue(eng, out wid))//add word
     {
         var word = new DBWord() { Letters = eng };
         db.Insert(word);
         words[eng] = wid = word.Id;
         eles.Add(word.ToStat());
         WrongCount += word.wrong + 1;
     }
     foreach (var str in chi)
     {
         if (!means.TryGetValue(str, out mid))//add meaning
         {
             var mean = new DBMeaning() { Meaning = str };
             db.Insert(mean);
             means[str] = mid = mean.Id;
             eles.Add(mean.ToStat());
             WrongCount += mean.wrong + 1;
         }
         if (!e2c.Contains(wid, mid))
         {
             db.Insert(new DBTranslation() { Wid = wid, Mid = mid });
             e2c.Add(wid, mid);
             c2e.Add(mid, wid);
         }
     }
     updTimeAll = updTimeDetail = DateTime.Now.Ticks;
 }
Пример #4
0
 private static bool AddImport(JObject wordJO, JObject meanJO, JObject linkJO)
 {
     var wMap = new Dictionary<int, int>();
     var mMap = new Dictionary<int, int>();
     int tmp;
     var w = new DBWord();
     foreach (var jp in wordJO)
     {
         if (words.TryGetValue(w.Letters = jp.Key.ToLower(), out tmp))
             wMap.Add(w.Id = jp.Value.ToInt(), tmp);
         else
         {
             db.Insert(w);
             wMap.Add(jp.Value.ToInt(), w.Id);
             words.Add(w.Letters, w.Id);
             eles.Add(w.ToStat());
             WrongCount += w.wrong + 1;
         }
     }
     var m = new DBMeaning();
     foreach (var jp in meanJO)
     {
         if (means.TryGetValue(m.Meaning = jp.Key, out tmp))
             mMap.Add(m.Id = jp.Value.ToInt(), tmp);
         else
         {
             db.Insert(m);
             mMap.Add(jp.Value.ToInt(), m.Id);
             means.Add(m.Meaning, m.Id);
             eles.Add(m.ToStat());
             WrongCount += m.wrong + 1;
         }
     }
     var t = new DBTranslation();
     foreach (var jp in linkJO)
     {
         t.Wid = wMap[jp.Key.ToInt()];
         foreach (var ji in jp.Value as JArray)
         {
             t.Mid = mMap[ji.ToInt()];
             if (!e2c.Contains(t.Wid, t.Mid))
             {
                 e2c.Add(t.Wid, t.Mid);
                 c2e.Add(t.Mid, t.Wid);
                 db.Insert(t);
             }
         }
     }
     updTimeAll = updTimeDetail = DateTime.Now.Ticks;
     return true;
 }