Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hotfix: 좌표와 날짜를 구분하도록 파싱메서드 수정 #99

Merged
merged 2 commits into from
Jun 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -23,36 +23,36 @@ public class GptConfig {
Please write the itinerary without using any special characters, only in plain text.

I would like the format to be as follows:
For example
---
2024-02-06
1. Go to location 26.69549000, 127.87642000
2. See the place 26.69549000, 127.87642000
3. Eat the Lunch 26.69549000, 127.87642000
4. Go to location 26.69549000, 127.87642000
5. See the place 26.69549000, 127.87642000
6. Eat the dinner 26.69549000, 127.87642000
7. shopping 26.69549000, 127.87642000
아래는 예시니까 참고만 해줘.

2024.02.06
- Go to location 26.69549000, 127.87642000
- See the place 26.69549000, 127.87642000
- Eat the Lunch 26.69549000, 127.87642000
- Go to location 26.69549000, 127.87642000
- See the place 26.69549000, 127.87642000
- Eat the dinner 26.69549000, 127.87642000
- shopping 26.69549000, 127.87642000

2024-02-07
1. Go to location 26.69549000, 127.87642000
2. See the place 26.69549000, 127.87642000
3. Eat the Lunch 26.69549000, 127.87642000
4. Go to location 26.69549000, 127.87642000
5. See the place 26.69549000, 127.87642000
6. Eat the dinner 26.69549000, 127.87642000
7. shopping 26.69549000, 127.87642000
- Go to location 26.69549000, 127.87642000
- See the place 26.69549000, 127.87642000
- Eat the Lunch 26.69549000, 127.87642000
- Go to location 26.69549000, 127.87642000
- See the place 26.69549000, 127.87642000
- Eat the dinner 26.69549000, 127.87642000
- shopping 26.69549000, 127.87642000

2024-02-08
1. Go to location 26.69549000, 127.87642000
2. See the place 26.69549000, 127.87642000
3. Eat the Lunch 26.69549000, 127.87642000
4. Go to location 26.69549000, 127.87642000
5. See the place 26.69549000, 127.87642000
6. Eat the dinner 26.69549000, 127.87642000
7. shopping 26.69549000, 127.87642000
---
- Go to location 26.69549000, 127.87642000
- See the place 26.69549000, 127.87642000
- Eat the Lunch 26.69549000, 127.87642000
- Go to location 26.69549000, 127.87642000
- See the place 26.69549000, 127.87642000
- Eat the dinner 26.69549000, 127.87642000
- shopping 26.69549000, 127.87642000

너가 여행 일정을 만들 때 필요한 정보는 아래와 같아.
여행지: %s
이번 여행의 목적: %s
여행에서 꼭 하고 싶은 활동: %s
Expand All @@ -61,11 +61,14 @@ public class GptConfig {
한국에 귀국하는 날짜: %s

No need to say anything else, just plan your schedule right away.
Please create the result in Korean.
날짜 형식은 반드시 0000.00.00 을 지켜줘
And only include schedule-related content in the schedule you're creating.
Do not add any information I haven't provided to you.
Under no circumstances should you include any activities other than traveling. Absolutely not.
우리는 매일 점심과 저녁은 항상 식당에 가서 먹을거야. 반드시 실제로 존재하는 맛있고 유명한 식당으로 추천해줘
금액 정보는 알려주지마. 대신 다양한 경험을 할 수 있게 일정을 만들어줘.
그리고 일정 옆에 장소의 위도 경도 좌표값 소수점 여덟자리까지 함께 작성해줘.""";
We will have lunch and dinner at restaurants every day.
Be sure to recommend real, delicious, and famous restaurants.
Instead, create an itinerary that allows for a variety of experiences.
Include the latitude and longitude coordinates of each place with eight decimal places next to the itinerary item.
위에 예시로 적어둔 영어 문구는 "절대" 포함하지마.
시간은 안적어줘도돼.
Please create the result in Korean.""";

}
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ public WebClient webClient() {
HttpClient httpClient = HttpClient.create()
.option(ChannelOption.CONNECT_TIMEOUT_MILLIS, 30000)
.doOnConnected(conn -> conn
.addHandlerLast(new ReadTimeoutHandler(30))
.addHandlerLast(new WriteTimeoutHandler(30)));
.addHandlerLast(new ReadTimeoutHandler(50))
.addHandlerLast(new WriteTimeoutHandler(50)));
return WebClient.builder()
.clientConnector(new ReactorClientHttpConnector(httpClient))
.build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,11 @@
import java.util.List;

public class ParsingConstants {
public static final String DATE_REGEX = "(\\d{4}-\\d{2}-\\d{2})";
public static final String DATE_REGEX = "(\\d{4}\\.\\d{2}\\.\\d{2})";
public static final String NEW_LINE_REGEX = "\n";
public static final String CURRENT_DATE = "";
public static final String COMMA = ", ";
public static final int BEGIN_INDEX = 3;
public static final List<String> FILTER_STRINGS = List.of(
"Message(role=assistant, content=", ")"
);
public static final int GROUP_MATCH = 1;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,71 +14,43 @@
public class GptScheduleParser {

public List<GptSchedule> parseScheduleText(String scheduleText) {
System.out.println(scheduleText);
List<GptSchedule> schedules = new ArrayList<>();
Pattern datePattern = Pattern.compile(ParsingConstants.DATE_REGEX);
Pattern detailPattern = Pattern.compile("^-\\s*(.*?)(\\d+\\.\\d{1,8}),\\s*(\\d+\\.\\d{1,8})$");

List<String> lines = List.of(scheduleText.split(ParsingConstants.NEW_LINE_REGEX));
List<GptScheduleDetail> currentScheduleDetail = new ArrayList<>();
String currentDate = ParsingConstants.CURRENT_DATE;
String currentDate = "";

for (String line : lines) {
currentDate = processLine(line, currentDate, currentScheduleDetail, schedules);
}

if (!currentDate.isEmpty()) {
addSchedule(schedules, currentDate, currentScheduleDetail);
}

return schedules;
}

private String processLine(String line, String currentDate, List<GptScheduleDetail> currentScheduleDetail, List<GptSchedule> schedules) {
if (isDateLine(line)) {
if (!currentDate.isEmpty()) {
addSchedule(schedules, currentDate, currentScheduleDetail);
currentScheduleDetail.clear();
Matcher dateMatcher = datePattern.matcher(line);
if (dateMatcher.find()) {
if (!currentDate.isEmpty() && !currentScheduleDetail.isEmpty()) {
schedules.add(new GptSchedule(currentDate, currentScheduleDetail));
currentScheduleDetail = new ArrayList<>();
}
currentDate = dateMatcher.group(0);
} else if (!line.trim().isEmpty()) {
Matcher detailMatcher = detailPattern.matcher(line.trim());
if (detailMatcher.find()) {
String detail = detailMatcher.group(1).trim();
Double latitude = formatCoordinate(Double.valueOf(detailMatcher.group(2)));
Double longitude = formatCoordinate(Double.valueOf(detailMatcher.group(3)));
Coordinate coordinate = new Coordinate(latitude, longitude);
currentScheduleDetail.add(new GptScheduleDetail(detail, coordinate));
}
}
return extractDate(line);
} else if (shouldProcessLine(line)) {
addDetail(line, currentScheduleDetail);
}
return currentDate;
}

private boolean isDateLine(String line) {
Pattern datePattern = Pattern.compile(ParsingConstants.DATE_REGEX);
Matcher dateMatcher = datePattern.matcher(line);
return dateMatcher.find();
}

private String extractDate(String line) {
Pattern datePattern = Pattern.compile(ParsingConstants.DATE_REGEX);
Matcher dateMatcher = datePattern.matcher(line);
if (dateMatcher.find()) {
return dateMatcher.group(ParsingConstants.GROUP_MATCH);
if (!currentDate.isEmpty() && !currentScheduleDetail.isEmpty()) {
schedules.add(new GptSchedule(currentDate, currentScheduleDetail));
}
return ParsingConstants.CURRENT_DATE;
}

private boolean shouldProcessLine(String line) {
return !line.trim().isEmpty() && ParsingConstants.FILTER_STRINGS.stream().noneMatch(line::contains);
}

private void addDetail(String line, List<GptScheduleDetail> currentScheduleDetail) {
Pattern detailPattern = Pattern.compile("^(?:\\d+\\.\\s*)?(.*?)(\\d+\\.\\d{1,8}),\\s*(\\d+\\.\\d{1,8})$");
Matcher detailMatcher = detailPattern.matcher(line.trim());
if (detailMatcher.find()) {
String detail = detailMatcher.group(1).trim();
Double latitude = Double.valueOf(detailMatcher.group(2));
Double longitude = Double.valueOf(detailMatcher.group(3));

String formattedLatitude = String.format("%.8f", latitude);
String formattedLongitude = String.format("%.8f", longitude);

Coordinate coordinate = new Coordinate(Double.parseDouble(formattedLatitude), Double.parseDouble(formattedLongitude));
currentScheduleDetail.add(new GptScheduleDetail(detail, coordinate));
}
return schedules;
}

private void addSchedule(List<GptSchedule> schedules, String date, List<GptScheduleDetail> details) {
schedules.add(new GptSchedule(date, details));
private Double formatCoordinate(Double coordinate) {
return Double.valueOf(String.format("%.8f", coordinate));
}
}
Loading