Java String Ends With endsWithSentenceSeparator(char[] token)

Here you can find the source of endsWithSentenceSeparator(char[] token)

Description

Check if token ends with a sentence separator

License

Open Source License

Parameter

Parameter Description
token a parameter

Declaration

public static boolean endsWithSentenceSeparator(char[] token) 

Method Source Code

//package com.java2s;
/**/*from  w ww.  ja  v a  2s. c om*/
 *  ClusteringWiki - personalized and collaborative clustering of search results
 *  Copyright (C) 2010  Texas State University-San Marcos
 *  
 *  Contact: http://dmlab.cs.txstate.edu
 * 
 *  This program is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 * 
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 * 
 *  You should have received a copy of the GNU General Public License
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

public class Main {
    /**
     * Check if token ends with a sentence separator
     * @param token
     * @return
     */
    public static boolean endsWithSentenceSeparator(char[] token) {
        return token.length > 2 && isSentenceSeparator(token[token.length - 1]);
    }

    /**
     * Check if token ends with a sentence separator
     * @param token
     * @return
     */
    public static boolean endsWithSentenceSeparator(String token) {
        final int ln = token.length();
        return ln > 0 && isSentenceSeparator(token.charAt(ln - 1));
    }

    /**
     * Check if token is a sentence separator
     * @param token
     * @return
     */
    public static boolean isSentenceSeparator(char[] token) {
        return isSentenceSeparator(token, 0, token.length);
    }

    /**
     * Check if token is a sentence separator
     * @param token
     * @return
     */
    public static boolean isSentenceSeparator(String token) {
        return isSentenceSeparator(token.toCharArray(), 0, token.length());
    }

    /**
     * Check if token is a sentence separator
     * @param token
     * @param start
     * @param end
     * @return
     */
    public static boolean isSentenceSeparator(char[] token, int start, int end) {
        for (int i = start; i < end; i++)
            if (!isSentenceSeparator(token[i]))
                return false;
        return true;
    }

    /**
     * Check if character is sentence separator. We define sentences
     * ending in period, question mark, or exclamation point.
     * @param token
     * @return
     */
    public static boolean isSentenceSeparator(char token) {
        switch (token) {
        case '.':
        case '!':
        case '?':
            return true;
        default:
            //nothing
        }
        return false;
    }
}

Related

  1. endsWithOne(final String src, final String[] dest)
  2. endsWithOne(String src, String... dest)
  3. endsWithOneOf(String value, String... ends)
  4. endsWithoutPathSeparator(final String path)
  5. endsWithoutSlash(String url)
  6. endsWithSeparator(String str)
  7. endsWithSingleQuoteS(String s)
  8. endsWithSlash(final String path)
  9. endsWithSomeChar(char cs[], String activationToken)