List of usage examples for java.lang String split
public String[] split(String regex)
From source file:edu.usc.ee599.CommunityStats.java
public static void main(String[] args) throws Exception { File dir = new File("results5"); PrintWriter writer = new PrintWriter(new FileWriter("results5_stats.txt")); File[] files = dir.listFiles(); DescriptiveStatistics statistics1 = new DescriptiveStatistics(); DescriptiveStatistics statistics2 = new DescriptiveStatistics(); for (File file : files) { BufferedReader reader = new BufferedReader(new FileReader(file)); String line1 = reader.readLine(); String line2 = reader.readLine(); int balanced = Integer.parseInt(line1.split(",")[1]); int unbalanced = Integer.parseInt(line2.split(",")[1]); double bp = (double) balanced / (double) (balanced + unbalanced); double up = (double) unbalanced / (double) (balanced + unbalanced); statistics1.addValue(bp);// w w w.j ava 2s.co m statistics2.addValue(up); } writer.println("AVG Balanced %: " + statistics1.getMean()); writer.println("AVG Unbalanced %: " + statistics2.getMean()); writer.println("STD Balanced %: " + statistics1.getStandardDeviation()); writer.println("STD Unbalanced %: " + statistics2.getStandardDeviation()); writer.flush(); writer.close(); }
From source file:com.ifeng.sorter.NginxApp.java
public static void main(String[] args) { String input = "src/test/resources/data/nginx_report.txt"; PrintWriter pw = null;/*from w ww . ja v a2s . co m*/ Map<String, List<LogBean>> resultMap = new HashMap<String, List<LogBean>>(); List<String> ips = new ArrayList<String>(); try { List<String> lines = FileUtils.readLines(new File(input)); List<LogBean> items = new ArrayList<LogBean>(); for (String line : lines) { String[] values = line.split("\t"); if (values != null && values.length == 3) {// ip total seria try { String ip = values[0].trim(); String total = values[1].trim(); String seria = values[2].trim(); LogBean bean = new LogBean(ip, Integer.parseInt(total), seria); items.add(bean); } catch (NumberFormatException e) { e.printStackTrace(); } } } Collections.sort(items); for (LogBean bean : items) { String key = bean.getIp(); if (resultMap.containsKey(key)) { resultMap.get(key).add(bean); } else { List<LogBean> keyList = new ArrayList<LogBean>(); keyList.add(bean); resultMap.put(key, keyList); ips.add(key); } } pw = new PrintWriter("src/test/resources/output/result.txt", "UTF-8"); for (String ip : ips) { List<LogBean> list = resultMap.get(ip); for (LogBean bean : list) { pw.append(bean.toString()); pw.println(); } } } catch (IOException e) { e.printStackTrace(); } finally { pw.flush(); pw.close(); } }
From source file:io.zz.TestSaveToCassandra.java
public static void main(String[] args) throws IOException, InterruptedException { SparkConf conf = new SparkConf().setAppName("aaaa").setMaster("spark://192.168.100.105:7077") .set("spark.serializer", "org.apache.spark.serializer.KryoSerializer") .set("spark.cassandra.connection.host", "192.168.100.105"); JavaStreamingContext streamingContext = new JavaStreamingContext(conf, new Duration(10000)); JavaDStream<String> stream = streamingContext.socketTextStream("192.168.100.105", 9999); // stream.count().print(); SQLContext sql = SQLContext.getOrCreate(streamingContext.sparkContext().sc()); Dataset<Name> ds = sql.createDataset(ImmutableList.of(new Name("a", "b")), Encoders.bean(Name.class)); CassandraConnector cc = CassandraConnector.apply(conf); try (Session session = cc.openSession()) { String file = IOUtils.toString(TestSaveToCassandra.class.getResourceAsStream("/c.sql")); Arrays.stream(file.split(";")).map(s -> s.trim()).filter(s -> !s.isEmpty()).map(s -> s + ";") .forEach((String str) -> session.execute(str)); }//from ww w.j a va 2 s . c om // ds.toDF().write().mode(SaveMode.Overwrite).option("truncate", "true").jdbc("", "", new Properties()); JavaDStream<Name> map = stream.map(s -> new Name(s, "e")); map.foreachRDD((s, t) -> process(s)); CassandraStreamingJavaUtil.javaFunctions(map) .writerBuilder("keyspace1", "name", CassandraJavaUtil.mapToRow(Name.class)).saveToCassandra(); streamingContext.start(); streamingContext.awaitTermination(); streamingContext.stop(); }
From source file:jsonparser.ToJSON.java
public static void main(String args[]) throws FileNotFoundException, IOException { String text_file = "C:/Users/Kevin/Documents/NetBeansProjects/JsonParser/src/jsonparser/sample.txt"; File file = new File(text_file); String s1, s2, s3; s1 = (String) FileUtils.readLines(file).get(0); String split1[] = s1.split("="); contact_id = split1[1];/* w w w . ja v a 2 s . c om*/ s2 = (String) FileUtils.readLines(file).get(1); String split2[] = s2.split("="); confidence_level = Float.valueOf(split2[1]); s3 = (String) FileUtils.readLines(file).get(2); String split3[] = s3.split("="); if (split3[1].equals(" Found")) { is_matched = true; } else { is_matched = false; } System.out.println("Read from text file:"); System.out.println("contact_id =" + contact_id); System.out.println("confidence_level = " + confidence_level); System.out.println("is_matched = " + is_matched); FacialRecognition fr = new FacialRecognition(); fr.setContactID(contact_id); fr.setConfidenceLevel(confidence_level); fr.setIsMatched(is_matched); Gson gson = new GsonBuilder().setPrettyPrinting().create(); //convert java object to JSON format String json = gson.toJson(fr); //write JSON to a file try { //write converted json data to a file named "CountryGSON.json" FileWriter writer = new FileWriter( "C:/Users/Kevin/Documents/NetBeansProjects/JsonParser/src/jsonparser/test.json", true); writer.write("" + json + ",\n"); writer.close(); } catch (IOException e) { e.printStackTrace(); } //eventually need to change to send over back to client-side System.out.println(); System.out.println("Coverting strings into JSON..."); System.out.println(json); }
From source file:featureExtractor.popularityMeasure.java
public static void main(String[] args) throws IOException { //ReadKnownPopularityScores(); FileWriter fw = new FileWriter(Out_resultFile); BufferedWriter bw = new BufferedWriter(fw); FileReader inputFile = new FileReader(In_entities); BufferedReader bufferReader = new BufferedReader(inputFile); String line; while ((line = bufferReader.readLine()) != null) { String[] row = line.split("\t"); double score = 0; String entityName = row[0].toLowerCase().trim(); System.out.println("Searching for : " + entityName); if (knownScore_table.containsKey(entityName)) { //System.out.println("Already known for: " + entityName); score = knownScore_table.get(entityName); } else {/*from w ww . j av a2s . co m*/ System.out.println("Not known for: " + entityName); String json = searchTest(entityName, "&scoring=entity"); try { score = ParseJSON_getScore(json); } catch (Exception e) { score = 0; } System.out.println("Putting : " + entityName); knownScore_table.put(entityName, score); } bw.write(row[0] + "\t" + score + "\n"); System.out.println(row[0]); } bw.close(); }
From source file:GCS_Auth.java
public static void main(String[] args) { String client_id = null;/*from w ww . j av a 2 s . c o m*/ String key = null; for (String a : args) { if (a.startsWith("--key=")) key = a.split("=")[1]; if (a.startsWith("--client_id=")) client_id = a.split("=")[1]; } if ((args.length < 2) || client_id == null || key == null) { System.out.println("specify --key= --client_id="); System.exit(-1); } GCS_Auth j = new GCS_Auth(client_id, key); }
From source file:com.linkedin.pinot.perf.MultiValueReaderWriterBenchmark.java
public static void main(String[] args) throws Exception { List<String> lines = IOUtils.readLines(new FileReader(new File(args[0]))); int totalDocs = lines.size(); int max = Integer.MIN_VALUE; int maxNumberOfMultiValues = Integer.MIN_VALUE; int totalNumValues = 0; int data[][] = new int[totalDocs][]; for (int i = 0; i < lines.size(); i++) { String line = lines.get(i); String[] split = line.split(","); totalNumValues = totalNumValues + split.length; if (split.length > maxNumberOfMultiValues) { maxNumberOfMultiValues = split.length; }//www . j av a 2s.c om data[i] = new int[split.length]; for (int j = 0; j < split.length; j++) { String token = split[j]; int val = Integer.parseInt(token); data[i][j] = val; if (val > max) { max = val; } } } int maxBitsNeeded = (int) Math.ceil(Math.log(max) / Math.log(2)); int size = 2048; int[] offsets = new int[size]; int bitMapSize = 0; File outputFile = new File("output.mv.fwd"); FixedBitSkipListSCMVWriter fixedBitSkipListSCMVWriter = new FixedBitSkipListSCMVWriter(outputFile, totalDocs, totalNumValues, maxBitsNeeded); for (int i = 0; i < totalDocs; i++) { fixedBitSkipListSCMVWriter.setIntArray(i, data[i]); if (i % size == size - 1) { MutableRoaringBitmap rr1 = MutableRoaringBitmap.bitmapOf(offsets); ByteArrayOutputStream bos = new ByteArrayOutputStream(); DataOutputStream dos = new DataOutputStream(bos); rr1.serialize(dos); dos.close(); //System.out.println("Chunk " + i / size + " bitmap size:" + bos.size()); bitMapSize += bos.size(); } else if (i == totalDocs - 1) { MutableRoaringBitmap rr1 = MutableRoaringBitmap.bitmapOf(Arrays.copyOf(offsets, i % size)); ByteArrayOutputStream bos = new ByteArrayOutputStream(); DataOutputStream dos = new DataOutputStream(bos); rr1.serialize(dos); dos.close(); //System.out.println("Chunk " + i / size + " bitmap size:" + bos.size()); bitMapSize += bos.size(); } } fixedBitSkipListSCMVWriter.close(); System.out.println("Output file size:" + outputFile.length()); System.out.println("totalNumberOfDoc\t\t\t:" + totalDocs); System.out.println("totalNumberOfValues\t\t\t:" + totalNumValues); System.out.println("chunk size\t\t\t\t:" + size); System.out.println("Num chunks\t\t\t\t:" + totalDocs / size); int numChunks = totalDocs / size + 1; int totalBits = (totalNumValues * maxBitsNeeded); int dataSizeinBytes = (totalBits + 7) / 8; System.out.println("Raw data size with fixed bit encoding\t:" + dataSizeinBytes); System.out.println("\nPer encoding size"); System.out.println(); System.out.println("size (offset + length)\t\t\t:" + ((totalDocs * (4 + 4)) + dataSizeinBytes)); System.out.println(); System.out.println("size (offset only)\t\t\t:" + ((totalDocs * (4)) + dataSizeinBytes)); System.out.println(); System.out.println("bitMapSize\t\t\t\t:" + bitMapSize); System.out.println("size (with bitmap)\t\t\t:" + (bitMapSize + (numChunks * 4) + dataSizeinBytes)); System.out.println(); System.out.println("Custom Bitset\t\t\t\t:" + (totalNumValues + 7) / 8); System.out.println("size (with custom bitset)\t\t\t:" + (((totalNumValues + 7) / 8) + (numChunks * 4) + dataSizeinBytes)); }
From source file:de.tudarmstadt.ukp.experiments.argumentation.convincingness.sampling.Step5bAgreementMeasures.java
@SuppressWarnings("unchecked") public static void main(String[] args) throws Exception { String inputDir = args[0];/*from www . ja v a2 s .c om*/ // all annotations List<AnnotatedArgumentPair> allArgumentPairs = new ArrayList<>(); Collection<File> files = IOHelper.listXmlFiles(new File(inputDir)); for (File file : files) { allArgumentPairs.addAll((List<AnnotatedArgumentPair>) XStreamTools.getXStream().fromXML(file)); } // for collecting the rank of n-th best worker per HIT SortedMap<Integer, DescriptiveStatistics> nThWorkerOnHITRank = new TreeMap<>(); // confusion matrix wrt. gold data for each n-th best worker on HIT SortedMap<Integer, ConfusionMatrix> nThWorkerOnHITConfusionMatrix = new TreeMap<>(); // initialize maps for (int i = 0; i < TOP_K_VOTES; i++) { nThWorkerOnHITRank.put(i, new DescriptiveStatistics()); nThWorkerOnHITConfusionMatrix.put(i, new ConfusionMatrix()); } for (AnnotatedArgumentPair argumentPair : allArgumentPairs) { // sort turker rank and their vote SortedMap<Integer, String> rankAndVote = new TreeMap<>(); System.out.println(argumentPair.mTurkAssignments.size()); for (AnnotatedArgumentPair.MTurkAssignment assignment : argumentPair.mTurkAssignments) { rankAndVote.put(assignment.getTurkRank(), assignment.getValue()); } String goldLabel = argumentPair.getGoldLabel(); System.out.println(rankAndVote); // top K workers for the HIT List<String> topKVotes = new ArrayList<>(rankAndVote.values()).subList(0, TOP_K_VOTES); // rank of top K workers List<Integer> topKRanks = new ArrayList<>(rankAndVote.keySet()).subList(0, TOP_K_VOTES); System.out.println("Top K votes: " + topKVotes); System.out.println("Top K ranks: " + topKRanks); // extract only category (a1, a2, or equal) List<String> topKVotesOnlyCategory = new ArrayList<>(); for (String vote : topKVotes) { String category = vote.split("_")[2]; topKVotesOnlyCategory.add(category); } System.out.println("Top " + TOP_K_VOTES + " workers' decisions: " + topKVotesOnlyCategory); if (goldLabel == null) { System.out.println("No gold label estimate for " + argumentPair.getId()); } else { // update statistics for (int i = 0; i < TOP_K_VOTES; i++) { nThWorkerOnHITConfusionMatrix.get(i).increaseValue(goldLabel, topKVotesOnlyCategory.get(i)); // rank is +1 (we don't start ranking from zero) nThWorkerOnHITRank.get(i).addValue(topKRanks.get(i) + 1); } } } for (int i = 0; i < TOP_K_VOTES; i++) { System.out.println("n-th worker : " + (i + 1) + " -----------"); System.out.println(nThWorkerOnHITConfusionMatrix.get(i).printNiceResults()); System.out.println(nThWorkerOnHITConfusionMatrix.get(i)); System.out.println("Average rank: " + nThWorkerOnHITRank.get(i).getMean() + ", stddev " + nThWorkerOnHITRank.get(i).getStandardDeviation()); } }
From source file:eval.dataset.ParseWikiLog.java
public static void main(String[] ss) throws FileNotFoundException, ParserConfigurationException, IOException { FileInputStream fin = new FileInputStream("data/enwiki-20151201-pages-logging.xml.gz"); GzipCompressorInputStream gzIn = new GzipCompressorInputStream(fin); InputStreamReader reader = new InputStreamReader(gzIn); BufferedReader br = new BufferedReader(reader); PrintWriter pw = new PrintWriter(new FileWriter("data/user_page.txt")); pw.println(//w ww. j a v a 2s . c om "#list of user names and pages that they have edited, deleted or created. These info are mined from logitems of enwiki-20150304-pages-logging.xml.gz"); TreeMap<String, Set<String>> userPageList = new TreeMap(); TreeSet<String> pageList = new TreeSet(); int counterEntry = 0; String currentUser = null; String currentPage = null; try { for (String line = br.readLine(); line != null; line = br.readLine()) { if (line.trim().equals("</logitem>")) { counterEntry++; if (currentUser != null && currentPage != null) { updateMap(userPageList, currentUser, currentPage); pw.println(currentUser + "\t" + currentPage); pageList.add(currentPage); } currentUser = null; currentPage = null; } else if (line.trim().startsWith("<username>")) { currentUser = line.trim().split(">")[1].split("<")[0].replace(" ", "_"); } else if (line.trim().startsWith("<logtitle>")) { String content = line.trim().split(">")[1].split("<")[0]; if (content.split(":").length == 1) { currentPage = content.replace(" ", "_"); } } } } catch (IOException ex) { Logger.getLogger(ParseWikiLog.class.getName()).log(Level.SEVERE, null, ex); } pw.println("#analysed " + counterEntry + " entries of wikipesia log file"); pw.println("#gathered a list of unique user of size " + userPageList.size()); pw.println("#gathered a list of pages of size " + pageList.size()); pw.close(); gzIn.close(); PrintWriter pwUser = new PrintWriter(new FileWriter("data/user_list_page_edited.txt")); pwUser.println( "#list of unique users and pages that they have edited, extracted from logitems of enwiki-20150304-pages-logging.xml.gz"); for (String user : userPageList.keySet()) { pwUser.print(user); Set<String> getList = userPageList.get(user); for (String page : getList) { pwUser.print("\t" + page); } pwUser.println(); } pwUser.close(); PrintWriter pwPage = new PrintWriter(new FileWriter("data/all_pages.txt")); pwPage.println("#list of the unique pages that are extracted from enwiki-20150304-pages-logging.xml.gz"); for (String page : pageList) { pwPage.println(page); } pwPage.close(); System.out.println("#analysed " + counterEntry + " entries of wikipesia log file"); System.out.println("#gathered a list of unique user of size " + userPageList.size()); System.out.println("#gathered a list of pages of size " + pageList.size()); }
From source file:org.bimserver.build.CreateGitHubRelease.java
public static void main(String[] args) { String username = args[0];/*from w ww . j ava2 s . c om*/ String password = args[1]; String repo = args[2]; String project = args[3]; String tagname = args[4]; String name = args[5]; String body = args[6]; String draft = args[7]; String prerelease = args[8]; String filesString = args[9]; String[] filenames = filesString.split(";"); GitHubClient gitHubClient = new GitHubClient("api.github.com"); gitHubClient.setCredentials(username, password); Map<String, String> map = new HashMap<String, String>(); map.put("tag_name", tagname); // map.put("target_commitish", "test"); map.put("name", name); map.put("body", body); // map.put("draft", draft); // map.put("prerelease", prerelease); try { String string = "/repos/" + repo + "/" + project + "/releases"; System.out.println(string); JsonObject gitHubResponse = gitHubClient.post(string, map, JsonObject.class); System.out.println(gitHubResponse); String id = gitHubResponse.get("id").getAsString(); HttpHost httpHost = new HttpHost("uploads.github.com", 443, "https"); BasicCredentialsProvider basicCredentialsProvider = new BasicCredentialsProvider(); basicCredentialsProvider.setCredentials(new AuthScope(httpHost), new UsernamePasswordCredentials(username, password)); HostnameVerifier hostnameVerifier = new AllowAllHostnameVerifier(); SSLContextBuilder builder = new SSLContextBuilder(); builder.loadTrustMaterial(null, new TrustSelfSignedStrategy()); SSLConnectionSocketFactory sslsf = new SSLConnectionSocketFactory(builder.build()); CloseableHttpClient client = HttpClients.custom() .setDefaultCredentialsProvider(basicCredentialsProvider) .setHostnameVerifier((X509HostnameVerifier) hostnameVerifier).setSSLSocketFactory(sslsf) .build(); AuthCache authCache = new BasicAuthCache(); BasicScheme basicAuth = new BasicScheme(); authCache.put(httpHost, basicAuth); HttpClientContext context = HttpClientContext.create(); context.setCredentialsProvider(basicCredentialsProvider); context.setAuthCache(authCache); for (String filename : filenames) { File file = new File(filename); String url = "https://uploads.github.com/repos/" + repo + "/" + project + "/releases/" + id + "/assets?name=" + file.getName(); HttpPost post = new HttpPost(url); post.setHeader("Accept", "application/vnd.github.manifold-preview"); post.setHeader("Content-Type", "application/zip"); post.setEntity(new InputStreamEntity(new FileInputStream(file), file.length())); HttpResponse execute = client.execute(httpHost, post, context); execute.getEntity().getContent().close(); } } catch (IOException e) { e.printStackTrace(); } catch (NoSuchAlgorithmException e) { e.printStackTrace(); } catch (KeyStoreException e) { e.printStackTrace(); } catch (KeyManagementException e) { e.printStackTrace(); } }