From 399c8efac7c8b7c8ad6da3281314142d3eff0ccd Mon Sep 17 00:00:00 2001 From: hellouz818 Date: Wed, 1 Jun 2022 03:29:38 +0900 Subject: [PATCH] [#25] feat: Add Event num & Event List --- .../Notice/controller/NoticeController.java | 4 +++- .../notinote/Notice/dto/NoticeEventListDto.java | 16 ++++++++++++++++ .../answer/notinote/Notice/dto/NoticeOCRDto.java | 6 +++++- .../notinote/Notice/service/NoticeService.java | 11 +++++++++++ 4 files changed, 35 insertions(+), 2 deletions(-) create mode 100644 spring/notinote/src/main/java/com/answer/notinote/Notice/dto/NoticeEventListDto.java diff --git a/spring/notinote/src/main/java/com/answer/notinote/Notice/controller/NoticeController.java b/spring/notinote/src/main/java/com/answer/notinote/Notice/controller/NoticeController.java index 1bed0e6..0f1b80f 100644 --- a/spring/notinote/src/main/java/com/answer/notinote/Notice/controller/NoticeController.java +++ b/spring/notinote/src/main/java/com/answer/notinote/Notice/controller/NoticeController.java @@ -41,7 +41,9 @@ public NoticeOCRDto executeOCR (@RequestPart MultipartFile uploadfile, HttpServl String en_full = noticeService.englishText(korean); // 영어 추출 List eventWords = noticeService.detectEvent(korean, trans_full, targetLanguage, en_full); //이벤트 추출 List fullText = noticeService.extractSentenceFromEventRequestDto(trans_full, eventWords); - return new NoticeOCRDto(korean, trans_full, fullText); + List events = noticeService.extractEventList(fullText); + Integer event_num = events.size(); + return new NoticeOCRDto(korean, trans_full, fullText, event_num, events); } @RequestMapping(value = "/notice/save", method = RequestMethod.POST) diff --git a/spring/notinote/src/main/java/com/answer/notinote/Notice/dto/NoticeEventListDto.java b/spring/notinote/src/main/java/com/answer/notinote/Notice/dto/NoticeEventListDto.java new file mode 100644 index 0000000..05c5ea4 --- /dev/null +++ b/spring/notinote/src/main/java/com/answer/notinote/Notice/dto/NoticeEventListDto.java @@ -0,0 +1,16 @@ +package com.answer.notinote.Notice.dto; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Getter; + +import java.time.LocalDate; + +@Getter +@AllArgsConstructor +@Builder +public class NoticeEventListDto { + String title; + LocalDate date; + +} diff --git a/spring/notinote/src/main/java/com/answer/notinote/Notice/dto/NoticeOCRDto.java b/spring/notinote/src/main/java/com/answer/notinote/Notice/dto/NoticeOCRDto.java index bcec703..cc3b5df 100644 --- a/spring/notinote/src/main/java/com/answer/notinote/Notice/dto/NoticeOCRDto.java +++ b/spring/notinote/src/main/java/com/answer/notinote/Notice/dto/NoticeOCRDto.java @@ -12,10 +12,14 @@ public class NoticeOCRDto { private String korean; private String trans_full; private List fullText; + private Integer event_num; + private List events; - public NoticeOCRDto(String korean, String trans_full, List fullText){ + public NoticeOCRDto(String korean, String trans_full, List fullText, Integer event_num, List events){ this.korean = korean; this.trans_full = trans_full; this.fullText = fullText; + this.event_num = event_num; + this.events = events; } } diff --git a/spring/notinote/src/main/java/com/answer/notinote/Notice/service/NoticeService.java b/spring/notinote/src/main/java/com/answer/notinote/Notice/service/NoticeService.java index 1a8d0b6..ac049cc 100644 --- a/spring/notinote/src/main/java/com/answer/notinote/Notice/service/NoticeService.java +++ b/spring/notinote/src/main/java/com/answer/notinote/Notice/service/NoticeService.java @@ -277,6 +277,17 @@ public List extractSentenceFromEventRequestDto(String text, L return sentences; } + public List extractEventList(List fullText){ + List events = new ArrayList<>(); + + for (int i = 0; i < fullText.size(); i++){ + if(fullText.get(i).isHighlight()){ + NoticeEventListDto event = new NoticeEventListDto(fullText.get(i).getContent(), fullText.get(i).getDate()); + events.add(event); + } + } + return events; + } public Notice findNoticeById(Long id) { return noticeRepository.findById(id).orElseThrow(