변경2
This commit is contained in:
@@ -55,7 +55,12 @@ public class ChunkingService {
|
||||
for (String sentence : sentences) {
|
||||
// 현재 청크에 문장 추가 시 크기 초과하면 저장
|
||||
if (currentChunk.length() + sentence.length() > chunkSize && currentChunk.length() >= MIN_CHUNK_SIZE) {
|
||||
chunks.add(createChunk(currentChunk.toString().trim(), chunkIndex++));
|
||||
// 의미없는 청크는 건너뛰기
|
||||
if (!isUselessChunk(currentChunk.toString())) {
|
||||
chunks.add(createChunk(currentChunk.toString().trim(), chunkIndex++));
|
||||
} else {
|
||||
log.debug("목차/표지 청크 건너뛰기: {}", currentChunk.toString().substring(0, Math.min(50, currentChunk.length())));
|
||||
}
|
||||
|
||||
// 오버랩 처리
|
||||
String overlap = getOverlapText(currentChunk.toString());
|
||||
@@ -69,9 +74,9 @@ public class ChunkingService {
|
||||
}
|
||||
|
||||
// 마지막 청크 저장
|
||||
if (currentChunk.length() >= MIN_CHUNK_SIZE) {
|
||||
if (currentChunk.length() >= MIN_CHUNK_SIZE && !isUselessChunk(currentChunk.toString())) {
|
||||
chunks.add(createChunk(currentChunk.toString().trim(), chunkIndex));
|
||||
} else if (currentChunk.length() > 0 && !chunks.isEmpty()) {
|
||||
} else if (currentChunk.length() > 0 && !chunks.isEmpty() && !isUselessChunk(currentChunk.toString())) {
|
||||
// 너무 짧으면 이전 청크에 병합
|
||||
ChunkResult lastChunk = chunks.get(chunks.size() - 1);
|
||||
String merged = lastChunk.getContent() + " " + currentChunk.toString().trim();
|
||||
@@ -96,6 +101,31 @@ public class ChunkingService {
|
||||
.trim();
|
||||
}
|
||||
|
||||
/**
|
||||
* 의미없는 청크인지 확인 (목차, 표지 등)
|
||||
*/
|
||||
private boolean isUselessChunk(String content) {
|
||||
if (content == null || content.length() < 30) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// 목차/표지 페이지 필터링
|
||||
String lower = content.toLowerCase();
|
||||
if (lower.contains("목차 페이지입니다") ||
|
||||
lower.contains("표지 페이지입니다") ||
|
||||
lower.contains("개정이력 페이지입니다")) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// 점선(...)이 너무 많으면 목차
|
||||
int dotCount = content.split("\\.\\.\\.").length - 1;
|
||||
if (dotCount > 3) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* 문장 단위로 분할
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user