Java Code Examples for org.apache.commons.lang.StringUtils.indexOfAny()

The following are Jave code examples for showing how to use indexOfAny() of the org.apache.commons.lang.StringUtils class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
Example 1
Project: wrdocletbase   File: AbstractDocBuilder.java   Source Code and License Vote up 6 votes
protected String getBriefFromCommentText(String commentText) {
	int index = StringUtils.indexOf(commentText, '\n');
	if (index != -1) {
		commentText = StringUtils.substring(commentText, 0, index);
	}
	index = StringUtils.indexOfAny(commentText, ".!?。!?…");
	if (index > 0) {
		commentText = StringUtils.substring(commentText, 0, index);
	}
	if (StringUtils.length(commentText) > 8) {
		commentText = StringUtils.substring(commentText, 0, 8) + "…";
	}
	return commentText;
}
 
Example 2
Project: sirocco   File: StructuredSplitter.java   Source Code and License Vote up 6 votes
public static void uncapitalizeShortMessages(String[] paragraphs) throws Exception {
    if (paragraphs.length > 1)
        return ;
     
    // Verify whether this is a short message by looking at sentence separators.
    int firstIdx = StringUtils.indexOfAny(paragraphs[0], LangDictionary.getInstance().getSentenceSeparators());
    
    if ((firstIdx < 0) || (firstIdx == paragraphs[0].length()))
    {
        float firstCapRatio = 0.0F;
        float allCapsRatio = 0.0F;
        RefSupport<Float> refVar0 = new RefSupport<Float>();
        RefSupport<Float> refVar1 = new RefSupport<Float>();
        ratioOfCapitalizedWords(paragraphs[0],refVar0,refVar1);
        allCapsRatio = refVar0.getValue();
        firstCapRatio = refVar1.getValue();
        
        if (Math.max(allCapsRatio,firstCapRatio) > MaxCapitalizedRatio)
            paragraphs[0] = lowercaseCapitalizedWords(paragraphs[0],1);
         
    }
     
}
 
Example 3
Project: sirocco   File: StructuredSplitter.java   Source Code and License Vote up 4 votes
public static void ratioOfCapitalizedWords(String sentence, RefSupport<Float> allCapsRatio, RefSupport<Float> firstCapRatio) throws Exception {
    Integer numFirstCapitalEntities = 0;
    Integer numAllCapitalEntities = 0;
    Integer numLowerCaseEntities = 0;
    Integer idx = 0;
    while ((idx < sentence.length()) && (idx > 0))
    {
        String tailOfsentence = sentence.substring(idx);
    	Integer idxInTail = StringUtils.indexOfAny(tailOfsentence, LangDictionary.getInstance().getWordSeparators());
    	
        if (idxInTail == 0)
        	idx = 0;
        else
        {
        	idx=idx+idxInTail;
            if (Character.isUpperCase(sentence.charAt(idx + 1)))
            {
                // just check one next character (for performance reasons)
                if ((idx + 2) < sentence.length())
                    if (Character.isUpperCase(sentence.charAt(idx + 2)))
                        numAllCapitalEntities++;
                    else
                        numFirstCapitalEntities++; 
                else
                    numFirstCapitalEntities++; 
            }
            else if (Character.isLowerCase(sentence.charAt(idx + 1)))
            	numLowerCaseEntities++;
              
        }
         
    }
    Integer numAllEntities = numAllCapitalEntities + numFirstCapitalEntities + numLowerCaseEntities;
    if (numAllEntities == 0)
    {
    	firstCapRatio.setValue(0.0F);
        allCapsRatio.setValue(0.0F);
    }
    else
    {
        allCapsRatio.setValue(((float)numAllCapitalEntities / (float)numAllEntities));
        firstCapRatio.setValue(((float)numFirstCapitalEntities / (float)numAllEntities));
    } 
}