List of usage examples for java.lang String toLowerCase
public String toLowerCase()
From source file:org.test.LookupSVNUsers.java
/** * @param args// w w w .j av a 2 s .c o m * @throws IOException */ public static void main(String[] args) throws IOException { if (args.length != 2) { log.error("USAGE: <svn users file(input)> <git authors file (output)>"); System.exit(-1); } Set<String> unmatchedNameSet = new LinkedHashSet<String>(); Map<String, GitUser> gitUserMap = new LinkedHashMap<String, GitUser>(); String svnAuthorsFile = args[0]; List<String> lines = FileUtils.readLines(new File(svnAuthorsFile)); for (String line : lines) { // intentionally handle both upper and lower case varients of the same name. String svnUserName = line.trim(); if (svnUserName.contains("(")) continue; // skip over this line as we can't use it on the url if (gitUserMap.keySet().contains(svnUserName)) continue; // skip this duplicate. log.info("starting on user = " + svnUserName); String gitName = extractFullName(svnUserName); if (gitName == null) { gitName = extractFullName(svnUserName.toLowerCase()); } if (gitName == null) { unmatchedNameSet.add(svnUserName); } else { gitUserMap.put(svnUserName, new GitUser(svnUserName, gitName)); log.info("mapped user (" + svnUserName + ") to: " + gitName); } } List<String> mergedList = new ArrayList<String>(); mergedList.add("# GENERATED "); List<String> userNameList = new ArrayList<String>(); userNameList.addAll(gitUserMap.keySet()); Collections.sort(userNameList); for (String userName : userNameList) { GitUser gUser = gitUserMap.get(userName); mergedList.add(gUser.getSvnAuthor() + " = " + gUser.getGitUser() + " <" + gUser.getSvnAuthor() + "@users.sourceforge.net>"); } for (String username : unmatchedNameSet) { log.warn("failed to match SVN User = " + username); // add in the unmatched entries as is. mergedList.add(username + " = " + username + " <" + username + "@users.sourceforge.net>"); } FileUtils.writeLines(new File(args[1]), "UTF-8", mergedList); }
From source file:CreateNewType.java
public static void main(String[] args) { String url = "jdbc:mySubprotocol:myDataSource"; Connection con;/*from www . j av a2s . c o m*/ Statement stmt; try { Class.forName("myDriver.ClassName"); } catch (java.lang.ClassNotFoundException e) { System.err.print("ClassNotFoundException: "); System.err.println(e.getMessage()); } try { con = DriverManager.getConnection(url, "myLogin", "myPassword"); stmt = con.createStatement(); String typeToCreate = null; String prompt = "Enter 's' to create a structured type " + "or 'd' to create a distinct type\n" + "and hit Return: "; do { typeToCreate = getInput(prompt) + " "; typeToCreate = typeToCreate.toLowerCase().substring(0, 1); } while (!(typeToCreate.equals("s") || typeToCreate.equals("d"))); Vector dataTypes = getDataTypes(con, typeToCreate); String typeName; String attributeName; String sqlType; prompt = "Enter the new type name and hit Return: "; typeName = getInput(prompt); String createTypeString = "create type " + typeName; if (typeToCreate.equals("d")) createTypeString += " as "; else createTypeString += " ("; String commaAndSpace = ", "; boolean firstTime = true; while (true) { System.out.println(""); prompt = "Enter an attribute name " + "(or nothing when finished) \nand hit Return: "; attributeName = getInput(prompt); if (firstTime) { if (attributeName.length() == 0) { System.out.print("Need at least one attribute;"); System.out.println(" please try again"); continue; } else { createTypeString += attributeName + " "; firstTime = false; } } else if (attributeName.length() == 0) { break; } else { createTypeString += commaAndSpace + attributeName + " "; } String localTypeName = null; String paramString = ""; while (true) { System.out.println(""); System.out.println("LIST OF TYPES YOU MAY USE: "); boolean firstPrinted = true; int length = 0; for (int i = 0; i < dataTypes.size(); i++) { DataType dataType = (DataType) dataTypes.get(i); if (!dataType.needsToBeSet()) { if (!firstPrinted) System.out.print(commaAndSpace); else firstPrinted = false; System.out.print(dataType.getSQLType()); length += dataType.getSQLType().length(); if (length > 50) { System.out.println(""); length = 0; firstPrinted = true; } } } System.out.println(""); int index; prompt = "Enter an attribute type " + "from the list and hit Return: "; sqlType = getInput(prompt); for (index = 0; index < dataTypes.size(); index++) { DataType dataType = (DataType) dataTypes.get(index); if (dataType.getSQLType().equalsIgnoreCase(sqlType) && !dataType.needsToBeSet()) { break; } } localTypeName = null; paramString = ""; if (index < dataTypes.size()) { // there was a match String params; DataType dataType = (DataType) dataTypes.get(index); params = dataType.getParams(); localTypeName = dataType.getLocalType(); if (params != null) { prompt = "Enter " + params + ": "; paramString = "(" + getInput(prompt) + ")"; } break; } else { // use the name as given prompt = "Are you sure? " + "Enter 'y' or 'n' and hit Return: "; String check = getInput(prompt) + " "; check = check.toLowerCase().substring(0, 1); if (check.equals("n")) continue; else { localTypeName = sqlType; break; } } } createTypeString += localTypeName + paramString; if (typeToCreate.equals("d")) break; } if (typeToCreate.equals("s")) createTypeString += ")"; System.out.println(""); System.out.print("Your CREATE TYPE statement as "); System.out.println("sent to your DBMS: "); System.out.println(createTypeString); System.out.println(""); stmt.executeUpdate(createTypeString); stmt.close(); con.close(); } catch (SQLException ex) { System.err.println("SQLException: " + ex.getMessage()); } }
From source file:BihuHttpUtil.java
public static void main(String[] args) throws Exception { long start = System.currentTimeMillis(); String key = "csdfse784"; String agent = "3820"; // String carNO = "HD3639"; // String EngineNo = "1026510"; // String CarVin = "LHGRU5746F2026462"; // String RegisterDate = "2015-04-03"; // String MoldName = "HG7180HAM5"; // String IntentionCompany = "0"; // String carNO = "N3HU88"; // String EngineNo = "8634342"; // String CarVin = "LDCC13L25A0206503"; // String RegisterDate = "2010-04-28"; // String MoldName = "?DC7165DTA"; // String IntentionCompany = "2"; //String carNO = "P55M11"; String EngineNo = "4LA4D8297"; String CarVin = "LGXC16DF4A0169664"; String RegisterDate = "2006-10-01"; String MoldName = "F3"; String IntentionCompany = "1"; //"ForceTotal":627.56,"TaxTotal":400 //String carNO = "PT3G98"; //String carNO = "N3HU88"; //String carNO = "A723KG"; //String carNO = "QA5M75"; //String carNO = "KT3495"; //String carNO = "KV5909"; //String carNO = "QWZ015"; //String carNO = "Q8D075"; //String carNO = "KV5909"; //String carNO="F03E65"; //String carNO="P55M11"; //String carNO="A723KG"; //String carNO="QA5M75"; //String carNO="?JC1112"; //String carNO="QWZ015"; //String carNO = "MH0501"; //String carNO = "P2QZ85"; //String carNO = "NQA575"; //String carNO = "Q2PE81"; //String carNO = "LQ1190"; //String carNO = "HGD056"; //String carNO = "MM3767"; String carNO = "F20403"; String custKey = "e8370f8fb7d7d6ec7bcaa8b3b738e409"; String param1 = "LicenseNo=" + carNO + "&CityCode=1&Agent=" + agent + "&IsPublic=0&CustKey=" + custKey; //String paramTest = "LicenseNo=P55M11&CityCode=1&Agent=3820&IsPublic=0&CustKey=492f4a6c11781385e9cf08651e77e148&SecCode=6634bf16b66dddd263a824f79f9a7e3a"; String secCode1 = MD5(param1 + key); param1 = param1 + "&SecCode=" + secCode1.toLowerCase(); String url1 = "http://it.91bihu.com/api/CarInsurance/getreinfo"; String result = sendGet(url1, param1); System.err.println(result);// ww w .ja va2 s. c o m System.err.println("" + String.valueOf(System.currentTimeMillis() - start)); // // String url = "http://i.91bihu.com/api/CarInsurance/PostPrecisePrice"; // //?JSON? // Map<String, String> jsonObj = new HashMap<>(); // //? // jsonObj.put("IsSingleSubmit", "1");//IsSingleSubmit Int ?????1=0=? // jsonObj.put("IntentionCompany", IntentionCompany);//IntentionCompany String ????(-1:????0:?1:?2:?) // //? // jsonObj.put("LicenseNo", carNO);//LicenseNo String ? // jsonObj.put("EngineNo", EngineNo);//EngineNo String ?? // jsonObj.put("CarVin", CarVin);//CarVin String ? // jsonObj.put("RegisterDate", RegisterDate);//RegisterDate string // jsonObj.put("MoldName", MoldName);//MoldName String ?? // jsonObj.put("CarType", "0");//CarType Int 01 // jsonObj.put("IsNewCar", "0");//IsNewCar Int ?0?1 // jsonObj.put("CarUsedType", "0");//CarUsedType string 0?????? // jsonObj.put("Citycode", "10");//Citycode Int Id???:110000 // //?? // jsonObj.put("ForceTax", "1");//ForceTax Int +(1:0?) // jsonObj.put("BoLi", "1");//BoLi Double ?0-??12? // jsonObj.put("CheDeng", "0");//CheDeng Double ??????0-??1-2-? // jsonObj.put("SheShui", "1");//SheShui Double ?0-??1? // jsonObj.put("HuaHen", "2000");//HuaHen Double ?0-??>0?(?)200050001000020000 // jsonObj.put("SiJi", "10000");//SiJi Double (?) 0-??>0?(?1000020000300004000050000100000200000 // jsonObj.put("ChengKe", "10000");//ChengKe Double () 0-??>0?(?)1000020000300004000050000100000200000 // jsonObj.put("CheSun", "1");//CheSun Double ??0-??>0? // jsonObj.put("DaoQiang", "1");//DaoQiang Double ?0-??>0? // jsonObj.put("SanZhe", "50000");//SanZhe Double ?0-??>0?(?)5000010000015000020000030000050000010000001500000 // jsonObj.put("ZiRan", "1");//ZiRan Double ?0-??1? // jsonObj.put("BuJiMianCheSun", "1");//BuJiMianCheSun Double ??(?) 0-??1? // jsonObj.put("BuJiMianDaoQiang", "1");//BuJiMianDaoQiang Double ??() 0-??1? // jsonObj.put("BuJiMianFuJia", "1");//BuJiMianFuJia Double ??() 0-??1? // jsonObj.put("BuJiMianRenYuan", "1");//BuJiMianRenYuan Double ??() 0-??1? // jsonObj.put("BuJiMianSanZhe", "1");//BuJiMianSanZhe Double ??() 0-??1? //?? // // jsonObj.put("CustKey", custKey); // jsonObj.put("Agent", agent);//Agent Int ? // StringBuffer paramSb = new StringBuffer(); // for(String mapKey : jsonObj.keySet()){ // String value = jsonObj.get(mapKey); // paramSb.append(mapKey + "=" + value + "&"); // } // String secCode = MD5(paramSb.toString() + key).toLowerCase(); // paramSb.append("secCode=" + secCode); // String result2 = sendGet(url, paramSb.toString()); // System.err.println(result2); //?? // for(int i=0;i<40;i++){ // Thread.sleep(1000L); // String param = "LicenseNo=" + carNO + "&IntentionCompany=" + IntentionCompany + "&Agent=" + agent + "&CustKey=" + custKey; // String secCode2 = MD5(param + key); // param = param + "&SecCode=" + secCode2.toLowerCase(); // String url2 = "http://i.91bihu.com/api/CarInsurance/GetPrecisePrice"; // String result1 = sendGet(url2, param); // System.err.println(result1); // } // //??? // String param = "LicenseNo=" + carNO + "&IntentionCompany=" + IntentionCompany + "&Agent=" + agent; // String secCode2 = MD5(param + key); // param = param + "&SecCode=" + secCode2.toLowerCase(); // String url4 = "http://i.91bihu.com/api/CarInsurance/GetSubmitInfo"; // String result4 = sendGet(url4, param); // System.err.println(result4); //?? String param5 = "LicenseNo=" + carNO + "&Agent=" + agent + "&CustKey=" + custKey; String secCode5 = MD5(param5 + key); param5 = param5 + "&SecCode=" + secCode5.toLowerCase(); String url5 = "http://i.91bihu.com/api/Claim/GetCreditInfo"; String result5 = sendGet(url5, param5); System.err.println(result5); System.err.println("" + String.valueOf(System.currentTimeMillis() - start)); }
From source file:com.seanmadden.fast.ldap.main.Main.java
/** * The Main Event./*from w w w.ja va2s. co m*/ * * @param args */ @SuppressWarnings("static-access") public static void main(String[] args) { BasicConfigurator.configure(); log.debug("System initializing"); try { Logger.getRootLogger().addAppender( new FileAppender(new PatternLayout(PatternLayout.TTCC_CONVERSION_PATTERN), "log.log")); } catch (IOException e1) { log.error("Unable to open the log file..?"); } /* * Initialize the configuration engine. */ XMLConfiguration config = new XMLConfiguration(); config.setListDelimiter('|'); /* * Initialize the Command-Line parsing engine. */ CommandLineParser parser = new PosixParser(); Options opts = new Options(); opts.addOption(OptionBuilder.withLongOpt("config-file").hasArg() .withDescription("The configuration file to load").withArgName("config.xml").create("c")); opts.addOption(OptionBuilder.withLongOpt("profile").hasArg().withDescription("The profile to use") .withArgName("Default").create("p")); opts.addOption(OptionBuilder.withLongOpt("password").hasArg().withDescription("Password to connect with") .withArgName("password").create("P")); opts.addOption(OptionBuilder.withLongOpt("debug").hasArg(false).create('d')); opts.addOption(OptionBuilder.withLongOpt("verbose").hasArg(false).create('v')); File configurationFile = new File("config.xml"); try { // Parse the command-line options CommandLine cmds = parser.parse(opts, args); if (!cmds.hasOption('p')) { Logger.getRootLogger().addAppender(new GuiErrorAlerter(Level.ERROR)); } Logger.getRootLogger().setLevel(Level.ERROR); if (cmds.hasOption('v')) { Logger.getRootLogger().setLevel(Level.INFO); } if (cmds.hasOption('d')) { Logger.getRootLogger().setLevel(Level.DEBUG); } log.debug("Enabling configuration file parsing"); // The user has given us a file to parse. if (cmds.hasOption("c")) { configurationFile = new File(cmds.getOptionValue("c")); } log.debug("Config file: " + configurationFile); // Load the configuration file if (configurationFile.exists()) { config.load(configurationFile); } else { log.error("Cannot find config file"); } /* * Convert the profiles into memory */ Vector<ConnectionProfile> profs = new Vector<ConnectionProfile>(); List<?> profList = config.configurationAt("Profiles").configurationsAt("Profile"); for (Object p : profList) { SubnodeConfiguration profile = (SubnodeConfiguration) p; String name = profile.getString("[@name]"); String auth = profile.getString("LdapAuthString"); String server = profile.getString("LdapServerString"); String group = profile.getString("LdapGroupsLocation"); ConnectionProfile prof = new ConnectionProfile(name, server, auth, group); profs.add(prof); } ConnectionProfile prof = null; if (!cmds.hasOption('p')) { /* * Deploy the profile selector, to select a profile */ ProfileSelector profSel = new ProfileSelector(profs); prof = profSel.getSelection(); if (prof == null) { return; } /* * Empty the profiles and load a clean copy - then save it back * to the file */ config.clearTree("Profiles"); for (ConnectionProfile p : profSel.getProfiles()) { config.addProperty("Profiles.Profile(-1)[@name]", p.getName()); config.addProperty("Profiles.Profile.LdapAuthString", p.getLdapAuthString()); config.addProperty("Profiles.Profile.LdapServerString", p.getLdapServerString()); config.addProperty("Profiles.Profile.LdapGroupsLocation", p.getLdapGroupsString()); } config.save(configurationFile); } else { for (ConnectionProfile p : profs) { if (p.getName().equals(cmds.getOptionValue('p'))) { prof = p; break; } } } log.info("User selected " + prof); String password = ""; if (cmds.hasOption('P')) { password = cmds.getOptionValue('P'); } else { password = PasswordPrompter.promptForPassword("Password?"); } if (password.equals("")) { return; } LdapInterface ldap = new LdapInterface(prof.getLdapServerString(), prof.getLdapAuthString(), prof.getLdapGroupsString(), password); /* * Gather options information from the configuration engine for the * specified report. */ Hashtable<String, Hashtable<String, ReportOption>> reportDataStructure = new Hashtable<String, Hashtable<String, ReportOption>>(); List<?> repConfig = config.configurationAt("Reports").configurationsAt("Report"); for (Object p : repConfig) { SubnodeConfiguration repNode = (SubnodeConfiguration) p; // TODO Do something with the report profile. // Allowing the user to deploy "profiles" is a nice feature // String profile = repNode.getString("[@profile]"); String reportName = repNode.getString("[@report]"); Hashtable<String, ReportOption> reportOptions = new Hashtable<String, ReportOption>(); reportDataStructure.put(reportName, reportOptions); // Loop through the options and add each to the table. for (Object o : repNode.configurationsAt("option")) { SubnodeConfiguration option = (SubnodeConfiguration) o; String name = option.getString("[@name]"); String type = option.getString("[@type]"); String value = option.getString("[@value]"); ReportOption ro = new ReportOption(); ro.setName(name); if (type.toLowerCase().equals("boolean")) { ro.setBoolValue(Boolean.parseBoolean(value)); } else if (type.toLowerCase().equals("integer")) { ro.setIntValue(Integer.valueOf(value)); } else { // Assume a string type here then. ro.setStrValue(value); } reportOptions.put(name, ro); log.debug(ro); } } System.out.println(reportDataStructure); /* * At this point, we now need to deploy the reports window to have * the user pick a report and select some happy options to allow * that report to work. Let's go. */ /* * Deploy the Reports selector, to select a report */ Reports.getInstance().setLdapConnection(ldap); ReportsWindow reports = new ReportsWindow(Reports.getInstance().getAllReports(), reportDataStructure); Report report = reports.getSelection(); if (report == null) { return; } /* * Empty the profiles and load a clean copy - then save it back to * the file */ config.clearTree("Reports"); for (Report r : Reports.getInstance().getAllReports()) { config.addProperty("Reports.Report(-1)[@report]", r.getClass().getCanonicalName()); config.addProperty("Reports.Report[@name]", "Standard"); for (ReportOption ro : r.getOptions().values()) { config.addProperty("Reports.Report.option(-1)[@name]", ro.getName()); config.addProperty("Reports.Report.option[@type]", ro.getType()); config.addProperty("Reports.Report.option[@value]", ro.getStrValue()); } } config.save(configurationFile); ProgressBar bar = new ProgressBar(); bar.start(); report.execute(); ASCIIFormatter format = new ASCIIFormatter(); ReportResult res = report.getResult(); format.format(res, new File(res.getForName() + "_" + res.getReportName() + ".txt")); bar.stop(); JOptionPane.showMessageDialog(null, "The report is at " + res.getForName() + "_" + res.getReportName() + ".txt", "Success", JOptionPane.INFORMATION_MESSAGE); } catch (ParseException e) { HelpFormatter formatter = new HelpFormatter(); formatter.printHelp("FAST Ldap Searcher", opts); } catch (ConfigurationException e) { e.printStackTrace(); log.fatal("OH EM GEES! Configuration errors."); } catch (Exception e) { e.printStackTrace(); } }
From source file:de.codesourcery.eve.skills.ui.model.FilteringTreeModel.java
public static void main(String[] args) { final JFrame frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); final FilteringTreeModel model = new FilteringTreeModel(createTreeModel()); // setup text field final JTextField filterTextField = new JTextField(30); filterTextField.addActionListener(new ActionListener() { @Override//from w w w. j a v a2 s . com public void actionPerformed(ActionEvent e) { model.viewFilterChanged(); } }); // setup tree final JTree tree = new JTree(); final IViewFilter<ITreeNode> filter = new AbstractViewFilter<ITreeNode>() { @Override public boolean isHiddenUnfiltered(ITreeNode node) { final String nodeValue = node.toString(); final String expected = filterTextField.getText(); final boolean isHidden = !StringUtils.isBlank(nodeValue) && !StringUtils.isBlank(expected) && nodeValue.startsWith("child") && !nodeValue.toLowerCase().contains(expected.toLowerCase()); System.out.println(nodeValue + " does not match " + expected + " => " + isHidden); return isHidden; } }; model.setViewFilter(filter); tree.setModel(model); // set final JPanel panel = new JPanel(); new GridLayoutBuilder() .add(new GridLayoutBuilder.HorizontalGroup(new GridLayoutBuilder.Cell(new JScrollPane(tree)), new GridLayoutBuilder.FixedCell(filterTextField))) .addTo(panel); frame.getContentPane().add(panel); frame.pack(); frame.setLocationRelativeTo(null); frame.setVisible(true); }
From source file:com.appeligo.ccdataindexer.Indexer.java
public static void main(String args[]) throws Exception { ConfigurationService.setRootDir(new File("config")); ConfigurationService.setEnvName("live"); ConfigurationService.init();/*from w w w .j a va2 s . c o m*/ if (args.length < 4 || args.length > 5) { usage(); System.exit(-1); } File file = new File(args[0]); if (!file.isDirectory()) { usage(); System.exit(-1); } Date date = null; if (args.length == 5) { DateFormat format = new SimpleDateFormat("yyyy-MM-dd"); date = format.parse(args[4]); } long now = System.currentTimeMillis(); String epgUrl = args[1]; String indexLocation = args[2]; String compositeIndexLocation = args[3]; if (indexLocation.toLowerCase().trim().equals("null")) { indexLocation = null; } if (compositeIndexLocation.toLowerCase().trim().equals("null")) { compositeIndexLocation = null; } if (indexLocation == null && compositeIndexLocation == null) { log.error("At least one of indexLocation or compositeIndexLocation cannot be null."); usage(); } Indexer indexer = new Indexer(file, epgUrl, indexLocation, compositeIndexLocation); if (date != null) { indexer.setAfterDate(date); } if (date == null) { log.info("Processing all files"); } else { log.info("Processing all files after " + date + " sanityCheck " + indexer.getAfterDate()); } int count = indexer.index(); long after = System.currentTimeMillis(); log.info("Processing took " + ((after - now) / (60 * 1000)) + " minutes to index the programs."); log.info("Time spent looking up scheduled programs in epg: " + (lookupTime / (60 * 1000)) + " minutes"); log.info("Indexed " + count + " programs"); }
From source file:edu.harvard.liblab.ecru.LoadCsvData.java
/** * @param args/*from w ww . java 2 s. c om*/ */ public static void main(String[] args) { if (args.length > 7 | args.length == 0 || !args[0].equals("-f") || !args[2].equals("-u") || !args[4].equals("-i")) { System.err.println(USAGE); System.exit(1); } String filename = args[1].trim(); url = args[3].trim(); needsPrefix = !args[5].equals("unique"); isVerbose = (args.length == 7 && args[6].equals("-v")); System.out.println("Loading data from " + filename + " " + (needsPrefix ? "IDs will be prefixed " : " ")); long start = System.currentTimeMillis(); boolean isReading = false; CSVPrinter printer = null; CSVFormat format = CSVFormat.EXCEL.withHeader().withDelimiter(',').withAllowMissingColumnNames(true); CSVParser parser; try { if (isVerbose) { printer = new CSVPrinter(System.err, format.withDelimiter('|')); } parser = CSVParser.parse(new File(filename), Charset.forName("UTF-8"), format); solrSrvr = SingletonSolrServer.getSolrServer(url); for (CSVRecord record : parser) { numRecs++; HashMap<String, String> recMap = new HashMap<String, String>(); for (String field : FIELDS) { String value = null; try { value = record.get(field); } catch (IllegalArgumentException e) { if (e.getMessage().indexOf("expected one of") == -1) { e.printStackTrace(); System.exit(1); } } value = value == null ? "" : value.trim(); recMap.put(field, value); } String id = recMap.get("ID"); if (id.isEmpty()) { if (isVerbose) { System.err.println("Record missing ID: "); printer.printRecord(record); } } else { String type = recMap.get("Type"); SolrDocument sdoc = getDocFromSolr(recMap.get("ID")); try { if (type.toLowerCase().equals("course")) { processCourse(recMap, sdoc); isReading = false; } else { if (!isReading) { addUpdateCommit(); // just in case the preceeding course(s) are related } processReading(recMap, sdoc); isReading = true; } } catch (Exception e) { if (isVerbose) { System.err.println("Record # " + numRecs + " not used:\n\t" + e.getMessage()); } errRecs++; } } if (beans.size() > 20) { addUpdateCommit(); } } parser.close(); if (beans.size() > 0 || docUpdates.size() > 0) { addUpdateCommit(); } } catch (FileNotFoundException e) { System.err.println(filename + " not found"); System.exit(1); } catch (Exception e) { e.printStackTrace(); System.exit(1); } long end = System.currentTimeMillis(); long courseTime = (end - start) / (long) 1000; try { solrSrvr.optimize(); } catch (SolrServerException e) { e.printStackTrace(); System.exit(1); } catch (IOException e) { e.printStackTrace(); System.exit(1); } System.out.println(numRecs + " records found, of which " + errRecs + " had a problem; time: " + courseTime + " seconds " + ((courseTime > 60) ? ("(" + (courseTime / (long) 60) + " minutes)") : "")); System.exit(0); }
From source file:edu.uiowa.javatm.JavaTM.java
/** * @param args First one indicates which topic model to use *///from w ww . j a v a 2 s . co m public static void main(String[] args) { TMGibbsSampler tmGibbsSampler = null; Option modelType = Option.builder("model").longOpt("model-type").desc("Type of topic models to use") .hasArg().required().build(); Option dataName = Option.builder("name").longOpt("data-name").desc("Data name: used for saving outputs") .hasArg().required().build(); Option alpha = Option.builder("a").longOpt("alpha") .desc("Dirichlet prior for document (author) over topic multinomial").hasArg().required().build(); Option beta = Option.builder("b").longOpt("beta").desc("Dirichlet prior for topic over word multinomial") .hasArg().required().build(); Option pi = Option.builder("p").longOpt("pi").desc("Dirichlet prior for topic over time multinomial") .hasArg().build(); Option K = Option.builder("K").longOpt("K").desc("The number of timestamp indices").hasArg().build(); /*Option tau = Option.builder("tau").longOpt("tau") .desc("Smoothing constant for topic time") .hasArg().build();*/ Option doc = Option.builder("doc").longOpt("document-file").desc("WD matrix to use").hasArg().required() .build(); Option voc = Option.builder("voc").longOpt("vocabulary-file") .desc("Vocabulary file of the corpus of interest").hasArg().required().build(); Option auth = Option.builder("auth").longOpt("auth-file").desc("Author indices for each token").hasArg() .build(); Option authArray = Option.builder("authArray").longOpt("author-list-file").desc("Author list").hasArg() .build(); Option dkArray = Option.builder("dk").longOpt("document-time-file").desc("Document timestamp file").hasArg() .build(); Option citationMat = Option.builder("cm").longOpt("citation-matrix") .desc("Citation overtime for the corpus").hasArg().build(); Option numTopics = Option.builder("topic").longOpt("num-topics").desc("The total number of topics").hasArg() .required().build(); Option numIters = Option.builder("iter").longOpt("num-iters").desc("The total number of iterations") .hasArg().required().build(); Option outputDir = Option.builder("odir").longOpt("output-dir").desc("Output directory").hasArg().required() .build(); Options options = new Options(); options.addOption(modelType).addOption(alpha).addOption(beta).addOption(numTopics).addOption(K) .addOption(pi).addOption(citationMat).addOption(numIters).addOption(doc).addOption(voc) .addOption(dkArray).addOption(outputDir).addOption(auth).addOption(authArray).addOption(dataName); CommandLineParser parser = new DefaultParser(); try { // parse the command line arguments CommandLine line = parser.parse(options, args); String model = line.getOptionValue("model"); String name = line.getOptionValue("name"); String docFile = line.getOptionValue("doc"); String vocFile = line.getOptionValue("voc"); int topics = Integer.parseInt(line.getOptionValue("topic")); int iters = Integer.parseInt(line.getOptionValue("iter")); double a = Double.parseDouble(line.getOptionValue("a")); double b = Double.parseDouble(line.getOptionValue("b")); String modelLower = model.toLowerCase(); if (modelLower.equals("lda")) { tmGibbsSampler = new LDAGibbsSampler(topics, iters, a, b, docFile, vocFile); } else if (modelLower.equals("at")) { String authFile = line.getOptionValue("auth"); String authArrayFile = line.getOptionValue("authArray"); //double tau_val = Double.parseDouble(line.getOptionValue("tau")); tmGibbsSampler = new ATGibbsSampler(topics, iters, a, b, docFile, vocFile, authFile, authArrayFile); } else if (modelLower.equals("tot")) { String dkFile = line.getOptionValue("dk"); //double tau_val = Double.parseDouble(line.getOptionValue("tau")); tmGibbsSampler = new ToTGibbsSampler(topics, iters, a, b, docFile, vocFile, dkFile); } else if (modelLower.equals("tiot")) { String timeFile = line.getOptionValue("dk"); String citationFile = line.getOptionValue("cm"); double p = Double.parseDouble(line.getOptionValue("p")); //int k = Integer.parseInt(line.getOptionValue("K")); tmGibbsSampler = new TIOTGibbsSampler(topics, iters, a, b, p, docFile, vocFile, timeFile, citationFile); } else { System.err.println("Invalid model type selection. Must be lda, at, tot or atot."); System.exit(ExitStatus.ILLEGAL_ARGUMENT); } long startTime = System.nanoTime(); tmGibbsSampler.fit(); TMOutcome outcome = tmGibbsSampler.get_outcome(); long endTime = System.nanoTime(); long duration = (endTime - startTime); System.out.println("Overall elapsed time: " + duration / 1000000000. + " seconds"); tmGibbsSampler.showTopics(10); outcome.showTopicDistribution(); String oDir = line.getOptionValue("odir"); if (!oDir.endsWith("/")) { oDir = oDir + "/"; } // append name to `oDir` oDir = oDir + name + "-"; if (modelLower.contains("tot")) { // topic over time (tot and atot) has beta distribution parameters to write Utils.write2DArray(((ToTOutcome) outcome).getPsi(), oDir + "psi-" + modelLower + ".csv"); } if (modelLower.contains("tiot")) { // topic over time (tot and atot) has beta distribution parameters to write Utils.write2DArray(((TIOTOutcome) outcome).getPsi(), oDir + "psi-" + modelLower + ".csv"); double[][][] ga = ((TIOTOutcome) outcome).getGa(); for (int t = 0; t < ga.length; t++) { Utils.write2DArray(ga[t], oDir + "gamma-" + t + "-" + modelLower + ".csv"); } } Utils.write2DArray(outcome.getPhi(), oDir + "phi-" + modelLower + ".csv"); Utils.write2DArray(outcome.getTheta(), oDir + "theta-" + modelLower + ".csv"); System.out.println("Output files saved to " + oDir); } catch (ParseException exp) { // oops, something went wrong System.err.println("Parsing failed. Reason: " + exp.getMessage()); } }
From source file:CTmousetrack.java
public static void main(String[] args) { String outLoc = new String("." + File.separator + "CTdata"); // Location of the base output data folder; only used when writing out CT data to a local folder String srcName = "CTmousetrack"; // name of the output CT source long blockPts = 10; // points per block flush long sampInterval = 10; // time between sampling updates, msec double trimTime = 0.0; // amount of data to keep (trim time), sec boolean debug = false; // turn on debug? // Specify the CT output connection CTWriteMode writeMode = CTWriteMode.LOCAL; // The selected mode for writing out CT data String serverHost = ""; // Server (FTP or HTTP/S) host:port String serverUser = ""; // Server (FTP or HTTPS) username String serverPassword = ""; // Server (FTP or HTTPS) password // For UDP output mode DatagramSocket udpServerSocket = null; InetAddress udpServerAddress = null; String udpHost = ""; int udpPort = -1; // Concatenate all of the CTWriteMode types String possibleWriteModes = ""; for (CTWriteMode wm : CTWriteMode.values()) { possibleWriteModes = possibleWriteModes + ", " + wm.name(); }//from ww w. ja v a2 s.c om // Remove ", " from start of string possibleWriteModes = possibleWriteModes.substring(2); // // Argument processing using Apache Commons CLI // // 1. Setup command line options Options options = new Options(); options.addOption("h", "help", false, "Print this message."); options.addOption(Option.builder("o").argName("base output dir").hasArg().desc( "Base output directory when writing data to local folder (i.e., this is the location of CTdata folder); default = \"" + outLoc + "\".") .build()); options.addOption(Option.builder("s").argName("source name").hasArg() .desc("Name of source to write data to; default = \"" + srcName + "\".").build()); options.addOption(Option.builder("b").argName("points per block").hasArg() .desc("Number of points per block; UDP output mode will use 1 point/block; default = " + Long.toString(blockPts) + ".") .build()); options.addOption(Option.builder("dt").argName("samp interval msec").hasArg() .desc("Sampling period in msec; default = " + Long.toString(sampInterval) + ".").build()); options.addOption(Option.builder("t").argName("trim time sec").hasArg().desc( "Trim (ring-buffer loop) time (sec); this is only used when writing data to local folder; specify 0 for indefinite; default = " + Double.toString(trimTime) + ".") .build()); options.addOption( Option.builder("w").argName("write mode").hasArg() .desc("Type of write connection; one of " + possibleWriteModes + "; all but UDP mode write out to CT; default = " + writeMode.name() + ".") .build()); options.addOption(Option.builder("host").argName("host[:port]").hasArg() .desc("Host:port when writing via FTP, HTTP, HTTPS, UDP.").build()); options.addOption(Option.builder("u").argName("username,password").hasArg() .desc("Comma-delimited username and password when writing to CT via FTP or HTTPS.").build()); options.addOption("x", "debug", false, "Enable CloudTurbine debug output."); // 2. Parse command line options CommandLineParser parser = new DefaultParser(); CommandLine line = null; try { line = parser.parse(options, args); } catch (ParseException exp) { // oops, something went wrong System.err.println("Command line argument parsing failed: " + exp.getMessage()); return; } // 3. Retrieve the command line values if (line.hasOption("help")) { // Display help message and quit HelpFormatter formatter = new HelpFormatter(); formatter.setWidth(120); formatter.printHelp("CTmousetrack", "", options, "NOTE: UDP output is a special non-CT output mode where single x,y points are sent via UDP to the specified host:port."); return; } outLoc = line.getOptionValue("o", outLoc); if (!outLoc.endsWith("\\") && !outLoc.endsWith("/")) { outLoc = outLoc + File.separator; } // Make sure the base output folder location ends in "CTdata" if (!outLoc.endsWith("CTdata\\") && !outLoc.endsWith("CTdata/")) { outLoc = outLoc + "CTdata" + File.separator; } srcName = line.getOptionValue("s", srcName); blockPts = Long.parseLong(line.getOptionValue("b", Long.toString(blockPts))); sampInterval = Long.parseLong(line.getOptionValue("dt", Long.toString(sampInterval))); trimTime = Double.parseDouble(line.getOptionValue("t", Double.toString(trimTime))); // Type of output connection String writeModeStr = line.getOptionValue("w", writeMode.name()); boolean bMatch = false; for (CTWriteMode wm : CTWriteMode.values()) { if (wm.name().toLowerCase().equals(writeModeStr.toLowerCase())) { writeMode = wm; bMatch = true; } } if (!bMatch) { System.err.println("Unrecognized write mode, \"" + writeModeStr + "\"; write mode must be one of " + possibleWriteModes); System.exit(0); } if (writeMode != CTWriteMode.LOCAL) { // User must have specified the host // If FTP or HTTPS, they may also specify username/password serverHost = line.getOptionValue("host", serverHost); if (serverHost.isEmpty()) { System.err.println( "When using write mode \"" + writeModeStr + "\", you must specify the server host."); System.exit(0); } if (writeMode == CTWriteMode.UDP) { // Force blockPts to be 1 blockPts = 1; // User must have specified both host and port int colonIdx = serverHost.indexOf(':'); if ((colonIdx == -1) || (colonIdx >= serverHost.length() - 1)) { System.err.println( "For UDP output mode, both the host and port (<host>:<port>)) must be specified."); System.exit(0); } udpHost = serverHost.substring(0, colonIdx); String udpPortStr = serverHost.substring(colonIdx + 1); try { udpPort = Integer.parseInt(udpPortStr); } catch (NumberFormatException nfe) { System.err.println("The UDP port must be a positive integer."); System.exit(0); } } if ((writeMode == CTWriteMode.FTP) || (writeMode == CTWriteMode.HTTPS)) { String userpassStr = line.getOptionValue("u", ""); if (!userpassStr.isEmpty()) { // This string should be comma-delimited username and password String[] userpassCSV = userpassStr.split(","); if (userpassCSV.length != 2) { System.err.println("When specifying a username and password for write mode \"" + writeModeStr + "\", separate the username and password by a comma."); System.exit(0); } serverUser = userpassCSV[0]; serverPassword = userpassCSV[1]; } } } debug = line.hasOption("debug"); System.err.println("CTmousetrack parameters:"); System.err.println("\toutput mode = " + writeMode.name()); if (writeMode == CTWriteMode.UDP) { System.err.println("\twrite to " + udpHost + ":" + udpPort); } else { System.err.println("\tsource = " + srcName); System.err.println("\ttrim time = " + trimTime + " sec"); } System.err.println("\tpoints per block = " + blockPts); System.err.println("\tsample interval = " + sampInterval + " msec"); try { // // Setup CTwriter or UDP output // CTwriter ctw = null; CTinfo.setDebug(debug); if (writeMode == CTWriteMode.LOCAL) { ctw = new CTwriter(outLoc + srcName, trimTime); System.err.println("\tdata will be written to local folder \"" + outLoc + "\""); } else if (writeMode == CTWriteMode.FTP) { CTftp ctftp = new CTftp(srcName); try { ctftp.login(serverHost, serverUser, serverPassword); } catch (Exception e) { throw new IOException( new String("Error logging into FTP server \"" + serverHost + "\":\n" + e.getMessage())); } ctw = ctftp; // upcast to CTWriter System.err.println("\tdata will be written to FTP server at " + serverHost); } else if (writeMode == CTWriteMode.HTTP) { // Don't send username/pw in HTTP mode since they will be unencrypted CThttp cthttp = new CThttp(srcName, "http://" + serverHost); ctw = cthttp; // upcast to CTWriter System.err.println("\tdata will be written to HTTP server at " + serverHost); } else if (writeMode == CTWriteMode.HTTPS) { CThttp cthttp = new CThttp(srcName, "https://" + serverHost); // Username/pw are optional for HTTPS mode; only use them if username is not empty if (!serverUser.isEmpty()) { try { cthttp.login(serverUser, serverPassword); } catch (Exception e) { throw new IOException(new String( "Error logging into HTTP server \"" + serverHost + "\":\n" + e.getMessage())); } } ctw = cthttp; // upcast to CTWriter System.err.println("\tdata will be written to HTTPS server at " + serverHost); } else if (writeMode == CTWriteMode.UDP) { try { udpServerSocket = new DatagramSocket(); } catch (SocketException se) { System.err.println("Error creating socket for UDP:\n" + se); System.exit(0); } try { udpServerAddress = InetAddress.getByName(udpHost); } catch (UnknownHostException uhe) { System.err.println("Error getting UDP server host address:\n" + uhe); System.exit(0); } } if (writeMode != CTWriteMode.UDP) { ctw.setBlockMode(blockPts > 1, blockPts > 1); ctw.autoFlush(0); // no autoflush ctw.autoSegment(1000); } // screen dims Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); double width = screenSize.getWidth(); double height = screenSize.getHeight(); // use Map for consolidated putData Map<String, Object> cmap = new LinkedHashMap<String, Object>(); // loop and write some output for (int i = 0; i < 1000000; i++) { // go until killed long currentTime = System.currentTimeMillis(); Point mousePos = MouseInfo.getPointerInfo().getLocation(); float x_pt = (float) (mousePos.getX() / width); // normalize float y_pt = (float) ((height - mousePos.getY()) / height); // flip Y (so bottom=0) if (writeMode != CTWriteMode.UDP) { // CT output mode ctw.setTime(currentTime); cmap.clear(); cmap.put("x", x_pt); cmap.put("y", y_pt); ctw.putData(cmap); if (((i + 1) % blockPts) == 0) { ctw.flush(); System.err.print("."); } } else { // UDP output mode // We force blockPts to be 1 for UDP output mode, i.e. we "flush" the data every time // Write the following data (21 bytes total): // header = "MOUSE", 5 bytes // current time, long, 8 bytes // 2 floats (x,y) 4 bytes each, 8 bytes int len = 21; ByteBuffer bb = ByteBuffer.allocate(len); String headerStr = "MOUSE"; bb.put(headerStr.getBytes("UTF-8")); bb.putLong(currentTime); bb.putFloat(x_pt); bb.putFloat(y_pt); // Might be able to use the following, but not sure: // byte[] sendData = bb.array(); byte[] sendData = new byte[len]; bb.position(0); bb.get(sendData, 0, len); DatagramPacket sendPacket = new DatagramPacket(sendData, sendData.length, udpServerAddress, udpPort); try { udpServerSocket.send(sendPacket); } catch (IOException e) { System.err.println("Test server caught exception trying to send data to UDP client:\n" + e); } System.err.print("."); } try { Thread.sleep(sampInterval); } catch (Exception e) { } ; } if (writeMode != CTWriteMode.UDP) { ctw.flush(); // wrap up } } catch (Exception e) { System.err.println("CTmousetrack exception: " + e); e.printStackTrace(); } }
From source file:data_gen.Data_gen.java
public static void main(String[] args) throws FileNotFoundException, IOException { long startTime = System.nanoTime(); if (args.length < 2) { System.out.println("Usage:"); System.out.println(/*from www . j a va 2 s. co m*/ "java -jar \"jarfile\" [Directory of text source folder] [Dierctory of configration file]" + "\n"); System.exit(0); } String Dir = args[0]; // get text source dir from user String config_dir = args[1]; File folder = new File(Dir); if (folder.isDirectory() == false) { System.out.println("Text souce folder is not a Directory." + "\n"); System.exit(0); } if (!config_dir.endsWith(".properties") && !config_dir.endsWith(".PROPERTIES")) { System.out.println("\n" + "There was error parsing dataset parameters from configuration file, make sure you have the 4 parameters specified and the right type of file" + "\n"); System.exit(0); } listOfFiles = folder.listFiles(new FilenameFilter() { @Override public boolean accept(File dir, String name) { return name.toLowerCase().endsWith(".txt"); } }); if (listOfFiles.length == 0) { System.out.println("Text source folder is empty ! Have at least one .txt file there" + "\n"); System.exit(0); } System.out.println("\n"); Parse_Document_values(config_dir);// parse config file to get class attribute values document_size = Docments_Total_size / documents_count; // to get each document size max = (long) ((double) document_size * 1.8); min = (long) ((double) document_size * 0.2); schema_fields = Parse_Document_fields(config_dir); try { LineIterator it = FileUtils.lineIterator(listOfFiles[0]); while (it.hasNext()) { tx.add(it.nextLine()); } } catch (NullPointerException | FileNotFoundException e) { System.out.println("The text source file could not be found." + "\n"); System.exit(0); } new File(output_dir).mkdir(); //////////////////////////////////////////////////////////////// build json or .dat //////////////////////////////////////////////////////////////////// if (Default_DataSet_name.endsWith(".json")) { Build_json_file(config_dir, startTime); } if (Default_DataSet_name.endsWith(".dat")) { Build_dat_file(config_dir, startTime); } generate_xml(); generate_field_map(); }