Пример #1
0
        public PhraseOfCollectMode(SubtitleItem SubItem_) : this()
        {
            SubtitleItem = SubItem_;

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

            Word Word = new Word();

            string SignificantChars = "'qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNMйцукенгшщзхъфывапролджэячсмитьбюёЁЙЦУКЕНГШЩЗХЪФЫВАПРОЛДЖЭЯЧСМИТЬБЮ";

            bool? PreviousCharIsSignificant = null;
            bool CurrentCharIsSignificant;
            for (int i = 0; i < FullPhrase.Length; i++)
            {
                string curchar = FullPhrase.Substring(i, 1);
                CurrentCharIsSignificant = SignificantChars.Contains(curchar);
                if (CurrentCharIsSignificant != PreviousCharIsSignificant)
                {
                    Word = new Word();
                    Word.isSignificant = CurrentCharIsSignificant;

                    Words.Add(Word);

                    PreviousCharIsSignificant = CurrentCharIsSignificant;
                }
                Word.word += 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); });

            // remove all unsignificant parts 
            RemoveAllUnsignificantPartOfPhrase();
        }
        public UnderstandingTest_ViewModel(ILogger Logger_,INavigationService NavigationService_,IDialogService DialogService_)
        {
            Logger = Logger_;
            NavigationService = NavigationService_;
            DialogService = DialogService_;

            ButtonsCollection = new ObservableCollection<ButtonModel>();
            Speak_Command = new RelayCommand(Speak_cmd);
            PressWordButton_Command = new RelayCommand<ButtonModel>(PressWordButton_Cmd);

            if (IsInDesignMode)
            {
                string[] tarr = { "Good news everyone !","What's happening here ?","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." };
            }

        }
Пример #3
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;
        }
Пример #4
0
        public ObservableCollection<WordOfDictionary> GetListOfNewWords(SubtitleItem subItem)
        {
            ObservableCollection<WordOfDictionary> coll = new ObservableCollection<WordOfDictionary>();
            ObservableCollection<string> processedwords = new ObservableCollection<string>();
            foreach (SubtitleItem.Word wrd in subItem.WordsCollection)
            {
                string strWord = wrd.word.ToLower();
                if (processedwords.Contains(strWord)) continue;
                if (Words.Any(x => x.word.ToLower() == strWord)) 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;
        }
        // Commands of the subtitle's grid
        public void Grid_CommandDispatcher(SubtitleItem item,string cmd)
        {
            if (item == null) return;

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

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

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

                case "TimeEndTuningRight":
                    item.TimeEnd = item.TimeEnd + 100;
                    // 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;
                    // 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":
                    if (item != null)
                    {
                        //SubtitleItem newitem = item.Owner.InsertSub(item.Number + 1);
                        //item.Owner.Items.Add(new SubtitleItem());
                        SubtitleItem newitem = new SubtitleItem() { TimeStart = item.TimeEnd + 300, TimeEnd = item.TimeEnd + 100 };
                        item.Subtitles.Items.Add(newitem);
                        item.Subtitles.ReenumerationItems();
                    }
                    break;

                case "SplitRow":
                    if (item != null)
                    {
                        //SubtitleItem newitem = item.Owner.InsertSub(item.Number + 1);
                        SubtitleItem newitem = new SubtitleItem();
                        long 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 != null)
                    {
                        Subtitles sub = item.Subtitles;
                        sub.Items.Remove(item);
                        sub.ReenumerationItems();
                        //item.Owner.DeleteSub(item);
                    }
                    break;
                default:
                    throw new NotImplementedException();
            }
        }
        private async void SubGrid_PhrasesForDictionary_Cmd(SubtitleItem.Word word, string cmd,bool recursion = false)
        {
            switch (cmd)
            {
                case "EditWord":
                    NavigationService.OpenDialog(Form.SubWordEditor, new SubWordEditor_parameters() { Word = word });
                    break;

                case "EditTranslation":
                    if (word.word_of_dictionary == null)
                    {
                        DialogService.Message(Tx.T("SubtitleEditor.Messages.PleaseMakeTranslationBeforeEdit"));
                        return;
                    }
                    ObservableCollection<WordOfDictionary> wrdcoll = new ObservableCollection<WordOfDictionary>{word.word_of_dictionary};
                    NavigationService.OpenDialog(Form.WordsTranslation, new WordsTranslation_parameters {Mode = WordsTranslation_ViewModel.Mode.Edit,WordsCollection = wrdcoll },"EmptyDialog");
                    break;

                case "DeleteWord":
                    EFDbContext.DataBase.SubtitleItem_Words.Remove(word);
                    break;

                case "AddTranslating":
                    word.Translating(Subtitles.Dictionary);
                    break;

                case "MarkTranslation":
                    if (word.word_of_dictionary == null) return;
                    word.word_of_dictionary.status = WordOfDictionary.WordStatuses.GetByStatus(WordOfDictionary.WordStatuses.enStatus.ManualEditing);
                    EFDbContext.SaveChgs();
                    break;

                case "AddToWordRulesList":
                    Subtitles.PrimaryLanguage.ProcessingWordsRules.Add(new ProcessingWordsRules {word = word.word});
                    break;
            }

            if (!recursion && (
                //cmd == "MarkWordAsIgnore" || 
                cmd=="DeleteWord" || 
                cmd=="AddTranslating"))
            {
                bool res = await DialogService.Ask(Tx.Text("SubtitleEditor.Messages.ApplyToAllWords"));
                if (res){
                    foreach(SubtitleItem SubItem in Subtitles.Items)
                    {
                        foreach(SubtitleItem.Word wrd_in_collection in SubItem.WordsCollection) {
                            if(wrd_in_collection.word.ToLower() == word.word.ToLower())
                            {
                                SubGrid_PhrasesForDictionary_Cmd(wrd_in_collection, cmd,true);
                            }
                        }
                    }
                }
            }

            if (!recursion && EFDbContext.HasChanges)
            {
                EFDbContext.SaveChgs();    
            }

        }
Пример #7
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 = ((long)(CurrentClusterTimeCode + DurationFromCluster));

                                // reading the BlockDuration
                                ebmlReader.ReadNext();
                                ulong BlockDuration = ebmlReader.ReadUInt();
                                subitem.TimeEnd = subitem.TimeStart + ((long)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();
        }
        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 = Visibility.Visible});
            }
            player.Play();
        }
 public PlayerEvent(PlyaerEventEnum KindOfEvent_, SubtitleItem SubItem_) { KindOfEvent = KindOfEvent_; SubItem = SubItem_; }
Пример #10
0
 public SubtitleItem GetNextSub(SubtitleItem item)
 {
     return GetNextSubByPosition(item.TimeEnd + 1);
  }
Пример #11
0
 public SubtitleItem GetPreviousSub(SubtitleItem item)
 {
     return GetPreviousSubByPosition(item.TimeStart - 1);
     //return Items.Where(x => x.Number < item.Number).OrderByDescending(x => x.Number).FirstOrDefault();
 }