|
19 | 19 |
|
20 | 20 | import java.io.IOException;
|
21 | 21 |
|
22 |
| -import opennlp.tools.cmdline.ArgumentParser; |
23 | 22 | import opennlp.tools.cmdline.ArgumentParser.ParameterDescription;
|
24 | 23 | import opennlp.tools.cmdline.CmdLineUtil;
|
25 | 24 | import opennlp.tools.cmdline.StreamFactoryRegistry;
|
|
30 | 29 | /**
|
31 | 30 | * @see BioNLP2004NameSampleStream
|
32 | 31 | */
|
33 |
| -public class BioNLP2004NameSampleStreamFactory<P> extends AbstractSampleStreamFactory<NameSample, P> { |
| 32 | +public class BioNLP2004NameSampleStreamFactory extends |
| 33 | + AbstractSampleStreamFactory<NameSample, BioNLP2004NameSampleStreamFactory.Parameters> { |
34 | 34 |
|
35 |
| - interface Parameters extends BasicFormatParams { |
| 35 | + public interface Parameters extends BasicFormatParams { |
36 | 36 | @ParameterDescription(valueName = "DNA,protein,cell_type,cell_line,RNA")
|
37 | 37 | String getTypes();
|
38 | 38 | }
|
39 | 39 |
|
40 | 40 | public static void registerFactory() {
|
41 | 41 | StreamFactoryRegistry.registerFactory(NameSample.class,
|
42 |
| - "bionlp2004", new BioNLP2004NameSampleStreamFactory<>(Parameters.class)); |
| 42 | + "bionlp2004", new BioNLP2004NameSampleStreamFactory(Parameters.class)); |
43 | 43 | }
|
44 | 44 |
|
45 |
| - protected BioNLP2004NameSampleStreamFactory(Class<P> params) { |
| 45 | + protected BioNLP2004NameSampleStreamFactory(Class<Parameters> params) { |
46 | 46 | super(params);
|
47 | 47 | }
|
48 | 48 |
|
49 | 49 | @Override
|
50 | 50 | public ObjectStream<NameSample> create(String[] args) {
|
51 |
| - |
52 |
| - Parameters params = ArgumentParser.parse(args, Parameters.class); |
| 51 | + Parameters params = validateBasicFormatParameters(args, Parameters.class); |
53 | 52 |
|
54 | 53 | int typesToGenerate = 0;
|
55 |
| - |
56 |
| - if (params.getTypes().contains("DNA")) { |
| 54 | + String types = params.getTypes(); |
| 55 | + if (types.contains("DNA")) { |
57 | 56 | typesToGenerate = typesToGenerate |
|
58 | 57 | BioNLP2004NameSampleStream.GENERATE_DNA_ENTITIES;
|
59 | 58 | }
|
60 |
| - else if (params.getTypes().contains("protein")) { |
| 59 | + if (types.contains("protein")) { |
61 | 60 | typesToGenerate = typesToGenerate |
|
62 | 61 | BioNLP2004NameSampleStream.GENERATE_PROTEIN_ENTITIES;
|
63 | 62 | }
|
64 |
| - else if (params.getTypes().contains("cell_type")) { |
| 63 | + if (types.contains("cell_type")) { |
65 | 64 | typesToGenerate = typesToGenerate |
|
66 | 65 | BioNLP2004NameSampleStream.GENERATE_CELLTYPE_ENTITIES;
|
67 | 66 | }
|
68 |
| - else if (params.getTypes().contains("cell_line")) { |
| 67 | + if (types.contains("cell_line")) { |
69 | 68 | typesToGenerate = typesToGenerate |
|
70 | 69 | BioNLP2004NameSampleStream.GENERATE_CELLLINE_ENTITIES;
|
71 | 70 | }
|
72 |
| - else if (params.getTypes().contains("RNA")) { |
| 71 | + if (types.contains("RNA")) { |
73 | 72 | typesToGenerate = typesToGenerate |
|
74 | 73 | BioNLP2004NameSampleStream.GENERATE_RNA_ENTITIES;
|
75 | 74 | }
|
76 | 75 |
|
77 | 76 | try {
|
78 | 77 | return new BioNLP2004NameSampleStream(
|
79 | 78 | CmdLineUtil.createInputStreamFactory(params.getData()), typesToGenerate);
|
80 |
| - } catch (IOException e) { |
81 |
| - throw new IllegalStateException(e); |
| 79 | + } catch (IOException ex) { |
| 80 | + CmdLineUtil.handleCreateObjectStreamError(ex); |
82 | 81 | }
|
| 82 | + return null; |
83 | 83 | }
|
84 | 84 | }
|
0 commit comments