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 File
file
static Pattern
REGEX_AIGENPROMPTSTART
Start pattern forinfilePrompting(String)
, group "id" is the id.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.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 File
getFile()
The basic file we write into.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.static String[]
infilePrompting(String id)
Generates the patterns for storing prompt and generated data within one file.protected String
joinSegments()
protected void
readAndParseFile()
Reads the file and splits it according to the separators.protected void
sanityCheck(String content)
String
toString()
static String
wholeLineRegex(String separator)
void
writeSegment(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 IOException
Reads 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 IOException
Reads 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 IOException
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.- Throws:
IOException
-
getFile
public File getFile()
The basic file we write into.
-
sanityCheck
protected void sanityCheck(String content)
-
joinSegments
protected String joinSegments()
-
-