신규 요약 기능 추가.
This commit is contained in:
@@ -8,6 +8,28 @@ namespace MessageSummarizer.Services;
|
|||||||
public class SummarizeService : ISummarizeService
|
public class SummarizeService : ISummarizeService
|
||||||
{
|
{
|
||||||
public async Task<string> SummarizeAsync(string input, CancellationToken cancellationToken = default)
|
public async Task<string> SummarizeAsync(string input, CancellationToken cancellationToken = default)
|
||||||
|
{
|
||||||
|
if (string.IsNullOrWhiteSpace(input))
|
||||||
|
return string.Empty;
|
||||||
|
|
||||||
|
// 첫 줄 추출
|
||||||
|
var firstLine = GetFirstLine(input);
|
||||||
|
|
||||||
|
if (firstLine.Contains("핵심 요약", StringComparison.OrdinalIgnoreCase))
|
||||||
|
{
|
||||||
|
return await SummarizeArticleAsync(input, cancellationToken);
|
||||||
|
}
|
||||||
|
|
||||||
|
return await SummarizeMessageAsync(input, cancellationToken);
|
||||||
|
}
|
||||||
|
|
||||||
|
private string GetFirstLine(string input)
|
||||||
|
{
|
||||||
|
using var reader = new StringReader(input);
|
||||||
|
return reader.ReadLine() ?? string.Empty;
|
||||||
|
}
|
||||||
|
|
||||||
|
private async Task<string> SummarizeMessageAsync(string input, CancellationToken cancellationToken = default)
|
||||||
{
|
{
|
||||||
if (string.IsNullOrWhiteSpace(input))
|
if (string.IsNullOrWhiteSpace(input))
|
||||||
return string.Empty;
|
return string.Empty;
|
||||||
@@ -38,4 +60,53 @@ public class SummarizeService : ISummarizeService
|
|||||||
var summary = $"{date},{ticker},{stockName},{amount}";
|
var summary = $"{date},{ticker},{stockName},{amount}";
|
||||||
return summary;
|
return summary;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public async Task<string> SummarizeArticleAsync(string input, CancellationToken cancellationToken = default)
|
||||||
|
{
|
||||||
|
var lines = Regex
|
||||||
|
.Split(input, @"\r\n|\r|\n|\u2028|\u2029")
|
||||||
|
.Select(l => l.Trim())
|
||||||
|
.Where(l => !string.IsNullOrEmpty(l))
|
||||||
|
.ToList();
|
||||||
|
|
||||||
|
var sb = new StringBuilder();
|
||||||
|
|
||||||
|
bool articleHeaderWritten = false;
|
||||||
|
|
||||||
|
foreach (var line in lines)
|
||||||
|
{
|
||||||
|
cancellationToken.ThrowIfCancellationRequested();
|
||||||
|
|
||||||
|
// 1️.숫자만 있는 라인 제거 (1, 2, 3 ...)
|
||||||
|
if (Regex.IsMatch(line, @"^\d+$"))
|
||||||
|
continue;
|
||||||
|
|
||||||
|
// 2️. 타임라인 (MM:SS) 제거
|
||||||
|
if (Regex.IsMatch(line, @"^\d{1,2}:\d{2}$"))
|
||||||
|
continue;
|
||||||
|
|
||||||
|
// 3️. 핵심 요약 헤더
|
||||||
|
if (line == "핵심 요약")
|
||||||
|
{
|
||||||
|
sb.AppendLine("## 핵심 요약");
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 4️. 아티클 관련 헤더 통합
|
||||||
|
if (line is "타임라인" or "아티클" or "AI 채팅")
|
||||||
|
{
|
||||||
|
if (!articleHeaderWritten)
|
||||||
|
{
|
||||||
|
sb.AppendLine("## 아티클");
|
||||||
|
articleHeaderWritten = true;
|
||||||
|
}
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 5️. 그 외 모든 텍스트는 bullet 처리
|
||||||
|
sb.AppendLine($"* {line}");
|
||||||
|
}
|
||||||
|
|
||||||
|
return sb.ToString().TrimEnd();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user