| 36 | import com.winvector.util.TrivialReader; |
| 37 | |
| 38 | public class LogisticScore { |
| 39 | private static final String DATAURIKEY = "dataURI"; |
| 40 | private static final String DATASEP = "sep"; |
| 41 | private static final String DATAHDLKEY = "dataHDL"; |
| 42 | private static final String DATATBLKEY = "dataTBL"; |
| 43 | private static final String MODELKEY = "modelFile"; |
| 44 | private static final String RESULTFILEKEY = "resultFile"; |
| 45 | |
| 46 | private static CommandLine parseCommandLine(final String[] args) throws org.apache.commons.cli.ParseException { |
| 47 | final CommandLineParser clparser = new GnuParser(); |
| 48 | final Options cloptions = new Options(); |
| 49 | cloptions.addOption(MODELKEY,true,"file to read serialized model from"); |
| 50 | cloptions.addOption(DATAURIKEY,true,"URI to get scoring data from"); |
| 51 | cloptions.addOption(DATASEP,true,"(optional) data input separator"); |
| 52 | cloptions.addOption(DATAHDLKEY,true,"XML file to get JDBC connection to scoring data table"); |
| 53 | cloptions.addOption(DATATBLKEY,true,"table to use from database for scoring data"); |
| 54 | cloptions.addOption(RESULTFILEKEY,true,"file to write results to"); |
| 55 | for(final String optkey: new String[] {MODELKEY, RESULTFILEKEY} ) { |
| 56 | cloptions.getOption(optkey).setRequired(true); |
| 57 | } |
| 58 | final HelpFormatter hf = new HelpFormatter(); |
| 59 | final CommandLine cl = clparser.parse(cloptions, args); |
| 60 | if((cl.getOptionValue(DATAURIKEY)==null)==(cl.getOptionValue(DATAHDLKEY)==null)) { |
| 61 | hf.printHelp("com.winvector.logistic.LogisticScore", cloptions); |
| 62 | throw new org.apache.commons.cli.ParseException("Must set exacty one of --" + DATAURIKEY + " or --" + DATAHDLKEY); |
| 63 | } |
| 64 | if((cl.getOptionValue(DATAHDLKEY)!=null)&&(cl.getOptionValue(DATATBLKEY)==null)) { |
| 65 | hf.printHelp("com.winvector.logistic.LogisticScore", cloptions); |
| 66 | throw new org.apache.commons.cli.ParseException("If --" + DATAHDLKEY + " is set then must specify a table with --" + DATATBLKEY); |
| 67 | } |
| 68 | return cl; |
| 69 | } |
| 70 | |
| 71 | /** |
| 72 | * @param args |
| 73 | * @throws IOException |
| 74 | * @throws FileNotFoundException |
| 75 | * @throws ClassNotFoundException |
| 76 | * @throws URISyntaxException |
| 77 | * @throws ParseException |
| 78 | * @throws SQLException |
| 79 | */ |
| 80 | public static void main(String[] args) throws FileNotFoundException, IOException, ClassNotFoundException, URISyntaxException, ParseException, SQLException { |
| 81 | final Log log = LogFactory.getLog(LogisticScore.class); |
| 82 | log.info("start LogisticScore\t" + new Date()); |
| 83 | final CommandLine cl = parseCommandLine(args); |
| 84 | final File modelFile = new File(cl.getOptionValue(MODELKEY)); |
| 85 | final File resultFile = new File(cl.getOptionValue(RESULTFILEKEY)); |
| 86 | log.info("cwd: " + new File(".").getAbsolutePath()); |
| 87 | log.info("reading model: " + modelFile.getAbsolutePath()); |
| 88 | final ObjectInputStream ois = new ObjectInputStream(new FileInputStream(modelFile)); |
| 89 | final Model model = (Model)ois.readObject(); |
| 90 | ois.close(); |
| 91 | log.info("model:\n" + model.config.formatSoln(model.coefs)); |
| 92 | DBHandle handle = null; |
| 93 | Statement stmt = null; |
| 94 | final Iterable<BurstMap> testSource; |
| 95 | if(cl.getOptionValue(DATAURIKEY)!=null) { |
nothing calls this directly
no outgoing calls
no test coverage detected