List of usage examples for java.util ArrayList add
public boolean add(E e)
From source file:com.fonoster.astive.server.AstiveServer.java
public static void main(String[] args) throws Exception { DOMConfigurator.configure(AbstractAstiveServer.ASTIVE_HOME + "/conf/log4j.xml"); astivedSP = getServiceProperties(ASTIVED_PROPERTIES, "astived"); adminDaemonSP = getServiceProperties(ADMIN_DAEMON_PROPERTIES, "admin thread"); telnedSP = getServiceProperties(TELNED_PROPERTIES, "telned"); ArrayList<ServiceProperties> serviceProperties = new ArrayList(); serviceProperties.add(astivedSP); // Adding security measure AstPolicy ap = AstPolicy.getInstance(); ap.addPermissions(astivedSP);//from www . j a v a 2s . co m ap.addPermissions(adminDaemonSP); ap.addPermissions(telnedSP); if (!adminDaemonSP.isDisabled()) { serviceProperties.add(adminDaemonSP); } if (!telnedSP.isDisabled()) { serviceProperties.add(telnedSP); } if ((args.length == 0) || args[0].equals("-h") || args[0].equals("--help")) { printUsage(); System.exit(1); } // Create a Parser CommandLineParser parser = new BasicParser(); Options start = new Options(); start.addOption("h", "help", false, AppLocale.getI18n("optionHelp")); start.addOption("v", "version", false, AppLocale.getI18n("optionVersion")); start.addOption("d", "debug", false, AppLocale.getI18n("optionDebug")); start.addOption("q", "quiet", false, AppLocale.getI18n("optionQuiet")); start.addOption(OptionBuilder.hasArg(true).withArgName("host").withLongOpt("admin-bind") .withDescription(AppLocale.getI18n("optionBind", new Object[] { "admin" })).create()); start.addOption(OptionBuilder.hasArg(true).withArgName("port").withLongOpt("admin-port") .withDescription(AppLocale.getI18n("optionPort", new Object[] { "admin" })).create()); start.addOption(OptionBuilder.hasArg(true).withArgName("port").withLongOpt("astived-port") .withDescription(AppLocale.getI18n("optionPort", new Object[] { "astived" })).create()); start.addOption(OptionBuilder.hasArg(true).withArgName("host").withLongOpt("astived-host") .withDescription(AppLocale.getI18n("optionBind", new Object[] { "astived" })).create()); start.addOption(OptionBuilder.hasArg(true).withArgName("port").withLongOpt("telned-port") .withDescription(AppLocale.getI18n("optionPort", new Object[] { "telned" })).create()); start.addOption(OptionBuilder.hasArg(true).withArgName("host").withLongOpt("telned-host") .withDescription(AppLocale.getI18n("optionBind", new Object[] { "telned" })).create()); Options stop = new Options(); stop.addOption(OptionBuilder.hasArg(true).withArgName("host").withLongOpt("host") .withDescription(AppLocale.getI18n("optionHelp")).create()); stop.addOption("h", "host", false, AppLocale.getI18n("optionStopHost", new Object[] { DEFAULT_AGI_SERVER_BIND_ADDR })); stop.addOption("p", "port", false, AppLocale.getI18n("optionStopPort", new Object[] { DEFAULT_AGI_SERVER_PORT })); Options deploy = new Options(); deploy.addOption("h", "help", false, AppLocale.getI18n("optionHelp")); Options undeploy = new Options(); undeploy.addOption("h", "help", false, AppLocale.getI18n("optionHelp")); if (args.length == 0) { printUsage(); System.exit(1); } else if (!isCommand(args[0])) { printUnavailableCmd(args[0]); System.exit(1); } AdminCommand cmd = AdminCommand.get(args[0]); // Parse the program arguments try { if (cmd.equals(AdminCommand.START)) { CommandLine commandLine = parser.parse(start, args); Logger root = LogManager.getRootLogger(); Enumeration allLoggers = root.getLoggerRepository().getCurrentLoggers(); if (commandLine.hasOption('q')) { root.setLevel(Level.ERROR); while (allLoggers.hasMoreElements()) { Category tmpLogger = (Category) allLoggers.nextElement(); tmpLogger.setLevel(Level.ERROR); } } else if (commandLine.hasOption('d')) { root.setLevel(Level.DEBUG); while (allLoggers.hasMoreElements()) { Category tmpLogger = (Category) allLoggers.nextElement(); tmpLogger.setLevel(Level.DEBUG); } } else { root.setLevel(Level.INFO); while (allLoggers.hasMoreElements()) { Category tmpLogger = (Category) allLoggers.nextElement(); tmpLogger.setLevel(Level.INFO); } } if (commandLine.hasOption('h')) { printUsage(cmd, start); System.exit(0); } if (commandLine.hasOption('v')) { out.println(AppLocale.getI18n("astivedVersion", new String[] { Version.VERSION, Version.BUILD_TIME })); System.exit(0); } if (commandLine.hasOption("astived-bind")) { astivedSP.setBindAddr(InetAddress.getByName(commandLine.getOptionValue("astived-port"))); } if (commandLine.hasOption("astived-port")) { astivedSP.setPort(Integer.parseInt(commandLine.getOptionValue("astived-port"))); } if (commandLine.hasOption("admin-bind")) { adminDaemonSP.setBindAddr(InetAddress.getByName(commandLine.getOptionValue("admin-bind"))); } if (commandLine.hasOption("admin-port")) { adminDaemonSP.setPort(Integer.parseInt(commandLine.getOptionValue("admin-port"))); } if (commandLine.hasOption("telned-bind")) { telnedSP.setBindAddr(InetAddress.getByName(commandLine.getOptionValue("telned-bind"))); } if (commandLine.hasOption("telned-port")) { telnedSP.setPort(Integer.parseInt(commandLine.getOptionValue("telned-port"))); } if (!NetUtil.isPortAvailable(astivedSP.getPort())) { out.println(AppLocale.getI18n("errorCantStartFastAgiServerSocket", new Object[] { astivedSP.getBindAddr().getHostAddress(), astivedSP.getPort() })); System.exit(-1); } if (!NetUtil.isPortAvailable(adminDaemonSP.getPort())) { adminDaemonSP.setUnableToOpen(true); } if (!NetUtil.isPortAvailable(telnedSP.getPort())) { telnedSP.setUnableToOpen(true); } new InitOutput().printInit(serviceProperties); AstiveServer server = new AstiveServer(astivedSP.getPort(), astivedSP.getBacklog(), astivedSP.getBindAddr()); server.start(); } if (!cmd.equals(AdminCommand.START) && adminDaemonSP.isDisabled()) { LOG.warn("errorUnableToAccessAdminDaemon"); } if (cmd.equals(AdminCommand.STOP)) { CommandLine commandLine = parser.parse(stop, args); if (commandLine.hasOption("--help")) { printUsage(cmd, stop); System.exit(0); } if (commandLine.hasOption('h')) { if (commandLine.getOptionValue('h') == null) { printUsage(cmd, stop); System.exit(0); } astivedSP.setBindAddr(InetAddress.getByName(commandLine.getOptionValue('h'))); } if (commandLine.hasOption('p')) { if (commandLine.getOptionValue('p') == null) { printUsage(cmd, stop); System.exit(0); } astivedSP.setPort(Integer.parseInt(commandLine.getOptionValue('p'))); } AdminDaemonClient adClient = new AdminDaemonClient(adminDaemonSP.getBindAddr(), adminDaemonSP.getPort()); adClient.stop(); } // TODO: This needs to be researched before a full implementation. // for now is only possible to do deployments into a local server. if (cmd.equals(AdminCommand.DEPLOY)) { CommandLine commandLine = parser.parse(deploy, args); if (args.length < 2) { printUsage(cmd, deploy); System.exit(1); } else if (commandLine.hasOption('h')) { printUsage(cmd, deploy); System.exit(0); } AdminDaemonClient adClient = new AdminDaemonClient(adminDaemonSP.getBindAddr(), adminDaemonSP.getPort()); adClient.deploy(args[1]); } if (cmd.equals(AdminCommand.UNDEPLOY)) { CommandLine commandLine = parser.parse(undeploy, args); if (args.length < 2) { printUsage(cmd, undeploy); System.exit(1); } else if (commandLine.hasOption('h')) { printUsage(cmd, undeploy); System.exit(0); } AdminDaemonClient adClient = new AdminDaemonClient(adminDaemonSP.getBindAddr(), adminDaemonSP.getPort()); adClient.undeploy(args[1]); } } catch (java.net.ConnectException ex) { LOG.error(AppLocale.getI18n("errorServerNotRunning")); } catch (Exception ex) { LOG.error(AppLocale.getI18n("errorUnexpectedFailure", new Object[] { ex.getMessage() })); } }
From source file:edu.ucla.cs.scai.swim.qa.ontology.dbpedia.tipicality.Test.java
public static void main(String[] args) throws IOException, ClassNotFoundException { String path = DBpediaOntology.DBPEDIA_CSV_FOLDER; if (args != null && args.length > 0) { path = args[0];// w w w . j a v a2 s.c om if (!path.endsWith("/")) { path = path + "/"; } } stopAttributes.add("http://www.w3.org/1999/02/22-rdf-syntax-ns#type"); stopAttributes.add("http://www.w3.org/2002/07/owl#sameAs"); stopAttributes.add("http://dbpedia.org/ontology/wikiPageRevisionID"); stopAttributes.add("http://dbpedia.org/ontology/wikiPageID"); stopAttributes.add("http://purl.org/dc/elements/1.1/description"); stopAttributes.add("http://dbpedia.org/ontology/thumbnail"); stopAttributes.add("http://dbpedia.org/ontology/type"); try (ObjectInputStream ois = new ObjectInputStream(new FileInputStream(path + "counts.bin"))) { categories = (HashSet<String>) ois.readObject(); attributes = (HashSet<String>) ois.readObject(); categoryCount = (HashMap<String, Integer>) ois.readObject(); attributeCount = (HashMap<String, Integer>) ois.readObject(); categoryAttributeCount = (HashMap<String, HashMap<String, Integer>>) ois.readObject(); attributeCategoryCount = (HashMap<String, HashMap<String, Integer>>) ois.readObject(); } System.out.println(categories.size() + " categories found"); System.out.println(attributes.size() + " attributes found"); n = 0; for (Map.Entry<String, Integer> e : categoryCount.entrySet()) { n += e.getValue(); } System.out.println(n); HashMap<String, ArrayList<Pair>> sortedCategoryAttributes = new HashMap<>(); for (String category : categories) { //System.out.println(category); //System.out.println("-----------"); ArrayList<Pair> attributesRank = new ArrayList<Pair>(); Integer c = categoryCount.get(category); if (c == null || c == 0) { continue; } HashMap<String, Integer> thisCategoryAttributeCount = categoryAttributeCount.get(category); for (Map.Entry<String, Integer> e : thisCategoryAttributeCount.entrySet()) { attributesRank.add(new Pair(e.getKey(), 1.0 * e.getValue() / c)); } Collections.sort(attributesRank); for (Pair p : attributesRank) { //System.out.println("A:" + p.getS() + "\t" + p.getP()); } //System.out.println("==============================="); sortedCategoryAttributes.put(category, attributesRank); } for (String attribute : attributes) { //System.out.println(attribute); //System.out.println("-----------"); ArrayList<Pair> categoriesRank = new ArrayList<>(); Integer a = attributeCount.get(attribute); if (a == null || a == 0) { continue; } HashMap<String, Integer> thisAttributeCategoryCount = attributeCategoryCount.get(attribute); for (Map.Entry<String, Integer> e : thisAttributeCategoryCount.entrySet()) { categoriesRank.add(new Pair(e.getKey(), 1.0 * e.getValue() / a)); } Collections.sort(categoriesRank); for (Pair p : categoriesRank) { //System.out.println("C:" + p.getS() + "\t" + p.getP()); } //System.out.println("==============================="); } HashMap<Integer, Integer> histogram = new HashMap<>(); histogram.put(0, 0); histogram.put(1, 0); histogram.put(2, 0); histogram.put(Integer.MAX_VALUE, 0); int nTest = 0; if (args != null && args.length > 0) { path = args[0]; if (!path.endsWith("/")) { path = path + "/"; } } for (File f : new File(path).listFiles()) { if (f.isFile() && f.getName().endsWith(".csv")) { String category = f.getName().replaceFirst("\\.csv", ""); System.out.println("Category: " + category); ArrayList<HashSet<String>> entities = extractEntities(f, 2); for (HashSet<String> attributesOfThisEntity : entities) { nTest++; ArrayList<String> rankedCategories = rankedCategories(attributesOfThisEntity); boolean found = false; for (int i = 0; i < rankedCategories.size() && !found; i++) { if (rankedCategories.get(i).equals(category)) { Integer count = histogram.get(i); if (count == null) { histogram.put(i, 1); } else { histogram.put(i, count + 1); } found = true; } } if (!found) { histogram.put(Integer.MAX_VALUE, histogram.get(Integer.MAX_VALUE) + 1); } } System.out.println("Tested entities: " + nTest); System.out.println("1: " + histogram.get(0)); System.out.println("2: " + histogram.get(1)); System.out.println("3: " + histogram.get(2)); System.out.println("+3: " + (nTest - histogram.get(2) - histogram.get(1) - histogram.get(0) - histogram.get(Integer.MAX_VALUE))); System.out.println("NF: " + histogram.get(Integer.MAX_VALUE)); } } }
From source file:edu.cmu.lti.oaqa.knn4qa.apps.CollectionSplitter.java
public static void main(String[] args) { Options options = new Options(); options.addOption("i", null, true, "Input file"); options.addOption("o", null, true, "Output file prefix"); options.addOption("p", null, true, "Comma separated probabilities e.g., 0.1,0.2,0.7."); options.addOption("n", null, true, "Comma separated part names, e.g., dev,test,train"); CommandLineParser parser = new org.apache.commons.cli.GnuParser(); try {//from w w w .java 2 s.c o m CommandLine cmd = parser.parse(options, args); InputStream input = null; if (cmd.hasOption("i")) { input = CompressUtils.createInputStream(cmd.getOptionValue("i")); } else { Usage("Specify Input file"); } ArrayList<Double> probs = new ArrayList<Double>(); String[] partNames = null; if (cmd.hasOption("p")) { String parts[] = cmd.getOptionValue("p").split(","); try { double sum = 0; for (String s : parts) { double p = Double.parseDouble(s); if (p <= 0 || p > 1) Usage("All probabilities must be in the range (0,1)"); sum += p; probs.add(p); } if (Math.abs(sum - 1.0) > Float.MIN_NORMAL) { Usage("The sum of probabilities should be equal to 1, but it's: " + sum); } } catch (NumberFormatException e) { Usage("Can't convert some of the probabilities to a floating-point number."); } } else { Usage("Specify part probabilities."); } if (cmd.hasOption("n")) { partNames = cmd.getOptionValue("n").split(","); if (partNames.length != probs.size()) Usage("The number of probabilities is not equal to the number of parts!"); } else { Usage("Specify part names"); } BufferedWriter[] outFiles = new BufferedWriter[partNames.length]; if (cmd.hasOption("o")) { String outPrefix = cmd.getOptionValue("o"); for (int partId = 0; partId < partNames.length; ++partId) { outFiles[partId] = new BufferedWriter(new OutputStreamWriter( CompressUtils.createOutputStream(outPrefix + "_" + partNames[partId] + ".gz"))); } } else { Usage("Specify Output file prefix"); } System.out.println("Using probabilities:"); for (int partId = 0; partId < partNames.length; ++partId) System.out.println(partNames[partId] + " : " + probs.get(partId)); System.out.println("================================================="); XmlIterator inpIter = new XmlIterator(input, YahooAnswersReader.DOCUMENT_TAG); String oneRec = inpIter.readNext(); int docNum = 1; for (; !oneRec.isEmpty(); ++docNum, oneRec = inpIter.readNext()) { double p = Math.random(); if (docNum % 1000 == 0) { System.out.println(String.format("Processed %d documents", docNum)); } BufferedWriter out = null; for (int partId = 0; partId < partNames.length; ++partId) { double pp = probs.get(partId); if (p <= pp || partId + 1 == partNames.length) { out = outFiles[partId]; break; } p -= pp; } oneRec = oneRec.trim() + System.getProperty("line.separator"); out.write(oneRec); } System.out.println(String.format("Processed %d documents", docNum - 1)); // It's important to close all the streams here! for (BufferedWriter f : outFiles) f.close(); } catch (ParseException e) { Usage("Cannot parse arguments"); } catch (Exception e) { System.err.println("Terminating due to an exception: " + e); System.exit(1); } }
From source file:unalcol.termites.boxplots.InformationCollected2.java
/** * For testing from the command line.//from w w w .j ava 2 s . c om * * @param args ignored. */ public static void main(final String[] args) { // double pf = Double.valueOf(args[0]); // System.out.println("pf:" + args[0]); /** * For saso paper */ /* double pf = 0; ArrayList<Double> pf0 = new ArrayList<>(); ArrayList<Double> pfg1 = new ArrayList<>(); ArrayList<Double> pfg2 = new ArrayList<>(); ArrayList<Double> pfg3 = new ArrayList<>(); pf0.add(0.0); pfg1.add(1.0E-4); pfg1.add(3.0E-4); pfg2.add(5.0E-4); pfg2.add(7.0E-4); pfg3.add(9.0E-4); // pfg3.add(1.0E-3); //Log.getInstance().addTarget(new PrintStreamLogTarget(System.out)); final InformationCollected2 demo = new InformationCollected2("Information Collected", pf0); final InformationCollected2 demo1 = new InformationCollected2("Information Collected", pfg1); final InformationCollected2 demo2 = new InformationCollected2("Information Collected", pfg2); final InformationCollected2 demo3 = new InformationCollected2("Information Collected", pfg3); //demo.pack(); //RefineryUtilities.centerFrameOnScreen(demo); //demo.setVisible(true); */ /* Main with all Pictures by pf */ ArrayList<Double> pf0 = new ArrayList<>(); ArrayList<Double> pf1 = new ArrayList<>(); ArrayList<Double> pf3 = new ArrayList<>(); ArrayList<Double> pf5 = new ArrayList<>(); ArrayList<Double> pf7 = new ArrayList<>(); ArrayList<Double> pf9 = new ArrayList<>(); ArrayList<Double> pf01 = new ArrayList<>(); /* For the web site */ pf0.add(0.0); pf1.add(1.0E-4); pf3.add(3.0E-4); pf5.add(5.0E-4); pf7.add(7.0E-4); pf9.add(9.0E-4); pf01.add(1.0E-3); //pfg3.add(1.0E-3); //Log.getInstance().addTarget(new PrintStreamLogTarget(System.out)); final InformationCollected2 demo = new InformationCollected2("Information Collected", pf0); final InformationCollected2 demo1 = new InformationCollected2("Information Collected", pf1); final InformationCollected2 demo2 = new InformationCollected2("Information Collected", pf3); final InformationCollected2 demo3 = new InformationCollected2("Information Collected", pf5); final InformationCollected2 demo4 = new InformationCollected2("Information Collected", pf7); final InformationCollected2 demo5 = new InformationCollected2("Information Collected", pf9); final InformationCollected2 demo6 = new InformationCollected2("Information Collected", pf01); }
From source file:de.unileipzig.ub.scroller.Main.java
public static void main(String[] args) throws IOException { Options options = new Options(); // add t option options.addOption("h", "help", false, "display this help"); // elasticsearch options options.addOption("t", "host", true, "elasticsearch hostname (default: 0.0.0.0)"); options.addOption("p", "port", true, "transport port (that's NOT the http port, default: 9300)"); options.addOption("c", "cluster", true, "cluster name (default: elasticsearch_mdma)"); options.addOption("i", "index", true, "index to use"); options.addOption("f", "filter", true, "filter(s) - e.g. meta.kind=title"); options.addOption("j", "junctor", true, "values: and, or (default: and)"); options.addOption("n", "notice-every", true, "show speed after every N items"); options.addOption("v", "verbose", false, "be verbose"); // options.addOption("z", "end-of-message", true, "sentinel to print to stdout, once the regular input finished (default: EOM)"); CommandLineParser parser = new PosixParser(); CommandLine cmd = null;//from w w w . j a v a2 s .c o m try { cmd = parser.parse(options, args); } catch (ParseException ex) { logger.error(ex); System.exit(1); } // process options if (cmd.hasOption("h")) { HelpFormatter formatter = new HelpFormatter(); formatter.printHelp("scroller", options, true); System.exit(0); } String endOfMessage = "EOM"; boolean verbose = false; if (cmd.hasOption("verbose")) { verbose = true; } if (!cmd.hasOption("i")) { System.err.println("error: no index specified"); System.exit(1); } long noticeEvery = 10000; if (cmd.hasOption("n")) { noticeEvery = Long.parseLong(cmd.getOptionValue("n")); } // ES options String[] hosts = new String[] { "0.0.0.0" }; int port = 9300; String clusterName = "elasticsearch_mdma"; int bulkSize = 3000; if (cmd.hasOption("host")) { hosts = cmd.getOptionValues("host"); } if (cmd.hasOption("port")) { port = Integer.parseInt(cmd.getOptionValue("port")); } if (cmd.hasOption("cluster")) { clusterName = cmd.getOptionValue("cluster"); } // Index String indexName = cmd.getOptionValue("index"); Map<String, String> filterMap = new HashMap<String, String>(); if (cmd.hasOption("filter")) { try { filterMap = getMapForKeys(cmd.getOptionValues("filter")); } catch (ParseException pe) { System.err.println(pe); System.exit(1); } } Collection<HashMap> filterList = new ArrayList<HashMap>(); if (cmd.hasOption("filter")) { try { filterList = getFilterList(cmd.getOptionValues("filter")); } catch (ParseException pe) { System.err.println(pe); System.exit(1); } } // ES Client final Settings settings = ImmutableSettings.settingsBuilder().put("cluster.name", "elasticsearch_mdma") .put("client.transport.ping_timeout", "60s").build(); final TransportClient client = new TransportClient(settings); for (String host : hosts) { client.addTransportAddress(new InetSocketTransportAddress(host, port)); } // build the query String junctor = "and"; if (cmd.hasOption("j")) { junctor = cmd.getOptionValue("j"); } // ArrayList<TermFilterBuilder> filters = new ArrayList<TermFilterBuilder>(); // if (filterMap.size() > 0) { // for (Map.Entry<String, String> entry : filterMap.entrySet()) { // filters.add(new TermFilterBuilder(entry.getKey(), entry.getValue())); // } // } ArrayList<TermFilterBuilder> filters = new ArrayList<TermFilterBuilder>(); if (filterList.size() > 0) { for (HashMap map : filterList) { for (Object obj : map.entrySet()) { Map.Entry entry = (Map.Entry) obj; filters.add(new TermFilterBuilder(entry.getKey().toString(), entry.getValue().toString())); } } } FilterBuilder fb = null; if (junctor.equals("and")) { AndFilterBuilder afb = new AndFilterBuilder(); for (TermFilterBuilder tfb : filters) { afb.add(tfb); } fb = afb; } if (junctor.equals("or")) { OrFilterBuilder ofb = new OrFilterBuilder(); for (TermFilterBuilder tfb : filters) { ofb.add(tfb); } fb = ofb; } // TermFilterBuilder tfb0 = new TermFilterBuilder("meta.kind", "title"); // TermFilterBuilder tfb1 = new TermFilterBuilder("meta.timestamp", "201112081240"); // // AndFilterBuilder afb0 = new AndFilterBuilder(tfb0, tfb1); QueryBuilder qb0 = null; if (filterMap.isEmpty()) { qb0 = matchAllQuery(); } else { qb0 = filteredQuery(matchAllQuery(), fb); } // sorting // FieldSortBuilder sortBuilder = new FieldSortBuilder("meta.timestamp"); // sortBuilder.order(SortOrder.DESC); // FilteredQueryBuilder fqb0 = filteredQuery(matchAllQuery(), tfb0); final CountResponse countResponse = client.prepareCount(indexName).setQuery(qb0).execute().actionGet(); final long total = countResponse.getCount(); SearchResponse scrollResp = client.prepareSearch(indexName).setSearchType(SearchType.SCAN) .setScroll(new TimeValue(60000)).setQuery(qb0) // .addSort(sortBuilder) // sort has no effect on scroll type (see: https://github.com/CPAN-API/cpan-api/issues/172) .setSize(1000) //1000 hits per shard will be returned for each scroll .execute().actionGet(); //Scroll until no hits are returned System.err.println("[Scroller] query: " + qb0.toString()); System.err.println("[Scroller] took: " + scrollResp.getTookInMillis() + "ms"); System.err.println("[Scroller] docs found: " + total); long counter = 0; long start = System.currentTimeMillis(); while (true) { scrollResp = client.prepareSearchScroll(scrollResp.getScrollId()).setScroll(new TimeValue(600000)) .execute().actionGet(); if (scrollResp.getHits().hits().length == 0) { break; } for (SearchHit hit : scrollResp.getHits()) { System.out.println(hit.sourceAsString()); counter += 1; if (counter % noticeEvery == 0) { final double elapsed = (System.currentTimeMillis() - start) / 1000; final double speed = counter / elapsed; final long eta = (long) ((elapsed / counter) * (total - counter) * 1000); System.err.println( counter + "/" + total + " records recvd @ speed " + String.format("%1$,.1f", speed) + " r/s eta: " + DurationFormatUtils.formatDurationWords(eta, false, false)); } } } System.out.close(); // System.out.println(endOfMessage); }
From source file:de.prozesskraft.pkraft.PkraftPartUi1.java
/** * @param args// w w w .ja v a2 s . co m */ public static void main(String[] args) { /*---------------------------- get options from ini-file ----------------------------*/ File inifile = new java.io.File( WhereAmI.getInstallDirectoryAbsolutePath(PkraftPartUi1.class) + "/" + "../etc/pkraft-gui.ini"); if (inifile.exists()) { try { ini = new Ini(inifile); } catch (InvalidFileFormatException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } catch (IOException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } } else { System.err.println("ini file does not exist: " + inifile.getAbsolutePath()); System.exit(1); } /*---------------------------- create boolean options ----------------------------*/ Option help = new Option("help", "print this message"); Option v = new Option("v", "prints version and build-date"); /*---------------------------- create argument options ----------------------------*/ /*---------------------------- create options object ----------------------------*/ Options options = new Options(); options.addOption(help); options.addOption(v); /*---------------------------- create the parser ----------------------------*/ CommandLineParser parser = new GnuParser(); try { // parse the command line arguments line = parser.parse(options, args); } catch (Exception exp) { // oops, something went wrong System.err.println("Parsing failed. Reason: " + exp.getMessage()); } /*---------------------------- usage/help ----------------------------*/ if (line.hasOption("help")) { HelpFormatter formatter = new HelpFormatter(); // formatter.printHelp("checkin --version [% version %]", options); formatter.printHelp("pkraft-gui", options); System.exit(0); } if (line.hasOption("v")) { System.err.println("author: [% email %]"); System.err.println("version: [% version %]"); System.err.println("date: [% date %]"); System.exit(0); } /*---------------------------- die lizenz ueberpruefen und ggf abbrechen ----------------------------*/ // check for valid license ArrayList<String> allPortAtHost = new ArrayList<String>(); allPortAtHost.add(ini.get("license-server", "license-server-1")); allPortAtHost.add(ini.get("license-server", "license-server-2")); allPortAtHost.add(ini.get("license-server", "license-server-3")); // muss final sein - wird sonst beim installieren mit maven angemeckert (nicht so aus eclipse heraus) final MyLicense lic = new MyLicense(allPortAtHost, "1", "user-edition", "0.1"); // lizenz-logging ausgeben for (String actLine : (ArrayList<String>) lic.getLog()) { System.err.println(actLine); } // abbruch, wenn lizenz nicht valide if (!lic.isValid()) { System.exit(1); } /*---------------------------- other things ----------------------------*/ // gui final Display display = new Display(); Realm.runWithDefault(SWTObservables.getRealm(display), new Runnable() { public void run() { try { // SPLASHSCREEN // final Image image = new Image(display, 300, 300); Image image = null; // set an image. die 2 versionen sind dazu da um von eclipse aus und in der installierten version zu funktionieren if (this.getClass().getResourceAsStream("/logo_beschnitten_transparent_small.png") != null) { image = new Image(display, this.getClass().getResourceAsStream("/logo_beschnitten_transparent_small.png")); } else if ((new java.io.File("logo_beschnitten_transparent_small.png")).exists()) { image = new Image(display, "logo_beschnitten_transparent_small.png"); } final Shell splash = new Shell(SWT.ON_TOP); splash.setLayout(new GridLayout(1, false)); splash.setSize(300, 300); splash.setBackground(new Color(display, 255, 255, 255)); // Weiss Label labelImage = new Label(splash, SWT.NONE); labelImage.setImage(image); // labelImage.setLayout(new GridLayout(1, false)); GridData gd_labelImage = new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1); gd_labelImage.widthHint = 300; gd_labelImage.minimumWidth = 300; // gd_labelImage.minimumHeight = 10; labelImage.setLayoutData(gd_labelImage); Label labelZeile1 = new Label(splash, SWT.NONE | SWT.BORDER | SWT.CENTER); String text = "version [% version %]"; text += "\nlicense status: " + lic.getLicense().getValidationStatus(); switch (lic.getLicense().getValidationStatus()) { case LICENSE_VALID: text += "\nlicensee: " + lic.getLicense().getLicenseText().getUserEMail(); text += "\nexpires in: " + lic.getLicense().getLicenseText().getLicenseExpireDaysRemaining(null) + " day(s)."; break; case LICENSE_INVALID: break; default: text += "\nno valid license found"; } text += "\nsupport: support@prozesskraft.de"; Button buttonOk = new Button(splash, SWT.NONE); GridData gd_buttonOk = new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1); gd_buttonOk.widthHint = 62; buttonOk.setLayoutData(gd_buttonOk); buttonOk.setText("Ok"); buttonOk.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent event) { splash.close(); } }); labelZeile1.setText(text); // labelImage.setLayout(new GridLayout(1, false)); GridData gd_labelZeile1 = new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1); gd_labelZeile1.horizontalAlignment = SWT.CENTER; gd_labelZeile1.widthHint = 300; gd_labelZeile1.minimumWidth = 300; // gd_labelImage.minimumHeight = 10; labelZeile1.setLayoutData(gd_labelZeile1); splash.pack(); Rectangle splashRect = splash.getBounds(); Rectangle displayRect = display.getBounds(); int x = (displayRect.width - splashRect.width) / 2; int y = (displayRect.height - splashRect.height) / 2; splash.setLocation(x, y); splash.open(); // DAS HAUPTFENSTER Shell shell = new Shell(display); // shell.setSize(1200, 800); shell.setMaximized(true); shell.setText("pkraft " + "v[% version %]"); // set an icon. die 2 versionen sind dazu da um von eclipse aus und in der installierten version zu funktionieren if (this.getClass().getResourceAsStream("/logoSymbol50Transp.png") != null) { shell.setImage( new Image(display, this.getClass().getResourceAsStream("/logoSymbol50Transp.png"))); } else if ((new java.io.File("logoSymbol50Transp.png")).exists()) { shell.setImage(new Image(display, "logoSymbol50Transp.png")); } shell.setLayout(new FillLayout()); Composite composite = new Composite(shell, SWT.NO_FOCUS); GridLayout gl_composite = new GridLayout(2, false); gl_composite.marginWidth = 0; gl_composite.marginHeight = 0; new PkraftPartUi1(composite); try { shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) { display.sleep(); } } } finally { if (!shell.isDisposed()) { shell.dispose(); } } } finally { display.dispose(); } } }); System.exit(0); }
From source file:com.minoritycode.Application.java
public static void main(String[] args) { System.out.println("Trello Backup Application"); File configFile = new File(workingDir + "\\config.properties"); InputStream input = null;/*from www . j av a 2s . c o m*/ try { input = new FileInputStream(configFile); config.load(input); input.close(); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } // String workingDir = System.getProperty("user.dir"); manualOperation = Boolean.parseBoolean(config.getProperty("manualOperation")); logger.startErrorLogger(); setBackupDir(); try { report.put("backupDate", backupDate); } catch (JSONException e) { e.printStackTrace(); logger.logLine(e.getMessage()); } lock = new ReentrantLock(); lockErrorRep = new ReentrantLock(); lockErrorLog = new ReentrantLock(); Application.key = config.getProperty("trellokey"); Application.token = config.getProperty("trellotoken"); boolean useProxy = Boolean.parseBoolean(config.getProperty("useProxy")); boolean proxySet = true; if (useProxy) { proxySet = setProxy(); } // GUI swingContainerDemo = new GUI(); // swingContainerDemo.showJPanelDemo(); if (proxySet) { Credentials credentials = new Credentials(); if (Application.key.isEmpty()) { Application.key = credentials.getKey(); } else { Application.key = config.getProperty("trellokey"); } if (token.isEmpty()) { Application.token = credentials.getToken(); } else { Application.token = config.getProperty("trellotoken"); } BoardDownloader downloader = new BoardDownloader(); downloader.downloadMyBoard(url); boards = downloader.downloadOrgBoard(url); if (boards != null) { try { report.put("boardNum", boards.size()); } catch (JSONException e) { e.printStackTrace(); logger.logLine(e.getMessage()); } Integer numberOfThreads = Integer.parseInt(config.getProperty("numberOfThreads")); if (numberOfThreads == null) { logger.logLine("error number of threads not set in config file"); if (manualOperation) { String message = "How many threads do you want to use (10) is average"; numberOfThreads = Integer.parseInt(Credentials.getInput(message)); Credentials.saveProperty("numberOfThreads", numberOfThreads.toString()); } else { if (Boolean.parseBoolean(config.getProperty("useMailer"))) { Mailer mailer = new Mailer(); mailer.SendMail(); } System.exit(-1); } } ArrayList<Thread> threadList = new ArrayList<Thread>(); for (int i = 0; i < numberOfThreads; i++) { Thread thread = new Thread(new Application(), "BoardDownloadThread"); threadList.add(thread); thread.start(); } } else { //create empty report try { report.put("boardsNotDownloaded", "99999"); report.put("boardNum", 0); report.put("boardNumSuccessful", 0); } catch (JSONException e) { e.printStackTrace(); logger.logLine(e.getMessage()); } if (Boolean.parseBoolean(config.getProperty("useMailer"))) { Mailer mailer = new Mailer(); mailer.SendMail(); } logger.logger(report); } } else { //create empty report try { report.put("boardsNotDownloaded", "99999"); report.put("boardNum", 0); report.put("boardNumSuccessful", 0); } catch (JSONException e) { e.printStackTrace(); logger.logLine(e.getMessage()); } if (Boolean.parseBoolean(config.getProperty("useMailer"))) { Mailer mailer = new Mailer(); mailer.SendMail(); } } }
From source file:eu.crisis_economics.utilities.EmpiricalDistribution.java
public static void main(String[] args) { System.out.println("testing EmpiricalDistribution type.."); {//from w ww .j ava 2 s.c om System.out.println("EmpiricalDistribution test 1.."); EmpiricalDistribution memory = new EmpiricalDistribution(10); for (int i = 0; i < 10; ++i) { memory.add(i); Assert.assertEquals(memory.size(), i + 1); Assert.assertEquals(memory.maxSize(), 10); Assert.assertEquals(memory.getMaxRecordedValue(), (double) i); Assert.assertEquals(memory.getMinRecordedValue(), 0.); } Assert.assertEquals(4.5, memory.meanOverHistory(), 1.e-12); for (int i = 0; i < 10; ++i) { Assert.assertEquals(i, memory.numRecordsLessThan(i)); Assert.assertEquals(i, memory.numRecordsNotLessThan(10 - i)); Assert.assertEquals(1 - i / 10., memory.estimateProbabilityNotLessThan(i), 1.e-12); } for (int i = 0; i < 10; ++i) { // re-write memory memory.add(i); Assert.assertEquals(memory.size(), 10); } Assert.assertEquals(4.5, memory.meanOverHistory(), 1.e-12); for (int i = 0; i < 10; ++i) { Assert.assertEquals(i, memory.numRecordsLessThan(i)); Assert.assertEquals(i, memory.numRecordsNotLessThan(10 - i)); Assert.assertEquals(1 - i / 10., memory.estimateProbabilityNotLessThan(i), 1.e-12); } for (int i = 0; i < 10; ++i) { // re-write memory memory.add(i * 10); Assert.assertEquals(memory.size(), 10); Assert.assertEquals(memory.getMaxRecordedValue(), i == 0 ? 9. : (double) 10 * i); Assert.assertEquals(memory.getMinRecordedValue(), 0.); } Assert.assertEquals(4.5 * 10, memory.meanOverHistory(), 1.e-12); for (int i = 0; i < 100; ++i) { int roundDown = (i + 9) / 10; Assert.assertEquals(roundDown, memory.numRecordsLessThan(i)); Assert.assertEquals(roundDown, memory.size() - memory.numRecordsNotLessThan(i)); Assert.assertEquals(1 - roundDown / 10., memory.estimateProbabilityNotLessThan(i), 1.e-12); } memory.flush(); for (int i = 0; i < 10; ++i) { Assert.assertEquals(memory.size(), i); memory.add(0); Assert.assertEquals(0, memory.numRecordsLessThan(0)); Assert.assertEquals(i + 1, memory.numRecordsLessThan(1)); Assert.assertEquals(memory.getMaxRecordedValue(), 0.); Assert.assertEquals(memory.getMinRecordedValue(), 0.); } System.out.println(memory); } { MersenneTwisterFast random = Simulation.getSimState().random; for (int i = 0; i < 100; ++i) { if (i % 10 == 0) System.out.println("EmpiricalDistribution test " + (i + 1) + ".."); int memorySize = random.nextInt(100) + 1; EmpiricalDistribution memory = new EmpiricalDistribution(memorySize); double queryValue = random.nextDouble(); ArrayList<Double> lessThanQueryValue = new ArrayList<Double>(), notLessThanQueryValue = new ArrayList<Double>(); for (int j = 0; j < 2 * memorySize; ++j) { double insertValue = random.nextDouble(); memory.add(insertValue); if (j >= memorySize) { if (insertValue < queryValue) lessThanQueryValue.add(insertValue); else notLessThanQueryValue.add(insertValue); } } Assert.assertEquals(memory.numRecordsLessThan(queryValue), lessThanQueryValue.size()); Assert.assertEquals(memory.numRecordsNotLessThan(queryValue), notLessThanQueryValue.size()); Assert.assertEquals(memory.estimateProbabilityNotLessThan(queryValue), notLessThanQueryValue.size() / (double) memorySize); System.out.println(memory); System.out.flush(); } } System.out.println("EmpiricalDistribution tests pass"); System.out.flush(); }
From source file:unalcol.termites.boxplots.HybridInformationCollected.java
/** * For testing from the command line.//from w ww . j ava 2 s . c o m * * @param args ignored. */ public static void main(final String[] args) { //double pf = Double.valueOf(args[0]); // System.out.println("pf:" + args[0]); //double pf = 0; /* For the Paper */ /* ArrayList<Double> pf0 = new ArrayList<>(); ArrayList<Double> pfg1 = new ArrayList<>(); ArrayList<Double> pfg2 = new ArrayList<>(); ArrayList<Double> pfg3 = new ArrayList<>(); pf0.add(0.0); pfg1.add(1.0E-4); pfg1.add(3.0E-4); pfg2.add(5.0E-4); pfg2.add(7.0E-4); pfg3.add(9.0E-4); //pfg3.add(1.0E-3); //Log.getInstance().addTarget(new PrintStreamLogTarget(System.out)); final InformationCollected1 demo = new InformationCollected1("Information Collected", pf0); final InformationCollected1 demo1 = new InformationCollected1("Information Collected", pfg1); final InformationCollected1 demo2 = new InformationCollected1("Information Collected", pfg2); final InformationCollected1 demo3 = new InformationCollected1("Information Collected", pfg3); //demo.pack(); //RefineryUtilities.centerFrameOnScreen(demo); //demo.setVisible(true); **/ if (args.length > 0) { experimentsDir = args[0]; } if (args.length > 1) { mazeMode = args[1]; } aMode = new String[args.length - 2]; for (int i = 2; i < args.length; i++) { aMode[i - 2] = args[i]; } /* Main with all Pictures by pf */ ArrayList<Double> pf0 = new ArrayList<>(); ArrayList<Double> pf1 = new ArrayList<>(); ArrayList<Double> pf3 = new ArrayList<>(); ArrayList<Double> pf5 = new ArrayList<>(); ArrayList<Double> pf7 = new ArrayList<>(); ArrayList<Double> pf9 = new ArrayList<>(); ArrayList<Double> pf01 = new ArrayList<>(); /* For the Paper */ pf0.add(0.0); pf1.add(1.0E-4); pf3.add(3.0E-4); pf5.add(5.0E-4); pf7.add(7.0E-4); pf9.add(9.0E-4); pf01.add(1.0E-3); //pfg3.add(1.0E-3); //Log.getInstance().addTarget(new PrintStreamLogTarget(System.out)); final HybridInformationCollected demo = new HybridInformationCollected("Information Collected", pf0); final HybridInformationCollected demo1 = new HybridInformationCollected("Information Collected", pf1); final HybridInformationCollected demo2 = new HybridInformationCollected("Information Collected", pf3); final HybridInformationCollected demo3 = new HybridInformationCollected("Information Collected", pf5); final HybridInformationCollected demo4 = new HybridInformationCollected("Information Collected", pf7); final HybridInformationCollected demo5 = new HybridInformationCollected("Information Collected", pf9); final HybridInformationCollected demo6 = new HybridInformationCollected("Information Collected", pf01); }
From source file:io.anserini.index.UpdateIndex.java
@SuppressWarnings("static-access") public static void main(String[] args) throws Exception { Options options = new Options(); options.addOption(new Option(HELP_OPTION, "show help")); options.addOption(new Option(OPTIMIZE_OPTION, "merge indexes into a single segment")); options.addOption(new Option(STORE_TERM_VECTORS_OPTION, "store term vectors")); options.addOption(// w ww .j a v a 2 s.c om OptionBuilder.withArgName("dir").hasArg().withDescription("index location").create(INDEX_OPTION)); options.addOption(OptionBuilder.withArgName("file").hasArg().withDescription("file with deleted tweetids") .create(DELETES_OPTION)); options.addOption(OptionBuilder.withArgName("id").hasArg().withDescription("max id").create(MAX_ID_OPTION)); CommandLine cmdline = null; 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(HELP_OPTION) || !cmdline.hasOption(INDEX_OPTION)) { HelpFormatter formatter = new HelpFormatter(); formatter.printHelp(UpdateIndex.class.getName(), options); System.exit(-1); } String indexPath = cmdline.getOptionValue(INDEX_OPTION); final FieldType textOptions = new FieldType(); textOptions.setIndexOptions(IndexOptions.DOCS_AND_FREQS_AND_POSITIONS); textOptions.setStored(true); textOptions.setTokenized(true); textOptions.setStoreTermVectors(true); LOG.info("index: " + indexPath); File file = new File("PittsburghUserTimeline"); if (!file.exists()) { System.err.println("Error: " + file + " does not exist!"); System.exit(-1); } final StatusStream stream = new JsonStatusCorpusReader(file); Status status; String s; HashMap<Long, String> hm = new HashMap<Long, String>(); try { while ((s = stream.nextRaw()) != null) { try { status = DataObjectFactory.createStatus(s); if (status.getText() == null) { continue; } hm.put(status.getUser().getId(), hm.get(status.getUser().getId()) + status.getText().replaceAll("[\\r\\n]+", " ")); } catch (Exception e) { } } } catch (Exception e) { e.printStackTrace(); } finally { stream.close(); } ArrayList<String> userIDList = new ArrayList<String>(); try (BufferedReader br = new BufferedReader(new FileReader(new File("userID")))) { String line; while ((line = br.readLine()) != null) { userIDList.add(line.replaceAll("[\\r\\n]+", "")); // process the line. } } try { reader = DirectoryReader .open(FSDirectory.open(new File(cmdline.getOptionValue(INDEX_OPTION)).toPath())); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } final Directory dir = new SimpleFSDirectory(Paths.get(cmdline.getOptionValue(INDEX_OPTION))); final IndexWriterConfig config = new IndexWriterConfig(ANALYZER); config.setOpenMode(IndexWriterConfig.OpenMode.CREATE_OR_APPEND); final IndexWriter writer = new IndexWriter(dir, config); IndexSearcher searcher = new IndexSearcher(reader); System.out.println("The total number of docs indexed " + searcher.collectionStatistics(TweetStreamReader.StatusField.TEXT.name).docCount()); for (int city = 0; city < cityName.length; city++) { // Pittsburgh's coordinate -79.976389, 40.439722 Query q_long = NumericRangeQuery.newDoubleRange(TweetStreamReader.StatusField.LONGITUDE.name, new Double(longitude[city] - 0.05), new Double(longitude[city] + 0.05), true, true); Query q_lat = NumericRangeQuery.newDoubleRange(TweetStreamReader.StatusField.LATITUDE.name, new Double(latitude[city] - 0.05), new Double(latitude[city] + 0.05), true, true); BooleanQuery bqCityName = new BooleanQuery(); Term t = new Term("place", cityName[city]); TermQuery query = new TermQuery(t); bqCityName.add(query, BooleanClause.Occur.SHOULD); System.out.println(query.toString()); for (int i = 0; i < cityNameAlias[city].length; i++) { t = new Term("place", cityNameAlias[city][i]); query = new TermQuery(t); bqCityName.add(query, BooleanClause.Occur.SHOULD); System.out.println(query.toString()); } BooleanQuery bq = new BooleanQuery(); BooleanQuery finalQuery = new BooleanQuery(); // either a coordinate match bq.add(q_long, BooleanClause.Occur.MUST); bq.add(q_lat, BooleanClause.Occur.MUST); finalQuery.add(bq, BooleanClause.Occur.SHOULD); // or a place city name match finalQuery.add(bqCityName, BooleanClause.Occur.SHOULD); TotalHitCountCollector totalHitCollector = new TotalHitCountCollector(); // Query hasFieldQuery = new ConstantScoreQuery(new // FieldValueFilter("timeline")); // // searcher.search(hasFieldQuery, totalHitCollector); // // if (totalHitCollector.getTotalHits() > 0) { // TopScoreDocCollector collector = // TopScoreDocCollector.create(Math.max(0, // totalHitCollector.getTotalHits())); // searcher.search(finalQuery, collector); // ScoreDoc[] hits = collector.topDocs().scoreDocs; // // // HashMap<String, Integer> hasHit = new HashMap<String, Integer>(); // int dupcount = 0; // for (int i = 0; i < hits.length; ++i) { // int docId = hits[i].doc; // Document d; // // d = searcher.doc(docId); // // System.out.println(d.getFields()); // } // } // totalHitCollector = new TotalHitCountCollector(); searcher.search(finalQuery, totalHitCollector); if (totalHitCollector.getTotalHits() > 0) { TopScoreDocCollector collector = TopScoreDocCollector .create(Math.max(0, totalHitCollector.getTotalHits())); searcher.search(finalQuery, collector); ScoreDoc[] hits = collector.topDocs().scoreDocs; System.out.println("City " + cityName[city] + " " + collector.getTotalHits() + " hits."); HashMap<String, Integer> hasHit = new HashMap<String, Integer>(); int dupcount = 0; for (int i = 0; i < hits.length; ++i) { int docId = hits[i].doc; Document d; d = searcher.doc(docId); if (userIDList.contains(d.get(IndexTweets.StatusField.USER_ID.name)) && hm.containsKey(Long.parseLong(d.get(IndexTweets.StatusField.USER_ID.name)))) { // System.out.println("Has timeline field?" + (d.get("timeline") != null)); // System.out.println(reader.getDocCount("timeline")); // d.add(new Field("timeline", hm.get(Long.parseLong(d.get(IndexTweets.StatusField.USER_ID.name))), // textOptions)); System.out.println("Found a user hit"); BytesRefBuilder brb = new BytesRefBuilder(); NumericUtils.longToPrefixCodedBytes(Long.parseLong(d.get(IndexTweets.StatusField.ID.name)), 0, brb); Term term = new Term(IndexTweets.StatusField.ID.name, brb.get()); // System.out.println(reader.getDocCount("timeline")); Document d_new = new Document(); // for (IndexableField field : d.getFields()) { // d_new.add(field); // } // System.out.println(d_new.getFields()); d_new.add(new StringField("userBackground", d.get(IndexTweets.StatusField.USER_ID.name), Store.YES)); d_new.add(new Field("timeline", hm.get(Long.parseLong(d.get(IndexTweets.StatusField.USER_ID.name))), textOptions)); // System.out.println(d_new.get()); writer.addDocument(d_new); writer.commit(); // t = new Term("label", "why"); // TermQuery tqnew = new TermQuery(t); // // totalHitCollector = new TotalHitCountCollector(); // // searcher.search(tqnew, totalHitCollector); // // if (totalHitCollector.getTotalHits() > 0) { // collector = TopScoreDocCollector.create(Math.max(0, totalHitCollector.getTotalHits())); // searcher.search(tqnew, collector); // hits = collector.topDocs().scoreDocs; // // System.out.println("City " + cityName[city] + " " + collector.getTotalHits() + " hits."); // // for (int k = 0; k < hits.length; k++) { // docId = hits[k].doc; // d = searcher.doc(docId); // System.out.println(d.get(IndexTweets.StatusField.ID.name)); // System.out.println(d.get(IndexTweets.StatusField.PLACE.name)); // } // } // writer.deleteDocuments(term); // writer.commit(); // writer.addDocument(d); // writer.commit(); // System.out.println(reader.getDocCount("timeline")); // writer.updateDocument(term, d); // writer.commit(); } } } } reader.close(); writer.close(); }