예제 #1
0
        private void UpdateAnnotations(AnnotationList <ShapeNode> annList, ShapeNode node)
        {
            if (annList.Count == 0)
            {
                return;
            }

            Annotation <ShapeNode> startAnn;

            annList.Find(node, Direction.LeftToRight, out startAnn);
            if (startAnn == annList.Begin)
            {
                startAnn = annList.First;
            }

            Annotation <ShapeNode> endAnn;

            annList.Find(node, Direction.RightToLeft, out endAnn);
            if (endAnn == annList.End)
            {
                endAnn = annList.Last;
            }

            if (startAnn.CompareTo(endAnn) > 0)
            {
                return;
            }

            foreach (Annotation <ShapeNode> ann in annList.GetNodes(startAnn, endAnn).Where(ann => ann.Span.Contains(node)).ToArray())
            {
                if (!ann.IsLeaf)
                {
                    UpdateAnnotations(ann.Children, node);
                }

                if (ann.Span.Start == node && ann.Span.End == node)
                {
                    annList.Remove(ann);
                }
                else if (ann.Span.Start == node || ann.Span.End == node)
                {
                    Span <ShapeNode> span = ann.Span.Start == node?_spanFactory.Create(node.Next, ann.Span.End) : _spanFactory.Create(ann.Span.Start, node.Prev);

                    var newAnn = new Annotation <ShapeNode>(span, ann.FeatureStruct.DeepClone())
                    {
                        Optional = ann.Optional
                    };
                    if (!ann.IsLeaf)
                    {
                        foreach (Annotation <ShapeNode> child in ann.Children.ToArray())
                        {
                            newAnn.Children.Add(child, false);
                        }
                    }
                    annList.Remove(ann, false);
                    annList.Add(newAnn, false);
                }
            }
        }
예제 #2
0
        public void Find()
        {
            var annList = new AnnotationList <int>();

            annList.Add(1, 2, FeatureStruct.New().Value);
            annList.Add(9, 10, FeatureStruct.New().Value);
            annList.Add(24, 25, FeatureStruct.New().Value);
            annList.Add(49, 50, FeatureStruct.New().Value);
            annList.Add(99, 100, FeatureStruct.New().Value);
            annList.Add(99, 100, FeatureStruct.New().Value);
            annList.Add(new Annotation <int>(Range <int> .Create(20, 70), FeatureStruct.New().Value), false);

            Annotation <int> result;

            Assert.IsFalse(annList.Find(0, out result));
            Assert.AreSame(annList.Begin, result);

            Assert.IsTrue(annList.Find(1, out result));
            Assert.AreSame(annList.First, result);

            Assert.IsFalse(annList.Find(100, out result));
            Assert.AreSame(annList.Last, result);

            Assert.IsFalse(annList.Find(101, out result));
            Assert.AreSame(annList.Last, result);

            Assert.IsFalse(annList.Find(30, out result));
            Assert.AreSame(annList.ElementAt(3), result);

            Assert.IsTrue(annList.Find(9, out result));
            Assert.AreSame(annList.First.Next, result);

            Assert.IsFalse(annList.Find(101, Direction.RightToLeft, out result));
            Assert.AreSame(annList.End, result);

            Assert.IsTrue(annList.Find(100, Direction.RightToLeft, out result));
            Assert.AreSame(annList.Last, result);

            Assert.IsFalse(annList.Find(1, Direction.RightToLeft, out result));
            Assert.AreSame(annList.First, result);

            Assert.IsFalse(annList.Find(0, Direction.RightToLeft, out result));
            Assert.AreSame(annList.First, result);

            Assert.IsFalse(annList.Find(15, Direction.RightToLeft, out result));
            Assert.AreSame(annList.ElementAt(2), result);

            Assert.IsTrue(annList.Find(10, Direction.RightToLeft, out result));
            Assert.AreSame(annList.First.Next, result);
        }