Reflectum.SemanticSpace 1.0.1

dotnet add package Reflectum.SemanticSpace --version 1.0.1
                    
NuGet\Install-Package Reflectum.SemanticSpace -Version 1.0.1
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Reflectum.SemanticSpace" Version="1.0.1" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Reflectum.SemanticSpace" Version="1.0.1" />
                    
Directory.Packages.props
<PackageReference Include="Reflectum.SemanticSpace" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Reflectum.SemanticSpace --version 1.0.1
                    
#r "nuget: Reflectum.SemanticSpace, 1.0.1"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Reflectum.SemanticSpace@1.0.1
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Reflectum.SemanticSpace&version=1.0.1
                    
Install as a Cake Addin
#tool nuget:?package=Reflectum.SemanticSpace&version=1.0.1
                    
Install as a Cake Tool

Reflectum.SemanticSpace

CI NuGet Tests

Biblioteka .NET do pracy z przestrzenią semantyczną i wykrywania powtórzeń w interakcjach tekstowych. Wyciągnięte z projektu ReflectumEngine - najbardziej wartościowe komponenty bez danych behawioralnych.

🎯 Po co to komu?

Przypadki użycia

  • Chatboty - wykrywanie powtórzeń, unikanie zapętlenia odpowiedzi
  • Systemy rekomendacyjne - rekomendacje oparte na treści, porównywanie podobieństwa
  • Wyszukiwarki semantyczne - wyszukiwanie podobnych słów, ekspansja zapytań
  • Analiza tekstu - porównywanie dokumentów, klasteryzacja, ekstrakcja konceptów

✨ Cechy

  • Architektura warstwowa - Domain/Application/Infrastructure (Clean Architecture)
  • SOLID - zaprojektowane zgodnie z zasadami SOLID
  • Dependency Injection - pełne wsparcie dla Microsoft.Extensions.DependencyInjection
  • Wydajność - indeks prefiksowy, cache wektorów
  • Rozszerzalność - interfejsy umożliwiają własne implementacje
  • Testowalność - łatwe mockowanie, brak zależności zewnętrznych
  • Testy jednostkowe - 87 testów pokrywających wszystkie komponenty (100% passing)
  • Dokumentacja - kompletna dokumentacja markdown (docs/) i komentarze XML w kodzie (IntelliSense)

📦 Instalacja

NuGet (gdy opublikowane)

dotnet add package Reflectum.SemanticSpace

Z kodu źródłowego

git clone https://github.com/Maggio333/Reflectum.SemanticSpace.git
cd Reflectum.SemanticSpace
dotnet build
dotnet test  # Uruchom testy

🚀 Szybki start

1. Konfiguracja z Dependency Injection

using Reflectum.SemanticSpace.DependencyInjection;
using Microsoft.Extensions.DependencyInjection;

var services = new ServiceCollection();
services.AddSemanticSpace();

var serviceProvider = services.BuildServiceProvider();

2. Załaduj wektory

var semanticSpace = serviceProvider.GetRequiredService<ISemanticSpace>();

// Załaduj wektory (np. z FastText, Word2Vec)
var vectors = LoadVectorsFromFile("vectors.vec");

if (semanticSpace is Infrastructure.SemanticSpace.SemanticSpace space)
{
    space.Load(vectors);
    space.BuildPrefixIndex(); // Ważne dla wydajności!
}

3. Wyszukiwanie podobnych słów

var searchService = serviceProvider.GetRequiredService<ISemanticSearchService>();

var similar = searchService.TopK("miłość", k: 5, threshold: 0.65);
foreach (var word in similar)
{
    Console.WriteLine($"Podobne: {word.Word}");
}

4. Wykrywanie powtórzeń

using Reflectum.SemanticSpace.Domain.Interfaces;

var detector = serviceProvider.GetRequiredService<IAntiLoopService>();

if (detector.IsEcho("Cześć, jak się masz?", threshold: 0.85f))
{
    Console.WriteLine("Wykryto powtórzenie!");
}

5. Porównywanie wektorów

using Reflectum.SemanticSpace.Domain.Entities;
using Reflectum.SemanticSpace.Domain.Interfaces;

var cache = serviceProvider.GetRequiredService<IVectorCache>();
var tokenizer = serviceProvider.GetRequiredService<ITextTokenizer>();
var calculator = serviceProvider.GetRequiredService<ISimilarityCalculator>();

var vector1 = SemanticVector.FromInput("miłość i przyjaźń", tokenizer, cache, calculator);
var vector2 = SemanticVector.FromInput("uczucie i bliskość", tokenizer, cache, calculator);

double similarity = vector1.SemanticSimilarity(vector2, semanticSpace);
Console.WriteLine($"Podobieństwo: {similarity:F2}");

📚 Dokumentacja

🏗️ Architektura

Biblioteka została zaprojektowana zgodnie z Clean Architecture i zasadami SOLID:

Warstwy

  • Domain - encje domenowe (MeaningVector, SemanticVector) i interfejsy (ISemanticSpace, ISimilarityCalculator, etc.)
  • Application - serwisy aplikacyjne (SemanticSearchService, ResonanceCalculator, AntiLoopService)
  • Infrastructure - implementacje techniczne (SemanticSpace, CosineSimilarityCalculator, InMemoryVectorCache, etc.)

Zasady SOLID

  • Single Responsibility - każda klasa ma jedną odpowiedzialność
  • Open/Closed - otwarte na rozszerzenia, zamknięte na modyfikacje
  • Liskov Substitution - implementacje są zamienne
  • Interface Segregation - małe, specyficzne interfejsy
  • Dependency Inversion - zależności od abstrakcji

Główne komponenty

  • ISemanticSpace - przestrzeń semantyczna (Domain)
  • ISemanticSearchService - wyszukiwanie semantyczne (Application)
  • ISimilarityCalculator - obliczanie podobieństwa (Domain)
  • IResonanceCalculator - obliczanie rezonansu (Application)
  • IAntiLoopService - wykrywanie powtórzeń (Application)

Zobacz ARCHITECTURE.md dla szczegółów.

🔧 Rozszerzanie

Możesz łatwo dodać własne implementacje:

// Własna metryka podobieństwa
public class EuclideanSimilarityCalculator : ISimilarityCalculator { ... }

// Własny tokenizer
public class CustomTokenizer : ITextTokenizer { ... }

// Rejestracja
services.AddSingleton<ISimilarityCalculator, EuclideanSimilarityCalculator>();
services.AddSingleton<ITextTokenizer, CustomTokenizer>();

⚡ Wydajność

  • Indeks prefiksowy - redukuje przestrzeń wyszukiwania z O(n) do O(k)
  • Cache wektorów - automatyczne cache'owanie obliczonych wektorów
  • Normalizacja - wektory są automatycznie normalizowane

🧪 Testowanie

Biblioteka jest w pełni pokryta testami jednostkowymi:

Statystyki testów

  • 87 testów jednostkowych - wszystkie przechodzą ✅
  • Pokrycie: Domain, Application, Infrastructure, Math
  • Framework: xUnit
  • Mockowanie: Moq

Uruchamianie testów

# Z katalogu głównego
dotnet test

# Z katalogu testów
cd tests/Reflectum.SemanticSpace.Tests
dotnet test

Struktura testów

tests/Reflectum.SemanticSpace.Tests/
├── Domain/              # Testy encji domenowych
├── Application/          # Testy serwisów aplikacyjnych
├── Infrastructure/       # Testy implementacji
└── Math/                 # Testy narzędzi matematycznych

Przykład testu

var mockSpace = new Mock<ISemanticSpace>();
var mockCalculator = new Mock<ISimilarityCalculator>();
var searchService = new SemanticSearchService(mockSpace.Object, mockCalculator.Object, ...);

Wszystkie testy są automatycznie uruchamiane w CI przy każdym push/PR.

🤝 Wkład

Zobacz CONTRIBUTING.md jak możesz pomóc.

📄 Licencja

MIT License - zobacz LICENSE

🔗 Linki

👤 Autor

Arkadiusz Słota


Status: Biblioteka gotowa do użycia. Architektura warstwowa (Domain/Application/Infrastructure), zgodna z SOLID, z pełnym wsparciem DI, 87 testów jednostkowych (100% passing), gotowa do publikacji na NuGet.

Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.0.1 125 1/5/2026
1.0.0 127 1/5/2026

v1.0.1: Fixed repository URLs, updated documentation. v1.0.0: Initial release with Clean Architecture, SOLID, 87 unit tests, comprehensive documentation