public void MakeTagAnnotation_With1Wordform()
        {
            // Provide hvoTagPoss and SelectedWordforms, create a markup tag and examine it.

            // Setup the SelectedWordforms property
            var tempList = new List <AnalysisOccurrence> {
                m_occurrences[1]
            };

            m_tagChild.SelectedWordforms = tempList;

            // SUT
            // Use the last possibility tag in the first list of tags
            ITextTag ttag    = null;
            var      hvoTtag = -1;

            UndoableUnitOfWorkHelper.Do("UndoTagTest", "RedoTagTest", Cache.ActionHandlerAccessor, () =>
            {
                ttag = m_tagChild.CallMakeTextTagInstance(m_possTags[m_cposs - 1]);
                if (ttag != null)
                {
                    hvoTtag = ttag.Hvo;
                }
            });

            // Verification
            AssertTagExists(hvoTtag, "Tag should have been created.");
            VerifyTextTag(ttag, m_possTags[m_cposs - 1], tempList[0], tempList[0]);
        }
예제 #2
0
        /// <summary>
        /// Caches a possibility label for each analysis occurrence that a tag applies to.
        /// </summary>
        /// <param name="ttag"></param>
        /// <returns></returns>
        internal void CacheTagString(ITextTag ttag)
        {
            var occurrences = ttag.GetOccurrences();
            var cwordArray  = occurrences.Count;

            if (cwordArray == 0)
            {
                return;                 // No words tagged! Again... shouldn't happen. :)
            }
            var       tagPossibility = ttag.TagRA;
            ITsString label;

            if (tagPossibility == null)
            {
                label = m_emptyAnalysisStr;
            }
            else
            {
                label = tagPossibility.Abbreviation.BestAnalysisAlternative;
            }

            // use 'for' loop because we need to know when we're at the beginning
            // and end of the loop
            for (var i = 0; i < cwordArray; i++)
            {
                // TODO: Someday when we handle more than one layer of tagging, this may change!
                var current = occurrences[i];
                if (current == null || !current.IsValid)
                {
                    continue;                     // Shouldn't happen...
                }
                var strBldr = label.GetBldr();
                if (i == 0)                 // First occurrence for this tag.
                {
                    StartTagSetup(strBldr);
                }
                else                 // Until someone has a better idea, only show the label on the first occurrence.
                                     // but I have a feeling the label will be shown on the left-most occurrence
                                     // whether it's a RTL or LTR language!
                {
                    //strBldr.Clear(); This didn't keep the WS!
                    label   = m_emptyAnalysisStr;
                    strBldr = label.GetBldr();
                }
                if (i == cwordArray - 1)                 // Last occurrence for this tag.
                {
                    EndTagSetup(strBldr);
                }
                var key = GetDictKey(current);
                if (m_tagStrings.ContainsKey(key))
                {
                    m_tagStrings.Remove(key);
                }
                m_tagStrings[key] = strBldr.GetString();
            }
        }
 /// <summary>
 /// Verify that the parameter tag points to the right possibility marker
 /// and that it refers to the correct begin and end points in the text.
 /// </summary>
 /// <param name="ttag"></param>
 /// <param name="poss"></param>
 /// <param name="point1"></param>
 /// <param name="point2"></param>
 private static void VerifyTextTag(ITextTag ttag, ICmPossibility poss,
                                   AnalysisOccurrence point1, AnalysisOccurrence point2)
 {
     Assert.IsNotNull(ttag, "There should be a TextTag object.");
     Assert.AreEqual(poss.Hvo, ttag.TagRA.Hvo, "Text Tag has wrong possibility Hvo.");
     Assert.AreEqual(point1.Segment.Hvo, ttag.BeginSegmentRA.Hvo, "Tag has wrong BeginSegment");
     Assert.AreEqual(point1.Index, ttag.BeginAnalysisIndex, "Tag has wrong BeginAnalysisIndex");
     Assert.AreEqual(point2.Segment.Hvo, ttag.EndSegmentRA.Hvo, "Tag has wrong EndSegment");
     Assert.AreEqual(point2.Index, ttag.EndAnalysisIndex, "Tag has wrong EndAnalysisIndex");
 }
        private ITextTag MakeTag(FDO.IText text, ICmPossibility tag, ISegment beginSeg, int begin, ISegment endSeg, int end)
        {
            ITextTag ttag = Cache.ServiceLocator.GetInstance <ITextTagFactory>().Create();

            text.ContentsOA.TagsOC.Add(ttag);
            ttag.TagRA              = tag;
            ttag.BeginSegmentRA     = beginSeg;
            ttag.BeginAnalysisIndex = begin;
            ttag.EndSegmentRA       = endSeg;
            ttag.EndAnalysisIndex   = end;
            return(ttag);
        }
        public void MakeTagAnnot_ExistTag_NoOverlap()
        {
            // Setup the SelectedWordforms property for first tag
            var tempList = new List <AnalysisOccurrence> {
                m_occurrences[0], m_occurrences[1]
            };

            m_tagChild.SelectedWordforms = tempList;

            var      hvoTag     = -1;
            ITextTag initialTag = null;

            UndoableUnitOfWorkHelper.Do("UndoTagTest", "RedoTagTest", Cache.ActionHandlerAccessor, () =>
            {
                initialTag = m_tagChild.CallMakeTextTagInstance(m_possTags[0]);
                if (initialTag != null)
                {
                    hvoTag = initialTag.Hvo;
                }
            });

            // Setup the SelectedWordforms property for second tag
            var tempList1 = new List <AnalysisOccurrence> {
                m_occurrences[2], m_occurrences[3], m_occurrences[4]
            };

            m_tagChild.SelectedWordforms = tempList1;

            // SUT
            // Make a second tag annotation with a different possibility pointing to the new Wordforms
            var      hvoTagSUT = -1;
            ITextTag tagSUT    = null;

            UndoableUnitOfWorkHelper.Do("UndoTagTest", "RedoTagTest", Cache.ActionHandlerAccessor, () =>
            {
                tagSUT = m_tagChild.CallMakeTextTagInstance(m_possTags[2]);
                if (tagSUT != null)
                {
                    hvoTagSUT = tagSUT.Hvo;
                }
            });

            // Verification
            // Verify new tag
            AssertTagExists(hvoTagSUT, "Should have created new tag.");
            VerifyTextTag(tagSUT, m_possTags[2], tempList1[0], tempList1[2]);

            // The old tag should still exist in the Cache
            AssertTagExists(hvoTag, "Should have left old tag in cache.");
            VerifyTextTag(initialTag, m_possTags[0], tempList[0], tempList[1]);
        }
예제 #6
0
        private ITextTag[] getRelatedTypeTextTag(Lyric lyric, ITextTag sample)
        {
            switch (sample)
            {
            case RubyTag _:
                return(lyric.RubyTags?.OfType <ITextTag>().ToArray());

            case RomajiTag _:
                return(lyric.RomajiTags?.OfType <ITextTag>().ToArray());

            default:
                throw new InvalidCastException(nameof(sample));
            }
        }
        public void MakeTagAnnot_ExistTag_RearOverlap()
        {
            // This test will need changing when we allow multiple lines of tagging.

            // Setup the SelectedWordforms property for first tag
            var tempList = new List <AnalysisOccurrence> {
                m_occurrences[1], m_occurrences[2]
            };

            m_tagChild.SelectedWordforms = tempList;

            var hvoTag = -1;

            UndoableUnitOfWorkHelper.Do("UndoTagTest", "RedoTagTest", Cache.ActionHandlerAccessor, () =>
            {
                var initialTag = m_tagChild.CallMakeTextTagInstance(m_possTags[0]);
                if (initialTag != null)
                {
                    hvoTag = initialTag.Hvo;
                }
            });

            // Setup the SelectedWordforms property for second tag
            var tempList1 = new List <AnalysisOccurrence> {
                m_occurrences[2], m_occurrences[3], m_occurrences[4]
            };

            m_tagChild.SelectedWordforms = tempList1;

            // SUT
            // Make a second tag annotation with a different possibility pointing to the new Wordforms
            ITextTag tagSUT    = null;
            var      hvoSUTTag = -1;

            UndoableUnitOfWorkHelper.Do("UndoTagTest", "RedoTagTest", Cache.ActionHandlerAccessor, () =>
            {
                tagSUT = m_tagChild.CallMakeTextTagInstance(m_possTags[2]);
                if (tagSUT != null)
                {
                    hvoSUTTag = tagSUT.Hvo;
                }
            });

            // Verification
            // Verify new tag
            AssertTagExists(hvoSUTTag, "Should have created second tag.");
            VerifyTextTag(tagSUT, m_possTags[2], tempList1[0], tempList1[2]);
            // The old tag should no longer exist in the Cache
            AssertTagDoesntExist(hvoTag, "Should have deleted the initial tag.");
        }
        private void AssertTagExists(int hvoTag, string msgFailure)
        {
            ITextTag tag = null;

            try
            {
                tag = m_tagRepo.GetObject(hvoTag);
            }
            catch (KeyNotFoundException)
            {
                Assert.Fail(msgFailure);
            }
            Assert.IsNotNull(tag.TagRA, msgFailure);
        }
예제 #9
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Compares TextTags in two segments to see if they are similar enough to be considered
		/// the same. Mostly designed for testing, but in production code because it has some
		/// application in charting (searches?). Tests wordforms tagged for same baseline text
		/// and checks to see that they both reference the same CmPossibility tag.
		/// </summary>
		/// ------------------------------------------------------------------------------------
		public bool IsAnalogousTo(ITextTag otherTag)
		{
			if (otherTag == null)
				return false;
			if (this.TagRA != otherTag.TagRA)
				return false;
			var myWordforms = this.GetOccurrences();
			var otherWordforms = otherTag.GetOccurrences();
			if (myWordforms == null || otherWordforms == null)
				throw new ArgumentException("Found an invalid TextTag.");
			if (myWordforms.Count != otherWordforms.Count)
				return false;
			// Below LINQ returns false if it finds any tagged wordforms in the two lists
			// that have different baseline text (at the same index)
			return !myWordforms.Where((t, i) => t.BaselineText.Text != otherWordforms[i].BaselineText.Text).Any();
		}
예제 #10
0
        public RectangleF GetTextTagPosition(ITextTag textTag)
        {
            var spriteText = getSpriteText();

            if (spriteText == null)
            {
                return(new RectangleF());
            }

            switch (textTag)
            {
            case RubyTag rubyTag:
                return(spriteText.GetRubyTagPosition(rubyTag));

            case RomajiTag romajiTag:
                return(spriteText.GetRomajiTagPosition(romajiTag));

            default:
                throw new ArgumentOutOfRangeException(nameof(textTag));
            }
        }
        public void InvalidTags()
        {
            var      para = (IStTxtPara)m_text.ContentsOA.ParagraphsOS.First();
            ISegment seg  = para.SegmentsOS.First();

            var model = new ComplexConcPatternModel(Cache);

            model.Root.Children.Add(new ComplexConcWordNode {
                Category = m_verb
            });
            model.Compile();
            Assert.That(model.Search(m_text.ContentsOA), Is.EquivalentTo(new IParaFragment[] { new ParaFragment(seg, 0, 11, null) }).Using(m_fragmentComparer));

            // create a tag that occurs after the segment
            ITextTag ttag = MakeTag(m_text, m_np, seg, 6, seg, 6);

            Assert.That(model.Search(m_text.ContentsOA), Is.EquivalentTo(new IParaFragment[] { new ParaFragment(seg, 0, 11, null) }).Using(m_fragmentComparer));

            ttag.Delete();
            // create a tag where the begin index is greater than the end index
            MakeTag(m_text, m_np, seg, 5, seg, 4);
            Assert.That(model.Search(m_text.ContentsOA), Is.EquivalentTo(new IParaFragment[] { new ParaFragment(seg, 0, 11, null) }).Using(m_fragmentComparer));
        }
        public void MakeTagAnnotation_WithNoWordform()
        {
            // Provide hvoTagPoss and SelectedWordforms, create a markup tag and examine it.
            // Setup the SelectedWordforms property
            m_tagChild.SelectedWordforms = null;

            // SUT
            ITextTag ttag    = null;
            var      hvoTtag = -1;

            UndoableUnitOfWorkHelper.Do("UndoTagTest", "RedoTagTest", Cache.ActionHandlerAccessor, () =>
            {
                ttag = m_tagChild.CallMakeTextTagInstance(m_possTags[m_cposs - 1]);
                if (ttag != null)
                {
                    hvoTtag = ttag.Hvo;
                }
            });

            // Verification
            AssertTagDoesntExist(hvoTtag, "MakeTextTagInstance must return null if no Wordforms are selected.");
            Assert.IsNull(ttag, "MakeTextTagInstance must return null if no Wordforms are selected.");
        }
예제 #13
0
 private Lyric getNextLyricWithTextTag(Lyric current, ITextTag textTag)
 => Lyrics.GetNextMatch(current, x => getRelatedTypeTextTag(x, textTag)?.Any() ?? false);
예제 #14
0
            public LabelledTextTagTextBox(ITextTag textTag)
            {
                this.textTag = textTag;

                // apply current text from text-tag.
                Component.Text = textTag.Text;

                // should change preview text box if selected ruby/romaji changed.
                OnCommit += (sender, newText) =>
                {
                    textTag.Text = sender.Text;
                };

                // change style if focus.
                selectedTextTag.BindCollectionChanged((e, a) =>
                {
                    var highLight = selectedTextTag.Contains(textTag);

                    Component.BorderColour    = highLight ? colours.Yellow : colours.Blue;
                    Component.BorderThickness = highLight ? 3 : 0;
                });

                if (!(InternalChildren[1] is FillFlowContainer fillFlowContainer))
                {
                    return;
                }

                // change padding to place delete button.
                fillFlowContainer.Padding = new MarginPadding
                {
                    Horizontal = CONTENT_PADDING_HORIZONTAL,
                    Vertical   = CONTENT_PADDING_VERTICAL,
                    Right      = CONTENT_PADDING_HORIZONTAL + DELETE_BUTTON_SIZE + CONTENT_PADDING_HORIZONTAL,
                };

                // add delete button.
                AddInternal(new Container
                {
                    RelativeSizeAxes = Axes.X,
                    AutoSizeAxes     = Axes.Y,
                    Padding          = new MarginPadding
                    {
                        Top   = CONTENT_PADDING_VERTICAL + 10,
                        Right = CONTENT_PADDING_HORIZONTAL,
                    },
                    Child = new DeleteIconButton
                    {
                        Anchor = Anchor.TopRight,
                        Origin = Anchor.TopRight,
                        Size   = new Vector2(DELETE_BUTTON_SIZE),
                        Action = () => OnDeleteButtonClick?.Invoke(),
                        Hover  = hover =>
                        {
                            if (hover)
                            {
                                // trigger selected if hover on delete button.
                                selectedTextTag.Add(textTag);
                            }
                            else
                            {
                                // do not clear current selected if typing.
                                if (Component.HasFocus)
                                {
                                    return;
                                }

                                selectedTextTag.Remove(textTag);
                            }
                        }
                    }
                });
            }
예제 #15
0
		/// <summary>
		/// The test version doesn't want anything to do with views (which the superclass version does).
		/// </summary>
		/// <param name="ttag"></param>
		protected override void CacheNullTagString(ITextTag ttag)
		{
			// dummy method
		}
예제 #16
0
		private static void SetTagBeginPoint(ITextTag ttag, AnalysisOccurrence point1)
		{
			ttag.BeginSegmentRA = point1.Segment;
			ttag.BeginAnalysisIndex = point1.Index;
		}
예제 #17
0
		private static void SetTagEndPoint(ITextTag ttag, AnalysisOccurrence point2)
		{
			ttag.EndSegmentRA = point2.Segment;
			ttag.EndAnalysisIndex = point2.Index;
		}
예제 #18
0
 /// <summary>
 /// Protected virtual so the testing subclass doesn't have to know about Views.
 /// </summary>
 /// <param name="textTag"></param>
 protected virtual void CacheTagString(ITextTag textTag)
 {
     // Cache the new tagging string and call PropChanged?
     (m_vc as InterlinTaggingVc).CacheTagString(textTag);
 }
예제 #19
0
 /// <summary>
 /// Protected virtual so the testing subclass doesn't have to know about Views.
 /// </summary>
 /// <param name="textTag"></param>
 protected virtual void CacheNullTagString(ITextTag textTag)
 {
     // Cache a string for each occurrence this tag references. (PropChanged?)
     (m_vc as InterlinTaggingVc).CacheNullTagString(textTag.GetOccurrences());
 }
예제 #20
0
 private static void SetTagEndPoint(ITextTag ttag, AnalysisOccurrence point2)
 {
     ttag.EndSegmentRA     = point2.Segment;
     ttag.EndAnalysisIndex = point2.Index;
 }
예제 #21
0
 private static void SetTagBeginPoint(ITextTag ttag, AnalysisOccurrence point1)
 {
     ttag.BeginSegmentRA     = point1.Segment;
     ttag.BeginAnalysisIndex = point1.Index;
 }
예제 #22
0
 /// <summary>
 /// The test version doesn't want anything to do with views (which the superclass version does).
 /// </summary>
 /// <param name="ttag"></param>
 protected override void CacheNullTagString(ITextTag ttag)
 {
     // dummy method
 }
 public CreateTextTagCaretPosition(Lyric lyric, ITextTag textTag)
 {
     Lyric   = lyric;
     TextTag = textTag; // use text tag in order to let us know will create ruby or romaji.
 }
예제 #24
0
		/// <summary>
		/// Verify that the parameter tag points to the right possibility marker
		/// and that it refers to the correct begin and end points in the text.
		/// </summary>
		/// <param name="ttag"></param>
		/// <param name="poss"></param>
		/// <param name="point1"></param>
		/// <param name="point2"></param>
		private static void VerifyTextTag(ITextTag ttag, ICmPossibility poss,
										  AnalysisOccurrence point1, AnalysisOccurrence point2)
		{
			Assert.IsNotNull(ttag, "There should be a TextTag object.");
			Assert.AreEqual(poss.Hvo, ttag.TagRA.Hvo, "Text Tag has wrong possibility Hvo.");
			Assert.AreEqual(point1.Segment.Hvo, ttag.BeginSegmentRA.Hvo, "Tag has wrong BeginSegment");
			Assert.AreEqual(point1.Index, ttag.BeginAnalysisIndex, "Tag has wrong BeginAnalysisIndex");
			Assert.AreEqual(point2.Segment.Hvo, ttag.EndSegmentRA.Hvo, "Tag has wrong EndSegment");
			Assert.AreEqual(point2.Index, ttag.EndAnalysisIndex, "Tag has wrong EndAnalysisIndex");
		}
예제 #25
0
		/// <summary>
		/// Protected virtual so the testing subclass doesn't have to know about Views.
		/// </summary>
		/// <param name="textTag"></param>
		protected virtual void CacheTagString(ITextTag textTag)
		{
			// Cache the new tagging string and call PropChanged?
			(m_vc as InterlinTaggingVc).CacheTagString(textTag);
		}
예제 #26
0
		/// <summary>
		/// Protected virtual so the testing subclass doesn't have to know about Views.
		/// </summary>
		/// <param name="textTag"></param>
		protected virtual void CacheNullTagString(ITextTag textTag)
		{
			// Cache a string for each occurrence this tag references. (PropChanged?)
			(m_vc as InterlinTaggingVc).CacheNullTagString(textTag.GetOccurrences());
		}
예제 #27
0
		/// <summary>
		/// Caches a possibility label for each analysis occurrence that a tag applies to.
		/// </summary>
		/// <param name="ttag"></param>
		/// <returns></returns>
		internal void CacheTagString(ITextTag ttag)
		{
			var occurrences = ttag.GetOccurrences();
			var cwordArray = occurrences.Count;
			if (cwordArray == 0)
				return; // No words tagged! Again... shouldn't happen. :)

			var tagPossibility = ttag.TagRA;
			ITsString label;
			if (tagPossibility == null)
				label = m_emptyAnalysisStr;
			else
				label = tagPossibility.Abbreviation.BestAnalysisAlternative;

			// use 'for' loop because we need to know when we're at the beginning
			// and end of the loop
			for(var i=0; i < cwordArray; i++)
			{
				// TODO: Someday when we handle more than one layer of tagging, this may change!
				var current = occurrences[i];
				if (current == null || !current.IsValid)
					continue; // Shouldn't happen...
				var strBldr = label.GetBldr();
				if (i == 0) // First occurrence for this tag.
				{
					StartTagSetup(strBldr);
				}
				else // Until someone has a better idea, only show the label on the first occurrence.
					// but I have a feeling the label will be shown on the left-most occurrence
					// whether it's a RTL or LTR language!
				{
					//strBldr.Clear(); This didn't keep the WS!
					label = m_emptyAnalysisStr;
					strBldr = label.GetBldr();
				}
				if (i == cwordArray - 1) // Last occurrence for this tag.
					EndTagSetup(strBldr);
				var key = GetDictKey(current);
				if (m_tagStrings.ContainsKey(key))
					m_tagStrings.Remove(key);
				m_tagStrings[key] = strBldr.GetString();
			}
		}
예제 #28
0
 private Lyric tagInLyric(ITextTag textTag)
 {
     return(Lyrics.FirstOrDefault(x => getRelatedTypeTextTag(x, textTag)?.Contains(textTag) ?? false));
 }
 public TypingTextTagCaretPosition(Lyric lyric, ITextTag textTag, int typingCaretIndex)
 {
     Lyric            = lyric;
     TextTag          = textTag;
     TypingCaretIndex = typingCaretIndex;
 }
예제 #30
0
 public EditTextTagCaretPosition(Lyric lyric, ITextTag textTag)
 {
     Lyric   = lyric;
     TextTag = textTag;
 }