Skip to content

Commit 6c0f0f0

Browse files
committed
fix: import
1 parent 2a790ef commit 6c0f0f0

File tree

2 files changed

+25
-8
lines changed

2 files changed

+25
-8
lines changed

backend/src/main/java/ch/xxx/aidoclibchat/usecase/service/DocumentService.java

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,18 @@ public class DocumentService {
7777
""";
7878

7979
private final String bookPrompt = """
80-
You're a language expert for creating a summary of a text.\n
81-
Create a concise summary of the text provided. Concentrate on the most important points in the text.\n
80+
You're a english professor and expert in long text summaries. Your job is creating a summary of a text.\n
81+
Create a summary in bullit points of the most important points of the text. Create a short and precise description of the most important points. \n
82+
83+
Follow these Rules:
84+
If a new character is mentioned introduce the character. \n
85+
-Write in english language and grammar.
86+
-Write in third person.
87+
-Write in present tense.
88+
-Write the summary in short and precise bullet points.
89+
-Write as few and precise bullet points as possible.
90+
-Write short logical grounded descriptions of the most important points in the text.
91+
8292
TEXT: {text}
8393
""";
8494

@@ -108,9 +118,11 @@ public Book storeBook(Book book, List<ChapterHeading> chapterHeadings) {
108118
.map(document -> document.getFormattedContent()).collect(Collectors.joining("")).lines().toList();
109119
var myBook = this.bookRepository.save(book);
110120
// TODO split the content of the one tikaDocument
111-
var atomicRef = new AtomicReference<List<String>>(tikaText.stream()
112-
.dropWhile(myLine -> !chapterHeadings.isEmpty() && !myLine.contains(chapterHeadings.getFirst().title()))
113-
.toList());
121+
int dropLines = 0;
122+
for(int i = 0;i<tikaText.size();i++) {
123+
dropLines = tikaText.get(i).equalsIgnoreCase(chapterHeadings.getFirst().title()) ? i : dropLines;
124+
}
125+
var atomicRef = new AtomicReference<List<String>>(tikaText.stream().skip(dropLines > 0 ? dropLines -1 : 0).toList());
114126
var myChapters = chapterHeadings.stream()
115127
.filter(heading -> !chapterHeadings.getFirst().title().equals(heading.title()))
116128
.flatMap(heading -> Stream.of(this.createChapter(myBook, heading.title(), atomicRef))).toList();
@@ -142,11 +154,11 @@ public void addBookSummaries(Book book) {
142154
}
143155

144156
private Chapter createChapter(Book book, String heading, AtomicReference<List<String>> atomicRef) {
145-
var result = new Chapter();
146-
result.setTitle(heading);
157+
var result = new Chapter();
158+
result.setTitle(atomicRef.get().stream().filter(myLine -> !myLine.isBlank()).findFirst().orElse(""));
147159
result.setBook(book);
148160
var chapterText = atomicRef.get().stream().takeWhile(myLine -> !myLine.contains(heading))
149-
.collect(Collectors.joining(""));
161+
.collect(Collectors.joining(System.lineSeparator()));
150162
result.setChapterText(chapterText);
151163
atomicRef.set(atomicRef.get().stream().dropWhile(myLine -> !myLine.contains(heading)).toList());
152164
return result;

backend/src/main/resources/dbchangelog/changes/db.changelog-3.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,4 +51,9 @@
5151
<column name="author" type="varchar(255)"/>
5252
</addColumn>
5353
</changeSet>
54+
<changeSet id="22" author="angular2guy">
55+
<modifyDataType tableName="book" columnName="summary" newDataType="clob"/>
56+
<modifyDataType tableName="chapter" columnName="summary" newDataType="clob"/>
57+
<modifyDataType tableName="chapter" columnName="chapter_text" newDataType="clob"/>
58+
</changeSet>
5459
</databaseChangeLog>

0 commit comments

Comments
 (0)