Esempio n. 1
0
        /// <summary>
        /// Initializes a new instance of <see cref="AlignedDiff{T}"/>.
        /// </summary>
        /// <param name="collection1">
        /// The first collection of items.
        /// </param>
        /// <param name="collection2">
        /// The second collection of items.
        /// </param>
        /// <param name="equalityComparer">
        /// The <see cref="IEqualityComparer{T}"/> that will be used to compare elements from
        /// <paramref name="collection1"/> with elements from <paramref name="collection2"/>.
        /// </param>
        /// <param name="similarityComparer">
        /// The <see cref="ISimilarityComparer{T}"/> that will be used to attempt to align elements
        /// inside blocks that consists of elements from the first collection being replaced
        /// with elements from the second collection.
        /// </param>
        /// <param name="alignmentFilter">
        /// The <see cref="ISimilarityComparer{T}"/> that will be used to determine if
        /// two aligned elements are similar enough to be report them as a change from
        /// one to another, or to report them as one being deleted and the other added in
        /// its place.
        /// </param>
        /// <exception cref="ArgumentNullException">
        /// <para><paramref name="collection1"/> is <c>null</c>.</para>
        /// <para>- or -</para>
        /// <para><paramref name="collection2"/> is <c>null</c>.</para>
        /// <para>- or -</para>
        /// <para><paramref name="equalityComparer"/> is <c>null</c>.</para>
        /// <para>- or -</para>
        /// <para><paramref name="alignmentFilter"/> is <c>null</c>.</para>
        /// </exception>
        public AlignedDiff(IEnumerable <T> collection1, IEnumerable <T> collection2, IEqualityComparer <T> equalityComparer,
                           ISimilarityComparer <T> similarityComparer, IAlignmentFilter <T> alignmentFilter)
        {
            if (collection1 == null)
            {
                throw new ArgumentNullException("collection1");
            }
            if (collection2 == null)
            {
                throw new ArgumentNullException("collection2");
            }
            if (equalityComparer == null)
            {
                throw new ArgumentNullException("equalityComparer");
            }
            if (similarityComparer == null)
            {
                throw new ArgumentNullException("similarityComparer");
            }
            if (alignmentFilter == null)
            {
                throw new ArgumentNullException("alignmentFilter");
            }

            _Collection1      = collection1.ToRandomAccess();
            _Collection2      = collection2.ToRandomAccess();
            _EqualityComparer = equalityComparer;

            _SimilarityComparer = similarityComparer;
            _AlignmentFilter    = alignmentFilter;
            _BestAlignmentNodes = new Dictionary <AlignmentKey, ChangeNode>();
            _Upper1             = 0;
            _Upper2             = 0;
        }
Esempio n. 2
0
        /// <summary>
        /// Initializes a new instance of <see cref="AlignedDiff{T}"/>.
        /// </summary>
        /// <param name="collection1">
        /// The first collection of items.
        /// </param>
        /// <param name="collection2">
        /// The second collection of items.
        /// </param>
        /// <param name="equalityComparer">
        /// The <see cref="IEqualityComparer{T}"/> that will be used to compare elements from
        /// <paramref name="collection1"/> with elements from <paramref name="collection2"/>.
        /// </param>
        /// <param name="similarityComparer">
        /// The <see cref="ISimilarityComparer{T}"/> that will be used to attempt to align elements
        /// inside blocks that consists of elements from the first collection being replaced
        /// with elements from the second collection.
        /// </param>
        /// <param name="alignmentFilter">
        /// The <see cref="ISimilarityComparer{T}"/> that will be used to determine if
        /// two aligned elements are similar enough to be report them as a change from
        /// one to another, or to report them as one being deleted and the other added in
        /// its place.
        /// </param>
        /// <exception cref="ArgumentNullException">
        /// <para><paramref name="collection1"/> is <c>null</c>.</para>
        /// <para>- or -</para>
        /// <para><paramref name="collection2"/> is <c>null</c>.</para>
        /// <para>- or -</para>
        /// <para><paramref name="equalityComparer"/> is <c>null</c>.</para>
        /// <para>- or -</para>
        /// <para><paramref name="alignmentFilter"/> is <c>null</c>.</para>
        /// </exception>
        public AlignedDiff(IEnumerable <T> collection1, IEnumerable <T> collection2, IEqualityComparer <T> equalityComparer,
                           ISimilarityComparer <T> similarityComparer, IAlignmentFilter <T> alignmentFilter)
        {
            if (collection1 == null)
            {
                throw new ArgumentNullException("collection1");
            }
            if (collection2 == null)
            {
                throw new ArgumentNullException("collection2");
            }
            if (equalityComparer == null)
            {
                throw new ArgumentNullException("equalityComparer");
            }
            if (similarityComparer == null)
            {
                throw new ArgumentNullException("similarityComparer");
            }
            if (alignmentFilter == null)
            {
                throw new ArgumentNullException("alignmentFilter");
            }

            _Collection1 = collection1.ToRandomAccess();
            _Collection2 = collection2.ToRandomAccess();

            _Diff = new Diff <T>(_Collection1, _Collection2, equalityComparer);
            _SimilarityComparer = similarityComparer;
            _AlignmentFilter    = alignmentFilter;
        }
Esempio n. 3
0
        /// <summary>
        /// Compares the two collections and generate a diff by attempting to align similar individual elements inside
        /// replace-blocks.
        /// </summary>
        /// <typeparam name="T">Type of the element in the list</typeparam>
        /// <param name="first">The first collection.</param>
        /// <param name="second">The second collection.</param>
        /// <param name="equalityComparer">
        /// The <see cref="IEqualityComparer{T}"/> that will be used to compare elements from
        /// <paramref name="first"/> with elements from <paramref name="second"/>.
        /// </param>
        /// <param name="similarityComparer">
        /// The <see cref="ISimilarityComparer{T}"/> that will be used to attempt to align elements
        /// inside blocks that consists of elements from the first collection being replaced
        /// with elements from the second collection.
        /// </param>
        /// <param name="alignmentFilter">
        /// The <see cref="ISimilarityComparer{T}"/> that will be used to determine if
        /// two aligned elements are similar enough to be report them as a change from
        /// one to another, or to report them as one being deleted and the other added in
        /// its place.
        /// </param>
        /// <returns>
        /// A collection of <see cref="AlignedDiffChange"/> objects, one for
        /// each element in the list in the first or second collection (sometimes one instance for a line
        /// from both, when lines are equal or similar.)
        /// </returns>
        public static IEnumerable <AlignedDiffChange> CompareAndAlign <T>(IList <T> first, IList <T> second, IEqualityComparer <T> equalityComparer,
                                                                          ISimilarityComparer <T> similarityComparer, IAlignmentFilter <T> alignmentFilter)
        {
            if (first == null)
            {
                throw new ArgumentNullException("first");
            }
            if (second == null)
            {
                throw new ArgumentNullException("second");
            }
            if (equalityComparer == null)
            {
                throw new ArgumentNullException("equalityComparer");
            }
            if (similarityComparer == null)
            {
                throw new ArgumentNullException("similarityComparer");
            }
            if (alignmentFilter == null)
            {
                throw new ArgumentNullException("alignmentFilter");
            }

            var diff = new AlignedDiff <T>(first, second, equalityComparer, similarityComparer, alignmentFilter);

            return(diff.Generate());
        }
Esempio n. 4
0
        public Index(TermStemmer stemmer, ISimilarityComparer<Document> similarity)
        {
            this.stemmer = stemmer;
            this.similarity = similarity;

            stems = new Dictionary<string, List<DocumentReference>>();
            sites = new List<Document>();
        }
Esempio n. 5
0
        public Index(TermStemmer stemmer, ISimilarityComparer <Document> similarity)
        {
            this.stemmer    = stemmer;
            this.similarity = similarity;

            stems = new Dictionary <string, List <DocumentReference> >();
            sites = new List <Document>();
        }
 public LocalThreadWorkerNodesLifecycleManager(IMessageHub messageHub, IMessageSink messageSink,
                                               IDocumentTokenizer documentTokenizer, IWeightNormalizer weightNormalizer,
                                               ISimilarityComparer similarityComparer, Options options)
 {
     this.messageHub         = messageHub ?? throw new ArgumentNullException(nameof(messageHub));
     this.messageSink        = messageSink ?? throw new ArgumentNullException(nameof(messageSink));
     this.documentTokenizer  = documentTokenizer ?? throw new ArgumentNullException(nameof(documentTokenizer));
     this.weightNormalizer   = weightNormalizer ?? throw new ArgumentNullException(nameof(weightNormalizer));
     this.similarityComparer = similarityComparer ?? throw new ArgumentNullException(nameof(similarityComparer));
     this.options            = options ?? throw new ArgumentNullException(nameof(options));
 }
        public LocalThreadWorkerNode(int id, IMessageHub messageHub, IMessageSink messageSink,
                                     IDocumentTokenizer documentTokenizer, IWeightNormalizer weightNormalizer,
                                     ISimilarityComparer similarityComparer)
        {
            Id = id;

            this.messageHub         = messageHub ?? throw new ArgumentNullException(nameof(messageHub));
            this.messageSink        = messageSink ?? throw new ArgumentNullException(nameof(messageSink));
            this.documentTokenizer  = documentTokenizer ?? throw new ArgumentNullException(nameof(documentTokenizer));
            this.weightNormalizer   = weightNormalizer ?? throw new ArgumentNullException(nameof(weightNormalizer));
            this.similarityComparer = similarityComparer ?? throw new ArgumentNullException(nameof(similarityComparer));

            workIsDoneTCS = new TaskCompletionSource <int>();

            assignments = messageHub.WorkAssignemnts
                          .Where(assignment => assignment.NodeId == id);
        }
Esempio n. 8
0
 /// <summary>
 /// Compares the two collections and generate a diff by attempting to align similar individual elements inside
 /// replace-blocks.
 /// </summary>
 /// <typeparam name="T">Type of the element in the list</typeparam>
 /// <param name="first">The first collection.</param>
 /// <param name="second">The second collection.</param>
 /// <param name="similarityComparer">
 /// The <see cref="ISimilarityComparer{T}"/> that will be used to attempt to align elements
 /// inside blocks that consists of elements from the first collection being replaced
 /// with elements from the second collection.
 /// </param>
 /// <param name="alignmentFilter">
 /// The <see cref="ISimilarityComparer{T}"/> that will be used to determine if
 /// two aligned elements are similar enough to be report them as a change from
 /// one to another, or to report them as one being deleted and the other added in
 /// its place.
 /// </param>
 /// <returns>
 /// A collection of <see cref="AlignedDiffChange"/> objects, one for
 /// each element in the list in the first or second collection (sometimes one instance for a line
 /// from both, when lines are equal or similar.)
 /// </returns>
 public static IEnumerable <AlignedDiffChange> CompareAndAlign <T>(IList <T> first, IList <T> second, ISimilarityComparer <T> similarityComparer, IAlignmentFilter <T> alignmentFilter)
 {
     return(CompareAndAlign(first, second, EqualityComparer <T> .Default, similarityComparer, alignmentFilter));
 }