List of usage examples for java.lang String split
public String[] split(String regex)
From source file:com.jellymold.boss.WebSearch.java
public static void main(String[] args) { WebSearch ws = new WebSearch(); String sentence = "he gainned 100lb and go from a 56lb 8yr old to a 145 uncontrolable 9yr old "; System.out.println(ws.spellCheck(sentence.split(" ")).get(0).getSuggestion()); }
From source file:SequentialPersonalizedPageRank.java
@SuppressWarnings({ "static-access" }) public static void main(String[] args) throws IOException { Options options = new Options(); options.addOption(OptionBuilder.withArgName("path").hasArg().withDescription("input path").create(INPUT)); options.addOption(// ww w . jav a 2s .c o m OptionBuilder.withArgName("val").hasArg().withDescription("random jump factor").create(JUMP)); options.addOption(OptionBuilder.withArgName("node").hasArg() .withDescription("source node (i.e., destination of the random jump)").create(SOURCE)); 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(INPUT) || !cmdline.hasOption(SOURCE)) { System.out.println("args: " + Arrays.toString(args)); HelpFormatter formatter = new HelpFormatter(); formatter.setWidth(120); formatter.printHelp(SequentialPersonalizedPageRank.class.getName(), options); ToolRunner.printGenericCommandUsage(System.out); System.exit(-1); } String infile = cmdline.getOptionValue(INPUT); final String source = cmdline.getOptionValue(SOURCE); float alpha = cmdline.hasOption(JUMP) ? Float.parseFloat(cmdline.getOptionValue(JUMP)) : 0.15f; int edgeCnt = 0; DirectedSparseGraph<String, Integer> graph = new DirectedSparseGraph<String, Integer>(); BufferedReader data = new BufferedReader(new InputStreamReader(new FileInputStream(infile))); String line; while ((line = data.readLine()) != null) { line.trim(); String[] arr = line.split("\\t"); for (int i = 1; i < arr.length; i++) { graph.addEdge(new Integer(edgeCnt++), arr[0], arr[i]); } } data.close(); if (!graph.containsVertex(source)) { System.err.println("Error: source node not found in the graph!"); System.exit(-1); } WeakComponentClusterer<String, Integer> clusterer = new WeakComponentClusterer<String, Integer>(); Set<Set<String>> components = clusterer.transform(graph); int numComponents = components.size(); System.out.println("Number of components: " + numComponents); System.out.println("Number of edges: " + graph.getEdgeCount()); System.out.println("Number of nodes: " + graph.getVertexCount()); System.out.println("Random jump factor: " + alpha); // Compute personalized PageRank. PageRankWithPriors<String, Integer> ranker = new PageRankWithPriors<String, Integer>(graph, new Transformer<String, Double>() { @Override public Double transform(String vertex) { return vertex.equals(source) ? 1.0 : 0; } }, alpha); ranker.evaluate(); // Use priority queue to sort vertices by PageRank values. PriorityQueue<Ranking<String>> q = new PriorityQueue<Ranking<String>>(); int i = 0; for (String pmid : graph.getVertices()) { q.add(new Ranking<String>(i++, ranker.getVertexScore(pmid), pmid)); } // Print PageRank values. System.out.println("\nPageRank of nodes, in descending order:"); Ranking<String> r = null; while ((r = q.poll()) != null) { System.out.println(r.rankScore + "\t" + r.getRanked()); } }
From source file:edu.umd.shrawanraina.SequentialPersonalizedPageRank.java
@SuppressWarnings({ "static-access" }) public static void main(String[] args) throws IOException { Options options = new Options(); options.addOption(OptionBuilder.withArgName("path").hasArg().withDescription("input path").create(INPUT)); options.addOption(/*from w w w. ja v a 2 s . c om*/ OptionBuilder.withArgName("val").hasArg().withDescription("random jump factor").create(JUMP)); options.addOption(OptionBuilder.withArgName("node").hasArg() .withDescription("source node (i.e., destination of the random jump)").create(SOURCE)); 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(INPUT) || !cmdline.hasOption(SOURCE)) { System.out.println("args: " + Arrays.toString(args)); HelpFormatter formatter = new HelpFormatter(); formatter.setWidth(120); formatter.printHelp(SequentialPersonalizedPageRank.class.getName(), options); ToolRunner.printGenericCommandUsage(System.out); System.exit(-1); } String infile = cmdline.getOptionValue(INPUT); final String source = cmdline.getOptionValue(SOURCE); float alpha = cmdline.hasOption(JUMP) ? Float.parseFloat(cmdline.getOptionValue(JUMP)) : 0.15f; int edgeCnt = 0; DirectedSparseGraph<String, Integer> graph = new DirectedSparseGraph<String, Integer>(); BufferedReader data = new BufferedReader(new InputStreamReader(new FileInputStream(infile))); String line; while ((line = data.readLine()) != null) { line.trim(); String[] arr = line.split("\\t"); for (int i = 1; i < arr.length; i++) { graph.addEdge(new Integer(edgeCnt++), arr[0], arr[i]); } } data.close(); if (!graph.containsVertex(source)) { System.err.println("Error: source node not found in the graph!"); System.exit(-1); } WeakComponentClusterer<String, Integer> clusterer = new WeakComponentClusterer<String, Integer>(); Set<Set<String>> components = clusterer.transform(graph); int numComponents = components.size(); System.out.println("Number of components: " + numComponents); System.out.println("Number of edges: " + graph.getEdgeCount()); System.out.println("Number of nodes: " + graph.getVertexCount()); System.out.println("Random jump factor: " + alpha); // Compute personalized PageRank. PageRankWithPriors<String, Integer> ranker = new PageRankWithPriors<String, Integer>(graph, new Transformer<String, Double>() { public Double transform(String vertex) { return vertex.equals(source) ? 1.0 : 0; } }, alpha); ranker.evaluate(); // Use priority queue to sort vertices by PageRank values. PriorityQueue<Ranking<String>> q = new PriorityQueue<Ranking<String>>(); int i = 0; for (String pmid : graph.getVertices()) { q.add(new Ranking<String>(i++, ranker.getVertexScore(pmid), pmid)); } // Print PageRank values. System.out.println("\nPageRank of nodes, in descending order:"); Ranking<String> r = null; while ((r = q.poll()) != null) { System.out.println(r.rankScore + "\t" + r.getRanked()); } }
From source file:org.kuali.student.git.tools.Main.java
/** * @param args/*from w w w . j a va2 s. c o m*/ */ public static void main(String[] args) { if (args.length != 2) { log.error("USAGE: <path to git repository> <data file>"); System.exit(-1); } String pathToGitRepo = args[0]; String comparisonTagDataFile = args[1]; try { ClassPathXmlApplicationContext applicationContext = new ClassPathXmlApplicationContext( "git/applicationContext.xml"); applicationContext.registerShutdownHook(); GitExtractor extractor = applicationContext.getBean(GitExtractor.class); extractor.buildRepository(new File(pathToGitRepo)); List<String> pathsToCompare = FileUtils.readLines(new File(comparisonTagDataFile), "UTF-8"); for (String comparisonPath : pathsToCompare) { if (comparisonPath.trim().length() == 0 || comparisonPath.trim().startsWith("#")) continue; // skip empty lines and comments String parts[] = comparisonPath.split(":"); String targetTag = parts[0]; String copyFromTag = parts[1]; extractor.extractDifference(targetTag, copyFromTag); } } catch (Exception e) { log.error("Unexpected Exception", e); } }
From source file:com.doculibre.constellio.solr.handler.component.SearchLogComponent.java
public static void main(String[] args) { String shardUrl = "192.168.88.1:8983/solr/collection1/|192.168.88.1:8900/solr/collection1/"; String[] shardUrlStrs = shardUrl.split("\\|")[0].split("/"); String collectionName = shardUrlStrs[shardUrlStrs.length - 1]; System.out.println(collectionName); }
From source file:com.pureinfo.srm.reports.table.data.sci.SCIBySchoolStatistic.java
public static void main(String[] args) throws PureException { IProductMgr mgr = (IProductMgr) ArkContentHelper.getContentMgrOf(Product.class); IStatement stat = mgr.createQuery(//from w w w.ja v a2 s. c o m "select count({this.id}) _NUM, {this.englishScience} AS _SUB from {this} group by _SUB", 0); IObjects nums = stat.executeQuery(false); DolphinObject num = null; Map map = new HashedMap(); while ((num = nums.next()) != null) { String subest = num.getStrProperty("_SUB"); if (subest == null || subest.trim().length() == 0) continue; String[] subs = subest.split(";"); int nNum = num.getIntProperty("_NUM", 0); for (int i = 0; i < subs.length; i++) { String sSub = subs[i].trim(); Integer odValue = (Integer) map.get(sSub); int sum = odValue == null ? nNum : (nNum + odValue.intValue()); map.put(sSub, new Integer(sum)); } } List l = new ArrayList(map.size()); for (Iterator iter = map.entrySet().iterator(); iter.hasNext();) { Map.Entry en = (Map.Entry) iter.next(); l.add(new Object[] { en.getKey(), en.getValue() }); } Collections.sort(l, new Comparator() { public int compare(Object _sO1, Object _sO2) { Object[] arr1 = (Object[]) _sO1; Object[] arr2 = (Object[]) _sO2; Comparable s1 = (Comparable) arr1[1]; Comparable s2 = (Comparable) arr2[01]; return s1.compareTo(s2); } }); for (Iterator iter = l.iterator(); iter.hasNext();) { Object[] arr = (Object[]) iter.next(); System.out.println(arr[0] + " = " + arr[1]); } }
From source file:Main.java
public static void main(String[] args) { Map<String, Integer> wordCounts = new LinkedHashMap<String, Integer>(); String s = "Lorem ipsum dolor sit amet consetetur iam nonumy sadipscing " + "elitr, sed diam nonumy eirmod tempor invidunt ut erat sed " + "labore et dolore magna dolor sit amet aliquyam erat sed diam"; wordCounts.put("sed", 0); wordCounts.put("erat", 0); for (String t : s.split(" ")) { wordCounts.computeIfPresent(t, (k, v) -> v + 1); }/*from w w w. ja v a2 s . co m*/ System.out.println(wordCounts); }
From source file:edu.jhu.hlt.parma.inference.transducers.UnigramLM.java
/** * @param args//from ww w .java 2s. c o m */ public static void main(String[] args) { String test = "this this this is is a long string in which we say we say that we don't like lms"; List<String> testToks = new ArrayList<String>(Arrays.asList(test.split("\\s+"))); UnigramLM<String> lm = new UnigramLM<String>(); for (String tok : testToks) lm.incrementCount(tok); lm.smoothAndNormalize(); testToks.add("UNK"); for (String tok : testToks) { double pTok = lm.getProb(tok); System.out.printf("%s: %.5f%n", tok, pTok); } System.out.printf("Total mass: %.3f%n", lm.totalMass()); }
From source file:com.talkdesk.geo.PhoneNumberGeoMap.java
/** * @param args//from w w w . j a v a2 s.co m * @throws IOException * @throws SQLException * @throws ClassNotFoundException * @throws GeoResolverException */ public static void main(String[] args) throws GeoResolverException { // create Options object DBConnector connector = new DBConnector(); GeoCodeResolver resolver = new GeoCodeResolver(connector.getDefaultDBconnection()); ArrayList list = new ArrayList(Arrays.asList(args)); Hashtable<String, Double> infoTable = new Hashtable<String, Double>(); if (list.contains("--populate-data")) { GeoCodeRepositoryBuilder repositoryBuilder = new GeoCodeRepositoryBuilder(); if (list.contains("--country")) repositoryBuilder.populateCountryData(); else if (list.contains("--geo")) repositoryBuilder.populateGeoData(); else { repositoryBuilder.populateCountryData(); repositoryBuilder.populateGeoData(); } } else if (list.contains("--same-country-only")) { list.remove("--same-country-only"); infoTable = resolver.buildInfoTable(list, true); } else { infoTable = resolver.buildInfoTable(list, false); } String phoneNumber = resolver.getClosestNumber(infoTable); if (phoneNumber != null) { System.out.println("-----------------------"); System.out.println(phoneNumber); Locale locale = new Locale("en", phoneNumber.split(":")[0]); System.out.println(locale.getDisplayCountry()); } else { System.out.println("-----------------------"); System.out.println("No Result ..!!!"); } }
From source file:jfs.sync.meta.MetaFileStorageAccess.java
/** * * Extract one file from encrypted repository. * * TODO: list directories/*from www .j a v a 2 s. c o m*/ * */ public static void main(String[] args) throws Exception { final String password = args[0]; MetaFileStorageAccess storage = new MetaFileStorageAccess("Twofish", false) { protected String getPassword(String relativePath) { String result = ""; String pwd = password; int i = 0; int j = relativePath.length() - 1; while ((i < pwd.length()) || (j >= 0)) { if (i < pwd.length()) { result += pwd.charAt(i++); } // if if (j >= 0) { result += relativePath.charAt(j--); } // if } // while return result; } // getPassword() }; String encryptedPath = args[2]; String[] elements = encryptedPath.split("\\\\"); String path = ""; for (int i = 0; i < elements.length; i++) { String encryptedName = elements[i]; String plain = storage.getDecryptedFileName(path, encryptedName); path += storage.getSeparator(); path += plain; System.out.println(path); } // for String cipherSpec = storage.getCipherSpec(); byte[] credentials = storage.getFileCredentials(path); Cipher cipher = SecurityUtils.getCipher(cipherSpec, Cipher.DECRYPT_MODE, credentials); InputStream is = storage.getInputStream(args[1], path); is = JFSEncryptedStream.createInputStream(is, JFSEncryptedStream.DONT_CHECK_LENGTH, cipher); int b = 0; while (b >= 0) { b = is.read(); System.out.print((char) b); } // while is.close(); }