예제 #1
0
 private void CNewChapter(object sender, ExecutedRoutedEventArgs e)
 {
     TranscriptionChapter c = new TranscriptionChapter(Properties.Strings.DefaultChapterText);
     TranscriptionSection s = new TranscriptionSection(Properties.Strings.DefaultSectionText);
     TranscriptionParagraph p = new TranscriptionParagraph();
     p.Add(new TranscriptionPhrase());
     Transcription.Add(c);
     c.Add(s);
     s.Add(p);
     VirtualizingListBox.ActiveTransctiption = c;
 }
예제 #2
0
        public async Task<bool> NewTranscription()
        {
            if (!await TrySaveUnsavedChanges())
                return false;

            var source = new WPFTranscription();
            source.BeginUpdate(false);
            var c = new TranscriptionChapter(Properties.Strings.DefaultChapterText);
            var s = new TranscriptionSection(Properties.Strings.DefaultSectionText);
            var p = new TranscriptionParagraph();
            p.Add(new TranscriptionPhrase());
            c.Add(s);
            s.Add(p);
            source.Add(c);
            Transcription = source;
            SynchronizeSpeakers();
            VirtualizingListBox.ActiveTransctiption = p;

            TranscriptionList.Clear();
            source.ClearUndo();
            source.EndUpdate();

            Transcription.Saved = true;
            return true;
        }
예제 #3
0
 public ParagraphSpeakerAction(TranscriptionParagraph changedParagraph, TranscriptionIndex changeIndex,int changeAbsoluteIndex, Speaker oldSpeaker)
     : base(ChangeType.Modify, changedParagraph, changeIndex, changeAbsoluteIndex)
 {
     _oldSpeaker = oldSpeaker;
 }
예제 #4
0
        private static bool RefreshSpeakerButton(Element el, TranscriptionParagraph val)
        {
            if (val == null)
                return false;
            var currentvis = el.buttonSpeaker.Visibility;
            var setvis = Visibility.Visible;
            var previous = val.PreviousSibling() as TranscriptionParagraph;
            if (previous != null && val != null)
                if (val.Speaker == previous.Speaker && val.Language == previous.Language)
                    setvis = Visibility.Collapsed;

            if (currentvis != setvis)
            {
                el.buttonSpeaker.Visibility = setvis;
                return true;
            }

            return false;
        }
예제 #5
0
 public ParagraphAttibutesAction(TranscriptionParagraph changedParagraph, TranscriptionIndex changeIndex,int changeAbsoluteIndex, ParagraphAttributes oldAttributes)
     : base(ChangeType.Modify, changedParagraph, changeIndex, changeAbsoluteIndex)
 {
     _oldAttributes = oldAttributes;
 }
예제 #6
0
 public ParagraphLanguageAction(TranscriptionParagraph changedParagraph, TranscriptionIndex changeIndex, int changeAbsoluteIndex, string oldLanguage)
     : base(ChangeType.Modify, changedParagraph, changeIndex, changeAbsoluteIndex)
 {
     _oldLanguage = oldLanguage;
 }
예제 #7
0
        /// <summary>
        /// V2 deserialization beware of local variable names
        /// </summary>
        /// <param name="e"></param>
        /// <param name="isStrict"></param>
        /// <returns></returns>
        public static TranscriptionParagraph DeserializeV2(XElement e, bool isStrict)
        {
            TranscriptionParagraph par = new TranscriptionParagraph();
            par._internalID = int.Parse(e.Attribute(isStrict ? "speakerid" : "s").Value);
            par.AttributeString = (e.Attribute(isStrict ? "attributes" : "a") ?? EmptyAttribute).Value;

            par.Elements = e.Attributes().ToDictionary(a => a.Name.ToString(), a => a.Value);
            par.Elements.Remove(isStrict ? "begin" : "b");
            par.Elements.Remove(isStrict ? "end" : "e");
            par.Elements.Remove(isStrict ? "attributes" : "a");
            par.Elements.Remove(isStrict ? "speakerid" : "s");

            e.Elements(isStrict ? "phrase" : "p").Select(p => (TranscriptionElement)TranscriptionPhrase.DeserializeV2(p, isStrict)).ToList().ForEach(p => par.Add(p)); ;

            if (e.Attribute(isStrict ? "attributes" : "a") != null)
                par.AttributeString = e.Attribute(isStrict ? "attributes" : "a").Value;

            if (e.Attribute(isStrict ? "begin" : "b") != null)
            {
                string val = e.Attribute(isStrict ? "begin" : "b").Value;
                int ms;
                if (int.TryParse(val, out ms))
                    par.Begin = TimeSpan.FromMilliseconds(ms);
                else
                    par.Begin = XmlConvert.ToTimeSpan(val);
            }
            else
            {
                var ch = par._children.FirstOrDefault();
                par.Begin = ch == null ? TimeSpan.Zero : ch.Begin;
            }

            if (e.Attribute(isStrict ? "end" : "e") != null)
            {
                string val = e.Attribute(isStrict ? "end" : "e").Value;
                int ms;
                if (int.TryParse(val, out ms))
                    par.End = TimeSpan.FromMilliseconds(ms);
                else
                    par.End = XmlConvert.ToTimeSpan(val);
            }
            else
            {
                var ch = par._children.LastOrDefault();
                par.End = ch == null ? TimeSpan.Zero : ch.Begin;
            }

            return par;
        }
예제 #8
0
 /// <summary>
 /// copy constructor
 /// </summary>
 /// <param name="aKopie"></param>
 public TranscriptionParagraph(TranscriptionParagraph aKopie)
     : this()
 {
     this.Begin = aKopie.Begin;
     this.End = aKopie.End;
     this.trainingElement = aKopie.trainingElement;
     this.DataAttributes = aKopie.DataAttributes;
     if (aKopie.Phrases != null)
     {
         this.Phrases = new VirtualTypeList<TranscriptionPhrase>(this, this._children);
         for (int i = 0; i < aKopie.Phrases.Count; i++)
         {
             this.Phrases.Add(new TranscriptionPhrase(aKopie.Phrases[i]));
         }
     }
     this.Speaker = aKopie.Speaker;
 }
예제 #9
0
        void l_SplitRequest(object sender, EventArgs e)
        {
            Element el = (Element)sender;
            if (el.ValueElement is TranscriptionParagraph)
            {

                TranscriptionParagraph par = (TranscriptionParagraph)el.ValueElement;
                par.Parent.BeginUpdate();
                TimeSpan end = par.End;
                TranscriptionParagraph par2 = new TranscriptionParagraph();
                TranscriptionParagraph par1 = new TranscriptionParagraph();

                par1.AttributeString = par2.AttributeString = par.AttributeString;

                par1.Speaker = par2.Speaker = par.Speaker;
                par1.Begin = par.Begin;
                par2.End = end;
                int where = el.editor.CaretOffset;

                int sum = 0;
                for (int i = 0; i < par.Phrases.Count; i++)
                {
                    TranscriptionPhrase p = par.Phrases[i];

                    if (sum + p.Text.Length <= where) //patri do prvniho
                    {
                        par1.Add(new TranscriptionPhrase(p));
                    }
                    else if (sum >= where)
                    {
                        par2.Add(new TranscriptionPhrase(p));
                    }
                    else if (sum <= where && sum + p.Text.Length > where) //uvnitr fraze
                    {
                        int offs = where - sum;
                        double ratio = offs / (double)p.Text.Length;

                        TimeSpan length = p.End - p.Begin;
                        TimeSpan l1 = new TimeSpan((long)(ratio * length.Ticks));

                        TranscriptionPhrase p1 = new TranscriptionPhrase();
                        p1.Text = p.Text.Substring(0, offs);

                        p1.Begin = p.Begin;
                        p1.End = p1.Begin + l1;
                        //if (p1.End <= par.Begin)
                        //    p1.End = par.Begin + TimeSpan.FromMilliseconds(100); //pojistka kvuli nezarovnanejm textum
                        int idx = i;
                        par1.Add(p1);

                        TranscriptionPhrase p2 = new TranscriptionPhrase();
                        p2.Text = p.Text.Substring(offs);
                        p2.Begin = p1.End;
                        p2.End = p.End;

                        par2.Add(p2);
                        par2.Begin = p2.Begin;

                        par1.End = p1.End;

                    }
                    sum += p.Text.Length;
                }//for

                if (!Keyboard.Modifiers.HasFlag(ModifierKeys.Control))//TODO: the keyboard check should be somewhere else?
                {

                    if (RequestTimePosition != null)
                    {
                        TimeSpan pos;
                        RequestTimePosition(out pos);

                        par1.End = pos;
                        par2.Begin = pos;
                    }

                }

                var parent = par.Parent;
                int indx = par.ParentIndex;

                FixPosSetFor(par.Previous());

                parent.Remove(par);
                parent.Insert(indx, par2);
                parent.Insert(indx, par1);
                parent.EndUpdate();
                ActiveTransctiption = par2;

                this.Dispatcher.Invoke(() =>
                {
                    FixPosTryRestore();
                    SetCaretIn(par2, 0);
                }, DispatcherPriority.Background);

            }
        }
예제 #10
0
        void l_NewRequest(object sender, EventArgs e)
        {
            Element el = (Element)sender;
            TranscriptionParagraph p = new TranscriptionParagraph();
            p.Add(new TranscriptionPhrase());
            if (el.ValueElement is TranscriptionParagraph)
            {
                TimeSpan pos;
                RequestTimePosition(out pos);
                el.ValueElement.End = pos;

                if ((el.ValueElement.End - el.ValueElement.Begin) < TimeSpan.FromMilliseconds(100))
                {
                    el.ValueElement.End = el.ValueElement.Begin + TimeSpan.FromMilliseconds(100);
                }

                if (el.ValueElement.Parent.End < el.ValueElement.End)
                    el.ValueElement.Parent.End = el.ValueElement.End;

                p.Begin = el.ValueElement.Parent.End;

                p.Speaker = ((TranscriptionParagraph)el.ValueElement).Speaker;
                el.ValueElement.Parent.Insert(el.ValueElement.ParentIndex + 1, p);
            }
            else if (el.ValueElement is TranscriptionSection)
            {
                el.ValueElement.Parent.Insert(0, p);
            }
            else if (el.ValueElement is TranscriptionChapter)
            {
                el.ValueElement.Children[0].Insert(0, p);
            }
            FixPosSetFor(el.ValueElement);
            ActiveTransctiption = p;

            this.Dispatcher.Invoke(() =>
            {
                FixPosTryRestore();
                SetCaretIn(p, 0);
            }, DispatcherPriority.Background);
        }
예제 #11
0
        void l_SplitRequest(object sender, EventArgs e)
        {
            Element el = (Element)sender;
            if (el.ValueElement is TranscriptionParagraph)
            {

                TranscriptionParagraph par = (TranscriptionParagraph)el.ValueElement;
                par.Parent.BeginUpdate();
                TimeSpan end = par.End;
                TranscriptionParagraph par2 = new TranscriptionParagraph();
                TranscriptionParagraph par1 = new TranscriptionParagraph();

                par1.AttributeString = par2.AttributeString = par.AttributeString;

                par1.Speaker = par2.Speaker = par.Speaker;

                par2.End = end;
                int where = el.editor.CaretOffset;

                int sum = 0;
                for (int i = 0; i < par.Phrases.Count; i++)
                {
                    TranscriptionPhrase p = par.Phrases[i];

                    if (sum + p.Text.Length <= where) //patri do prvniho
                    {
                        par1.Add(new TranscriptionPhrase(p));
                    }
                    else if (sum >= where)
                    {
                        par2.Add(new TranscriptionPhrase(p));
                    }
                    else if (sum <= where && sum + p.Text.Length > where) //uvnitr fraze
                    {
                        int offs = where - sum;
                        double ratio = offs / (double)p.Text.Length;

                        TimeSpan length = p.End - p.Begin;
                        TimeSpan l1 = new TimeSpan((long)(ratio * length.Ticks));

                        TranscriptionPhrase p1 = new TranscriptionPhrase();
                        p1.Text = p.Text.Substring(0, offs);

                        p1.Begin = p.Begin;
                        p1.End = p1.Begin + l1;
                        if (p1.End <= par.Begin)
                            p1.End = par.Begin + TimeSpan.FromMilliseconds(100); //pojistka kvuli nezarovnanejm textum
                        int idx = i;
                        par1.Add(p1);

                        TranscriptionPhrase p2 = new TranscriptionPhrase();
                        p2.Text = p.Text.Substring(offs);
                        p2.Begin = p1.End;
                        p2.End = p.End;

                        par2.Add(p2);
                        par2.Begin = p2.Begin;

                        par1.End = p1.End;

                    }
                    sum += p.Text.Length;
                }//for

                if (!Keyboard.Modifiers.HasFlag(ModifierKeys.Control))//TODO: hodit to nejak jinak do funkci... :P
                {

                    if (RequestTimePosition != null)
                    {
                        TimeSpan pos;
                        RequestTimePosition(out pos);

                        par1.End = pos;
                        par2.Begin = pos;
                    }

                }
                //SpeakerChanged();
                var parent = par.Parent;
                int indx = par.ParentIndex;
                parent.Remove(par);
                parent.Insert(indx, par2);
                parent.Insert(indx, par1);
                parent.EndUpdate();
                ActiveTransctiption = par2;
            }
        }
예제 #12
0
        void l_NewRequest(object sender, EventArgs e)
        {
            Element el = (Element)sender;
            TranscriptionParagraph p = new TranscriptionParagraph();
            p.Add(new TranscriptionPhrase());
            if (el.ValueElement is TranscriptionParagraph)
            {
                TimeSpan pos;
                RequestTimePosition(out pos);
                el.ValueElement.End = pos;

                if ((el.ValueElement.End - el.ValueElement.Begin) < TimeSpan.FromMilliseconds(100))
                {
                    el.ValueElement.End = el.ValueElement.Begin + TimeSpan.FromMilliseconds(100);
                }

                if (el.ValueElement.Parent.End < el.ValueElement.End)
                    el.ValueElement.Parent.End = el.ValueElement.End;

                p.Begin = el.ValueElement.Parent.End;

                p.Speaker = ((TranscriptionParagraph)el.ValueElement).Speaker;
                el.ValueElement.Parent.Insert(el.ValueElement.ParentIndex + 1, p);
            }
            else if (el.ValueElement is TranscriptionSection)
            {
                el.ValueElement.Parent.Insert(0, p);
            }
            else if (el.ValueElement is TranscriptionChapter)
            {
                el.ValueElement.Children[0].Insert(0, p);
            }
            ActiveTransctiption = p;
        }
예제 #13
0
        private static IEnumerable<TranscriptionParagraph> MakeParagraphs(IEnumerable<XElement> elements, TimeSpan timeunit)
        {
            foreach (var e in elements)
            {
                var p = new TranscriptionParagraph()
                {
                    Begin = new TimeSpan( timeunit.Ticks * XmlConvert.ToInt64(e.Attribute("bt").Value)),
                    End = new TimeSpan( timeunit.Ticks * XmlConvert.ToInt64(e.Attribute("et").Value)),
                };

                var ph = new TranscriptionPhrase()
                {
                    Begin = p.Begin,
                    End = p.End,
                    Text = "",
                };

                var idel = e.Element("Id");
                if (idel != null)
                {
                    p.InternalID = XmlConvert.ToInt32(idel.Attribute("id").Value);
                    ph.Text = "score: "+idel.Attribute("score").Value;
                }
                p.Phrases.Add(ph);
                yield return p;
            }
        }