Example usage for java.lang Character isUpperCase

List of usage examples for java.lang Character isUpperCase

Introduction

In this page you can find the example usage for java.lang Character isUpperCase.

Prototype

public static boolean isUpperCase(int codePoint) 

Source Link

Document

Determines if the specified character (Unicode code point) is an uppercase character.

Usage

From source file:coreferenceresolver.process.FeatureExtractor.java

public static Boolean isNNP(Token tk) {
    if (Character.isUpperCase(tk.getWord().charAt(0))) {
        return true;
    }//from w ww.  ja v  a 2  s  .c  om
    if (tk.getWord().toLowerCase().equals("iphone") || tk.getWord().toLowerCase().equals("ipad")
            || tk.getWord().toLowerCase().equals("iphones") || tk.getWord().toLowerCase().equals("ipads")
            || tk.getWord().toLowerCase().equals("ipod")) {
        return true;
    }
    return false;
}

From source file:coreferenceresolver.process.FeatureExtractor.java

public static Boolean hasProperName(NounPhrase np, Sentence se) {
    ArrayList<String> aList = new ArrayList<String>();
    ArrayList<Integer> aListOfCheck = new ArrayList<Integer>();
    for (int i = 0; i < se.getTokens().size(); i++) {
        if ((se.getTokens().get(i).getOffsetBegin() >= np.getOffsetBegin())
                && (se.getTokens().get(i).getOffsetBegin() < np.getOffsetEnd())) {
            if (isNNP(se.getTokens().get(i))) {
                aList.add(se.getTokens().get(i).getWord());
                if (se.getTokens().get(i).getPOS().toString().equals("NNP")
                        || se.getTokens().get(i).getPOS().toString().equals("NNPS")) {
                    aListOfCheck.add(1);
                } else {
                    aListOfCheck.add(0);
                }//from   www  .  j  a  v a 2  s.c o  m
            } else if (i > 0 && i < (se.getTokens().size() - 1)) {
                if (Character.isDigit(se.getTokens().get(i).getWord().charAt(0))) {
                    if (se.getTokens().get(i - 1).getPOS().equals("DT")
                            || se.getTokens().get(i - 1).getPOS().equals("NNP")
                            || se.getTokens().get(i - 1).getPOS().equals("NNPS")
                            || Character.isUpperCase(se.getTokens().get(i - 1).getWord().charAt(0))) {
                        if ((se.getTokens().get(i + 1).getPOS().equals("NN"))
                                || (se.getTokens().get(i + 1).getPOS().equals("NNS"))
                                || (se.getTokens().get(i + 1).getPOS().equals("JJ"))) {
                        } else {
                            aList.add(se.getTokens().get(i).getWord());
                            aListOfCheck.add(1);
                        }

                    }
                }

            }
        }
    }
    if (aList.size() == 0) {
        return false;
    } else {
        for (int i = 0; i < aList.size(); i++) {
            if (aListOfCheck.get(i).equals(1)) {
                for (String st1 : aList) {
                }
                return true;
            } else {
                boolean checkContains = true;
                if (sDict.contains(aList.get(i).toLowerCase())) {
                    checkContains = false;
                } else if (check_adj_in_list(aList.get(i))) {
                    checkContains = false;
                }

                if (checkContains) {
                    return true;
                }
            }
        }

        return false;

    }
}

From source file:org.distantshoresmedia.keyboard.LatinIME.java

/**
 * Tries to apply any typed alternatives for the word if we have any cached
 * alternatives, otherwise tries to find new corrections and completions for
 * the word./*from   w  w w  . j a  va 2 s . co m*/
 *
 * @param touching
 *            The word that the cursor is touching, with position
 *            information
 * @return true if an alternative was found, false otherwise.
 */
private boolean applyTypedAlternatives(EditingUtil.SelectedWord touching) {
    // If we didn't find a match, search for result in typed word history
    WordComposer foundWord = null;
    WordAlternatives alternatives = null;
    for (WordAlternatives entry : mWordHistory) {
        if (TextUtils.equals(entry.getChosenWord(), touching.word)) {
            if (entry instanceof TypedWordAlternatives) {
                foundWord = ((TypedWordAlternatives) entry).word;
            }
            alternatives = entry;
            break;
        }
    }
    // If we didn't find a match, at least suggest completions
    if (foundWord == null && (mSuggest.isValidWord(touching.word)
            || mSuggest.isValidWord(touching.word.toString().toLowerCase()))) {
        foundWord = new WordComposer();
        for (int i = 0; i < touching.word.length(); i++) {
            foundWord.add(touching.word.charAt(i), new int[] { touching.word.charAt(i) });
        }
        foundWord.setFirstCharCapitalized(Character.isUpperCase(touching.word.charAt(0)));
    }
    // Found a match, show suggestions
    if (foundWord != null || alternatives != null) {
        if (alternatives == null) {
            alternatives = new TypedWordAlternatives(touching.word, foundWord);
        }
        showCorrections(alternatives);
        if (foundWord != null) {
            mWord = new WordComposer(foundWord);
        } else {
            mWord.reset();
        }
        return true;
    }
    return false;
}

From source file:coreferenceresolver.process.FeatureExtractor.java

public static void setNPForOPInSentence(Sentence fSentence) {
    int no = 0;//from   ww  w  .  jav a 2  s .  co  m
    for (Token token : fSentence.getTokens()) {
        no++;
        if (Character.isUpperCase(token.getWord().charAt(0))) {
            if (no == 1) {
            } else {
                continue;
            }
        }
        // get opinion word in the sentence
        if (token.getPOS().equals("RB") && (check_adj_in_list(token.getWord()))
                && !checkSpecialCase(fSentence, token)) {
            for (int i = fSentence.getNounPhrases().size() - 1; i >= 0; i--) {
                boolean checkFind = false;
                if (fSentence.getNounPhrases().get(i).getOffsetEnd() < token.getOffsetBegin()) {
                    for (Token tk : fSentence.getTokens()) {
                        if ((tk.getOffsetBegin() >= fSentence.getNounPhrases().get(i).getOffsetEnd())
                                && (tk.getOffsetEnd() <= token.getOffsetBegin())) {
                            if (tk.getPOS().equals("VB") || tk.getPOS().equals("VBD")
                                    || tk.getPOS().equals("VBG") || tk.getPOS().equals("VBN")
                                    || tk.getPOS().equals("VBP") || tk.getPOS().equals("VBZ")) {
                                if (!Util.isDiscardedQuantityNP(fSentence.getNounPhrases().get(i))) {
                                    checkFind = true;
                                    break;
                                }
                            }
                        }
                    }
                    if (checkFind == true) {
                        fSentence.getNounPhrases().get(i).addOpinionWord(token.getWord());
                        //                          System.out.println("NP: " + fSentence.getNounPhrases().get(i).getNpNode().getLeaves().toString() + " ADB:" + token.getWord());

                    }
                }
                if (checkFind == true) {
                    break;
                }
            }
        } else if ((token.getPOS().equals("JJ") || token.getPOS().equals("JJS")
                || token.getPOS().toString().equals("JJR")) && (check_adj_in_list(token.getWord()))) {
            boolean check = false;
            // if OW is nested in NP -> OW belongs to that NP
            for (NounPhrase np : fSentence.getNounPhrases()) {
                if (np.getOffsetBegin() <= token.getOffsetBegin()
                        && np.getOffsetEnd() >= token.getOffsetEnd()) {
                    if (!Util.isDiscardedQuantityNP(np)) {
                        np.addOpinionWord(token.getWord());
                        check = true;
                    }
                }
            }

            if (check == false) {
                // If the sentence is a exclamatory sentence
                if ((fSentence.getRawContent().indexOf("how " + token.getWord()) != -1)
                        || (fSentence.getRawContent().indexOf("How " + token.getWord()) != -1)) {
                    for (NounPhrase np : fSentence.getNounPhrases()) {
                        if (np.getOffsetBegin() > token.getOffsetEnd()) {
                            if (!Util.isDiscardedQuantityNP(np)) {
                                np.addOpinionWord(token.getWord().toString());
                                break;
                            }
                        }
                    }
                } else {
                    boolean check1 = false;
                    for (NounPhrase np : fSentence.getNounPhrases()) {
                        if ((np.getOffsetBegin() - token.getOffsetEnd()) > 0) {
                            if ((np.getOffsetBegin() - token.getOffsetEnd()) <= 1) {
                                if (!Util.isDiscardedQuantityNP(np)) {
                                    check1 = true;
                                    np.addOpinionWord(token.getWord().toString());
                                    break;
                                }
                            }
                        }
                    }
                    if (check1 == false) {
                        for (int j = fSentence.getNounPhrases().size() - 1; j >= 0; j--) {
                            boolean checkFindAdj = false;
                            if (fSentence.getNounPhrases().get(j).getOffsetEnd() < token.getOffsetBegin()) {
                                for (Token tk : fSentence.getTokens()) {
                                    if ((tk.getOffsetBegin() >= fSentence.getNounPhrases().get(j)
                                            .getOffsetEnd()) && (tk.getOffsetEnd() <= token.getOffsetBegin())) {
                                        if (tk.getPOS().equals("VB") || tk.getPOS().equals("VBD")
                                                || tk.getPOS().equals("VBG") || tk.getPOS().equals("VBN")
                                                || tk.getPOS().equals("VBP") || tk.getPOS().equals("VBZ")) {
                                            if (!Util
                                                    .isDiscardedQuantityNP(fSentence.getNounPhrases().get(j))) {
                                                checkFindAdj = true;
                                                break;
                                            }
                                        }
                                    }
                                }
                                if (checkFindAdj) {
                                    fSentence.getNounPhrases().get(j).addOpinionWord(token.getWord());
                                    //                                        System.out.println("NP: " + fSentence
                                    //                                                .getNounPhrases()
                                    //                                                .get(j).getNpNode().getLeaves().toString() + " OW:" + token.getWord());
                                    //                                        
                                    break;
                                }
                            }
                            if (checkFindAdj) {
                                break;
                            }
                        }
                    }
                }
            }
        }
    }
}

From source file:de.innovationgate.utils.WGUtils.java

/**
 * Reconstructs the original string from the output of {@link #toJSIdentifier(String, boolean)} with enforced upper case rules.
 * @param txt A string created by {@link #toJSIdentifier(String)} with enforced upper case rules
 * @return The original string/* w w w . j av a  2 s. co  m*/
 */
public static String fromJSIdentifier(String txt) {

    StringBuilder out = new StringBuilder();

    int newWordIdx = -1;
    for (int i = 0; i < txt.length(); i++) {
        Character c = txt.charAt(i);
        newWordIdx++;

        if (Character.isUpperCase(c)) {
            if (newWordIdx != 0) {
                out.append("_");
            }
            c = Character.toLowerCase(c);
        } else if (c == '.') {
            newWordIdx = -1;
        }

        out.append(c);

    }

    return out.toString();

}

From source file:org.apache.click.util.ClickUtils.java

/**
 * Return a field label string from the given field name. For example:
 * <pre class="codeHtml">/*from   w  w w.j a va2  s .co  m*/
 * <span class="blue">faxNumber</span> &nbsp; -&gt; &nbsp; <span class="red">Fax Number</span> </pre>
 * <p/>
 * <b>Note</b> toLabel will return an empty String ("") if a <tt>null</tt>
 * String name is specified.
 *
 * @param name the field name
 * @return a field label string from the given field name
 */
public static String toLabel(String name) {
    if (name == null) {
        return "";
    }

    HtmlStringBuffer buffer = new HtmlStringBuffer();

    for (int i = 0, size = name.length(); i < size; i++) {
        char aChar = name.charAt(i);

        if (i == 0) {
            buffer.append(Character.toUpperCase(aChar));

        } else {
            buffer.append(aChar);

            if (i < name.length() - 1) {
                char nextChar = name.charAt(i + 1);
                if (Character.isLowerCase(aChar)
                        && (Character.isUpperCase(nextChar) || Character.isDigit(nextChar))) {

                    // Add space before digits or uppercase letters
                    buffer.append(" ");

                } else if (Character.isDigit(aChar) && (!Character.isDigit(nextChar))) {

                    // Add space after digits
                    buffer.append(" ");
                }
            }
        }
    }

    return buffer.toString();
}

From source file:com.osparking.attendant.AttListForm.java

private boolean isEnglish(char firstCh) {
    if (Character.isLowerCase(firstCh) || Character.isUpperCase(firstCh)) {
        return true;
    } else {//from  w  w  w . j  a v  a 2 s .  c o m
        return false;
    }
}

From source file:it.cnr.icar.eric.client.ui.thin.RegistryObjectCollectionBean.java

/**
* RegistryObject name is passed to get proper field name used as one of lcm
* constants.//from w w  w .  j av a  2 s  . c  o m
* 
* @param String
* @return String
*/
public String getLifeCycleManagerType(String type) {
    char typeChars[] = type.toCharArray();
    StringBuffer strBuf = new StringBuffer();
    for (int i = 0; i < typeChars.length; i++) {
        if (i != 0 && Character.isUpperCase(typeChars[i])) {
            strBuf.append('_');
        }
        strBuf.append(typeChars[i]);
    }
    return ((strBuf.toString()).toUpperCase());
}

From source file:com.test.stringtest.StringUtils.java

/**
 * <p>Checks if the String contains only uppercase characters.</p>
 *
 * <p><code>null</code> will return <code>false</code>.
 * An empty String ("") will return <code>false</code>.</p>
 *
 * <pre>/*from  w w w .  j a v  a 2s  .co m*/
 * StringUtils.isAllUpperCase(null)   = false
 * StringUtils.isAllUpperCase("")     = false
 * StringUtils.isAllUpperCase("  ")   = false
 * StringUtils.isAllUpperCase("ABC")  = true
 * StringUtils.isAllUpperCase("aBC") = false
 * </pre>
 *
 * @param str  the String to check, may be null
 * @return <code>true</code> if only contains uppercase characters, and is non-null
 * @since 2.5
 */
public static boolean isAllUpperCase(String str) {
    if (str == null || isEmpty(str)) {
        return false;
    }
    int sz = str.length();
    for (int i = 0; i < sz; i++) {
        if (Character.isUpperCase(str.charAt(i)) == false) {
            return false;
        }
    }
    return true;
}

From source file:org.apache.commons.lang3.StringUtils.java

/**
 * <p>Swaps the case of a String changing upper and title case to
 * lower case, and lower case to upper case.</p>
 *
 * <ul>//from w  w  w.j  a  v  a 2s.  c o  m
 *  <li>Upper case character converts to Lower case</li>
 *  <li>Title case character converts to Lower case</li>
 *  <li>Lower case character converts to Upper case</li>
 * </ul>
 *
 * <p>For a word based algorithm, see {@link org.apache.commons.lang3.text.WordUtils#swapCase(String)}.
 * A {@code null} input String returns {@code null}.</p>
 *
 * <pre>
 * StringUtils.swapCase(null)                 = null
 * StringUtils.swapCase("")                   = ""
 * StringUtils.swapCase("The dog has a BONE") = "tHE DOG HAS A bone"
 * </pre>
 *
 * <p>NOTE: This method changed in Lang version 2.0.
 * It no longer performs a word based algorithm.
 * If you only use ASCII, you will notice no change.
 * That functionality is available in org.apache.commons.lang3.text.WordUtils.</p>
 *
 * @param str  the String to swap case, may be null
 * @return the changed String, {@code null} if null String input
 */
public static String swapCase(String str) {
    if (StringUtils.isEmpty(str)) {
        return str;
    }

    char[] buffer = str.toCharArray();

    for (int i = 0; i < buffer.length; i++) {
        char ch = buffer[i];
        if (Character.isUpperCase(ch)) {
            buffer[i] = Character.toLowerCase(ch);
        } else if (Character.isTitleCase(ch)) {
            buffer[i] = Character.toLowerCase(ch);
        } else if (Character.isLowerCase(ch)) {
            buffer[i] = Character.toUpperCase(ch);
        }
    }
    return new String(buffer);
}