private void SynchronizeWithLinguaLeo()
 {
     LinguaLeoAPI api = new LinguaLeoAPI();
     api.Login("*****@*****.**", "spice1");
     for (int i = 1; i < 100; i++)
     {
         LinguaLeoAPI.GetDictionaryResponse res = api.GetDictionary(i);
         if (res.userdict3.Count == 0) break;
         foreach (LinguaLeoAPI.UserDictionary dict in res.userdict3)
         {
             foreach (LinguaLeoAPI.Word wrd in dict.words)
             {
                 WordOfDictionary word = AddOrUpdateWord(wrd);
             }
         }
     }
     EFDbContext.SaveChgs();
 }
 public LinguaLeoTranslationService (){
     IsLogin = false;
     
     api = new LinguaLeoAPI();
 }
        public WordOfDictionary AddOrUpdateWord(LinguaLeoAPI.Word wrd)
        {
            wrd.picture_url = "http:" + wrd.picture_url;
            WordOfDictionary word = Dictionary.AddOrUpdateWord(wrd.word_id, wrd.word_value, wrd.transcription, wrd.picture_url, wrd.sound_url);

            foreach (LinguaLeoAPI.UserTranslates transl in wrd.user_translates)
            { 
                word.AddTranslationWithExternalId((int)transl.translate_id, transl.translate_value, transl.speech_part);
                if (transl.speech_part != null && word.speech_part == null) word.speech_part = transl.speech_part;
            }
            if (word.translations.Any())
            {
                word.translation_as_string = word.translations.OrderByDescending(x => x.votes).First().translation;
            }
            


            /*
            if(word.speech_part == null)
            {
                var resp = LinguaLeoAPI.TranslateWord_withoutlogin(wrd.word_value);
                if(resp.word_forms.Count() > 0)
                {
                    word.speech_part = resp.word_forms[0].speechpart;
                }
            }
            */

            return word;
        }
Exemplo n.º 4
0
        public WordOfDictionary(string word_,LinguaLeoAPI.TranslateAPIResponse resp) : this()
        {
            word = word_;
            outer_id = resp.word_id;
            transcription = resp.transcription;
            sound_url = resp.sound_url;
            pictures_url = resp.pic_url;

            foreach(var elm in resp.translate)
            {
                TranslationOfWord tr = new TranslationOfWord();
                tr.external_id = elm.id;
                tr.translation = elm.value;
                tr.votes = elm.votes;
                tr.picture_url = elm.pic_url;

                translations.Add(tr);
            }

            //selected_translation_ = new SynchronizedObservableCollection<TranslationOfWord>();
        }
Exemplo n.º 5
0
        public void LinguaLeo_API_Test()
        {
            ILinguaLeoAPI api  = new LinguaLeoAPI();

            var res1 = api.Login(login, psw);
            Assert.AreEqual(res1.error_msg, "",true,res1.error_msg);
            Assert.AreEqual(res1.user.nickname, "VLKAM",true, "Login failed");

            var res2 = api.GetDictionary();
            Assert.AreEqual(res2.error_msg, "", true, res2.error_msg);
            Assert.AreNotEqual(res2.count_words, 0, "Get dictionary failed");

            var res3 = api.GetTranslations("hello");
            Assert.AreEqual(res3.error_msg, "", true, res3.error_msg);
            Assert.AreNotEqual(res3.translate.transcription.Count(), 0,"Get translation failed");

            var res4 = api.GetWordFromDictionary("hello");
            Assert.AreEqual(res4.error_msg, "", true, res4.error_msg);
            Assert.AreNotEqual(res4.Word.related_words.Count(), 0, "Get word from dictionary failed");

            var res5 = api.GetWordById(res4.Word.word_id);
            Assert.AreEqual(res5.error_msg, "", true, res5.error_msg);
            Assert.AreEqual(res5.Word.word_value, "hello", false, "Get word by Id failed");

            var res6 = api.GetWordSets();
            Assert.AreEqual(res6.error_msg, "", true, res6.error_msg);
            Assert.AreNotEqual(res6.wordsets.Count(), 0,"Get word sets failed");

            var res7 = api.CreateWordSet("My word set");
            Assert.AreEqual(res7.error_msg, "", true, res7.error_msg);
            int previous = res6.wordsets.Count();
            res6 = api.GetWordSets();
            Assert.AreNotEqual(res6.wordsets.Count(), previous,"Create word set failed");

            var res9 = api.AddWordToDictionary(
                res3.translate.word_id,
                res3.translate.translations[0].translate_value,
                res3.translate.translations[0].translate_id,
                res3.translate.word_value,
                0,
                res6.wordsets.Last().id);
            Assert.AreEqual(res9.error_msg, "", true, res9.error_msg);
            previous = res2.count_words;
            res2 = api.GetDictionary();
            Assert.AreNotEqual(previous, res2.count_words,"Add word failed");

            var res11 = api.SetWordStatus(new long[]{ res3.translate.word_id },LinguaLeoAPI.WordStatusEnum.Learned);
            Assert.AreEqual(res11.error_msg, "", true, res11.error_msg);
            res5 = api.GetWordById(res3.translate.word_id);
            Assert.AreEqual(res5.Word.progress_percent, 100);

            var res10 = api.DeleteWordFromDictionary(new long[] { res3.translate.word_id });
            Assert.AreEqual(res10.error_msg, "", true, res10.error_msg);
            previous = res2.count_words;
            res2 = api.GetDictionary();
            Assert.AreNotEqual(previous, res2.count_words,"Delete word failed");

            var res8 = api.DeleteWordSet(res6.wordsets.Last().id);
            Assert.AreEqual(res8.error_msg, "", true, res8.error_msg);
            previous = res6.wordsets.Count();
            res6 = api.GetWordSets();
            Assert.AreNotEqual(res6.wordsets.Count(), previous, "Delete word set failed");

        }