Java Code Examples for org.apache.commons.text.WordUtils#capitalize()
The following examples show how to use
org.apache.commons.text.WordUtils#capitalize() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TextCase.java From citeproc-java with Apache License 2.0 | 6 votes |
/** * Transforms the text of a token * @param t the token * @return the new token with the transformed text */ private Token transform(Token t) { String s = t.getText(); if ("lowercase".equals(textCase)) { s = s.toLowerCase(); } else if ("uppercase".equals(textCase)) { s = s.toUpperCase(); } else if ("capitalize-first".equals(textCase)) { s = StringUtils.capitalize(s); } else if ("capitalize-all".equals(textCase)) { s = WordUtils.capitalize(s); } else if ("title".equals(textCase)) { s = StringHelper.toTitleCase(s); } return new Token.Builder(t) .text(s) .build(); }
Example 2
Source File: NativeQueryAccessField.java From spring-native-query with MIT License | 5 votes |
public NativeQueryAccessField(Field field) { this.name = WordUtils.capitalize(field.getName()); this.type = field.getType(); if (field.isAnnotationPresent(NativeQueryParam.class)) { this.param = field.getAnnotation(NativeQueryParam.class); } }
Example 3
Source File: WordUtilsUnitTest.java From tutorials with MIT License | 5 votes |
@Test public void whenCapitalized_thenCorrect() { String toBeCapitalized = "to be capitalized!"; String result = WordUtils.capitalize(toBeCapitalized); Assert.assertEquals("To Be Capitalized!", result); }
Example 4
Source File: NerdEngine.java From entity-fishing with Apache License 2.0 | 4 votes |
/** * Try to find the best KB Labels from a normalized string. In practice, this method has * a huge impact on performance, as it can maximize the chance to have the right entity * in the list of candidates. */ public static List<Label> bestLabels(String normalisedString, LowerKnowledgeBase wikipedia, String lang) { List<Label> labels = new ArrayList<Label>(); //String normalisedString = entity.getNormalisedName(); if (isEmpty(normalisedString)) return null; // normalised mention following case as it appears Label bestLabel = new Label(wikipedia.getEnvironment(), normalisedString); labels.add(bestLabel); // try case variants //if (!bestLabel.exists()) { // first letter upper case Label label = new Label(wikipedia.getEnvironment(), WordUtils.capitalize(normalisedString.toLowerCase())); if (label.exists()) labels.add(label); // full upper or lower case if (StringProcessor.isAllUpperCase(normalisedString)) { label = new Label(wikipedia.getEnvironment(), normalisedString.toLowerCase()); if (label.exists()) labels.add(label); } else if (StringProcessor.isAllLowerCase(normalisedString)) { label = new Label(wikipedia.getEnvironment(), normalisedString.toUpperCase()); if (label.exists()) labels.add(label); } else { label = new Label(wikipedia.getEnvironment(), normalisedString.toLowerCase()); if (label.exists()) labels.add(label); label = new Label(wikipedia.getEnvironment(), normalisedString.toUpperCase()); if (label.exists()) labels.add(label); } label = new Label(wikipedia.getEnvironment(), WordUtils.capitalizeFully(normalisedString.toLowerCase())); if (label.exists()) labels.add(label); // more aggressive label = new Label(wikipedia.getEnvironment(), WordUtils.capitalizeFully(normalisedString.toLowerCase(), ProcessText.delimiters.toCharArray())); if (label.exists()) labels.add(label); // only first word capitalize if (normalisedString.length()>1) { label = new Label(wikipedia.getEnvironment(), normalisedString.toLowerCase().substring(0, 1).toUpperCase() + normalisedString.toLowerCase().substring(1)); if (label.exists()) labels.add(label); } // try variant cases if (StringProcessor.isAllUpperCase(normalisedString)) { // a usual pattern in all upper case that is missed above is a combination of // acronym + normal term, e.g. NY RANGERS -> NY Rangers List<LayoutToken> localTokens = GrobidAnalyzer.getInstance().tokenizeWithLayoutToken(normalisedString, new Language(lang, 1.0)); for(int i=0; i<localTokens.size(); i++) { LayoutToken token = localTokens.get(i); if (token.getText().length() == 2) { StringBuilder newLabel = new StringBuilder(); for(int j=0; j<localTokens.size(); j++) { if ( j!= i) newLabel.append(WordUtils.capitalize(localTokens.get(j).getText().toLowerCase())); else newLabel.append(token); } label = new Label(wikipedia.getEnvironment(), newLabel.toString()); if (label.exists()) labels.add(label); } } } } return labels; }
Example 5
Source File: ParameterAdapter.java From swagger2markup with Apache License 2.0 | 4 votes |
public String getIn() { return WordUtils.capitalize(parameter.getIn()); }
Example 6
Source File: PTextWord.java From jphp with Apache License 2.0 | 4 votes |
@Signature public PTextWord capitalize(Environment env, @Optional(type = HintType.STRING) String delimiters) { return new PTextWord(env, WordUtils.capitalize(text, delimiters.isEmpty() ? null : delimiters.toCharArray())); }
Example 7
Source File: CasquatchNamingConvention.java From casquatch with Apache License 2.0 | 2 votes |
/** * Converts a CQL column to Java Class name * @param cql cql column name * @return name of the Java Class */ public static String cqlToJavaClass(String cql) { return WordUtils.capitalize(cqlToJavaVariable(cql)); }
Example 8
Source File: CasquatchNamingConvention.java From casquatch with Apache License 2.0 | 2 votes |
/** * Converts a java variable name to getter * @param javaVariable name of java variable * @return name of the getter */ public static String javaVariableToJavaGet(String javaVariable) { return "get"+ WordUtils.capitalize(javaVariable); }
Example 9
Source File: CasquatchNamingConvention.java From casquatch with Apache License 2.0 | 2 votes |
/** * Converts a java variable name to setter * @param javaVariable name of java variable * @return name of the setter */ public static String javaVariableToJavaSet(String javaVariable) { return "set"+WordUtils.capitalize(javaVariable); }