List of usage examples for org.apache.commons.lang3 StringUtils repeat
public static String repeat(final char ch, final int repeat)
From source file:org.languagetool.dev.bigdata.ConfusionRuleEvaluator.java
private Map<Long, RuleEvalResult> printEvalResult(List<Sentence> allTokenSentences, List<Sentence> allHomophoneSentences, List<String> inputsOrDir, String token, String homophoneToken) { Map<Long, RuleEvalResult> results = new LinkedHashMap<>(); int sentences = allTokenSentences.size() + allHomophoneSentences.size(); System.out.println("\nEvaluation results for " + token + "/" + homophoneToken + " with " + sentences + " sentences as of " + new Date() + ":"); System.out.printf(ENGLISH, "Inputs: %s\n", inputsOrDir); System.out.printf(ENGLISH, "Case sensit.: %s\n", caseSensitive); List<Long> factors = evalValues.keySet().stream().sorted().collect(toList()); for (Long factor : factors) { RuleEvalValues evalValues = this.evalValues.get(factor); float precision = (float) evalValues.truePositives / (evalValues.truePositives + evalValues.falsePositives); float recall = (float) evalValues.truePositives / (evalValues.truePositives + evalValues.falseNegatives); String date = new SimpleDateFormat("yyyy-MM-dd").format(new Date()); String spaces = StringUtils.repeat(" ", 82 - Long.toString(factor).length()); String word1 = token;/*from ww w.j a va2 s.co m*/ String word2 = homophoneToken; String delimiter = " -> "; if (bothDirections) { delimiter = "; "; if (word1.compareTo(word2) > 0) { String temp = word1; word1 = word2; word2 = temp; } } float fMeasureBeta = 0.5f; String summary = String.format(ENGLISH, "%s%s%s; %d; %s # p=%.3f, r=%.3f, f%.1f=%.3f, %d+%d, %dgrams, %s", word1, delimiter, word2, factor, spaces, precision, recall, fMeasureBeta, FMeasure.getFMeasure(precision, recall, fMeasureBeta), allTokenSentences.size(), allHomophoneSentences.size(), rule.getNGrams(), date); results.put(factor, new RuleEvalResult(summary, precision, recall)); if (verbose) { System.out.println(); System.out.printf(ENGLISH, "Factor: %d - %d false positives, %d false negatives, %d true positives, %d true negatives\n", factor, evalValues.falsePositives, evalValues.falseNegatives, evalValues.truePositives, evalValues.trueNegatives); //System.out.printf(ENGLISH, "Precision: %.3f (%d false positives)\n", precision, evalValues.falsePositives); //System.out.printf(ENGLISH, "Recall: %.3f (%d false negatives)\n", recall, evalValues.falseNegatives); //double fMeasure = FMeasure.getWeightedFMeasure(precision, recall); //System.out.printf(ENGLISH, "F-measure: %.3f (beta=0.5)\n", fMeasure); //System.out.printf(ENGLISH, "Good Matches: %d (true positives)\n", evalValues.truePositives); //System.out.printf(ENGLISH, "All matches: %d\n", evalValues.truePositives + evalValues.falsePositives); System.out.printf(summary + "\n"); } } return results; }
From source file:org.languagetool.dev.eval.RealWordCorpusEvaluator.java
private void checkLines(ErrorCorpus corpus) throws IOException { for (ErrorSentence sentence : corpus) { List<RuleMatch> matches = evaluator.check(sentence.getAnnotatedText()); sentenceCount++;//ww w . j a va 2 s . c om errorsInCorpusCount += sentence.getErrors().size(); System.out.println(sentence.getMarkupText() + " => " + matches.size()); for (RuleMatch match : matches) { int length = match.getToPos() - match.getFromPos(); System.out.println(StringUtils.repeat(" ", match.getFromPos()) + StringUtils.repeat("^", length)); } List<Span> detectedErrorPositions = new ArrayList<>(); for (RuleMatch match : matches) { boolean alreadyCounted = errorAlreadyCounted(match, detectedErrorPositions); if (!alreadyCounted && sentence.hasErrorCoveredByMatchAndGoodFirstSuggestion(match)) { //TODO: it depends on the order of matches whether [++] comes before [ +] (it should!) goodMatches++; perfectMatches++; matchCount++; if (isConfusionRule(match)) { perfectConfusionMatches++; } System.out.println(" [++] " + match + ": " + match.getSuggestedReplacements()); } else if (!alreadyCounted && sentence.hasErrorCoveredByMatch(match)) { //} else if (!alreadyCounted && sentence.hasErrorOverlappingWithMatch(match)) { goodMatches++; matchCount++; if (isConfusionRule(match)) { goodConfusionMatches++; } System.out.println(" [+ ] " + match + ": " + match.getSuggestedReplacements()); } else if (alreadyCounted) { System.out.println(" [//] " + match + ": " + match.getSuggestedReplacements()); } else { System.out.println(" [ ] " + match + ": " + match.getSuggestedReplacements()); matchCount++; if (isConfusionRule(match)) { badConfusionMatches++; badConfusionMatchWords .add(sentence.getMarkupText().substring(match.getFromPos(), match.getToPos())); } } detectedErrorPositions.add(new Span(match.getFromPos(), match.getToPos())); } } }
From source file:org.languagetool.dev.eval.SimpleCorpusEvaluator.java
private void checkLines(ErrorCorpus corpus) throws IOException { for (ErrorSentence sentence : corpus) { List<RuleMatch> matches = evaluator.check(sentence.getAnnotatedText()); sentenceCount++;//from ww w .j av a2 s. com errorsInCorpusCount += sentence.getErrors().size(); System.out.println(sentence.getMarkupText() + " => " + matches.size()); for (RuleMatch match : matches) { int length = match.getToPos() - match.getFromPos(); System.out.println(StringUtils.repeat(" ", match.getFromPos()) + StringUtils.repeat("^", length)); } List<Span> detectedErrorPositions = new ArrayList<>(); int tmpGoodMatches = 0; for (RuleMatch match : matches) { boolean alreadyCounted = errorAlreadyCounted(match, detectedErrorPositions); if (!alreadyCounted && sentence.hasErrorCoveredByMatchAndGoodFirstSuggestion(match)) { //TODO: it depends on the order of matches whether [++] comes before [ +] (it should!) tmpGoodMatches++; matchCount++; System.out.println(" [++] " + match + ": " + match.getSuggestedReplacements()); //} else if (!alreadyCounted && sentence.hasErrorCoveredByMatch(match)) { } else if (!alreadyCounted && sentence.hasErrorOverlappingWithMatch(match)) { tmpGoodMatches++; matchCount++; System.out.println(" [+ ] " + match + ": " + match.getSuggestedReplacements()); } else if (alreadyCounted) { System.out.println(" [//] " + match + ": " + match.getSuggestedReplacements()); } else { System.out.println(" [ ] " + match + ": " + match.getSuggestedReplacements()); matchCount++; } detectedErrorPositions.add(new Span(match.getFromPos(), match.getToPos())); } // Make sure we don't count matches twice, this could cause a recall > 1: goodMatches += Math.min(tmpGoodMatches, 1); } }
From source file:org.languagetool.dev.Fuzzer.java
String fuzz(Random rnd, int length) { StringBuilder sb = new StringBuilder(); for (int i = 0; i < charList.length; i++) { int randomPos = rnd.nextInt(charList.length); int repeat = rnd.nextInt(length); String s = StringUtils.repeat(charList[randomPos], repeat); sb.append(s);/* w w w. j a v a 2 s . com*/ } return sb.toString(); }
From source file:org.libreplan.business.reports.dtos.Util.java
public static String getPrefixSpacesDependingOnDepth(ITreeNode<?> node) { int depth = 0; while (node.getParent() != null && node.getParent().getParent() != null) { depth++;/*from w w w.ja va 2 s .c o m*/ node = node.getParent(); } return StringUtils.repeat(INDENT_PREFIX, depth); }
From source file:org.lockss.repository.TestRepositoryNodeImpl.java
void findMaxDirPath(File root) { int maxName = findMaxDirname(root) - 10; String one = mkstr("onedir", maxName) + "/"; for (int rpt = 1; rpt < 1000; rpt++) { String path = StringUtils.repeat(one, rpt); File dir = new File(root, path); String dirstr = dir.getPath(); boolean res = dir.mkdirs(); if (!res) { log.info("mkdirs failed at " + dirstr.length() + " chars"); break; }//from w ww. j a v a2 s .co m log.info("mkdirs ok: " + dirstr.length()); File f = new File(dir, "foobbb"); try { OutputStream os = new FileOutputStream(f); os.close(); log.info("file ok at " + f.getPath().length() + " chars"); } catch (FileNotFoundException fnfe) { log.info("FNF: " + f.getPath().length(), fnfe); } catch (IOException ioe) { log.error("IOE: " + f.getPath().length() + ", " + ioe.getMessage()); } } }
From source file:org.lockss.repository.TestRepositoryNodeImpl.java
void findMaxDirPathNio(File root) { int maxName = findMaxDirname(root) - 10; String one = mkstr("onedir", maxName) + "/"; for (int rpt = 1; rpt < 1000; rpt++) { String path = StringUtils.repeat(one, rpt); File dir = new File(root, path); String dirstr = dir.getPath(); boolean res = dir.mkdirs(); if (!res) { log.info("mkdirs failed at " + dirstr.length() + " chars"); break; }//from ww w . ja v a 2 s. c o m log.info("mkdirs ok: " + dirstr.length()); File f = new File(dir, "foobbb"); try { Path npath = Paths.get(f.getPath()); Files.createFile(npath); FileChannel ochan = FileChannel.open(npath, StandardOpenOption.WRITE); OutputStream os = Channels.newOutputStream(ochan); os.write((byte) 44); os.close(); FileChannel ichan = FileChannel.open(npath, StandardOpenOption.READ); InputStream is = Channels.newInputStream(ichan); int bb = is.read(); is.close(); assertEquals(44, bb); log.info("file ok at " + npath.toString().length() + " chars"); } catch (FileNotFoundException fnfe) { log.error("FNF: " + f.getPath().length(), fnfe); } catch (IOException ioe) { log.error("IOE: " + f.getPath().length() + ", " + ioe.getMessage()); } } }
From source file:org.lockss.truezip.TestTFileCache.java
String content(int n) { if (n > 10) { return "small content"; }/*w w w . jav a2s.c o m*/ return StringUtils.repeat(Integer.toString(n), n * n * n) + " shall be the number of the counting"; }
From source file:org.lockss.util.StringUtil.java
/** Return a string of n spaces */ public static String tab(int n) { return StringUtils.repeat(" ", n); }
From source file:org.mabb.fontverter.converter.WoffToOtfConverter.java
private void readTables() throws IOException, InstantiationException, IllegalAccessException { for (WoffTable tableOn : woffFont.getTables()) { OpenTypeTable.OtfTableRecord record = new OpenTypeTable.OtfTableRecord(); record.recordName = tableOn.getTag(); if (record.recordName.length() < 4) record.recordName = record.recordName + StringUtils.repeat(" ", 4 - record.recordName.length()); record.originalData = tableOn.getTableData(); OpenTypeTable table = OpenTypeTable.createFromRecord(record, otfFont); table.isFromParsedFont = true;/* ww w . j av a 2s . c o m*/ otfFont.addTable(table); } // have to order by dependant tables before doing table reads otfFont.orderTablesByDependencies(); for (OpenTypeTable tableOn : otfFont.getTables()) tableOn.readData(tableOn.record.originalData); }