Class RealValueFileEventStream

java.lang.Object
opennlp.tools.ml.model.FileEventStream
opennlp.tools.ml.model.RealValueFileEventStream
All Implemented Interfaces:
AutoCloseable, opennlp.tools.util.ObjectStream<opennlp.tools.ml.model.Event>

public class RealValueFileEventStream extends FileEventStream
Class for using a file of real-valued events as an event stream. The format of the file is one event per line with each line consisting of outcome followed by contexts, separated by space, tab, carriage return, line feed or form feed, see parseEvent(String).
See Also:
  • Constructor Details

  • Method Details

    • parseContexts

      public static float[] parseContexts(String[] contexts)
      Parses the specified contexts and re-populates context array with features and returns the values for these features. If all values are unspecified, then null is returned.

      The value follows the last = of a context. A context without such a value, or whose text after the last = is not a number, is kept whole with the value 1; a value that is not a number is logged as an error.

      Parameters:
      contexts - The contexts with real values specified. Must not be null.
      Returns:
      The value for each context or null if all values are unspecified.
      Throws:
      IllegalArgumentException - Thrown if contexts is null or a value is negative, NaN or infinite.
    • parseEvent

      public static opennlp.tools.ml.model.Event parseEvent(String line) throws opennlp.tools.util.InvalidFormatException
      Parses one real-valued event line. Fields are separated by runs of space, tab, carriage return, line feed and form feed, as in FileEventStream. The first field is the outcome and the remaining fields are contexts, whose values are parsed by parseContexts(String[]). A context whose value is not a number is kept whole with the value 1.
      Parameters:
      line - The event line. Must not be null.
      Returns:
      The parsed Event. A line with only an outcome yields an event without contexts. If no context carries a real value, the event has no values.
      Throws:
      IllegalArgumentException - Thrown if line is null or a context value is negative, NaN or infinite.
      opennlp.tools.util.InvalidFormatException - Thrown if line is empty or contains only separators.
      Since:
      3.0.0
    • read

      public opennlp.tools.ml.model.Event read() throws IOException
      Returns the next Event object. Calling this method repeatedly until it returns null will return each object from the underlying source exactly once.
      Specified by:
      read in interface opennlp.tools.util.ObjectStream<opennlp.tools.ml.model.Event>
      Overrides:
      read in class FileEventStream
      Returns:
      The next object or null to signal that the stream is exhausted.
      Throws:
      IOException - Thrown if there is an error during reading.
      opennlp.tools.util.InvalidFormatException - Thrown if a line is empty or contains only separators, or if a value is negative, NaN or infinite.