@@ -77,8 +77,18 @@ public class DocumentService {
77
77
""" ;
78
78
79
79
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
+
82
92
TEXT: {text}
83
93
""" ;
84
94
@@ -108,9 +118,11 @@ public Book storeBook(Book book, List<ChapterHeading> chapterHeadings) {
108
118
.map (document -> document .getFormattedContent ()).collect (Collectors .joining ("" )).lines ().toList ();
109
119
var myBook = this .bookRepository .save (book );
110
120
// 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 ());
114
126
var myChapters = chapterHeadings .stream ()
115
127
.filter (heading -> !chapterHeadings .getFirst ().title ().equals (heading .title ()))
116
128
.flatMap (heading -> Stream .of (this .createChapter (myBook , heading .title (), atomicRef ))).toList ();
@@ -142,11 +154,11 @@ public void addBookSummaries(Book book) {
142
154
}
143
155
144
156
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 ( "" ) );
147
159
result .setBook (book );
148
160
var chapterText = atomicRef .get ().stream ().takeWhile (myLine -> !myLine .contains (heading ))
149
- .collect (Collectors .joining ("" ));
161
+ .collect (Collectors .joining (System . lineSeparator () ));
150
162
result .setChapterText (chapterText );
151
163
atomicRef .set (atomicRef .get ().stream ().dropWhile (myLine -> !myLine .contains (heading )).toList ());
152
164
return result ;
0 commit comments