protected List<String> removeDollarWordAndNonAlphaFromList(List<String> list) { List<String> result = new ArrayList<String>(); Pattern p = Pattern.compile("^\\$(\\d{1,3}(\\,\\d{3})*|(\\d+))(\\.\\d{2})?$"); for (String w : list) { if (!(p.matcher(w).find()) && StringUtils.isAlphanumeric(w) && (w.length() >= 3 || !StringUtils.isAlpha(w))) result.add(w); } return result; }
static String checkFirstLetter(String letter) { letter = StringUtils.replaceChars(letter, "ABCDEFGHIJKLMNOPQRSTUVWXYZ", "abcdefghijklmnopqrstuvwxyz"); if (letter.equals("_") || letter.equals("$") || StringUtils.isAlpha(letter)){ return letter; } else if (StringUtils.isNumeric(letter)) { return "_"+letter; } else { return "_"; } }
static String checkFirstLetter(String letter) { letter = StringUtils.replaceChars(letter, "ABCDEFGHIJKLMNOPQRSTUVWXYZ", "abcdefghijklmnopqrstuvwxyz"); if (letter.equals("_") || letter.equals("$") || StringUtils.isAlpha(letter)){ return letter; } else if (StringUtils.isNumeric(letter)) { return "_"+letter; } else { return "_"; } }
/** * John -> J * J. -> J */ public static String getInitial(String fromName) { if (fromName == null) { return null; } String fromName_ = fromName.trim(); if (StringUtils.isEmpty(fromName_)) { return null; } String firstChar = fromName_.substring(0,1); if (StringUtils.isAlpha(firstChar)) { return firstChar.toUpperCase(); } else { return null; } }
/** * Construct a list of language codes (ISO 639-1) from the Accept-Languages header. This method filters out some * bugs in different browsers or containers, like returning '*' as a language (Jetty) or using '_' as a * language--country delimiter (some versions of Opera). * * @param request The client request. * @return A list of language codes, in the client preference order; might be empty if the header is not well * formed. */ @SuppressWarnings("unchecked") private List<String> getAcceptedLanguages(XWikiRequest request) { List<String> result = new ArrayList<String>(); Enumeration<Locale> e = request.getLocales(); while (e.hasMoreElements()) { String language = e.nextElement().getLanguage().toLowerCase(); // All language codes should have 2 letters. if (StringUtils.isAlpha(language)) { result.add(language); } } return result; }
/** * Extracts the file extension from the given filename and looks up the * content type * @param filename * @return the matched content type, or null if there is no match */ private static String getContentType(String filename){ if (filename == null) return null; if (filename.length() == 0) return null; if (filename.endsWith(".")) return null; if (filename.startsWith(".") && filename.lastIndexOf(".")==0) return null; if (filename.contains(".")){ String type = null; String[] parts = filename.split("\\."); String ext = parts[parts.length-1]; if (ext.length() != 0){ if (StringUtils.isAlpha(ext)){ type = getContentTypeForExtension(ext); if (type!=null) return type; } } } return null; }
private List<String> assessKeywordOverlap(String snapshot1, String snapshot2) { List<String> results = new ArrayList<String>(); List<String> firstList = TextProcessor.fastTokenize(snapshot1, false), secondList = TextProcessor.fastTokenize(snapshot2, false); firstList.retainAll(secondList); for(String s: firstList){ if (s.length()<4) continue; if (!StringUtils.isAlpha(s)) continue; results.add(s); } return results; }
public static String formClassifQuery(String pageContentReader, int maxRes) { // We want to control which delimiters we substitute. For example '_' & // \n we retain pageContentReader = pageContentReader.replaceAll("[^A-Za-z0-9 _\\n]", ""); Scanner in = new Scanner(pageContentReader); in.useDelimiter("\\s+"); Map<String, Integer> words = new HashMap<String, Integer>(); while (in.hasNext()) { String word = in.next(); if (!StringUtils.isAlpha(word) || word.length() < 4) continue; if (!words.containsKey(word)) { words.put(word, 1); } else { words.put(word, words.get(word) + 1); } } in.close(); words = ValueSortMap.sortMapByValue(words, false); List<String> resultsAll = new ArrayList<String>(words.keySet()), results = null; int len = resultsAll.size(); if (len > maxRes) results = resultsAll.subList(len - maxRes, len - 1); // get maxRes // elements else results = resultsAll; return results.toString().replaceAll("(\\[|\\]|,)", " ").trim(); }
public List<String> getMostFrequentWordsInText(String input) { int maxRes = 4; Scanner in = new Scanner(input); in.useDelimiter("\\s+"); Map<String, Integer> words = new HashMap<String, Integer>(); while (in.hasNext()) { String word = in.next(); if (!StringUtils.isAlpha(word) || word.length()<4 ) continue; if (!words.containsKey(word)) { words.put(word, 1); } else { words.put(word, words.get(word) + 1); } } words = ValueSortMap.sortMapByValue(words, false); List<String> results = new ArrayList<String>(words.keySet()); if (results.size() > maxRes ) results = results.subList(0, maxRes); // get maxRes elements return results; } public List<String> getMostFrequentWordsInTextArr(String[] longestSents) {
/** * Generate a unique id attribute using the passed text as the seed value. The generated id complies with the XHTML * specification. Extract from <a href="http://www.w3.org/TR/xhtml1/#C_8">XHTML RFC</a>: * <p> * <code> When defining fragment identifiers to be backward-compatible, only strings matching the pattern * [A-Za-z][A-Za-z0-9:_.-]* should be used.</code> * </p> * * @param prefix the prefix of the identifier. Has to match [a-zA-Z]. * @param text the text used to generate the unique id * @return the unique id. For example "Hello world" will generate prefix + "Helloworld". */ public String generateUniqueId(String prefix, String text) { // Verify that the passed prefix contains only alpha characters since the generated id must be a valid HTML id. if (StringUtils.isEmpty(prefix) || !StringUtils.isAlpha(prefix)) { throw new IllegalArgumentException("The prefix [" + prefix + "] should only contain alphanumerical characters and not be empty."); } String idPrefix = (prefix != null ? prefix : "") + normalizeId(text); int occurence = 0; String id = idPrefix; while (this.generatedIds.contains(id)) { occurence++; id = idPrefix + "-" + occurence; } // Save the generated id so that the next call to this method will not generate the same id. this.generatedIds.add(id); return id; }
protected boolean checkPasswordStrength(String password, List<String> errorMessages) { if (password == null) { errorMessages.add(ElementsThreadLocals.getText("null.password")); return false; } if (password.length() < 8) { errorMessages.add(ElementsThreadLocals.getText("password.too.short", 8)); return false; } if (StringUtils.isAlpha(password)) { errorMessages.add(ElementsThreadLocals.getText("password.only.letters")); return false; } return true; }
protected boolean checkPasswordStrength(String password, List<String> errorMessages) { if (password == null) { errorMessages.add(ElementsThreadLocals.getText("null.password")); return false; } if (password.length() < 8) { errorMessages.add(ElementsThreadLocals.getText("password.too.short", 8)); return false; } if (StringUtils.isAlpha(password)) { errorMessages.add(ElementsThreadLocals.getText("password.only.letters")); return false; } return true; } //
boolean isAlphaDelimiter = StringUtils.isAlpha(delimiter);
+ payload.length() + "\n\n" + "Is Numeric? " + StringUtils.isNumeric(payload) + "\n\n" + "Is Alpha? " + StringUtils.isAlpha(payload) + "\n\n" + "Has whitespaces? " + StringUtils.isWhitespace(payload) + "\n\n"); payloadsPanel.payloadInfoTextArea.setCaretPosition(0);
public SentencePairMatchResult(List<List<ParseTreeChunk>> matchResult, List<LemmaPair> resForMinedSent1) { super(); verbExists = false; imperativeVerb = false; // LOG.info("Assessing sentence for inclusion " + resForMinedSent1); this.matchResult = matchResult; this.resForMinedSent1 = resForMinedSent1; for (LemmaPair word : resForMinedSent1) { if (word.getPOS().startsWith("VB") && word.getLemma().length() > 2 && StringUtils.isAlpha(word.getLemma())) {// || // word.getPOS().startsWith("VP")) verbExists = true; // LOG.info("Found verb=" + word); } } // various form of sales pitch: 'get something', or 'we offer' if (resForMinedSent1.size() > 2 && (resForMinedSent1.get(1).getLemma().startsWith("We") || resForMinedSent1 .get(2).getLemma().startsWith("We"))) imperativeVerb = true; for (LemmaPair word : resForMinedSent1) { if (word.getPOS().startsWith("VB") && word.getStartPos() < 1 && word.getEndPos() < 1) { imperativeVerb = true; // LOG.info("Found imperative verb=" + word); } } }