/// <summary> /// Determines if two AdverbPhrases are similar. /// </summary> /// <param name="first">The first AdverbPhrase</param> /// <param name="second">The second AdverbPhrase</param> /// <returns><c>true</c> if the given AdverbPhrases are similar; otherwise, <c>false</c>.</returns> public static Similarity IsSimilarTo(this AdverbPhrase first, AdverbPhrase second) { var percentMatched = first.Words.OfAdverb() .Zip(second.Words.OfAdverb(), (x, y) => x.IsSimilarTo(y) == true) .PercentTrue(); return(Similarity.FromBoolean(first == second || percentMatched / 100 > Lexicon.SimilarityThreshold)); }
/// <summary> /// Determines if two IDescriptor instances are similar. /// </summary> /// <param name="first">The first IDescriptor</param> /// <param name="second">The second IDescriptor</param> /// <returns> /// <c>true</c> if the given IDescriptor instances are similar; otherwise, <c>false</c>. /// </returns> public static Similarity IsSimilarTo(this IDescriptor first, IDescriptor second) => first.Match() .When(Equals(first, second) || first.Text.EqualsIgnoreCase(second.Text)) .Then(() => Similarity.Similar) .Case((Adjective a1) => second.Match() .Case((Adjective a2) => Similarity.FromBoolean(a1.IsSimilarTo(a2))) .Case((AdjectivePhrase ap2) => ap2.IsSimilarTo(a1)) .Result()) .Case((AdjectivePhrase ap1) => second.Match() .Case((AdjectivePhrase ap2) => ap1.IsSimilarTo(ap2)) .Case((Adjective a2) => ap1.IsSimilarTo(a2)) .Result()) .Result();
/// <summary>Determines if two IEntity instances are similar.</summary> /// <param name="first">The first IEntity</param> /// <param name="second">The second IEntity</param> /// <returns><c>true</c> if the given IEntity instances are similar; otherwise, <c>false</c>.</returns> public static Similarity IsSimilarTo(this IEntity first, IEntity second) => first.Match() .When(Equals(first, second) || first.Text.EqualsIgnoreCase(second.Text)) .Then(Similarity.Similar) .Case((IAggregateEntity ae1) => second.Match() .Case((IAggregateEntity ae2) => ae1.IsSimilarTo(ae2)) .Case((IEntity e2) => Similarity.FromBoolean(ae1.Any(entity => entity.IsSimilarTo(e2)))) .Result()) .Case((Noun n1) => second.Match() .Case((Noun n2) => n1.IsSimilarTo(n2)) .Case((NounPhrase np2) => n1.IsSimilarTo(np2)) .Result()) .Case((NounPhrase np1) => second.Match() .Case((NounPhrase np2) => np1.IsSimilarTo(np2)) .Case((Noun n2) => np1.IsSimilarTo(n2)) .Result()) .Result();
/// <summary>Determines if the two provided Noun instances are similar.</summary> /// <param name="first">The first Noun.</param> /// <param name="second">The second Noun.</param> /// <returns><c>true</c> if the first Noun is similar to the second; otherwise, <c>false</c>.</returns> private static Similarity IsSimilarTo(this Noun first, Noun second) => Similarity.FromBoolean(Equals(first, second) || (first?.GetSynonyms().Contains(second?.Text) ?? false));
/// <summary>Determines if the provided Noun is similar to the provided NounPhrase.</summary> /// <param name="first">The <see cref="Noun" />.</param> /// <param name="second">The <see cref="NounPhrase" />.</param> /// <returns> /// <c>true</c> if the provided Noun is similar to the provided NounPhrase; otherwise, <c>false</c>. /// </returns> private static Similarity IsSimilarTo(this Noun first, NounPhrase second) { var phraseNouns = second.Words.OfNoun().ToList(); return(Similarity.FromBoolean(phraseNouns.Count == 1 && phraseNouns.First().IsSimilarTo(first))); }
/// <summary> /// Determines if the provided Adverb is similar to the provided AdverbPhrase. /// </summary> /// <param name="first">The Adverb.</param> /// <param name="second">The AdverbPhrase.</param> /// <returns> /// <c>true</c> if the provided Adverb is similar to the provided AdverbPhrase; otherwise, <c>false</c>. /// </returns> public static Similarity IsSimilarTo(this Adverb first, AdverbPhrase second) => Similarity.FromBoolean(second.Words.OfAdverb().Any(a => a.IsSimilarTo(first)));
/// <summary> /// Determines if the two provided Adverb instances are similar. /// </summary> /// <param name="first">The first Adverb.</param> /// <param name="second">The second Adverb.</param> /// <returns><c>true</c> if the first Adverb is similar to the second; otherwise, <c>false</c>.</returns> public static Similarity IsSimilarTo(this Adverb first, Adverb second) => Similarity.FromBoolean(Equals(first, second) || (first?.GetSynonyms().Contains(second?.Text) ?? false));
/// <summary> /// Determines if two IAdverbial instances are similar. /// </summary> /// <param name="first">The first IAdverbial</param> /// <param name="second">The second IAdverbial</param> /// <returns><c>true</c> if the given IAdverbial instances are similar; otherwise, <c>false</c>.</returns> public static Similarity IsSimilarTo(this IAdverbial first, IAdverbial second) => Similarity.FromBoolean( Equals(first, second) || first.Text.EqualsIgnoreCase(second.Text) || first.Match() .Case((Adverb a1) => second.Match() .Case((Adverb a2) => a1.IsSimilarTo(a2)) .Case((AdverbPhrase ap2) => ap2.IsSimilarTo(a1)) .Result()) .Case((AdverbPhrase ap1) => second.Match() .Case((AdverbPhrase ap2) => ap1.IsSimilarTo(ap2)) .Case((Adverb a2) => ap1.IsSimilarTo(a2)) .Result()) .Result());