List of usage examples for java.util Arrays toString
public static String toString(Object[] a)
From source file:com.tamingtext.classifier.bayes.ClassifyDocument.java
public static void main(String[] args) { log.info("Command-line arguments: " + Arrays.toString(args)); DefaultOptionBuilder obuilder = new DefaultOptionBuilder(); ArgumentBuilder abuilder = new ArgumentBuilder(); GroupBuilder gbuilder = new GroupBuilder(); Option inputOpt = obuilder.withLongName("input").withRequired(true) .withArgument(abuilder.withName("input").withMinimum(1).withMaximum(1).create()) .withDescription("Input file").withShortName("i").create(); Option modelOpt = obuilder.withLongName("model").withRequired(true) .withArgument(abuilder.withName("model").withMinimum(1).withMaximum(1).create()) .withDescription("Model to use when classifying data").withShortName("m").create(); Option helpOpt = obuilder.withLongName("help").withDescription("Print out help").withShortName("h") .create();/* w w w . ja v a 2 s .co m*/ Group group = gbuilder.withName("Options").withOption(inputOpt).withOption(modelOpt).withOption(helpOpt) .create(); try { Parser parser = new Parser(); parser.setGroup(group); CommandLine cmdLine = parser.parse(args); if (cmdLine.hasOption(helpOpt)) { CommandLineUtil.printHelp(group); return; } File inputFile = new File(cmdLine.getValue(inputOpt).toString()); if (!inputFile.isFile()) { throw new IllegalArgumentException(inputFile + " does not exist or is not a file"); } File modelDir = new File(cmdLine.getValue(modelOpt).toString()); if (!modelDir.isDirectory()) { throw new IllegalArgumentException(modelDir + " does not exist or is not a directory"); } BayesParameters p = new BayesParameters(); p.set("basePath", modelDir.getCanonicalPath()); Datastore ds = new InMemoryBayesDatastore(p); Algorithm a = new BayesAlgorithm(); ClassifierContext ctx = new ClassifierContext(a, ds); ctx.initialize(); //TODO: make the analyzer configurable StandardAnalyzer analyzer = new StandardAnalyzer(Version.LUCENE_36); TokenStream ts = analyzer.tokenStream(null, new InputStreamReader(new FileInputStream(inputFile), "UTF-8")); ArrayList<String> tokens = new ArrayList<String>(1000); while (ts.incrementToken()) { tokens.add(ts.getAttribute(CharTermAttribute.class).toString()); } String[] document = tokens.toArray(new String[tokens.size()]); ClassifierResult[] cr = ctx.classifyDocument(document, "unknown", 5); for (ClassifierResult r : cr) { System.err.println(r.getLabel() + "\t" + r.getScore()); } } catch (OptionException e) { log.error("Exception", e); CommandLineUtil.printHelp(group); } catch (IOException e) { log.error("IOException", e); } catch (InvalidDatastoreException e) { log.error("InvalidDataStoreException", e); } finally { } }
From source file:edu.umd.ujjwalgoel.AnalyzePMI.java
@SuppressWarnings({ "static-access" }) public static void main(String[] args) { Options options = new Options(); options.addOption(OptionBuilder.withArgName("path").hasArg().withDescription("input path").create(INPUT)); CommandLine cmdline = null;/*from w w w.j av a2s . co m*/ CommandLineParser parser = new GnuParser(); try { cmdline = parser.parse(options, args); } catch (ParseException exp) { System.err.println("Error parsing command line: " + exp.getMessage()); System.exit(-1); } if (!cmdline.hasOption(INPUT)) { System.out.println("args: " + Arrays.toString(args)); HelpFormatter formatter = new HelpFormatter(); formatter.setWidth(120); formatter.printHelp(AnalyzePMI.class.getName(), options); ToolRunner.printGenericCommandUsage(System.out); System.exit(-1); } String inputPath = cmdline.getOptionValue(INPUT); System.out.println("input path: " + inputPath); BufferedReader br = null; int countPairs = 0; List<PairOfWritables<PairOfStrings, FloatWritable>> pmis = new ArrayList<PairOfWritables<PairOfStrings, FloatWritable>>(); List<PairOfWritables<PairOfStrings, FloatWritable>> cloudPmis = new ArrayList<PairOfWritables<PairOfStrings, FloatWritable>>(); List<PairOfWritables<PairOfStrings, FloatWritable>> lovePmis = new ArrayList<PairOfWritables<PairOfStrings, FloatWritable>>(); PairOfWritables<PairOfStrings, FloatWritable> highestPMI = null; PairOfWritables<PairOfStrings, FloatWritable> highestCloudPMI = null; PairOfWritables<PairOfStrings, FloatWritable> highestCloudPMI2 = null; PairOfWritables<PairOfStrings, FloatWritable> highestCloudPMI3 = null; PairOfWritables<PairOfStrings, FloatWritable> highestLovePMI = null; PairOfWritables<PairOfStrings, FloatWritable> highestLovePMI2 = null; PairOfWritables<PairOfStrings, FloatWritable> highestLovePMI3 = null; try { FileSystem fs = FileSystem.get(new Configuration()); FileStatus[] status = fs.listStatus(new Path(inputPath)); //PairOfStrings pair = new PairOfStrings(); for (int i = 0; i < status.length; i++) { br = new BufferedReader(new InputStreamReader(fs.open(status[i].getPath()))); String line = br.readLine(); while (line != null) { String[] words = line.split("\\t"); float value = Float.parseFloat(words[1].trim()); String[] wordPair = words[0].replaceAll("\\(", "").replaceAll("\\)", "").split(","); PairOfStrings pair = new PairOfStrings(); pair.set(wordPair[0].trim(), wordPair[1].trim()); if (wordPair[0].trim().equals("cloud")) { PairOfWritables<PairOfStrings, FloatWritable> cloudPmi = new PairOfWritables<PairOfStrings, FloatWritable>(); cloudPmi.set(pair, new FloatWritable(value)); cloudPmis.add(cloudPmi); if ((highestCloudPMI == null) || (highestCloudPMI.getRightElement().compareTo(cloudPmi.getRightElement()) < 0)) { highestCloudPMI = cloudPmi; } else if ((highestCloudPMI2 == null) || (highestCloudPMI2.getRightElement().compareTo(cloudPmi.getRightElement()) < 0)) { highestCloudPMI2 = cloudPmi; } else if ((highestCloudPMI3 == null) || (highestCloudPMI3.getRightElement().compareTo(cloudPmi.getRightElement()) < 0)) { highestCloudPMI3 = cloudPmi; } } if (wordPair[0].trim().equals("love")) { PairOfWritables<PairOfStrings, FloatWritable> lovePmi = new PairOfWritables<PairOfStrings, FloatWritable>(); lovePmi.set(pair, new FloatWritable(value)); lovePmis.add(lovePmi); if ((highestLovePMI == null) || (highestLovePMI.getRightElement().compareTo(lovePmi.getRightElement()) < 0)) { highestLovePMI = lovePmi; } else if ((highestLovePMI2 == null) || (highestLovePMI2.getRightElement().compareTo(lovePmi.getRightElement()) < 0)) { highestLovePMI2 = lovePmi; } else if ((highestLovePMI3 == null) || (highestLovePMI3.getRightElement().compareTo(lovePmi.getRightElement()) < 0)) { highestLovePMI3 = lovePmi; } } PairOfWritables<PairOfStrings, FloatWritable> pmi = new PairOfWritables<PairOfStrings, FloatWritable>(); pmi.set(pair, new FloatWritable(value)); pmis.add(pmi); if (highestPMI == null) { highestPMI = pmi; } else if (highestPMI.getRightElement().compareTo(pmi.getRightElement()) < 0) { highestPMI = pmi; } countPairs++; line = br.readLine(); } } } catch (Exception ex) { System.out.println("ERROR" + ex.getMessage()); } /*Collections.sort(pmis, new Comparator<PairOfWritables<PairOfStrings, FloatWritable>>() { public int compare(PairOfWritables<PairOfStrings, FloatWritable> e1, PairOfWritables<PairOfStrings, FloatWritable> e2) { /*if (e2.getRightElement().compareTo(e1.getRightElement()) == 0) { return e1.getLeftElement().getLeftElement().compareTo(e2.getLeftElement().getLeftElement()); } return e2.getRightElement().compareTo(e1.getRightElement()); } }); Collections.sort(cloudPmis, new Comparator<PairOfWritables<PairOfStrings, FloatWritable>>() { public int compare(PairOfWritables<PairOfStrings, FloatWritable> e1, PairOfWritables<PairOfStrings, FloatWritable> e2) { if (e2.getRightElement().compareTo(e1.getRightElement()) == 0) { return e1.getLeftElement().getLeftElement().compareTo(e2.getLeftElement().getLeftElement()); } return e2.getRightElement().compareTo(e1.getRightElement()); } }); Collections.sort(lovePmis, new Comparator<PairOfWritables<PairOfStrings, FloatWritable>>() { public int compare(PairOfWritables<PairOfStrings, FloatWritable> e1, PairOfWritables<PairOfStrings, FloatWritable> e2) { if (e2.getRightElement().compareTo(e1.getRightElement()) == 0) { return e1.getLeftElement().getLeftElement().compareTo(e2.getLeftElement().getLeftElement()); } return e2.getRightElement().compareTo(e1.getRightElement()); } }); PairOfWritables<PairOfStrings, FloatWritable> highestPMI = pmis.get(0); PairOfWritables<PairOfStrings, FloatWritable> highestCloudPMI = cloudPmis.get(0); PairOfWritables<PairOfStrings, FloatWritable> highestCloudPMI2 = cloudPmis.get(1); PairOfWritables<PairOfStrings, FloatWritable> highestCloudPMI3 = cloudPmis.get(2); PairOfWritables<PairOfStrings, FloatWritable> highestLovePMI = lovePmis.get(0); PairOfWritables<PairOfStrings, FloatWritable> highestLovePMI2 = lovePmis.get(1); PairOfWritables<PairOfStrings, FloatWritable> highestLovePMI3 = lovePmis.get(2);*/ System.out.println("Total Distinct Pairs : " + countPairs); System.out.println("Pair with highest PMI : (" + highestPMI.getLeftElement().getLeftElement() + ", " + highestPMI.getLeftElement().getRightElement()); System.out .println("Word with highest PMI with Cloud : " + highestCloudPMI.getLeftElement().getRightElement() + " with value : " + highestCloudPMI.getRightElement().get()); System.out.println( "Word with second highest PMI with Cloud : " + highestCloudPMI2.getLeftElement().getRightElement() + " with value : " + highestCloudPMI2.getRightElement().get()); System.out.println( "Word with third highest PMI with Cloud : " + highestCloudPMI3.getLeftElement().getRightElement() + " with value : " + highestCloudPMI3.getRightElement().get()); System.out.println("Word with highest PMI with Love : " + highestLovePMI.getLeftElement().getRightElement() + " with value : " + highestLovePMI.getRightElement().get()); System.out.println( "Word with second highest PMI with Love : " + highestLovePMI2.getLeftElement().getRightElement() + " with value : " + highestLovePMI2.getRightElement().get()); System.out.println( "Word with third highest PMI with Love : " + highestLovePMI3.getLeftElement().getRightElement() + " with value : " + highestLovePMI3.getRightElement().get()); }
From source file:examples.SubnetUtilsExample.java
public static void main(String[] args) { String subnet = "192.168.0.1/29"; SubnetUtils utils = new SubnetUtils(subnet); SubnetInfo info = utils.getInfo();//from w w w .j a v a 2 s.c o m System.out.printf("Subnet Information for %s:\n", subnet); System.out.println("--------------------------------------"); System.out.printf("IP Address:\t\t\t%s\t[%s]\n", info.getAddress(), Integer.toBinaryString(info.asInteger(info.getAddress()))); System.out.printf("Netmask:\t\t\t%s\t[%s]\n", info.getNetmask(), Integer.toBinaryString(info.asInteger(info.getNetmask()))); System.out.printf("CIDR Representation:\t\t%s\n\n", info.getCidrSignature()); System.out.printf("Supplied IP Address:\t\t%s\n\n", info.getAddress()); System.out.printf("Network Address:\t\t%s\t[%s]\n", info.getNetworkAddress(), Integer.toBinaryString(info.asInteger(info.getNetworkAddress()))); System.out.printf("Broadcast Address:\t\t%s\t[%s]\n", info.getBroadcastAddress(), Integer.toBinaryString(info.asInteger(info.getBroadcastAddress()))); System.out.printf("First Usable Address:\t\t%s\t[%s]\n", info.getLowAddress(), Integer.toBinaryString(info.asInteger(info.getLowAddress()))); System.out.printf("Last Usable Address:\t\t%s\t[%s]\n", info.getHighAddress(), Integer.toBinaryString(info.asInteger(info.getHighAddress()))); System.out.printf("Total usable addresses: \t%d\n", info.getAddressCount()); System.out.printf("Address List: %s\n\n", Arrays.toString(info.getAllAddresses())); final String prompt = "Enter an IP address (e.g. 192.168.0.10):"; System.out.println(prompt); Scanner scanner = new Scanner(System.in); while (scanner.hasNextLine()) { String address = scanner.nextLine(); System.out.println("The IP address [" + address + "] is " + (info.isInRange(address) ? "" : "not ") + "within the subnet [" + subnet + "]"); System.out.println(prompt); } }
From source file:examples.cidr.SubnetUtilsExample.java
public static void main(String[] args) { String subnet = "192.168.0.3/31"; SubnetUtils utils = new SubnetUtils(subnet); SubnetInfo info = utils.getInfo();//from w ww . ja v a 2s . c om System.out.printf("Subnet Information for %s:\n", subnet); System.out.println("--------------------------------------"); System.out.printf("IP Address:\t\t\t%s\t[%s]\n", info.getAddress(), Integer.toBinaryString(info.asInteger(info.getAddress()))); System.out.printf("Netmask:\t\t\t%s\t[%s]\n", info.getNetmask(), Integer.toBinaryString(info.asInteger(info.getNetmask()))); System.out.printf("CIDR Representation:\t\t%s\n\n", info.getCidrSignature()); System.out.printf("Supplied IP Address:\t\t%s\n\n", info.getAddress()); System.out.printf("Network Address:\t\t%s\t[%s]\n", info.getNetworkAddress(), Integer.toBinaryString(info.asInteger(info.getNetworkAddress()))); System.out.printf("Broadcast Address:\t\t%s\t[%s]\n", info.getBroadcastAddress(), Integer.toBinaryString(info.asInteger(info.getBroadcastAddress()))); System.out.printf("Low Address:\t\t\t%s\t[%s]\n", info.getLowAddress(), Integer.toBinaryString(info.asInteger(info.getLowAddress()))); System.out.printf("High Address:\t\t\t%s\t[%s]\n", info.getHighAddress(), Integer.toBinaryString(info.asInteger(info.getHighAddress()))); System.out.printf("Total usable addresses: \t%d\n", Integer.valueOf(info.getAddressCount())); System.out.printf("Address List: %s\n\n", Arrays.toString(info.getAllAddresses())); final String prompt = "Enter an IP address (e.g. 192.168.0.10):"; System.out.println(prompt); Scanner scanner = new Scanner(System.in); while (scanner.hasNextLine()) { String address = scanner.nextLine(); System.out.println("The IP address [" + address + "] is " + (info.isInRange(address) ? "" : "not ") + "within the subnet [" + subnet + "]"); System.out.println(prompt); } }
From source file:ArrayCreator.java
public static void main(String... args) { Matcher m = p.matcher(s);/* w w w. j a v a 2 s . c o m*/ if (m.find()) { String cName = m.group(1); String[] cVals = m.group(2).split("[\\s,]+"); int n = cVals.length; try { Class<?> c = Class.forName(cName); Object o = Array.newInstance(c, n); for (int i = 0; i < n; i++) { String v = cVals[i]; Constructor ctor = c.getConstructor(String.class); Object val = ctor.newInstance(v); Array.set(o, i, val); } Object[] oo = (Object[]) o; out.format("%s[] = %s%n", cName, Arrays.toString(oo)); // production code should handle these exceptions more gracefully } catch (ClassNotFoundException x) { x.printStackTrace(); } catch (NoSuchMethodException x) { x.printStackTrace(); } catch (IllegalAccessException x) { x.printStackTrace(); } catch (InstantiationException x) { x.printStackTrace(); } catch (InvocationTargetException x) { x.printStackTrace(); } } }
From source file:QuickSort.java
/** * @param args/*w w w.j a va 2s. com*/ */ public static void main(String[] args) { Integer[] array = new Integer[15]; Random rng = new Random(); int split = 10; for (int i = 0; i < split; i++) { array[i] = new Integer(rng.nextInt(100)); } for (int i = split; i < array.length; i++) { array[i] = null; } System.out.println(Arrays.toString(array)); QuickSort.sort(array, new Comparator<Integer>() { @Override public int compare(Integer o1, Integer o2) { return o1.compareTo(o2); }; }, 0, split - 1); System.out.println(Arrays.toString(array)); }
From source file:com.flipkart.poseidon.serviceclients.generator.Generator.java
public static void main(String[] args) throws Exception { if (!validateInput(args)) { printUsage();/*from w ww. java 2 s . c o m*/ System.exit(-1); } logger.info("Using module parent path: {}", moduleParentPath); logger.info("Using module path: {}", modulePath); logger.info("Using module name: {}", moduleName); logger.info("Using version: {}", version); if (pojoOrdering != null && pojoOrdering.length > 0) { logger.info("Using pojo ordering: {}", Arrays.toString(pojoOrdering)); } ensurePaths(); generate(); }
From source file:ezbake.local.accumulo.LocalAccumulo.java
public static void main(String args[]) throws Exception { Logger logger = LoggerFactory.getLogger(LocalAccumulo.class); final File accumuloDirectory = Files.createTempDir(); int shutdownPort = 4445; MiniAccumuloConfig config = new MiniAccumuloConfig(accumuloDirectory, "strongpassword"); config.setZooKeeperPort(12181);/*from ww w .ja v a2s .c o m*/ final MiniAccumuloCluster accumulo = new MiniAccumuloCluster(config); Runtime.getRuntime().addShutdownHook(new Thread() { @Override public void run() { try { accumulo.stop(); FileUtils.deleteDirectory(accumuloDirectory); System.out.println("\nShut down gracefully on " + new Date()); } catch (IOException e) { e.printStackTrace(); } catch (InterruptedException e) { e.printStackTrace(); } } }); accumulo.start(); printInfo(accumulo, shutdownPort); if (args.length > 0) { logger.info("Adding the following authorizations: {}", Arrays.toString(args)); Authorizations auths = new Authorizations(args); Instance inst = new ZooKeeperInstance(accumulo.getConfig().getInstanceName(), accumulo.getZooKeepers()); Connector client = inst.getConnector("root", new PasswordToken(accumulo.getConfig().getRootPassword())); logger.info("Connected..."); client.securityOperations().changeUserAuthorizations("root", auths); logger.info("Auths updated"); } // start a socket on the shutdown port and block- anything connected to this port will activate the shutdown ServerSocket shutdownServer = new ServerSocket(shutdownPort); shutdownServer.accept(); System.exit(0); }
From source file:com.tamingtext.classifier.bayes.ExtractTrainingData.java
public static void main(String[] args) { log.info("Command-line arguments: " + Arrays.toString(args)); DefaultOptionBuilder obuilder = new DefaultOptionBuilder(); ArgumentBuilder abuilder = new ArgumentBuilder(); GroupBuilder gbuilder = new GroupBuilder(); Option inputOpt = obuilder.withLongName("dir").withRequired(true) .withArgument(abuilder.withName("dir").withMinimum(1).withMaximum(1).create()) .withDescription("Lucene index directory containing input data").withShortName("d").create(); Option categoryOpt = obuilder.withLongName("categories").withRequired(true) .withArgument(abuilder.withName("file").withMinimum(1).withMaximum(1).create()) .withDescription("File containing a list of categories").withShortName("c").create(); Option outputOpt = obuilder.withLongName("output").withRequired(false) .withArgument(abuilder.withName("output").withMinimum(1).withMaximum(1).create()) .withDescription("Output directory").withShortName("o").create(); Option categoryFieldsOpt = obuilder.withLongName("category-fields").withRequired(true) .withArgument(abuilder.withName("fields").withMinimum(1).withMaximum(1).create()) .withDescription("Fields to match categories against (comma-delimited)").withShortName("cf") .create();//from w w w . ja va2s . co m Option textFieldsOpt = obuilder.withLongName("text-fields").withRequired(true) .withArgument(abuilder.withName("fields").withMinimum(1).withMaximum(1).create()) .withDescription("Fields from which to extract training text (comma-delimited)").withShortName("tf") .create(); Option useTermVectorsOpt = obuilder.withLongName("use-term-vectors").withDescription( "Extract term vectors containing preprocessed data " + "instead of unprocessed, stored text values") .withShortName("tv").create(); Option helpOpt = obuilder.withLongName("help").withDescription("Print out help").withShortName("h") .create(); Group group = gbuilder.withName("Options").withOption(inputOpt).withOption(categoryOpt) .withOption(outputOpt).withOption(categoryFieldsOpt).withOption(textFieldsOpt) .withOption(useTermVectorsOpt).create(); try { Parser parser = new Parser(); parser.setGroup(group); CommandLine cmdLine = parser.parse(args); if (cmdLine.hasOption(helpOpt)) { CommandLineUtil.printHelp(group); return; } File inputDir = new File(cmdLine.getValue(inputOpt).toString()); if (!inputDir.isDirectory()) { throw new IllegalArgumentException(inputDir + " does not exist or is not a directory"); } File categoryFile = new File(cmdLine.getValue(categoryOpt).toString()); if (!categoryFile.isFile()) { throw new IllegalArgumentException(categoryFile + " does not exist or is not a directory"); } File outputDir = new File(cmdLine.getValue(outputOpt).toString()); outputDir.mkdirs(); if (!outputDir.isDirectory()) { throw new IllegalArgumentException(outputDir + " is not a directory or could not be created"); } Collection<String> categoryFields = stringToList(cmdLine.getValue(categoryFieldsOpt).toString()); if (categoryFields.size() < 1) { throw new IllegalArgumentException("At least one category field must be spcified."); } Collection<String> textFields = stringToList(cmdLine.getValue(textFieldsOpt).toString()); if (categoryFields.size() < 1) { throw new IllegalArgumentException("At least one text field must be spcified."); } boolean useTermVectors = cmdLine.hasOption(useTermVectorsOpt); extractTraininingData(inputDir, categoryFile, categoryFields, textFields, outputDir, useTermVectors); } catch (OptionException e) { log.error("Exception", e); CommandLineUtil.printHelp(group); } catch (IOException e) { log.error("IOException", e); } finally { closeWriters(); } }
From source file:com.github.benchdoos.weblocopener.updater.core.Main.java
public static void main(String[] args) { try {//from w w w .j a va 2s . c o m new Logging(ApplicationConstants.UPDATER_APPLICATION_NAME); log = Logger.getLogger(Logging.getCurrentClassName()); SystemUtils.checkIfSystemIsSupported(); enableLookAndFeel(); tryLoadProperties(); System.out.println("Updater args: " + Arrays.toString(args)); manageArguments(args); } catch (UnsupportedOsSystemException | UnsupportedSystemVersionException e) { UserUtils.showErrorMessageToUser(null, "Error", e.getMessage()); } }