Exemplo n.º 1
0
        public PhraseOfCollectMode(SubtitleItem SubItem_) : this()
        {
            SubtitleItem = SubItem_;

            Words.Clear();
            FullPhrase = SubtitleItem.Text;

            Word word = new Word();

            bool? previousCharIsSignificant = null;
            for (int i = 0; i < FullPhrase.Length; i++)
            {
                //string curchar = FullPhrase.Substring(i, 1);
                char curchar = FullPhrase[i];
                bool currentCharIsSignificant = char.IsLetter(curchar) ||  curchar == '\'';
                if (currentCharIsSignificant != previousCharIsSignificant)
                {
                    word = new Word {isSignificant = currentCharIsSignificant};

                    Words.Add(word);

                    previousCharIsSignificant = currentCharIsSignificant;
                }
                word.word_of_phrase += curchar;
                word.EndPosititonOfWordInPhrase = i;
            }

            // process unsignificant substring
            Word prev = null;
            foreach (Word wrd in Words)
            {
                if (wrd.isSignificant)
                {
                    prev = wrd;
                }
                else
                {
                    if (prev != null) prev.EndPosititonOfWordInPhrase = wrd.EndPosititonOfWordInPhrase;
                }
            }
            
            //Words.ForEach(wrd => { if (wrd.isSignificant) wrd.phrase = FullPhrase.Substring(0, wrd.EndPosititonOfWordInPhrase); });
            foreach(var wrd in Words)
            {
                if (wrd.isSignificant) wrd.phrase = FullPhrase.Substring(0, wrd.EndPosititonOfWordInPhrase);
            }
            

            // remove all unsignificant parts 
            RemoveAllUnsignificantPartOfPhrase();
        }
Exemplo n.º 2
0
        protected static SubtitleItem GetSubItemFromFile(StreamReader reader)
        {
            SubtitleItem elm;

            string str = reader.ReadLine();
            if (str == "" || str == null)
            {
                return null;
            }

            elm = new SubtitleItem();
            elm.Number = Int16.Parse(str);

            str = reader.ReadLine();
            int pos = str.IndexOf("-->");
            if (pos == 0)
            {
                return null;
            };

            elm.TimeStart = ConvertFromString(str.Substring(0, pos - 1));
            elm.TimeEnd = ConvertFromString(str.Substring(pos + 4));

            elm.Text = "";
            while (true)
            {
                str = reader.ReadLine();
                if (string.IsNullOrEmpty(str))
                {
                    break;
                }
                if (str.Substring(0, 1) == "\"")
                {
                    str = str.Substring(1);
                }
                if (elm.Text.Length > 0)
                {
                    elm.Text += "\r\n";
                }
                elm.Text += str;
            }

            return elm;
        }
        public UnderstandingTest_ViewModel(
            ILogger Logger_,
            INavigationService NavigationService_,
            IDialogService DialogService_,
            AppSetting AppSetting_,
            IAudioAPI AudioAPI_,
            IMvxMessenger Messenger_,
            ISpeechAPI SpeechAPI_,
            ILocalization Loc_
            )
        {
            if (!IsInDesignMode)
            {
                Logger = Logger_;
                NavigationService = NavigationService_;
                DialogService = DialogService_;
                AppSetting = AppSetting_;
                AudioAPI = AudioAPI_;
                Messenger = Messenger_;
                SpeechAPI = SpeechAPI_;
                Loc = Loc_;

                Speak_Command = new MvxCommand(Speak_cmd);
                PressWordButton_Command = new MvxCommand<ButtonModel>(PressWordButton_Cmd);
            }

            ButtonsCollection = new ObservableCollection<ButtonModel>();

            if (IsInDesignMode)
            {
                string[] tarr = {
                    "Good news everyone !\nLine1\nLine2",
                    "What's happening here ?\nLine1",
                    "Hello world!" };
                for(int i = 0; i < 3; i++) ButtonsCollection.Add(new ButtonModel() {Text = tarr[i] });
                CurrentSub = new SubtitleItem() {
                    Text = "This is current subtitles item.\nLine 2\nLine3" };
            }

        }
        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.º 5
0
 public SubtitleItem GetNextSub(SubtitleItem item) => GetNextSubByPosition(item.TimeEnd + 1);
Exemplo n.º 6
0
 public SubtitleItem GetPreviousSub(SubtitleItem item) => GetPreviousSubByPosition(item.TimeStart - 1);
 void TranslateSubtitles(SubtitleItem item)
 {
     if (!string.IsNullOrEmpty(item.Text))
     {
         item.Text2 = LanguageServices.TranslateText(Subtitles, item.Text).Result;
     }
 }
 void TranslationAllWordsInSubtitleItem(SubtitleItem item,string errors = null)
 {
     foreach(WordOfSubtitleItem wrd in item.WordsCollection)
     {
         try
         {
             wrd.Translating(Subtitles.Dictionary);
         }
         catch (Exception ex)
         {
             if (ex.IsFatal()) throw;
             errors += $"{wrd.word} ({ex.Message})\r\n";
             Logger.WriteExeption(this, ex,"Translation error");
         }
             
     }
 }
        void CheckTime(ChangingimeKind kind,SubtitleItem item,bool isRecursiveChecking)
        {
            switch (kind)
            {
                case ChangingimeKind.Start:
                    SubtitleItem prevSub = Subtitles.Items.FirstOrDefault((x) => x.TimeStart < item.TimeStart && x.TimeEnd >= item.TimeStart);
                    if (prevSub != null)
                    {
                        prevSub.TimeEndError = TimeErrors.Conflict;
                        item.TimeStartError = TimeErrors.Conflict;
                        if(isRecursiveChecking) CheckTime(kind, prevSub,isRecursiveChecking);
                    }
                    else
                    {
                        prevSub = Subtitles.GetPreviousSub(item);
                        if (prevSub != null)
                        {
                            prevSub.TimeEndError = TimeErrors.NoError;
                        }
                        item.TimeStartError = TimeErrors.NoError;
                    }
                    break;

                case ChangingimeKind.End:
                    SubtitleItem nextSub = Subtitles.Items.FirstOrDefault((x) => x.TimeEnd > item.TimeEnd && x.TimeStart <= item.TimeEnd);
                    if (nextSub != null )
                    {
                        item.TimeEndError = TimeErrors.Conflict;
                        nextSub.TimeStartError = TimeErrors.Conflict;
                        if(isRecursiveChecking) CheckTime(kind,nextSub,isRecursiveChecking);
                    }
                    else
                    {
                        nextSub = Subtitles.GetNextSub(item);
                        item.TimeEndError = TimeErrors.NoError;
                        if (nextSub != null)
                        {
                            nextSub.TimeStartError = TimeErrors.NoError;
                        }
                    }
                    break;
            }
        }
        // Commands of the subtitle's grid
        public void Grid_CommandDispatcher(SubtitleItem item,string cmd)
        {
            if (item == null) return;
            SubtitleItem newitem;

            switch (cmd)
            {
                case "Play":
                    Player.PlayFromTo(item.TimeStart, item.TimeEnd);
                    break;

                case "TimeStartTuningRight":
                    item.TimeStart = item.TimeStart + 100;
                    CheckTime(ChangingimeKind.Start, item,true);
                    Player.PlayFromTo(item.TimeStart, item.TimeEnd);
                    item.TimeProcessed = true;
                    break;

                case "TimeStartTuningLeft":
                    item.TimeStart = item.TimeStart - 100;
                    CheckTime(ChangingimeKind.Start, item,true);
                    Player.PlayFromTo(item.TimeStart, item.TimeEnd);
                    item.TimeProcessed = true;
                    break;

                case "TimeEndTuningRight":
                    item.TimeEnd = item.TimeEnd + 100;
                    CheckTime(ChangingimeKind.End, item,true);
                    // playing end of a phrase only
                    Player.PlayFromTo(item.TimeEnd - Math.Min(1000, item.TimeEnd - item.TimeStart), item.TimeEnd);
                    item.TimeProcessed = true;
                    break;

                case "TimeEndTuningLeft":
                    item.TimeEnd = item.TimeEnd - 100;
                    CheckTime(ChangingimeKind.End, item,true);
                    // playing end of a phrase only
                    Player.PlayFromTo(item.TimeEnd - Math.Min(1000, item.TimeEnd - item.TimeStart), item.TimeEnd);
                    item.TimeProcessed = true;
                    break;

                case "AddRow":
                    newitem = new SubtitleItem { TimeStart = item.TimeEnd + 300, TimeEnd = item.TimeEnd + 100 };
                    item.Subtitles.Items.Add(newitem);
                    item.Subtitles.ReenumerationItems();
                    break;

                case "SplitRow":
                    newitem = new SubtitleItem();
                    int delta = (item.TimeEnd - item.TimeStart) / 2;
                    newitem.TimeEnd = item.TimeEnd;
                    item.TimeEnd -= delta;
                    newitem.TimeStart = item.TimeEnd + 10;
                    if (item.Text != null && item.Text.Contains("\r\n"))
                    {
                        newitem.Text = item.Text.Substring(item.Text.IndexOf("\r\n") + 2);
                        item.Text = item.Text.Substring(0, item.Text.IndexOf("\r\n"));
                    }
                    if (item.Text2 != null && item.Text2.Contains("\r\n"))
                    {
                        newitem.Text2 = item.Text2.Substring(item.Text2.IndexOf("\r\n") + 2);
                        item.Text2 = item.Text2.Substring(0, item.Text2.IndexOf("\r\n"));
                    }
                    item.TimeProcessed = false;
                    item.Text2Processed = false;
                    item.Subtitles.Items.Add(newitem);

                    item.Subtitles.ReenumerationItems();
                    break;

                case "DeleteRow":
                    if (item.Subtitles?.Items == null) return;
                    Subtitles sub = item.Subtitles;
                    sub.Items.Remove(item);
                    sub.ReenumerationItems();
                    break;

                case "ExtractsWords":
                    SplitPhraseOnWords(item);
                    break;

                case "TranslateWords":
                    TranslationAllWordsInSubtitleItem(item);
                    break;

                default:
                    throw new NotImplementedException();
            }
        }
        void SplitPhraseOnWords(SubtitleItem item)
        {
            if (!item.DoNotCollectThisItem)
            {
                item.WordsCollection.Clear();
                PhraseOfCollectMode phrase = new PhraseOfCollectMode(item);
                byte idx = 1;
                foreach (var wrd in phrase.Words)
                {
                    if (item.WordsCollection.Any(x => string.Compare(x.word, wrd.word_of_phrase, true) == 0 )) continue;
                    item.WordsCollection.Add(new WordOfSubtitleItem
                    {
                        word = wrd.word_of_phrase,
                        number = idx,
                    });
                    idx++;

                }
            }
        }
        private void AddWordsToPanel(SubtitleItem SubItem)
        {
            player.Pause();
            CollectPhrases_Buttons.Clear();

            if (SubItem == null) return;

            if (SubItem.IsCollect)
            {
                CollectedPhraseText = SubItem.Text;
                return;
            }

            CurrentPhrase = new PhraseOfCollectMode(SubItem);
            CurrentPhrase.StartRandomSelection();
            for (int i = 0; i < CurrentPhrase.Words.Count; i++)
            {
                PhraseOfCollectMode.Word word = CurrentPhrase.GetNextRandom();
                CollectPhrases_Buttons.Add(new ButtonModel() { WordOfButton = word,Visibility = VisualState.Visible});
            }
            player.Play();
        }
 public PlayerEvent(object sender,PlyaerEventEnum kindOfEvent, SubtitleItem subItem) : base(sender)
 {
     KindOfEvent = kindOfEvent;
     SubItem = subItem;
 }
Exemplo n.º 14
0
        public ObservableCollection<WordOfDictionary> GetListOfNewWords(SubtitleItem subItem)
        {
            ObservableCollection<WordOfDictionary> coll = new ObservableCollection<WordOfDictionary>();
            ObservableCollection<string> processedwords = new ObservableCollection<string>();
            foreach (WordOfSubtitleItem wrd in subItem.WordsCollection)
            {
                string strWord = wrd.word.ToLower();
                if (processedwords.Contains(strWord)) continue;
                //if (Words.Any(x => x.word_of_dictionary.ToLower() == strWord)) continue;
                if (FindWord(strWord) != null) continue;
                if (ContainsLearnedWord(wrd.word)) continue;
                //if (wrd.Status == SubtitleItem.enWordStatus.Ignored || wrd.Status == SubtitleItem.enWordStatus.Ignored) continue;

                coll.Add(wrd.word_of_dictionary);
                processedwords.Add(strWord);
            }
            return coll;
        }
Exemplo n.º 15
0
        private static void ReadContainer(EbmlReader ebmlReader, MatroskaElementDescriptorProvider medp, ResultOfParsingMKV resPars, ulong CurrentClusterTimeCode, StringBuilder sb, string GroupName = "", string add = "")
        {
            ebmlReader.EnterContainer();
            while (ebmlReader.ReadNext())
            {
                var descriptor = medp.GetElementDescriptor(ebmlReader.ElementId);
                if (descriptor == null)
                {
                    sb.Append(add + "undefined \r\n");
                    continue;
                }
                string dName = descriptor.Name;
                sb.Append(add + dName);

                if (dName == "TrackEntry") {
                    AnalizeTrackEntry(ebmlReader,medp,resPars,sb,GroupName,add);
                    continue;
                }

                switch (descriptor.Type)
                {
                    case ElementType.MasterElement:
                        sb.Append("\r\n");
                        ReadContainer(ebmlReader, medp, resPars, CurrentClusterTimeCode, sb,descriptor.Name, add + "    ");
                        break;
                    case ElementType.AsciiString:
                        sb.Append(" = " + ebmlReader.ReadAscii());
                        break;
                    case ElementType.Binary:
                        if (GroupName == "BlockGroup" && (dName == "Block" || dName == "SimpleBlock"))
                        {
                            int lSize = ebmlReader.ElementSize > 1000?1000:Convert.ToInt16(ebmlReader.ElementSize);
                            byte[] arr = new byte[lSize];
                            ebmlReader.ReadBinary(arr, 0, lSize);
                            int TrackNumber = arr[0] & 0x0F;
                            ulong DurationFromCluster = Convert.ToUInt64(arr[1] * 0xFF + arr[2]);

                            if (resPars.dicSub.ContainsKey(TrackNumber))
                            {
                                Subtitles lsub = resPars.dicSub[TrackNumber];
                                SubtitleItem subitem = new SubtitleItem();
                                lsub.Items.Add(subitem);

                                //subitem.Text = System.Text.Encoding.ASCII.GetString(arr, 4, lSize-4);
                                subitem.Text = System.Text.Encoding.UTF8.GetString(arr, 4, lSize - 4);
                                subitem.TimeStart = ((int)(CurrentClusterTimeCode + DurationFromCluster));

                                // reading the BlockDuration
                                ebmlReader.ReadNext();
                                ulong BlockDuration = ebmlReader.ReadUInt();
                                subitem.TimeEnd = subitem.TimeStart + ((int)BlockDuration);

                            }
                        }
                        sb.Append(" (binary size " + ebmlReader.ElementSize + ")");
                        break;
                    case ElementType.Date:
                        sb.Append(" = " + ebmlReader.ReadDate());
                        break;
                    case ElementType.Float:
                        double flVal = ebmlReader.ReadFloat();
                        sb.Append(" = " + flVal);
                        break;
                    case ElementType.None:
                        sb.Append(" (none)");
                        break;
                    case ElementType.SignedInteger:
                        sb.Append(" = " + ebmlReader.ReadInt());
                        break;
                    case ElementType.UnsignedInteger:
                        ulong ulVal = ebmlReader.ReadUInt();
                        if (GroupName == "Cluster" && dName == "Timecode")
                        {
                            CurrentClusterTimeCode = ulVal;
                        }
                        sb.Append(" = " + ulVal);
                        break;
                    case ElementType.Utf8String:
                        sb.Append(" = " + ebmlReader.ReadUtf());
                        break;
                }
                sb.Append("\r\n");
            }
            ebmlReader.LeaveContainer();
        }