Ejemplo n.º 1
0
        /// <summary>
        /// Appends all the annotations present in the annotMan to the annotations currently loaded in this annotation Manager.
        /// </summary>
        /// <param name="annotMan"></param>
        public void appendAnnotations(AnnotationManager annotMan)
        {
            if (annotMan == null)
            {
                return;
            }

            foreach (var ann in annotMan.GetAnnotationSubjects())
            {
                appendAnnotations(ann.Key, ann.Value, annotMan.GetAnnotations(ann.Key));
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Compare the annotations loaded in this annotation manager to the annotations loaded in the annotNew.
        /// </summary>
        /// <param name="annotNew">Manager to which you want to compare the current annotations</param>
        /// <returns>An annotations manager diff structure which contains the difference between the two annotation managers</returns>
        public AnnotationManagerDiff Compare(AnnotationManager annotNew)
        {
            AnnotationManagerDiff diffMan = new AnnotationManagerDiff();
            // get the difference between the keys of the two managers.
            var keysInRef = new HashSet <string>(this.GetAnnotationSubjects().Select(x => x.Key).ToList());
            var keysInNew = new HashSet <string>(annotNew.GetAnnotationSubjects().Select(x => x.Key).ToList());
            // all keys present in annotReference and not in annotNew should be added in removedAnnotations
            var keysInRefNotInNew = keysInRef.Except(keysInNew);

            foreach (var annKey in keysInRefNotInNew)
            {
                diffMan.RemovedAnnotations.Add(new Tuple <string, string>(annKey, this.subjectType[annKey]), this.GetAnnotations(annKey));
            }
            // all keys present in annotNew and not in annotReference should be added in addedAnnotations
            var keysInNewNotInRef = keysInNew.Except(keysInRef);

            foreach (var annKey in keysInNewNotInRef)
            {
                diffMan.AddedAnnotations.Add(new Tuple <string, string>(annKey, annotNew.subjectType[annKey]), annotNew.GetAnnotations(annKey));
            }

            // if they have both the same key --> check if each annotation is the same
            var keysInBoth = keysInRef.Intersect(keysInNew);

            foreach (var annKey in keysInBoth)
            {
                var annInRef         = new HashSet <W3CAnnotation>(this.GetAnnotations(annKey));
                var annInNew         = new HashSet <W3CAnnotation>(annotNew.GetAnnotations(annKey));
                var annInRefNotInNew = annInRef.Except(annInNew, new W3CAnnotation(true)).ToList();
                if (annInRefNotInNew.Count > 0)
                {
                    diffMan.RemovedAnnotations.Add(new Tuple <string, string>(annKey, this.subjectType[annKey]), annInRefNotInNew);
                }
                var annInNewNotInRef = annInNew.Except(annInRef, new W3CAnnotation(true)).ToList();
                if (annInNewNotInRef.Count > 0)
                {
                    diffMan.AddedAnnotations.Add(new Tuple <string, string>(annKey, annotNew.subjectType[annKey]), annInNewNotInRef);
                }
            }

            return(diffMan);
        }