Beispiel #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);
                }
            }
        }
Beispiel #2
0
        public void Remove()
        {
            var annList = new AnnotationList <int>();

            annList.Add(0, 1, 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.Remove(annList.First);
            Assert.AreEqual(4, annList.Count);
            Assert.AreEqual(Range <int> .Create(9, 10), annList.First.Range);

            annList.Remove(annList.Last);
            Assert.AreEqual(3, annList.Count);
            Assert.AreEqual(Range <int> .Create(49, 50), annList.Last.Range);

            annList.Remove(annList.First.Next);
            Assert.AreEqual(2, annList.Count);
            annList.Remove(annList.First);
            Assert.AreEqual(1, annList.Count);
            annList.Remove(annList.First);
            Assert.AreEqual(0, annList.Count);

            annList.Add(0, 1, FeatureStruct.New().Value);
            annList.Add(9, 10, FeatureStruct.New().Value);
            annList.Add(49, 50, FeatureStruct.New().Value);
            annList.Add(69, 70, FeatureStruct.New().Value);
            annList.Add(99, 100, FeatureStruct.New().Value);
            annList.Add(0, 49, FeatureStruct.New().Value);
            annList.Add(51, 100, FeatureStruct.New().Value);

            annList.Remove(annList.First);
            Assert.AreEqual(4, annList.Count);
            annList.Remove(annList.Last, false);
            Assert.AreEqual(3, annList.Count);
        }