2020import java .io .IOException ;
2121
2222import opennlp .tools .cmdline .ArgumentParser ;
23- import opennlp .tools .cmdline .CmdLineUtil ;
2423import opennlp .tools .cmdline .StreamFactoryRegistry ;
24+ import opennlp .tools .cmdline .TerminateToolException ;
2525import opennlp .tools .cmdline .params .BasicFormatParams ;
2626import opennlp .tools .sentiment .SentimentSample ;
2727import opennlp .tools .sentiment .SentimentSampleStream ;
@@ -47,37 +47,33 @@ protected SentimentSampleStreamFactory(Class<P> params) {
4747 }
4848
4949 /**
50- * Creates a sentiment sample stream factory
50+ * Creates a sentiment sample stream.
5151 *
5252 * @param args
5353 * the necessary arguments
54- * @return SentimentSample stream (factory)
54+ * @return A {@link SentimentSample} stream.
5555 */
5656 @ Override
5757 public ObjectStream <SentimentSample > create (String [] args ) {
58- BasicFormatParams params = ArgumentParser .parse (args ,
59- BasicFormatParams .class );
58+ BasicFormatParams params = ArgumentParser .parse (args , BasicFormatParams .class );
6059
61- CmdLineUtil .checkInputFile ("Data" , params .getData ());
62- InputStreamFactory sampleDataIn = CmdLineUtil
63- .createInputStreamFactory (params .getData ());
64- ObjectStream <String > lineStream = null ;
60+ FormatUtil .checkInputFile ("Data" , params .getData ());
61+ ObjectStream <String > lineStream ;
6562 try {
66- lineStream = new PlainTextByLineStream ( sampleDataIn ,
67- params .getEncoding ());
63+ InputStreamFactory sampleDataIn = FormatUtil . createInputStreamFactory ( params . getData ());
64+ lineStream = new PlainTextByLineStream ( sampleDataIn , params .getEncoding ());
6865 } catch (IOException ex ) {
69- CmdLineUtil .handleCreateObjectStreamError (ex );
66+ throw new TerminateToolException (-1 ,
67+ "IO Error while creating an Input Stream: " + ex .getMessage (), ex );
7068 }
71-
7269 return new SentimentSampleStream (lineStream );
7370 }
7471
7572 /**
7673 * Registers a SentimentSample stream factory
7774 */
7875 public static void registerFactory () {
79- StreamFactoryRegistry .registerFactory (SentimentSample .class ,
80- StreamFactoryRegistry .DEFAULT_FORMAT ,
76+ StreamFactoryRegistry .registerFactory (SentimentSample .class , StreamFactoryRegistry .DEFAULT_FORMAT ,
8177 new SentimentSampleStreamFactory <>(BasicFormatParams .class ));
8278 }
8379
0 commit comments