Class SegmentedFile
- java.lang.Object
-
- net.stoerr.ai.aigenpipeline.framework.task.SegmentedFile
-
public class SegmentedFile extends Object
ALlows reading and writing individual segments of a file where the segments are separated by a regular expression.
-
-
Field Summary
Fields Modifier and Type Field Description protected Filefilestatic PatternREGEX_AIGENPROMPTSTARTStart pattern forinfilePrompting(String), group "id" is the id.protected List<String>segmentsSegment before first separator, content matching first separator, segment before second separator, content matching second separator , and so forth, and then the rest of the file.protected List<Pattern>separatorPatterns
-
Constructor Summary
Constructors Constructor Description SegmentedFile(File file, String... separatorRegexes)Reads the file and checks that the separators can be found and that they don't match at other places.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description FilegetFile()The basic file we write into.StringgetSegment(int i)Retrieves the segment - 0 is before first separator, 1 is between first and second separator, and so forth, segments.size()-1 is the rest of the file.static String[]infilePrompting(String id)Generates the patterns for storing prompt and generated data within one file.protected StringjoinSegments()protected voidreadAndParseFile()Reads the file and splits it according to the separators.protected voidsanityCheck(String content)StringtoString()static StringwholeLineRegex(String separator)voidwriteSegment(int i, String newSegment)Retrieves the segment - 0 is before first separator, 1 is between first and second separator, and so forth, segments.size()-1 is the rest of the file.
-
-
-
Field Detail
-
file
protected final File file
-
segments
protected List<String> segments
Segment before first separator, content matching first separator, segment before second separator, content matching second separator , and so forth, and then the rest of the file.
-
REGEX_AIGENPROMPTSTART
public static final Pattern REGEX_AIGENPROMPTSTART
Start pattern forinfilePrompting(String), group "id" is the id.
-
-
Constructor Detail
-
SegmentedFile
public SegmentedFile(@Nonnull File file, @Nonnull String... separatorRegexes) throws IOExceptionReads the file and checks that the separators can be found and that they don't match at other places.- Throws:
IOException
-
-
Method Detail
-
readAndParseFile
protected void readAndParseFile() throws IOExceptionReads the file and splits it according to the separators.- Throws:
IOException
-
getSegment
public String getSegment(int i)
Retrieves the segment - 0 is before first separator, 1 is between first and second separator, and so forth, segments.size()-1 is the rest of the file.
-
writeSegment
public void writeSegment(int i, String newSegment) throws IOExceptionRetrieves the segment - 0 is before first separator, 1 is between first and second separator, and so forth, segments.size()-1 is the rest of the file.- Throws:
IOException
-
getFile
public File getFile()
The basic file we write into.
-
sanityCheck
protected void sanityCheck(String content)
-
joinSegments
protected String joinSegments()
-
-