⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 wordselect.java

📁 java编写的OCR软件
💻 JAVA
字号:
/*    Jacson - Text Filtering with Java.    Copyright (C) 2003 Patrick Carl, patrick.carl@web.de     This library is free software; you can redistribute it and/or    modify it under the terms of the GNU Lesser General Public    License as published by the Free Software Foundation; either    version 2.1 of the License, or (at your option) any later version.     This library 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    Lesser General Public License for more details.     You should have received a copy of the GNU Lesser General Public    License along with this library; if not, write to the Free Software    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA      $Id: WordSelect.java 13 2005-09-28 06:02:56Z pcs $  */package de.spieleck.app.jacson.select;import de.spieleck.app.jacson.SelectionResult;import de.spieleck.app.jacson.JacsonSelect;import de.spieleck.app.jacson.JacsonRegistry;import de.spieleck.app.jacson.JacsonConfigException;import de.spieleck.config.ConfigNode;import de.spieleck.config.ConfigVerify.Acceptor;/** * Selects every word out of a chunk and returns them as chunks. To separate * the words delimiters are used in a "StringTokenizer-way". * (@see java.util.StringTokenizer). The delimiters themselves are not returned * as words. * @author  Patrick Carl * @author fsn */public class WordSelect implements JacsonSelect, Acceptor {        public final static String DELIMS_NODE = "delims";    public final static String DEFAULT_DELIM = " ;.:?!.,-_()[]{}=<>\t\n";        protected String delims = DEFAULT_DELIM;    protected String currentChunk;    protected int lastMatch;    protected int length;        protected SimpleResult result;        /** Creates a new instance of WordSelect */    public WordSelect() {        result = new SimpleResult();    }        /**     * A word is delimited by one or multiple of the given delimiter     * characters or by the beginning and the end of the chunk     * @return the next word of the chunk in a SelectionResult.     */    public SelectionResult getNextSelection() {        if(currentChunk == null)            return null;                // Skip trailing/leading Delimiters        while ( lastMatch < length                 && delims.indexOf(currentChunk.charAt(lastMatch)) != -1 )            lastMatch++;        if(lastMatch  >= length)            return null;                // Grab the "word", that is all following non delimiters        int start = lastMatch;        while ( lastMatch < length                && delims.indexOf(currentChunk.charAt(lastMatch)) == -1 )            lastMatch++;        result.set(start, lastMatch, currentChunk.substring(start, lastMatch));        return result;    }        public void init(ConfigNode node, JacsonRegistry registry)    throws JacsonConfigException {        setDelims(node.getString(DELIMS_NODE, null));    }        /**     * inits the delimiters to be used     */    public void setDelims(String delimsString){        if ( delimsString == null || delimsString.length() == 0 )            delimsString = DEFAULT_DELIM;        // XXX We could check the delims for double characters here!        delims = delimsString;    }        public void setChunk(String chunk) {        currentChunk = chunk;        lastMatch = 0;        length = currentChunk.length();    }        public boolean accept(ConfigNode node) {        return DELIMS_NODE.equals(node.getName());    }    }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -