public override void CmdDispatcher(string cmd)
        {
            switch (cmd)
            {
                case "AddDictionary":
                    if (CurrentLanguage == null) return;
                    Dictionary dict = new Dictionary();
                    dict.Name = "default name "+CurrentLanguage.DictionariesCollection.Count;
                    CurrentLanguage.DictionariesCollection.Add(dict);
                    EFDbContext.SaveChgs();
                    break;

                case "DeleteDictionary":
                    throw new NotImplementedException();

                case "Ok":
                    EFDbContext.SaveChgs();
                    NavigationService.NavigateBack();
                    break;


                default:
                    throw new NotImplementedException();
            }
        }
        public DictionariesList_ViewModel(
            ILogger Logger_, 
            INavigationService NavigationService_, 
            IDialogService DialogService_,
            EFDbConnect EFDbConnect
            ) : base ()
        {
            NavigationService = NavigationService_;

            if (IsInDesignModeNet())
            {
                Dictionaries = new ObservableCollection<Dictionary>();

                Dictionary dic1 = new Dictionary { Name = "First" };
                Dictionaries.Add(dic1);

                Dictionary dic2 = new Dictionary { Name = "Second" };
                Dictionaries.Add(dic2);
            }
            else
            {
                List<Dictionary> dcts = EFDbContext.Context.Query(new QueryBuilder<Dictionary>(EFDbConnect));
                Dictionaries = new ObservableCollection<Dictionary>(dcts);
                CommandDispatcher = new MvxCommand<string>(CmdDispatcher);
                OpenDictionary_Command = new MvxCommand<Dictionary>(OpenDictionary);
            }
        }
Пример #3
0
        public void FindWord()
        {

            string db_name = "Dictionary_FindWord.db"; 

            EFDbContext db;
            db = RecreateDB(db_name);

            Dictionary dic = new Dictionary();
            db.AddNewItemToDBContext(dic);

            WordOfDictionary wrd0 = new WordOfDictionary();
            wrd0.word_of_dictionary = "Test";
            dic.Words.Add(wrd0);

            WordOfDictionary wrd1 = new WordOfDictionary();
            wrd1.word_of_dictionary = "I am";

            wrd1.AddForm("I'm");
            Assert.IsTrue(wrd1.Forms == "[i'm]");

            wrd1.RemoveForm("I'm");
            Assert.IsTrue(wrd1.Forms == "");

            wrd1.AddForm("I'm");
            dic.Words.Add(wrd1);

            WordOfDictionary wrd2 = new WordOfDictionary();
            wrd2.word_of_dictionary = "Hello";
            dic.Words.Add(wrd2);

            db.SaveChanges();
            db.Close();


            db = ConnectToDb(db_name);
            dic = db.FirstOrDefault<Dictionary>();

            WordOfDictionary fwrd = dic.FindWord("I'm");
            Assert.IsTrue(fwrd.word_of_dictionary == "I am");

            fwrd = dic.FindWord("I am");
            Assert.IsTrue(fwrd.word_of_dictionary == "I am");

            db.Close();

        }
        public ListOfWordsOfDictionary_ViewModel_WPF(ILogger Logger_, INavigationService NavigationService_, IDialogService DialogService_)
        {
            Logger = Logger_;
            NavigationService = NavigationService_;
            DialogService = DialogService_;

            ListOfWords = new ObservableCollection<DataGridItem>();

            if (!IsInDesignModeNet())
            {
                CommandDispatcher = new MvxCommand<string>(CmdDispatcher);
            }

            if (IsInDesignModeNet())
            {
                Dictionary dic = new Dictionary { Name = "Simple dictionary" };
                Dictionary dic1 = new Dictionary { Name = "Other dictionary" };
                
                ListOfWords.Add(new DataGridItem { Word = new WordOfDictionary { word_of_dictionary = "Hello" },Dictionary = dic });
                ListOfWords.Add(new DataGridItem { Word = new WordOfDictionary { word_of_dictionary = "White" },Dictionary = dic1,Analogy = new WordOfDictionary { word_of_dictionary = "White" } });
                ListOfWords.Add(new DataGridItem { Word = new WordOfDictionary { word_of_dictionary = "to run" } ,Dictionary = dic});
            }

        }
 private void Dispatcher_DictionaryGrid(Dictionary dict,string cmd)
 {
     switch (cmd)
     {
         case "Open":
             NavigationService.NavigateForward(Views.DictionaryWindow,new Dictionary_parameters { Dictionary = dict });
             break;
         default:
             throw new NotImplementedException();
     }
 }
 private void OpenDictionary(Dictionary dictionary)
 {
     NavigationService.NavigateForward(Views.DictionaryWindow, new DictionaryWindow_parameters { Dictionary = dictionary });
 }
Пример #7
0
 public IFolder DictionaryFolder(Dictionary dic)
 {
     return DictionariesFolder.CreateFolderAsync(dic.id.ToString(),CreationCollisionOption.OpenIfExists).Result;
 }
        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;
        }
Пример #9
0
 static public string GetPathToDictionaryFolder(Dictionary dic) {
     string path = Path.Combine(GetPathToDictionaries(),dic.id.ToString());
     CreateDirectory(path);
     return path;
 }
        public override void CmdDispatcher(string cmd)
        {
            switch (cmd)
            {
                case "AddNewDictionary":
                    if(Subtitles.SecondaryLanguage == null)
                    {
                        DialogService.Message(Tx.T("SubtitleEditor.Messages.SelectNativeLanguageForThisSubtitles"));
                        return;
                    }
                    Dictionary newdict = new Dictionary();
                    newdict.Name = "default name" + (Subtitles.PrimaryLanguage.DictionariesCollection.Count + 1);
                    newdict.SecondaryLanguage = Subtitles.SecondaryLanguage;
                    Subtitles.PrimaryLanguage.DictionariesCollection.Add(newdict);
                    EFDbContext.SaveChgs();
                    break;

                case "EditDictionary":
                    NavigationService.NavigateForward(Views.AppSettings,new AppSettings_parameters { language = Subtitles.PrimaryLanguage });
                    break;
                case "AddSubAsTranslating":
                    AddSubtitleAsTranslate();
                    break;
                case "Pause":
                    if (Player.IsPlaying)
                    {
                        Player.Pause();
                    }
                    else
                    {
                        Player.Play();
                    }
                    break;

                default:
                    throw new NotImplementedException();
            }
        }
Пример #11
0
 public ResultOfParsingMKV() {
     dicSub = new Dictionary<int, Subtitles>();
     AudioTracks = new SynchronizedObservableCollection<AudioTrack>();
 }
Пример #12
0
 public async static Task<WordOfDictionary> TranslateWord (Dictionary dic,string text)
 {
     return await TranslateWord(dic.Language, dic.SecondaryLanguage, dic.WordTranslationService,text);
 }
Пример #13
0
 public async static Task<string> TranslateText (Dictionary dic,string text)
 {
     return await TranslateText(dic.Language, dic.SecondaryLanguage, dic.TextTranslationService,text);
 }
Пример #14
0
        public static FrequencyDictionary LoadRussianFrequencyDictionary()
        {

            string url = "http://dict.ruslang.ru/";
            FrequencyDictionary fd =  EFDbContext.DataBase.Table<FrequencyDictionary>().FirstOrDefault(x=>x.Url == url);
            if (fd == null)
            {
                fd.Url = url;
            }

            if (fd.Items.Any())
            {
                fd.Items.Clear();
                EFDbContext.SaveChgs();
            }

            Dictionary<string, SpeechParts> dict = new Dictionary<string, SpeechParts>();
            dict.Add("s",SpeechParts.Noun);
            dict.Add("spro",SpeechParts.Pronoun);
            dict.Add("v",SpeechParts.Verb);
            dict.Add("a",SpeechParts.Adjective);

            dict.Add("pr",null);// SpeechParts.Preposition
            dict.Add("adv",null);// SpeechParts.Adverb
            dict.Add("conj",null);// SpeechParts.Conjuction
            dict.Add("intj",null);// SpeechParts.Interjection
            dict.Add("num",null);//SpeechParts.Numeral
            dict.Add("part",null);//SpeechParts.Part
            dict.Add("s.prop",null);// SpeechParts.NounProp
            dict.Add("advpro", null);
            dict.Add("anum", null);
            dict.Add("apro", null);

            using (TextReader reader = File.OpenText("Resources/russian_freq_dict.txt"))
            {
                // header
                string line = reader.ReadLine();
                int number = 1;
                while (true)
                {
                    line = reader.ReadLine();
                    if (line == null) break;

                    string[] res = line.Split('\t');

                    FrequencyDictionary.Item item = new FrequencyDictionary.Item();
                    item.Lemma = res[0];

                    item.freq = float.Parse(res[2]);
                    if (item.freq < 40) continue;

                    item.speechpart = dict[res[1].ToLower()];
                    if (item.speechpart == null) continue;

                    item.Number = number++;    

                    fd.Items.Add(item);
                    //fd.Items.Add(item);
                }


                fd.Count = fd.Items.Count();
                EFDbContext.SaveChgs();

                return fd;

                // блок нужно переработать кривое использование id
                /*
                foreach(var grp in items.GroupBy(x => x.speechpart))
                {
                    FrequencyDictionary.RangeOfSpeechParts range = new FrequencyDictionary.RangeOfSpeechParts();
                    range.speechpart = grp.Key;
                    range.Count = grp.Count();
                    fd.Range.Add(range);

                    FrequencyDictionary.Item first = null;

                    var list2 = grp.OrderByDescending(x => x.freq);
                    foreach(var elm in list2)
                    {
                        fd.Items.Add(elm);
                        if (first == null) first = elm;
                    }
                    DataBase.SaveChanges();
                    range.StartId = first.id;
                    if (fd.StartId == 0) fd.StartId = first.id;
                }
                */

                //var lst = items.OrderBy(x => x.speechpart).Select(x=>x.speechpart);
                /*
                int id_ = 1;
                SpeechParts CurSpeechPart = null;
                foreach(var elm in lst)
                {
                    if()
                }
                */
            }
        }
        public override void CmdDispatcher(string cmd)
        {

            switch (cmd)
            {
                case "SelectDataFolder":
                    string folder = DialogService.SelectFolder(Environment.CurrentDirectory);
                    //if (!string.IsNullOrEmpty(folder)) AppSettings.DataDirectory = folder;
                    break;
                case "Close":

                    if (NativeLanguage == null)
                    {
                        DialogService.Message(Tx.T("InitialWizard.Messages.DontSelectedNativeLanguage"));
                        return;
                    }

                    if(TargetLanguage == null)
                    {
                        DialogService.Message(Tx.T("InitialWizard.Messages.DontSelectedTargetLanguageLanguage"));
                        return;
                    }

                    if(AppSettings.LearningWordStrategy == null)
                    {
                        DialogService.Message(Tx.T("InitialWizard.Messages.DontSelectedLearningWordStrategy"));
                        return;
                    }

                    Dictionary dict = new Dictionary();
                    dict.Name = Tx.T("Common.Phrases.PersonalDictionary");
                    dict.Language = TargetLanguage;
                    dict.SecondaryLanguage = NativeLanguage;

                    AppSettings.DictionariesCollection.Add(dict);
                    AppSettings.PersonalDictionary = dict;

                    AppSettings.isFirstStart = false;

                    EFDbContext.SaveChgs();

                    NavigationService.NavigateBack();
                    break;

                default:
                    throw new NotImplementedException();
            }
        }
        void AddButtons()
        {
            int NumberOfAnalogue = 2;

            PhraseOfCollectMode CurrentPhrase = new PhraseOfCollectMode(LearningItem.CurrentSub);

            // finds analogue
            int WordsNumber = CurrentPhrase.Words.Count;
            List<PhraseOfCollectMode> analogue = LearningItem.MainSubs.PhrasesList.FindAll(x => x.Words.Count == WordsNumber);
            if (analogue.Count < (NumberOfAnalogue + 10))
            {
                analogue = LearningItem.MainSubs.PhrasesList.FindAll(
                    x => ((x.Words.Count >= WordsNumber - 1) && (x.Words.Count <= WordsNumber + 1)));
                    if (analogue.Count < (NumberOfAnalogue + 10))
                    {
                        analogue = LearningItem.MainSubs.PhrasesList;
                    }
             }

            // a list of phrases 
            Random rnd = new Random();
            Dictionary<int, PhraseOfCollectMode> PhrasesForShow = new Dictionary<int, PhraseOfCollectMode>();
            PhrasesForShow.Add(rnd.Next(0, 32000), CurrentPhrase);

            for (int i = 0; i < 100; i++)
            {
                if (PhrasesForShow.Count == AppSetting.NumberOfPrasesForUndestandingTest)  break;

                PhraseOfCollectMode rndphrase = analogue[rnd.Next(0, analogue.Count - 1)];

                if (string.IsNullOrEmpty(rndphrase.SubtitleItem.Text2)) continue;

                // Find duplicate
                bool IsThisDuplicate = false;
                foreach(var phr_ in PhrasesForShow)
                {
                    if (PhraseOfCollectMode.IsPhraseEqualent(phr_.Value,rndphrase))
                    {
                        IsThisDuplicate = true;
                        break;
                    }
                }
                if (IsThisDuplicate) continue;
                //var tlist = PhrasesForShow.Where(x => PhraseOfCollectMode.IsPhraseEqualent(x.Value, rndphrase));
                //if (tlist.Count() > 0) continue;

                PhrasesForShow.Add(rnd.Next(0, 32000), rndphrase);
            }

            if(PhrasesForShow.Count < AppSetting.NumberOfPrasesForUndestandingTest)
            {
                DialogService.Message(Loc.T("UnderstandingTest.Messages.NotEnoughPhrases"),Loc.T("Common.Titles.Error"));
                return;
            }

            // Add to panel
            ButtonsCollection.Clear();
            foreach (var elm in PhrasesForShow.OrderBy(x=>x.Key).ToList())
            {
                ButtonsCollection.Add(new ButtonModel() {Text = elm.Value.SubtitleItem.Text2,IsItTrue = elm.Value == CurrentPhrase});
            }
        }
        public Dictionary_ViewModel(
            ILogger Logger_, 
            INavigationService NavigationService_, 
            IDialogService DialogService_,
            IAudioAPI AudioAPI_,
            EFDbConnect EFDbConnect_)
        {
            if (!IsInDesignMode)
            {
                Logger = Logger_;
                NavigationService = NavigationService_;
                DialogService = DialogService_;
                EFDbConnect = EFDbConnect_;
                AudioAPI = AudioAPI_;

                Languages = new ObservableCollection<Language>(EFDbConnect.Table<Language>().ToList());

                SpeechItem_Command = new MvxCommand<WordOfDictionary>(SpeechItem_Cmd);
                CommandDispatcher = new MvxCommand<string>(CommandDispatcher_); 
            }

            ViewModeDataGrid = VisualState.Collapsed;
            ViewModeList = VisualState.Collapsed;
            currentMode = ViewModes.List;
            SpeechPartsCollection =  new ObservableCollection<SpeechParts>(Enumeration.GetAll<SpeechParts>());
            ViewModesCollection = new ObservableCollection<ViewModes>(Enumeration.GetAll<ViewModes>());

            if (IsInDesignMode)
            {
                currentMode = ViewModes.DataGrid;

                Dictionary = new Dictionary();

                Dictionary.Words.Add(new WordOfDictionary {
                    word_of_dictionary = "Hello",
                    translation_as_string = "Привет",
                    transcription = "hello",
                    RepetitionPersent = 25,
                    SpeechPart = SpeechParts.Noun
                });

                Dictionary.Words.Add(new WordOfDictionary {
                    word_of_dictionary ="day",
                    translation_as_string = "день",
                    transcription ="day",
                    RepetitionPersent = 80,
                    SpeechPart =  SpeechParts.Noun
                });

                Dictionary.Words.Add(new WordOfDictionary {
                    word_of_dictionary ="I am",
                    translation_as_string = "я являюсь ...",
                    transcription ="...",
                    Forms = "I'm",
                    RepetitionPersent = 80,
                    SpeechPart =  SpeechParts.Noun
                });

            }

        }