feat: implement AI-driven knowledge extraction service with semantic caching and persistent storage
This commit is contained in:
@@ -0,0 +1,37 @@
|
||||
using System.Security.Cryptography;
|
||||
using System.Text;
|
||||
using System.Text.RegularExpressions;
|
||||
|
||||
namespace NexusReader.Infrastructure.Helpers;
|
||||
|
||||
public static class ContentHasher
|
||||
{
|
||||
public static string ComputeHash(string input)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(input))
|
||||
{
|
||||
return string.Empty;
|
||||
}
|
||||
|
||||
var normalizedInput = Normalize(input);
|
||||
|
||||
var inputBytes = Encoding.UTF8.GetBytes(normalizedInput);
|
||||
var hashBytes = SHA256.HashData(inputBytes);
|
||||
|
||||
return Convert.ToHexString(hashBytes).ToLowerInvariant();
|
||||
}
|
||||
|
||||
public static string Normalize(string input)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(input))
|
||||
{
|
||||
return string.Empty;
|
||||
}
|
||||
|
||||
// Trim and collapse all consecutive whitespace characters into a single space
|
||||
var normalized = Regex.Replace(input.Trim(), @"\s+", " ");
|
||||
|
||||
// Convert to lower-case as AI analysis is generally not case-sensitive for concepts/quizzes
|
||||
return normalized.ToLowerInvariant();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user