From b2d778e25e7124511bd64b64abb2ec6f926e602e Mon Sep 17 00:00:00 2001 From: Diego Colombo Date: Mon, 9 Oct 2023 19:11:11 +0100 Subject: [PATCH] simplify --- .../EnumerableAI.cs | 13 ------------ .../{ObservableAI.cs => Text.cs} | 21 ++++++++++++------- 2 files changed, 13 insertions(+), 21 deletions(-) delete mode 100644 src/Microsoft.DotNet.Interactive.AIUtilities/EnumerableAI.cs rename src/Microsoft.DotNet.Interactive.AIUtilities/{ObservableAI.cs => Text.cs} (78%) diff --git a/src/Microsoft.DotNet.Interactive.AIUtilities/EnumerableAI.cs b/src/Microsoft.DotNet.Interactive.AIUtilities/EnumerableAI.cs deleted file mode 100644 index d3d7b3c751..0000000000 --- a/src/Microsoft.DotNet.Interactive.AIUtilities/EnumerableAI.cs +++ /dev/null @@ -1,13 +0,0 @@ -// Copyright (c) .NET Foundation and contributors. All rights reserved. -// Licensed under the MIT license. See LICENSE file in the project root for full license information. - -namespace Microsoft.DotNet.Interactive.AIUtilities; - -public static class EnumerableAI{ - - public static IEnumerable> ScoreBySimilarityTo(this IEnumerable source, T value, - ISimilarityComparer comparer) - { - return source.Select(item => new KeyValuePair(item, comparer.Score(item, value))); - } -} \ No newline at end of file diff --git a/src/Microsoft.DotNet.Interactive.AIUtilities/ObservableAI.cs b/src/Microsoft.DotNet.Interactive.AIUtilities/Text.cs similarity index 78% rename from src/Microsoft.DotNet.Interactive.AIUtilities/ObservableAI.cs rename to src/Microsoft.DotNet.Interactive.AIUtilities/Text.cs index 7003b18d31..c9cf909bc9 100644 --- a/src/Microsoft.DotNet.Interactive.AIUtilities/ObservableAI.cs +++ b/src/Microsoft.DotNet.Interactive.AIUtilities/Text.cs @@ -2,13 +2,19 @@ // Licensed under the MIT license. See LICENSE file in the project root for full license information. using System.Reactive.Disposables; -using System.Reactive.Linq; using Microsoft.DeepDev; +using System.Reactive.Linq; namespace Microsoft.DotNet.Interactive.AIUtilities; -public static class ObservableAI -{ +public static class Text { + + public static IEnumerable> ScoreBySimilarityTo(this IEnumerable source, T value, + ISimilarityComparer comparer) + { + return source.Select(item => new KeyValuePair(item, comparer.Score(item, value))); + } + public static IObservable ChunkByTokenCountWithOverlap(this IObservable source, ITokenizer tokenizer, int maxTokenCount, int overlapTokenCount) { if (maxTokenCount <= overlapTokenCount) @@ -21,7 +27,7 @@ public static IObservable ChunkByTokenCountWithOverlap(this IObservable< { return System.Reactive.Linq.Observable.Create(o => { - var chunks = tokenizer.ChunkByTokenCountWithOverlap(text ,maxTokenCount, overlapTokenCount); + var chunks = tokenizer.ChunkByTokenCountWithOverlap(text, maxTokenCount, overlapTokenCount); foreach (var chunk in chunks) { o.OnNext(chunk); @@ -36,7 +42,6 @@ public static IObservable ChunkByTokenCountWithOverlap(this IObservable< public static IObservable ChunkByTokenCount(this IObservable source, ITokenizer tokenizer, int maxTokenCount) { - return source.ChunkByTokenCountWithOverlap(tokenizer, maxTokenCount,0 ); - } -} - + return source.ChunkByTokenCountWithOverlap(tokenizer, maxTokenCount, 0); + } +} \ No newline at end of file