List of usage examples for java.util List add
boolean add(E e);
From source file:com.actelion.research.spiritcore.util.StatUtils.java
public static void main(String[] args) { // List<Double> list = new ArrayList<Double>(); //// list.add(30d); list.add(171d); list.add(184d); list.add(201d); list.add(212d); list.add(250d); list.add(265d); list.add(270d); list.add(272d); list.add(289d); list.add(305d); list.add(306d); list.add(322d); list.add(322d); list.add(336d); list.add(346d); list.add(351d); list.add(370d); list.add(390d); list.add(404d); list.add(409d); list.add(411d); list.add(436d); list.add(437d); list.add(439d); list.add(441d); list.add(444d); list.add(448d); list.add(451d); list.add(453d); list.add(470d); list.add(480d); list.add(482d); list.add(487d); list.add(494d); list.add(495d); list.add(499d); list.add(503d); list.add(514d); list.add(521d); list.add(522d); list.add(527d); list.add(548d); list.add(550d); list.add(559d); list.add(560d); list.add(570d); list.add(572d); list.add(574d); list.add(578d); list.add(585d); list.add(592d); list.add(592d); list.add(607d); list.add(616d); list.add(618d); list.add(621d); list.add(629d); list.add(637d); list.add(638d); list.add(640d); list.add(656d); list.add(668d); list.add(707d); list.add(709d); list.add(719d); list.add(737d); list.add(739d); list.add(752d); list.add(758d); list.add(766d); list.add(792d); list.add(792d); list.add(794d); list.add(802d); list.add(818d); list.add(830d); list.add(832d); list.add(843d); list.add(858d); list.add(860d); list.add(869d); list.add(918d); list.add(925d); list.add(953d); list.add(991d); list.add(1000d); list.add(1005d); list.add(1068d); list.add(1441d); // list.add(0.0); list.add(156.0); list.add(156.0); list.add(161.0); list.add(176.0); // /*from w w w . j ava 2s. com*/ // double[] fences = getFences(list); // System.out.println("median="+getMedian(list)); // System.out.println("std="+getStandardDeviationOfMean(list)); // System.out.println("fences="+Arrays.toString(fences)); int count = 0; int N = 1000; for (int t = 0; t < N; t++) { List<double[]> doubles = new ArrayList<double[]>(); for (int i = 0; i < 3; i++) { double[] array = new double[10]; doubles.add(array); for (int j = 0; j < array.length; j++) { array[j] = Math.random() * 10;// i<2 || j<10? j: j+100; } } double r = getKruskalWallis(doubles); if (r < 0.05) count++; System.out.println("[" + t + "] KW=" + r); } System.out.println("==> percentage of false positive " + (1.0 * count / N) + " ~ 0.05"); }
From source file:org.openbaton.monitoring.interfaces.MonitoringPluginCaller.java
public static void main(String[] args) throws IOException, TimeoutException, NotFoundException, ExecutionException, InterruptedException { ExecutorService executor = Executors.newFixedThreadPool(3); class Exec implements Callable<Object> { @Override/*from www . ja v a 2 s . co m*/ public Object call() throws Exception { List<String> hosts = new ArrayList<>(); hosts.add("hostname1"); hosts.add("hostname2"); return null /* new MonitoringPluginCaller("zabbix").getMeasurementResults(hosts, new ArrayList<String>(), "")*/; } } long time = new Date().getTime(); System.out.println("Time ---> " + time); Future fut1 = executor.submit(new Exec()); Future fut2 = executor.submit(new Exec()); System.out.println("2nd call"); System.out.println(fut2.get()); System.out.println("1st call"); System.out.println(fut1.get()); System.out.println("Time ---> " + (new Date().getTime() - time) / 1000); }
From source file:io.druid.examples.rabbitmq.RabbitMQProducerMain.java
public static void main(String[] args) throws Exception { // We use a List to keep track of option insertion order. See below. final List<Option> optionList = new ArrayList<Option>(); optionList.add(OptionBuilder.withLongOpt("help").withDescription("display this help message").create("h")); optionList.add(OptionBuilder.withLongOpt("hostname").hasArg() .withDescription("the hostname of the AMQP broker [defaults to AMQP library default]").create("b")); optionList.add(OptionBuilder.withLongOpt("port").hasArg() .withDescription("the port of the AMQP broker [defaults to AMQP library default]").create("n")); optionList.add(OptionBuilder.withLongOpt("username").hasArg() .withDescription("username to connect to the AMQP broker [defaults to AMQP library default]") .create("u")); optionList.add(OptionBuilder.withLongOpt("password").hasArg() .withDescription("password to connect to the AMQP broker [defaults to AMQP library default]") .create("p")); optionList.add(OptionBuilder.withLongOpt("vhost").hasArg() .withDescription("name of virtual host on the AMQP broker [defaults to AMQP library default]") .create("v")); optionList.add(OptionBuilder.withLongOpt("exchange").isRequired().hasArg() .withDescription("name of the AMQP exchange [required - no default]").create("e")); optionList.add(OptionBuilder.withLongOpt("key").hasArg() .withDescription("the routing key to use when sending messages [default: 'default.routing.key']") .create("k")); optionList.add(OptionBuilder.withLongOpt("type").hasArg() .withDescription("the type of exchange to create [default: 'topic']").create("t")); optionList.add(OptionBuilder.withLongOpt("durable") .withDescription("if set, a durable exchange will be declared [default: not set]").create("d")); optionList.add(OptionBuilder.withLongOpt("autodelete") .withDescription("if set, an auto-delete exchange will be declared [default: not set]") .create("a")); optionList.add(OptionBuilder.withLongOpt("single") .withDescription("if set, only a single message will be sent [default: not set]").create("s")); optionList.add(OptionBuilder.withLongOpt("start").hasArg() .withDescription("time to use to start sending messages from [default: 2010-01-01T00:00:00]") .create());/*from w w w . j a v a 2 s. c o m*/ optionList.add(OptionBuilder.withLongOpt("stop").hasArg().withDescription( "time to use to send messages until (format: '2013-07-18T23:45:59') [default: current time]") .create()); optionList.add(OptionBuilder.withLongOpt("interval").hasArg() .withDescription("the interval to add to the timestamp between messages in seconds [default: 10]") .create()); optionList.add(OptionBuilder.withLongOpt("delay").hasArg() .withDescription("the delay between sending messages in milliseconds [default: 100]").create()); // An extremely silly hack to maintain the above order in the help formatting. HelpFormatter formatter = new HelpFormatter(); // Add a comparator to the HelpFormatter using the ArrayList above to sort by insertion order. formatter.setOptionComparator(new Comparator() { @Override public int compare(Object o1, Object o2) { // I know this isn't fast, but who cares! The list is short. return optionList.indexOf(o1) - optionList.indexOf(o2); } }); // Now we can add all the options to an Options instance. This is dumb! Options options = new Options(); for (Option option : optionList) { options.addOption(option); } CommandLine cmd = null; try { cmd = new BasicParser().parse(options, args); } catch (ParseException e) { formatter.printHelp("RabbitMQProducerMain", e.getMessage(), options, null); System.exit(1); } if (cmd.hasOption("h")) { formatter.printHelp("RabbitMQProducerMain", options); System.exit(2); } ConnectionFactory factory = new ConnectionFactory(); if (cmd.hasOption("b")) { factory.setHost(cmd.getOptionValue("b")); } if (cmd.hasOption("u")) { factory.setUsername(cmd.getOptionValue("u")); } if (cmd.hasOption("p")) { factory.setPassword(cmd.getOptionValue("p")); } if (cmd.hasOption("v")) { factory.setVirtualHost(cmd.getOptionValue("v")); } if (cmd.hasOption("n")) { factory.setPort(Integer.parseInt(cmd.getOptionValue("n"))); } String exchange = cmd.getOptionValue("e"); String routingKey = "default.routing.key"; if (cmd.hasOption("k")) { routingKey = cmd.getOptionValue("k"); } boolean durable = cmd.hasOption("d"); boolean autoDelete = cmd.hasOption("a"); String type = cmd.getOptionValue("t", "topic"); boolean single = cmd.hasOption("single"); int interval = Integer.parseInt(cmd.getOptionValue("interval", "10")); int delay = Integer.parseInt(cmd.getOptionValue("delay", "100")); SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss"); Date stop = sdf.parse(cmd.getOptionValue("stop", sdf.format(new Date()))); Random r = new Random(); Calendar timer = Calendar.getInstance(); timer.setTime(sdf.parse(cmd.getOptionValue("start", "2010-01-01T00:00:00"))); String msg_template = "{\"utcdt\": \"%s\", \"wp\": %d, \"gender\": \"%s\", \"age\": %d}"; Connection connection = factory.newConnection(); Channel channel = connection.createChannel(); channel.exchangeDeclare(exchange, type, durable, autoDelete, null); do { int wp = (10 + r.nextInt(90)) * 100; String gender = r.nextBoolean() ? "male" : "female"; int age = 20 + r.nextInt(70); String line = String.format(msg_template, sdf.format(timer.getTime()), wp, gender, age); channel.basicPublish(exchange, routingKey, null, line.getBytes()); System.out.println("Sent message: " + line); timer.add(Calendar.SECOND, interval); Thread.sleep(delay); } while ((!single && stop.after(timer.getTime()))); connection.close(); }
From source file:com.act.analysis.surfactant.AnalysisDriver.java
public static void main(String[] args) throws Exception { Options opts = new Options(); for (Option.Builder b : OPTION_BUILDERS) { opts.addOption(b.build());/* ww w .ja va 2s .co m*/ } CommandLine cl = null; try { CommandLineParser parser = new DefaultParser(); cl = parser.parse(opts, args); } catch (ParseException e) { System.err.format("Argument parsing failed: %s\n", e.getMessage()); HELP_FORMATTER.printHelp(LoadPlateCompositionIntoDB.class.getCanonicalName(), HELP_MESSAGE, opts, null, true); System.exit(1); } if (cl.hasOption("help")) { HELP_FORMATTER.printHelp(LoadPlateCompositionIntoDB.class.getCanonicalName(), HELP_MESSAGE, opts, null, true); return; } Set<String> seenOutputIds = new HashSet<>(); TSVWriter<String, String> tsvWriter = null; if (cl.hasOption(OPTION_OUTPUT_FILE)) { File outputFile = new File(cl.getOptionValue(OPTION_OUTPUT_FILE)); List<Map<String, String>> oldResults = null; if (outputFile.exists()) { System.err.format( "Output file already exists, reading old results and skipping processed molecules.\n"); TSVParser outputParser = new TSVParser(); outputParser.parse(outputFile); oldResults = outputParser.getResults(); for (Map<String, String> row : oldResults) { // TODO: verify that the last row was written cleanly/completely. seenOutputIds.add(row.get("id")); } } List<String> header = new ArrayList<>(); header.add("name"); header.add("id"); header.add("inchi"); header.add("label"); for (SurfactantAnalysis.FEATURES f : SurfactantAnalysis.FEATURES.values()) { header.add(f.toString()); } // TODO: make this API more auto-closable friendly. tsvWriter = new TSVWriter<>(header); tsvWriter.open(outputFile); if (oldResults != null) { System.out.format("Re-writing %d existing result rows\n", oldResults.size()); tsvWriter.append(oldResults); } } try { Map<SurfactantAnalysis.FEATURES, Double> analysisFeatures; LicenseManager.setLicenseFile(cl.getOptionValue(OPTION_LICENSE_FILE)); if (cl.hasOption(OPTION_INCHI)) { analysisFeatures = SurfactantAnalysis.performAnalysis(cl.getOptionValue(OPTION_INCHI), cl.hasOption(OPTION_DISPLAY)); Map<String, String> tsvFeatures = new HashMap<>(); // Convert features to strings to avoid some weird formatting issues. It's ugly, but it works. for (Map.Entry<SurfactantAnalysis.FEATURES, Double> entry : analysisFeatures.entrySet()) { tsvFeatures.put(entry.getKey().toString(), String.format("%.6f", entry.getValue())); } tsvFeatures.put("name", "direct-inchi-input"); if (tsvWriter != null) { tsvWriter.append(tsvFeatures); } } else if (cl.hasOption(OPTION_INPUT_FILE)) { TSVParser parser = new TSVParser(); parser.parse(new File(cl.getOptionValue(OPTION_INPUT_FILE))); int i = 0; List<Map<String, String>> inputRows = parser.getResults(); for (Map<String, String> row : inputRows) { i++; // Just for warning messages. if (!row.containsKey("name") || !row.containsKey("id") || !row.containsKey("inchi")) { System.err.format( "WARNING: TSV rows must contain at least name, id, and inchi, skipping row %d\n", i); continue; } if (seenOutputIds.contains(row.get("id"))) { System.out.format("Skipping input row with id already in output: %s\n", row.get("id")); continue; } System.out.format("Analysis for chemical %s\n", row.get("name")); try { analysisFeatures = SurfactantAnalysis.performAnalysis(row.get("inchi"), false); } catch (Exception e) { // Ignore exceptions for now. Sometimes the regression analysis or Chemaxon processing chokes unexpectedly. System.err.format("ERROR caught exception while processing '%s':\n", row.get("name")); System.err.format("%s\n", e.getMessage()); e.printStackTrace(System.err); System.err.println("Skipping..."); continue; } System.out.format("--- Done analysis for chemical %s\n", row.get("name")); // This is a duplicate of the OPTION_INCHI block code, but it's inside of a tight loop, so... Map<String, String> tsvFeatures = new HashMap<>(); for (Map.Entry<SurfactantAnalysis.FEATURES, Double> entry : analysisFeatures.entrySet()) { tsvFeatures.put(entry.getKey().toString(), String.format("%.6f", entry.getValue())); } tsvFeatures.put("name", row.get("name")); tsvFeatures.put("id", row.get("id")); tsvFeatures.put("inchi", row.get("inchi")); tsvFeatures.put("label", row.containsKey("label") ? row.get("label") : "?"); if (tsvWriter != null) { tsvWriter.append(tsvFeatures); // Flush every time in case we crash or get interrupted. The features must flow! tsvWriter.flush(); } } } else { throw new RuntimeException("Must specify inchi or input file"); } } finally { if (tsvWriter != null) { tsvWriter.close(); } } }
From source file:com.yahoo.spaclu.data.extract.ExtractFeatureSpark.java
public static void main(String[] args) throws IOException { ExtractFeatureOptions optionsFormatRawToDatabase = new ExtractFeatureOptions(args); String inputPathString = optionsFormatRawToDatabase.getInputPath(); String outputPathString = optionsFormatRawToDatabase.getOutputPath(); // String indexPathString = optionsFormatRawToDatabase.getIndexPath(); int numberOfPartitions = optionsFormatRawToDatabase.getNumberOfPartitions(); // int maxCutoffThreshold = optionsFormatRawToDatabase // .getMaximumCutoffThreshold(); // int minCutoffThreshold = optionsFormatRawToDatabase // .getMinimumCutoffThreshold(); /*//from ww w .j av a2 s . c o m * Set<String> excludingFeatureNames = new HashSet<String>(); * excludingFeatureNames.add("login"); * excludingFeatureNames.add("time"); excludingFeatureNames.add("day"); * excludingFeatureNames.add("hms"); excludingFeatureNames.add("fail"); */ sLogger.info("Tool: " + ExtractFeatureSpark.class.getSimpleName()); sLogger.info(" - input path: " + inputPathString); sLogger.info(" - output path: " + outputPathString); // sLogger.info(" - index path: " + indexPathString); sLogger.info(" - number of partitions: " + numberOfPartitions); // sLogger.info(" - maximum cutoff: " + maxCutoffThreshold); // sLogger.info(" - minimum cutoff: " + minCutoffThreshold); // Create a default hadoop configuration Configuration conf = new Configuration(); // Parse created config to the HDFS FileSystem fs = FileSystem.get(conf); Path outputPath = new Path(outputPathString); if (fs.exists(outputPath)) { fs.delete(outputPath, true); } SparkConf sparkConf = new SparkConf().setAppName(optionsFormatRawToDatabase.toString()); JavaSparkContext sc = new JavaSparkContext(sparkConf); List<Integer> listOfFeatureIndices = new LinkedList<Integer>(); listOfFeatureIndices.add(CBBingCombinedFields.CBBingCombined_exactCanonicalQuery.ordinal()); listOfFeatureIndices.add(CBBingCombinedFields.CBBingCombined_title.ordinal()); listOfFeatureIndices.add(CBBingCombinedFields.CBBingCombined_description.ordinal()); listOfFeatureIndices.add(CBBingCombinedFields.CBBingCombined_displayUrl.ordinal()); listOfFeatureIndices.add(CBBingCombinedFields.CBBingCombined_targetUrl.ordinal()); JavaRDD<String> rawLines = sc.textFile(inputPathString).repartition(numberOfPartitions); JavaRDD<String> tokenizedLines = rawLines.map(new LineFilter(listOfFeatureIndices)); tokenizedLines.saveAsTextFile(outputPathString); /* * Iterator<String[]> strArrIter = tokenizedLines.collect().iterator(); * while(strArrIter.hasNext()){ * sLogger.info(Arrays.toString(strArrIter.next())); } */ sc.stop(); }
From source file:com.l2jfree.tools.ProjectSettingsSynchronizer.java
public static void main(String[] args) throws IOException { final File src = new File(".").getCanonicalFile(); System.out.println("Copying from: " + src); System.out.println();/* ww w .j ava2 s.c o m*/ final List<File> destinations = new ArrayList<File>(); for (File dest : src.getParentFile().listFiles()) { if (dest.isHidden() || !dest.isDirectory()) continue; destinations.add(dest); System.out.println("Copying to: " + dest); } System.out.println(); // .project System.out.println(".project"); System.out.println("================================================================================"); { final List<String> lines = FileUtils.readLines(new File(src, ".project")); for (File dest : destinations) { lines.set(2, lines.get(2).replaceAll(src.getName(), dest.getName())); writeLines(dest, ".project", lines); lines.set(2, lines.get(2).replaceAll(dest.getName(), src.getName())); } } System.out.println(); // .classpath System.out.println(".classpath"); System.out.println("================================================================================"); { final List<String> lines = FileUtils.readLines(new File(src, ".classpath")); for (File dest : destinations) { if (dest.getName().endsWith("-main") || dest.getName().endsWith("-datapack")) { final ArrayList<String> tmp = new ArrayList<String>(); for (String line : lines) if (!line.contains("classpathentry")) tmp.add(line); writeLines(dest, ".classpath", tmp); continue; } writeLines(dest, ".classpath", lines); } } System.out.println(); // .settings System.out.println(".settings"); System.out.println("================================================================================"); for (File settingsFile : new File(src, ".settings").listFiles()) { if (settingsFile.getName().endsWith(".prefs")) { System.out.println(".settings/" + settingsFile.getName()); System.out.println( "--------------------------------------------------------------------------------"); final List<String> lines = FileUtils.readLines(settingsFile); if (lines.get(0).startsWith("#")) lines.remove(0); for (File dest : destinations) { writeLines(new File(dest, ".settings"), settingsFile.getName(), lines); } System.out.println(); } } System.out.println(); }
From source file:com.boonya.http.async.examples.nio.client.AsyncClientPipelinedStreaming.java
public static void main(final String[] args) throws Exception { CloseableHttpPipeliningClient httpclient = HttpAsyncClients.createPipelining(); try {/*from w w w . j av a 2 s .co m*/ httpclient.start(); HttpHost targetHost = new HttpHost("localhost", 8080); HttpGet[] resquests = { new HttpGet("/docs/index.html"), new HttpGet("/docs/introduction.html"), new HttpGet("/docs/setup.html"), new HttpGet("/docs/config/index.html") }; List<MyRequestProducer> requestProducers = new ArrayList<MyRequestProducer>(); List<MyResponseConsumer> responseConsumers = new ArrayList<MyResponseConsumer>(); for (HttpGet request : resquests) { requestProducers.add(new MyRequestProducer(targetHost, request)); responseConsumers.add(new MyResponseConsumer(request)); } Future<List<Boolean>> future = httpclient.execute(targetHost, requestProducers, responseConsumers, null); future.get(); System.out.println("Shutting down"); } finally { httpclient.close(); } System.out.println("Done"); }
From source file:net.padaf.xmpbox.parser.XMLValueTypeDescriptionManager.java
/** * Sample of using to write/read information * //from w w w .java2 s .c o m * @param args * not used * @throws BuildPDFAExtensionSchemaDescriptionException * When errors during building/reading xml file */ public static void main(String[] args) throws BuildPDFAExtensionSchemaDescriptionException { XMLValueTypeDescriptionManager vtMaker = new XMLValueTypeDescriptionManager(); // add Descriptions for (int i = 0; i < 3; i++) { vtMaker.addValueTypeDescription("testType" + i, "nsURI" + i, "prefix" + i, "description" + i); } List<FieldDescription> fieldSample = new ArrayList<FieldDescription>(); for (int i = 0; i < 2; i++) { fieldSample.add(new FieldDescription("fieldName" + i, "valueType" + i, "description" + i)); } vtMaker.addValueTypeDescription("testTypeField", "http://test.withfield.com/vt/", "prefTest", " value type description", fieldSample); // Display XML conversion System.out.println("Display XML Result:"); vtMaker.toXML(System.out); // Sample to show how to build object from XML file ByteArrayOutputStream bos = new ByteArrayOutputStream(); vtMaker.toXML(bos); IOUtils.closeQuietly(bos); // emulate a new reading InputStream is = new ByteArrayInputStream(bos.toByteArray()); vtMaker = new XMLValueTypeDescriptionManager(); vtMaker.loadListFromXML(is); List<ValueTypeDescription> result = vtMaker.getValueTypesDescriptionList(); System.out.println(); System.out.println(); System.out.println("Result of XML Loading :"); for (ValueTypeDescription propertyDescription : result) { System.out.println(propertyDescription.getType() + " :" + propertyDescription.getDescription()); if (propertyDescription.getFields() != null) { Iterator<FieldDescription> fit = propertyDescription.getFields().iterator(); FieldDescription field; while (fit.hasNext()) { field = fit.next(); System.out.println("Field " + field.getName() + " :" + field.getValueType()); } } } }
From source file:com.twentyn.chemicalClassifier.Runner.java
public static void main(String[] args) throws Exception { BufferedReader reader = new BufferedReader(new FileReader(args[0])); BufferedWriter writer = new BufferedWriter(new FileWriter(args[1])); try {/*from w ww . j ava 2 s .c om*/ Oscar oscar = new Oscar(); String line = null; /* NOTE: this is exactly the wrong way to write a TSV reader. Caveat emptor. * See http://tburette.github.io/blog/2014/05/25/so-you-want-to-write-your-own-CSV-code/ * and then use org.apache.commons.csv.CSVParser instead. */ while ((line = reader.readLine()) != null) { // TSV means split on tabs! Nothing else will do. List<String> fields = Arrays.asList(line.split("\t")); // Choke if our invariants aren't satisfied. We expect ever line to have a name and an InChI. if (fields.size() != 2) { throw new RuntimeException( String.format("Found malformed line (all lines must have two fields: %s", line)); } String name = fields.get(1); List<ResolvedNamedEntity> entities = oscar.findAndResolveNamedEntities(name); System.out.println("**********"); System.out.println("Name: " + name); List<String> outputFields = new ArrayList<>(fields.size() + 1); outputFields.addAll(fields); if (entities.size() == 0) { System.out.println("No match"); outputFields.add("noMatch"); } else if (entities.size() == 1) { ResolvedNamedEntity entity = entities.get(0); NamedEntity ne = entity.getNamedEntity(); if (ne.getStart() != 0 || ne.getEnd() != name.length()) { System.out.println("Partial match"); printEntity(entity); outputFields.add("partialMatch"); } else { System.out.println("Exact match"); printEntity(entity); outputFields.add("exactMatch"); List<ChemicalStructure> structures = entity.getChemicalStructures(FormatType.STD_INCHI); for (ChemicalStructure s : structures) { outputFields.add(s.getValue()); } } } else { // Multiple matches found! System.out.println("Multiple matches"); for (ResolvedNamedEntity e : entities) { printEntity(e); } outputFields.add("multipleMatches"); } writer.write(String.join("\t", outputFields)); writer.newLine(); } } finally { writer.flush(); writer.close(); } }
From source file:gr.demokritos.iit.demos.Demo.java
public static void main(String[] args) { try {/*from w ww .jav a2 s .c om*/ Options options = new Options(); options.addOption("h", HELP, false, "show help."); options.addOption("i", INPUT, true, "The file containing JSON " + " representations of tweets or SAG posts - 1 per line" + " default file looked for is " + DEFAULT_INFILE); options.addOption("o", OUTPUT, true, "Where to write the output " + " default file looked for is " + DEFAULT_OUTFILE); options.addOption("p", PROCESS, true, "Type of processing to do " + " ner for Named Entity Recognition re for Relation Extraction" + " default is NER"); options.addOption("s", SAG, false, "Whether to process as SAG posts" + " default is off - if passed means process as SAG posts"); CommandLineParser parser = new BasicParser(); CommandLine cmd = parser.parse(options, args); // DEFAULTS String filename = DEFAULT_INFILE; String outfilename = DEFAULT_OUTFILE; String process = NER; boolean isSAG = false; if (cmd.hasOption(HELP)) { HelpFormatter formatter = new HelpFormatter(); formatter.printHelp("NER + RE extraction module", options); System.exit(0); } if (cmd.hasOption(INPUT)) { filename = cmd.getOptionValue(INPUT); } if (cmd.hasOption(OUTPUT)) { outfilename = cmd.getOptionValue(OUTPUT); } if (cmd.hasOption(SAG)) { isSAG = true; } if (cmd.hasOption(PROCESS)) { process = cmd.getOptionValue(PROCESS); } System.out.println(); System.out.println("Reading from file: " + filename); System.out.println("Process type: " + process); System.out.println("Processing SAG: " + isSAG); System.out.println("Writing to file: " + outfilename); System.out.println(); List<String> jsoni = new ArrayList(); Scanner in = new Scanner(new FileReader(filename)); while (in.hasNextLine()) { String json = in.nextLine(); jsoni.add(json); } PrintWriter writer = new PrintWriter(outfilename, "UTF-8"); System.out.println("Read " + jsoni.size() + " lines from " + filename); if (process.equalsIgnoreCase(RE)) { System.out.println("Running Relation Extraction"); System.out.println(); String json = API.RE(jsoni, isSAG); System.out.println(json); writer.print(json); } else { System.out.println("Running Named Entity Recognition"); System.out.println(); jsoni = API.NER(jsoni, isSAG); /* for(String json: jsoni){ NamedEntityList nel = NamedEntityList.fromJSON(json); nel.prettyPrint(); } */ for (String json : jsoni) { System.out.println(json); writer.print(json); } } writer.close(); } catch (ParseException | UnsupportedEncodingException | FileNotFoundException ex) { Logger.getLogger(Demo.class.getName()).log(Level.SEVERE, null, ex); } }