public SearchTester(String[] args) throws Exception { CmdLineParser argparser = new CmdLineParser(this); String home = null; String ranker_name = null; try { argparser.parseArgument(args); if (posargs.size() != 3) { throw new CmdLineException(argparser, Messages.ILLEGAL_LIST, "Command line fail"); } home = posargs.get(0); ranker_name = posargs.get(1); query_file = posargs.get(2); if (home == null) { throw new CmdLineException(argparser, Messages.ILLEGAL_PATH, "No home given"); } if (ranker_name == null) { throw new CmdLineException(argparser, Messages.ILLEGAL_OPERAND, "No ranker given"); } if (query_file == null) { throw new CmdLineException(argparser, Messages.ILLEGAL_PATH, "No query file given"); } } catch (CmdLineException cle) { System.err.println(cle.getMessage()); argparser.printUsage(System.err); System.err.println(); } fbs = new FreebaseSearcher(new FreebaseIndexer(home)); Class myClass = Class.forName(ranker_name); Class[] types = {IndexSearcher.class, Analyzer.class, Integer.TYPE}; Constructor constructor = myClass.getConstructor(types); ranker = (Ranker)constructor.newInstance(fbs.getIndexSearcher(), fbs.fbi.getIndexAnalyzer(), search_depth); }
@Override public ImmutablePair parse(String argument) throws CmdLineException, NumberFormatException { String[] typeParams = argument.split(":"); if (typeParams.length != 2) throw new CmdLineException(owner, Messages.ILLEGAL_OPERAND, option.toString(), argument); Split type = null; for (Split o : Split.class.getEnumConstants()) if (o.name().equalsIgnoreCase(typeParams[0])) { type = o; break; } List<Integer> parameters = new ArrayList<>(); try { for (String p : typeParams[1].split(",")) { parameters.add(Integer.parseInt(p)); } } catch (NumberFormatException e) { throw new CmdLineException(owner, Messages.ILLEGAL_OPERAND, option.toString(), argument); } if (type == null || parameters.size() == 0) { throw new CmdLineException(owner, Messages.ILLEGAL_OPERAND, option.toString(), argument); } return new ImmutablePair(type, typeParams[1]); }
@Override protected SetteToolConfiguration parse(@NonNull String toolName) throws NumberFormatException, CmdLineException { Optional<SetteToolConfiguration> toolConfig = configuration.getToolConfigurations() .stream() .filter(tc -> tc.getName().equalsIgnoreCase(toolName)) .findAny(); if (toolConfig.isPresent()) { return toolConfig.get(); } else { throw new CmdLineException(owner, Messages.ILLEGAL_OPERAND, option.toString(), toolName); } }
@Override protected Integer parse(@NonNull String time) throws NumberFormatException, CmdLineException { if (time.endsWith("ms")) { return Integer.parseInt(time.substring(0, time.length() - 2)); } else if (time.endsWith("s")) { return Integer.parseInt(time.substring(0, time.length() - 1)) * 1000; } else { throw new CmdLineException(owner, Messages.ILLEGAL_OPERAND, option.toString(), time); } }
@Override public String getDefaultMetaVariable() { return Messages.DEFAULT_META_STRING_ARRAY_OPTION_HANDLER.format(); }
/** * Returns {@code "STRING[]"}. * * @return return "STRING[]"; */ @Override public String getDefaultMetaVariable() { return Messages.DEFAULT_META_STRING_ARRAY_OPTION_HANDLER.format(); }