public override WordOfDictionary TranslateWord(string word,Language SourceLang,Language TargetLang)
        {
            
            WordOfDictionary WordOfDictionary = new WordOfDictionary();

            LinguaLeoAPI.TranslateAPIResponse resp = api.TranslateWord_withoutlogin(word);

            WordOfDictionary.word_of_dictionary = word;
            WordOfDictionary.outer_id = resp.word_id;
            WordOfDictionary.transcription = resp.transcription;
            WordOfDictionary.sound_url = resp.sound_url;
            WordOfDictionary.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;
                tr.SetPictureUrl(elm.pic_url);

                WordOfDictionary.translations.Add(tr);
            }

            if (WordOfDictionary.translations.Count > 0)
            {
                WordOfDictionary.translation_as_string = WordOfDictionary.translations.OrderByDescending(x => x.Votes).First().Translation;
                WordOfDictionary.translations[0].Selected = true;
                WordOfDictionary.translations[0].Index_of_selection = 1;
            }

            return WordOfDictionary;
        }
Exemplo n.º 2
0
 public void AddTranslationWithExternalId(int external_id_,string str_translation,SpeechParts part)
 {
     
     TranslationOfWord translation = translations.Where(x => x.external_id == external_id_).FirstOrDefault();
     if (translation == null)
     {
         translation = new TranslationOfWord();
         translations.Add(translation);
         
     }
     translation.external_id = external_id_;
     translation.Translation = str_translation;
     translation.SpeechPart = part;
     OnPropertyChanged(()=>translation_as_string);
 }
Exemplo n.º 3
0
        public void DeleteSelectedTranslation_Cmd(TranslationOfWord transl)
        {
            transl.Selected = false;
            transl.Index_of_selection = 0;
            selected_translation.Remove(transl);

            int idx = 1;
            foreach (var elm in selected_translation.ToList())
            {
                elm.Index_of_selection = idx;
                idx++;
            }
        }
Exemplo n.º 4
0
 public void AddSelectedTranslation_Cmd(TranslationOfWord transl)
 {
     transl.Selected = true;
     transl.Index_of_selection = selected_translation_.Count + 1;
     selected_translation.Add(transl);
 }
        EFDbConnect CreateDemoBase(string db_name)
        {
            string path = PathToDb(db_name);
            if (File.Exists(path))
            {
                File.Delete(path);
            }

            ILogger ILoggerMock = Mock.Of<ILogger>();
            ISQLitePlatform platf = new SQLitePlatformWin32();
            EFDbConnect EFDbConnect = new EFDbConnect(platf, path);

            EFDbContext ctx = new EFDbContext(EFDbConnect);

            LearningItem li1 = new LearningItem();
            li1.Name = "First";
            ctx.AddNewItemToDBContext(li1);
            LearningItem li2 = new LearningItem();
            li2.Name = "Second";
            ctx.AddNewItemToDBContext(li2);


            // Audio tracks
            AudioTrack at1 = new AudioTrack();
            li1.AudioTracks.Add(at1);

            AudioTrack at2 = new AudioTrack();
            li1.AudioTracks.Add(at2);

            AudioTrack at3 = new AudioTrack();
            li2.AudioTracks.Add(at3);

            // Frequency dictionary
            FrequencyDictionary fd1 = new FrequencyDictionary();
            FrequencyDictionary fd2 = new FrequencyDictionary();

            FrequencyDictionary.Item fdi1 = new FrequencyDictionary.Item();
            fd1.Items.Add(fdi1);
            FrequencyDictionary.Item fdi2 = new FrequencyDictionary.Item();
            fd1.Items.Add(fdi2);

            FrequencyDictionary.Item fdi3 = new FrequencyDictionary.Item();
            fd2.Items.Add(fdi3);
            FrequencyDictionary.Item fdi4 = new FrequencyDictionary.Item();
            fd2.Items.Add(fdi4);

            // Languages
            Language lang1 = new Language();
            lang1.FrequencyDictionary = fd1;

            Language lang2 = new Language();
            lang2.FrequencyDictionary = fd2;

            Subtitles sub1 = new Subtitles();
            li1.SubtitleCollection.Add(sub1);
            sub1.SecondaryLanguage = lang1;

            Subtitles sub2 = new Subtitles();
            li1.SubtitleCollection.Add(sub2);


            SubtitleItem si1 = new SubtitleItem();
            sub1.Items.Add(si1);
            SubtitleItem si2 = new SubtitleItem();
            sub1.Items.Add(si2);

            SubtitleItem si3 = new SubtitleItem();
            sub2.Items.Add(si3);
            SubtitleItem si4 = new SubtitleItem();
            sub2.Items.Add(si4);

            Subtitles sub3 = new Subtitles();
            li2.SubtitleCollection.Add(sub3);
            sub3.SecondaryLanguage = lang2;

            SubtitleItem si5 = new SubtitleItem();
            sub3.Items.Add(si5);


            WordOfSubtitleItem sw1 = new WordOfSubtitleItem();
            si1.WordsCollection.Add(sw1); 

            WordOfSubtitleItem sw2 = new WordOfSubtitleItem();
            si1.WordsCollection.Add(sw2); 

            WordOfSubtitleItem sw3 = new WordOfSubtitleItem();
            si5.WordsCollection.Add(sw3);



            // Dictionary
            Dictionary dic1 = new Dictionary();
            ctx.AddNewItemToDBContext(dic1);

            WordOfDictionary wd1 = new WordOfDictionary();
            dic1.Words.Add(wd1);

            TranslationOfWord tw1 = new TranslationOfWord();
            wd1.translations.Add(tw1);
            
            TranslationOfWord tw2 = new TranslationOfWord();
            wd1.translations.Add(tw2);

            WordOfDictionary wd2 = new WordOfDictionary();
            dic1.Words.Add(wd2);
            sw1.word_of_dictionary = wd1;
            sw2.word_of_dictionary = wd2;

            Dictionary dic2 = new Dictionary();
            ctx.AddNewItemToDBContext(dic2);
            WordOfDictionary wd3 = new WordOfDictionary();
            dic1.Words.Add(wd3);
            WordOfDictionary wd4 = new WordOfDictionary();
            dic1.Words.Add(wd4);
            sw3.word_of_dictionary = wd3;

            
            
            
            ctx.SaveChanges();

            return EFDbConnect;
        }
Exemplo n.º 6
0
 public void AddOrUpdateWord(WordOfDictionary currentWord)
 {
     //string strWord = currentWord.word_of_dictionary.ToLower();
     //WordOfDictionary searchedWord = Words.Where(x => x.word_of_dictionary.ToLower() == strWord).FirstOrDefault();
     WordOfDictionary searchedWord = FindWord(currentWord.word_of_dictionary);
     if (searchedWord == null)
     {
         WordOfDictionary newword = new WordOfDictionary {
             commentary = currentWord.commentary,
             word_of_dictionary = currentWord.word_of_dictionary,
             PictureFile = currentWord.PictureFile,
             SpeechPart = currentWord.SpeechPart,
             context = currentWord.context,
             outer_id = currentWord.outer_id,
             pictures_url = currentWord.pictures_url,
             sound_url = currentWord.sound_url,
             SoundFile = currentWord.SoundFile,
             Status = currentWord.Status,
             transcription = currentWord.transcription,
             translations = new SynchronizedObservableCollection<TranslationOfWord>(),
             translation_as_string = currentWord.translation_as_string,
         };
         foreach(TranslationOfWord transl in currentWord.translations)
         {
             TranslationOfWord newtransl = new TranslationOfWord
             {
                 external_id = transl.external_id,
                 picture_url = transl.picture_url,
                 SpeechPart = currentWord.SpeechPart,
                 Translation = transl.Translation,
                 Votes = transl.Votes,
                 Selected = transl.Selected,
                 Index_of_selection = transl.Index_of_selection,
             };
             newword.translations.Add(newtransl);
         }
         LearningWordStrategy.InitializeWord(newword);
         Words.Add(newword);
     }
     else
     {
         throw new NotImplementedException();
     }    
 }