private List<Word> segSentence(final String sentence){
        if(sentence.length() == 1){
            if(KEEP_WHITESPACE){
                List<Word> result = new ArrayList<>(1);
                result.add(new Word(KEEP_CASE ? sentence : sentence.toLowerCase()));
                return result;
            }else{
                if(!Character.isWhitespace(sentence.charAt(0))){
                    List<Word> result = new ArrayList<>(1);
                    result.add(new Word(KEEP_CASE ? sentence : sentence.toLowerCase()));
                    return result;
                }
            }
        }
        if(sentence.length() > 1){
            List<Word> list = segImpl(sentence);
            if(list != null){
                if(PERSON_NAME_RECOGNIZE){
                    list = PersonName.recognize(list);
                }
                return list;
            }else{
                LOGGER.error("文本 "+sentence+" 没有获得分词结果");
            }
        }
        return Collections.emptyList();
    }
private List < Word > segSentence ( final String sentence ) { if ( sentence . length ( ) == 1 ) { if ( KEEP_WHITESPACE ) { List < Word > result = new ArrayList < > ( 1 ) ; result . add ( new Word ( KEEP_CASE ? sentence : sentence . toLowerCase ( ) ) ) ; return result ; } else { if ( ! Character . isWhitespace ( sentence . charAt ( 0 ) ) ) { List < Word > result = new ArrayList < > ( 1 ) ; result . add ( new Word ( KEEP_CASE ? sentence : sentence . toLowerCase ( ) ) ) ; return result ; } } } if ( sentence . length ( ) > 1 ) { List < Word > list = segImpl ( sentence ) ; if ( list != null ) { if ( PERSON_NAME_RECOGNIZE ) { list = PersonName . recognize ( list ) ; } return list ; } else { LOGGER . error ( "文本 " + sentence + " 没有获得分词结果" ) ; } } return Collections . emptyList ( ) ; }
将句子切分为词
@param sentence 句子
@return 词集合