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>
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 Summary
ConstructorsConstructorDescriptionRealValueFileEventStream(File file) Instantiates aRealValueFileEventStreamvia aFile.RealValueFileEventStream(Reader reader) Instantiates aRealValueFileEventStreamvia aReader.RealValueFileEventStream(String fileName) Instantiates aRealValueFileEventStreamfrom the specified file name.RealValueFileEventStream(String fileName, String encoding) Instantiates aRealValueFileEventStreamfrom the specified file name. -
Method Summary
Modifier and TypeMethodDescriptionstatic float[]parseContexts(String[] contexts) Parses the specifiedcontextsand re-populates context array with features and returns the values for these features.static opennlp.tools.ml.model.EventparseEvent(String line) Parses one real-valued event line.opennlp.tools.ml.model.Eventread()Returns the nextEventobject.Methods inherited from class FileEventStream
close, reset, toLine
-
Constructor Details
-
RealValueFileEventStream
Instantiates aRealValueFileEventStreamfrom the specified file name.- Parameters:
fileName- The name fo the file containing the events.- Throws:
IOException- Thrown if the specified file can not be read.
-
RealValueFileEventStream
Instantiates aRealValueFileEventStreamfrom the specified file name.- Parameters:
fileName- The name fo the file containing the events.encoding- The name of thecharacter encoding.- Throws:
IOException- Thrown if the specified file can not be read.
-
RealValueFileEventStream
Instantiates aRealValueFileEventStreamvia aFile.- Parameters:
file- TheFilethat holds events.- Throws:
IOException- Thrown if the specified file can not be read.
-
RealValueFileEventStream
Instantiates aRealValueFileEventStreamvia aReader.- Parameters:
reader- TheReaderthat holds events.- Throws:
IOException- Thrown if the specified file can not be read.
-
-
Method Details
-
parseContexts
Parses the specifiedcontextsand re-populates context array with features and returns the values for these features. If all values are unspecified, thennullis 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 value1; a value that is not a number is logged as an error.- Parameters:
contexts- The contexts with real values specified. Must not benull.- Returns:
- The value for each context or
nullif all values are unspecified. - Throws:
IllegalArgumentException- Thrown ifcontextsisnullor 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 inFileEventStream. The first field is the outcome and the remaining fields are contexts, whose values are parsed byparseContexts(String[]). A context whose value is not a number is kept whole with the value1.- Parameters:
line- The event line. Must not benull.- 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 iflineisnullor a context value is negative, NaN or infinite.opennlp.tools.util.InvalidFormatException- Thrown iflineis empty or contains only separators.- Since:
- 3.0.0
-
read
Returns the nextEventobject. Calling this method repeatedly until it returnsnullwill return each object from the underlying source exactly once.- Specified by:
readin interfaceopennlp.tools.util.ObjectStream<opennlp.tools.ml.model.Event>- Overrides:
readin classFileEventStream- Returns:
- The next object or
nullto 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.
-