Java Code Examples for org.apache.commons.lang3.StringUtils.splitByCharacterTypeCamelCase()

The following are Jave code examples for showing how to use splitByCharacterTypeCamelCase() of the org.apache.commons.lang3.StringUtils class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: RDF2PT   File: LiteralConverterPortuguese.java   View Source Code Vote up 5 votes
/**
 * Convert the literal into natural language.
 * 
 * @param lit
 *            the literal
 * @return the natural language expression
 */
public String convert(LiteralLabel lit) {
	logger.debug("Literal to be converted" + lit.toString());
	
	RDFDatatype dt = lit.getDatatype();
	
	String s = lit.getLexicalForm();
	if (dt == null || dt instanceof RDFLangString) {// plain literal, i.e.
													// omit language tag if
													// exists
		s = lit.getLexicalForm();
		s = s.replaceAll("_", " ");
		s = s.replace('*', ' ');
		s = s.trim();
		if (encapsulateStringLiterals) {
			s = '"' + s + '"';
		}
	} else {// typed literal
		if (dt instanceof XSDDatatype) {// built-in XSD datatype
			if (dt instanceof XSDAbstractDateTimeType) {// date datetypes
				s = convertDateLiteral(lit);
			} else if (encapsulateStringLiterals && dt.equals(XSDDatatype.XSDstring)) {
				s = s.replace('*', ' ');
				s = s.trim();
				s = '"' + s + '"';
			}
		} else {// user-defined datatype
			String text = iriConverter.convert(dt.getURI(), false).toLowerCase();
			String[] split = StringUtils.splitByCharacterTypeCamelCase(text.trim());
			String datatype = Joiner.on(" ").join(Arrays.asList(split).stream().filter(str -> !str.trim().isEmpty())
					.collect(Collectors.toList()));
			s = lit.getLexicalForm() + " " + datatype;
		}
	}
	return s;
}
 
Example 2
Project: RDF2PT   File: LiteralConverter.java   View Source Code Vote up 5 votes
/**
 * Convert the literal into natural language.
 * @param lit the literal
 * @return the natural language expression
 */
public String convert(LiteralLabel lit) {
    RDFDatatype dt = lit.getDatatype();

    String s = lit.getLexicalForm();
    if (dt == null || dt instanceof RDFLangString) {// plain literal, i.e. omit language tag if exists
        s = lit.getLexicalForm();
        s = s.replaceAll("_", " ");
        if(encapsulateStringLiterals){
        	s = '"' + s + '"';
        }
    } else {// typed literal
        if (dt instanceof XSDDatatype) {// built-in XSD datatype
        	if(dt instanceof XSDAbstractDateTimeType){//date datetypes
        		s = convertDateLiteral(lit);
        	} else if(encapsulateStringLiterals && dt.equals(XSDDatatype.XSDstring)){
	s = '"' + s + '"';
}
        } else {// user-defined datatype
String text = iriConverter.convert(dt.getURI(), false).toLowerCase();
String[] split = StringUtils.splitByCharacterTypeCamelCase(text.trim());
String datatype = Joiner.on(" ").join(Arrays.asList(split).stream().filter(str -> !str.trim().isEmpty()).collect(Collectors.toList()));
s = lit.getLexicalForm() + " " + datatype;
        }
    }
    return s;
}
 
Example 3
Project: RDF2PT   File: SimpleIRIConverter.java   View Source Code Vote up 5 votes
private String splitCamelCase(String s) {
		// we only split if it contains a vowel
		if(!(s.matches(".*[aeiou].*"))){
			return s;
		}
		
		StringBuilder sb = new StringBuilder();
		for (String token : s.split(" ")) {
			String[] tokenSplit = StringUtils.splitByCharacterTypeCamelCase(token);
			
			String noVowels = "";
			for (String t : tokenSplit) {
				if(t.matches(".*[aeiou].*") || !StringUtils.isAllUpperCase(t)){
					if(!noVowels.isEmpty()){
						sb.append(noVowels).append(" ");
						noVowels = "";
					}
					sb.append(t).append(" ");
				} else {
					noVowels += t;
				}
//				sb = new StringBuilder(sb.toString().trim());
			}
			sb.append(noVowels);
//			sb.append(" ");
		}
		return sb.toString().trim();
		//	    	return s.replaceAll(
		//	    	      String.format("%s|%s|%s",
		//	    	         "(?<=[A-Z])(?=[A-Z][a-z])",
		//	    	         "(?<=[^A-Z])(?=[A-Z])",
		//	    	         "(?<=[A-Za-z])(?=[^A-Za-z])"
		//	    	      ),
		//	    	      " "
		//	    	   );
	}
 
Example 4
Project: RDF2PT   File: LiteralConverterFrench.java   View Source Code Vote up 5 votes
/**
 * Convert the literal into natural language.
 * 
 * @param lit
 *            the literal
 * @return the natural language expression
 */
public String convert(LiteralLabel lit) {
	RDFDatatype dt = lit.getDatatype();

	String s = lit.getLexicalForm();
	if (dt == null || dt instanceof RDFLangString) {// plain literal, i.e.
													// omit language tag if
													// exists
		s = lit.getLexicalForm();
		s = s.replaceAll("_", " ");
		if (encapsulateStringLiterals) {
			s = '"' + s + '"';
		}
	} else {// typed literal
		if (dt instanceof XSDDatatype) {// built-in XSD datatype
			if (dt instanceof XSDAbstractDateTimeType) {// date datetypes
				s = convertDateLiteral(lit);
			} else if (encapsulateStringLiterals && dt.equals(XSDDatatype.XSDstring)) {
				s = '"' + s + '"';
			}
		} else {// user-defined datatype
			String text = iriConverter.convert(dt.getURI(), false).toLowerCase();
			String[] split = StringUtils.splitByCharacterTypeCamelCase(text.trim());
			String datatype = Joiner.on(" ").join(Arrays.asList(split).stream().filter(str -> !str.trim().isEmpty())
					.collect(Collectors.toList()));
			s = lit.getLexicalForm() + " " + datatype;
		}
	}
	return s;
}
 
Example 5
Project: kraken   File: Environment.java   View Source Code Vote up 4 votes
private String readableHandlerName(final LifecycleHandler handler) {
    val words = StringUtils.splitByCharacterTypeCamelCase(handler.getClass().getSimpleName());
    return String.join(" ", words).toLowerCase();
}