示例#1
0
        public void GetEntitiesTest()
        {
            var target = CreateUnboundUnweightedTestDocument();
            IEnumerable <IEntity> expected = new IEntity[] {
                new NounPhrase(
                    new PersonalPronoun("We")
                    ),
                new PersonalPronoun("We"),
                new NounPhrase(
                    new Adjective("blue"),
                    new CommonSingularNoun("team")
                    ),
                new CommonSingularNoun("team"),
                new NounPhrase(
                    new PersonalPronoun("We")),
                new PersonalPronoun("We"),
                new NounPhrase(
                    new PersonalPronoun("this")
                    ), new PersonalPronoun("this"),
                new PronounPhrase(new PersonalPronoun("We")),
                new PronounPhrase(new PersonalPronoun("they")),
                new NounPhrase(new CommonPluralNoun("jerks")),
            };
            IEnumerable <IEntity> actual;

            actual = target.Entities;
            foreach (var e in expected)
            {
                Assert.Contains(e, actual, Equality.Create <IEntity>((a, b) => a.Text == b.Text && a.GetType() == b.GetType()));
            }
        }
示例#2
0
        public void EqualityCreatedWithoutSpecifyingHasherCausesNonNullsToCollide()
        {
            var comparer = Equality.Create <object>((x, y) => x.Equals(y));

            object[] values = { "hello", 123, new object(), (decimal?)1m };
            Check.That(values.Select(comparer.GetHashCode).Distinct()).HasSize(1);
        }
示例#3
0
        public void EqualityCreatedDeterminesEqualityAsSpecified()
        {
            var comparer = Equality.Create <string>((x, y) => x.EqualsIgnoreCase(y));
            var first    = "hello";
            var second   = "HELLO";

            Check.That(comparer.Equals(first, second)).IsTrue();
        }
示例#4
0
        public void EqualityCreatedWithoutSpecifyingHasherCausesNullsToCollide()
        {
            var comparer = Equality.Create <object>((x, y) => x.Equals(y));
            var values   = Enumerable.Repeat <object>(null, 2);

            Check.That(values.Select(comparer.GetHashCode).Distinct()).HasSize(1);
            Check.That(comparer.GetHashCode(string.Empty)).IsNotEqualTo(comparer.GetHashCode(null));
        }
示例#5
0
 /// <summary>
 /// Returns distinct elements from a sequence of TLexical constructs by using a specified
 /// equality comparison function.
 /// </summary>
 /// <typeparam name="TLexical">Any type which implements the ILexical interface.</typeparam>
 /// <param name="elements">The sequence of TLexical constructs in which to eliminate duplicates.</param>
 /// <param name="comparison">A function to compare two TLexicals for equality.</param>
 /// <returns>
 /// A new sequence of ILexical constructs containing only the distinct elements of the
 /// source sequence as determined by the provided comparison function.
 /// </returns>
 /// <example>
 /// <code>
 /// var distinctNounPhrases = myDoc.Phrases
 ///     .OfNounPhrase()
 ///     .Distinct((np1, np2) =&gt; np1.Text == np2.Text || np1.IsAliasFor(np2));
 /// </code>
 /// </example>
 public static IEnumerable <TLexical> Distinct <TLexical>(this IEnumerable <TLexical> elements, Func <TLexical, TLexical, bool> comparison)
     where TLexical : ILexical => elements.Distinct(Equality.Create(comparison));
示例#6
0
 /// <summary>
 /// Produces the set difference of two sequences by using the specified comparison function
 /// to compare values.
 /// </summary>
 /// <typeparam name="TLexical">
 /// The type of the elements of the input sequences. Any Type which implements the ILexical
 /// interface is applicable.
 /// </typeparam>
 /// <param name="first">
 /// A sequence whose elements that are not also in second will be returned.
 /// </param>
 /// <param name="second">
 /// A sequence whose elements that also occur in the first sequence will cause those
 /// elements to be removed from the returned sequence.
 /// </param>
 /// <param name="comparison">
 /// A function to compare two instances of type TLexical and return true or false.
 /// </param>
 /// <returns>A sequence that contains the set difference of the elements of two sequences.</returns>
 public static IEnumerable <TLexical> Except <TLexical>(this IEnumerable <TLexical> first, IEnumerable <TLexical> second, Func <TLexical, TLexical, bool> comparison)
     where TLexical : ILexical => first.Except(second, Equality.Create(comparison));
示例#7
0
 /// <summary>
 /// Determines whether a sequence of ILexical constructs contains a specified element by
 /// using a specified equality comparison function.
 /// </summary>
 /// <param name="elements">
 /// The sequence of ILexical constructs in which to search for the given element.
 /// </param>
 /// <param name="element">The element to search for.</param>
 /// <param name="comparison">A function to compare two ILexicals for equality.</param>
 /// <typeparam name="TLexical">Any type which implements the ILexical interface.</typeparam>
 /// <returns><c>true</c> if the sequence contains the given element; otherwise, <c>false</c>.</returns>
 /// <example>
 /// <code>
 /// var myNPs = myDoc.Phrases.OfNounPhrase();
 /// if (myNPs.Contains(NpToFind, (np1, np2) =&gt; np1.Text == np2.Text || np1.IsAliasFor(np2)))
 /// {
 ///     Console.WriteLine("Found!");
 /// }
 /// </code>
 /// </example>
 public static bool Contains <TLexical>(this IEnumerable <TLexical> elements, TLexical element, Func <TLexical, TLexical, bool> comparison)
     where TLexical : ILexical => elements.Contains(element, Equality.Create(comparison));
示例#8
0
 /// <summary>
 /// Produces the set union of two sequences of ILexical constructs by using the specified
 /// comparison function to compare values.
 /// </summary>
 /// <typeparam name="TLexical">Any type which implements the ILexical interface.</typeparam>
 /// <param name="first">
 /// A sequence of TLexical whose distinct elements form the first set of the union.
 /// </param>
 /// <param name="second">
 /// A sequence of TLexical whose distinct elements form the second set of the union.
 /// </param>
 /// <param name="equate">A function to compare two TLexicals for equality.</param>
 /// <returns>
 /// A sequence that contains the elements from both input sequences, excluding duplicates.
 /// </returns>
 /// <example>
 /// <code>
 /// var distinctActionsAcross = doc1.Verbals
 ///     .Union(doc2.Verbals, (a1, a2) =&gt; a1.IsSimilarTo(A2));
 /// </code>
 /// </example>
 public static ParallelQuery <TLexical> Union <TLexical>(this ParallelQuery <TLexical> first, ParallelQuery <TLexical> second, Func <TLexical, TLexical, bool> equate)
     where TLexical : ILexical => first.Union(second, Equality.Create(equate));
示例#9
0
 /// <summary>
 /// Determines whether two sequences of TLexical are equal by comparing their elements by
 /// the specified comparison function.
 /// </summary>
 /// <typeparam name="TLexical">Any type which implements the ILexical interface.</typeparam>
 /// <param name="first">The left hand sequence of TLexicals to compare.</param>
 /// <param name="second">The right hand sequence of TLexicals to compare.</param>
 /// <param name="equate">
 /// A function to compare two TLexicals for equality. This will be applied a single time to
 /// each pair of inputs.
 /// </param>
 /// <returns>
 /// <c>true</c> if the two source sequences are of equal length and their corresponding
 /// elements compare equal according to provided Lexical comparison function; otherwise, <c>false</c>.
 /// </returns>
 public static bool SequenceEqual <TLexical>(this ParallelQuery <TLexical> first, ParallelQuery <TLexical> second, Func <TLexical, TLexical, bool> equate)
     where TLexical : ILexical => first.SequenceEqual(second, Equality.Create(equate));
示例#10
0
 /// <summary>
 /// Produces the set intersection of two sequences of TLexical constructs by using the
 /// specified comparison function to compare values.
 /// </summary>
 /// <typeparam name="TLexical">Any type which implements the ILexical interface.</typeparam>
 /// <param name="first">
 /// A sequence of TLexical whose distinct elements that also appear in the second sequence
 /// of TLexical will be returned.
 /// </param>
 /// <param name="second">
 /// A sequence of TLexical whose distinct elements that also appear in the first sequence of
 /// TLexical will be returned.
 /// </param>
 /// <param name="comparison">A function to compare two TLexicals for equality.</param>
 /// <returns>
 /// A sequence that contains the elements that form the set intersection of the two sequences.
 /// </returns>
 /// <example>
 /// <code>
 /// var wordsInCommon = doc1.words.Intersect(doc2.words, (w1, w2) =&gt; w1.IsSynonymFor(w2));
 /// </code>
 /// </example>
 public static ParallelQuery <TLexical> Intersect <TLexical>(this ParallelQuery <TLexical> first, ParallelQuery <TLexical> second, Func <TLexical, TLexical, bool> comparison)
     where TLexical : ILexical => first.Intersect(second, Equality.Create(comparison));
示例#11
0
 /// <summary>
 /// Returns distinct elements from a sequence of TLexical constructs by using a specified
 /// equality comparison function.
 /// </summary>
 /// <typeparam name="TLexical">Any type which implements the ILexical interface.</typeparam>
 /// <param name="elements">The sequence of TLexical constructs in which to eliminate duplicates.</param>
 /// <param name="comparison">A function to compare two TLexicals for equality.</param>
 /// <returns>
 /// A new sequence of ILexical constructs containing only the distinct elements of the
 /// source sequence as determined by the provided comparison function.
 /// </returns>
 /// <example>
 /// <code>
 /// var distinctNounPhrases = myDoc.Phrases
 ///     .AsParallel()
 ///     .OfNounPhrase()
 ///     .Distinct((np1, np2) =&gt; np1.Text == np2.Text || np1.IsAliasFor(np2));
 /// </code>
 /// </example>
 public static ParallelQuery <TLexical> Distinct <TLexical>(this ParallelQuery <TLexical> elements, Func <TLexical, TLexical, bool> comparison)
     where TLexical : ILexical => elements.Distinct(Equality.Create(comparison));
示例#12
0
 /// <summary>
 /// Determines whether a sequence of ILexical constructs contains a specified element by
 /// using a specified equality comparison function.
 /// </summary>
 /// <param name="elements">
 /// The sequence of ILexical constructs in which to search for the given element.
 /// </param>
 /// <param name="element">The element to search for.</param>
 /// <param name="equate">A function to compare two ILexicals for equality.</param>
 /// <typeparam name="TLexical">Any type which implements the ILexical interface.</typeparam>
 /// <returns><c>true</c> if the sequence contains the given element; otherwise, <c>false</c>.</returns>
 /// <example>
 /// <code>
 /// var myNPs = myDoc.Phrases.OfNounPhrase();
 /// if (myNPs.Contains(NpToFind, (np1, np2) =&gt; np1.Text == np2.Text || np1.IsAliasFor(np2)))
 /// {
 ///     Console.WriteLine("Found!");
 /// }
 /// </code>
 /// </example>
 public static bool Contains <TLexical>(this ParallelQuery <TLexical> elements, TLexical element, Func <TLexical, TLexical, bool> equate)
     where TLexical : ILexical => elements.Contains(element, Equality.Create(equate));
示例#13
0
 /// <summary>
 /// Produces the set union of two sequences of ILexical constructs by using the specified
 /// comparison function to compare values.
 /// </summary>
 /// <typeparam name="TLexical">Any type which implements the ILexical interface.</typeparam>
 /// <param name="first">
 /// A sequence of TLexical whose distinct elements form the first set of the union.
 /// </param>
 /// <param name="second">
 /// A sequence of TLexical whose distinct elements form the second set of the union.
 /// </param>
 /// <param name="equate">A function to compare two TLexicals for equality.</param>
 /// <returns>
 /// A sequence that contains the elements from both input sequences, excluding duplicates.
 /// </returns>
 /// <example>
 /// <code>
 /// var distinctActionsAcross = doc1.GetActions().Union(doc2.GetActions(), (a1, a2) =&gt; a1.IsSimilarTo(A2));
 /// </code>
 /// </example>
 public static IEnumerable <TLexical> Union <TLexical>(
     this IEnumerable <TLexical> first,
     IEnumerable <TLexical> second,
     Func <TLexical, TLexical, bool> equate)
     where TLexical : ILexical => first.Union(second, Equality.Create(equate));
示例#14
0
 /// <summary>
 /// Determines whether two sequences of TLexical are equal by comparing their elements by
 /// the specified comparison function.
 /// </summary>
 /// <typeparam name="TLexical">Any type which implements the ILexical interface.</typeparam>
 /// <param name="first">The left hand sequence of TLexicals to compare.</param>
 /// <param name="second">The right hand sequence of TLexicals to compare.</param>
 /// <param name="comparison">
 /// A function to compare two TLexicals for equality. This will be applied a single time to
 /// each pair of inputs.
 /// </param>
 /// <returns>
 /// <c>true</c> if the two source sequences are of equal length and their corresponding
 /// elements compare equal according to provided Lexical comparison function; otherwise, <c>false</c>.
 /// </returns>
 public static bool SequenceEqual <TLexical>(this IEnumerable <TLexical> first, IEnumerable <TLexical> second, Func <TLexical, TLexical, bool> comparison)
     where TLexical : ILexical => first.SequenceEqual(second, Equality.Create(comparison));
示例#15
0
 public static IEnumerable <IEntity> Meld <TEntity>(this IEnumerable <TEntity> entities, Func <TEntity, TEntity, bool> meldWhen)
     where TEntity : class, IEntity => MeldImplementation(entities, Equality.Create(meldWhen));
示例#16
0
 public void ComparerCreatedWithExplicitHasherComputesEquivalentHashCodes()
 {
     var comparer = Equality.Create <int>((x, y) => x.Equals(y), x => x < 10 ? x : x % 5);
 }