Class RecordParser

java.lang.Object
com.tnsai.rag.files.RecordParser

public final class RecordParser extends Object
Reads the first line of a record in an agent's .history or .log file, in the grammar AgentRecordFormat's patterns write.

A record starts with a line that parses, and the lines after it that do not parse belong to it, as the other lines of a message written over several lines do. A line that does not parse gives an empty result. A line parses only from its start, so a line indented as AgentRecordFormat's patterns write a message's later lines never starts a record.

Only a line feed, with or without a carriage return before it, ends a line. Any other line terminator in a message, such as a lone carriage return or U+2028, is part of the line it is in, so the record that line starts keeps it.

The conversation field is read in three states: present with an id, present with "-" (or blank) for a line written outside any conversation, and absent on a line written before the field existed. Its value is opaque. A line without the field whose writer's name itself starts with a bracketed word, such as an agent named [x], is read as if that word were the field.

Since:
0.18.6
  • Method Details

    • history

      public static RecordParser history(String agentName)
      A parser of one agent's history file, whose lines carry the agent's name before the message.
      Parameters:
      agentName - the agent the history belongs to
      Returns:
      the parser
      Throws:
      NullPointerException - if agentName is null
    • log

      public static RecordParser log()
      A parser of a log file, whose lines carry a level and a logger name.
      Returns:
      the parser
    • parse

      Parses a line as the first line of a record.
      Parameters:
      line - one line, without its line break
      Returns:
      the record the line starts, or empty when it continues the one before it
      Throws:
      NullPointerException - if line is null