Skip to content

Commit 28d9a33

Browse files
authored
⚡️ OCR 파일 템플릿 확장 (#172)
1 parent 8161492 commit 28d9a33

File tree

2 files changed

+15
-9
lines changed

2 files changed

+15
-9
lines changed

src/main/java/com/going/server/domain/ocr/PdfOcrService.java

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,17 +20,22 @@ public Map<String, String> parse(String response) {
2020

2121
//첫번째 파일에서 데이터 추출
2222
JsonNode file = root.path("images").get(0);
23-
if(file == null || file.isEmpty()) {
24-
throw new IllegalArgumentException("OCR 응답에서 파일 데이터가 없습니다.");
23+
if (file == null || file.isEmpty()) {
24+
throw new IllegalArgumentException("OCR 응답에서 이미지 데이터가 없습니다.");
2525
}
2626

27-
//"fields" 배열에서 각 필드 추출
28-
JsonNode fields = file.path("fields");
29-
for (JsonNode field : fields) {
30-
String name = field.path("name").asText();
31-
String value = field.path("inferText").asText();
27+
JsonNode titleNode = file.path("title");
28+
if (!titleNode.isMissingNode()) {
29+
String name = titleNode.path("name").asText();
30+
String value = titleNode.path("inferText").asText();
3231
result.put(name, value);
3332
}
33+
// JsonNode fields = file.path("fields");
34+
// for (JsonNode field : fields) {
35+
// String name = field.path("name").asText();
36+
// String value = field.path("inferText").asText();
37+
// result.put(name, value);
38+
// }
3439
}catch (Exception e){
3540
log.error("OCR 응답 파싱 중 오류 발생",e);
3641
throw new RuntimeException("OCR 응답 파싱 실패",e);

src/main/java/com/going/server/domain/upload/service/UploadServiceImpl.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,10 @@ public class UploadServiceImpl implements UploadService {
5555
public UploadResponseDto uploadFile(UploadRequestDto dto) {
5656
try {
5757
String jsonResponse = ocrService.processOcr(dto.getFile(), apiUrl, secretKey);
58+
System.out.println(jsonResponse);
5859
Map<String, String> paresData = pdfOcrService.parse(jsonResponse);
59-
String text = paresData.get("6학년 읽기자료 내용");
60-
//System.out.println("추출된 텍스트: " + text);
60+
String text = paresData.get("읽기자료");
61+
System.out.println("추출된 텍스트: " + text);
6162

6263
//모델에 돌린 값을 받아옴
6364
String response = setModelData(text);

0 commit comments

Comments
 (0)