code
stringlengths
73
34.1k
label
stringclasses
1 value
public static ADictionary createDefaultDictionary(JcsegTaskConfig config, boolean loadDic) { return createDefaultDictionary(config, config.isAutoload(), loadDic); }
java
public static ADictionary createSingletonDictionary(JcsegTaskConfig config, boolean loadDic) { synchronized (LOCK) { if ( singletonDic == null ) { singletonDic = createDefaultDictionary(config, loadDic); } } return singletonDic; }
java
public static String TraToSimplified( String str ) { StringBuffer sb = new StringBuffer(); int idx; for ( int j = 0; j < str.length(); j++ ) { if ( (idx = TRASTR.indexOf(str.charAt(j))) != -1 ) { sb.append(SIMSTR.charAt(idx)); } else { ...
java
public static ISegment createSegment( Class<? extends ISegment> _class, Class<?> paramtypes[], Object args[] ) { ISegment seg = null; try { Constructor<?> cons = _class.getConstructor(paramtypes); seg = (ISegment) cons.newInstance(args); } catch (Exce...
java
public static ISegment createJcseg( int mode, Object...args ) throws JcsegException { Class<? extends ISegment> _clsname; switch ( mode ) { case JcsegTaskConfig.SIMPLE_MODE: _clsname = SimpleSeg.class; break; case JcsegTaskConfig.COMPLEX_MODE: _cl...
java
private void init() { //setup thread pool QueuedThreadPool threadPool = new QueuedThreadPool(); threadPool.setMaxThreads(config.getMaxThreadPoolSize()); threadPool.setIdleTimeout(config.getThreadIdleTimeout()); server = new Server(threadPool); //setu...
java
public JcsegServer registerHandler() { String basePath = this.getClass().getPackage().getName()+".controller"; AbstractRouter router = new DynamicRestRouter(basePath, MainController.class); router.addMapping("/extractor/keywords", KeywordsController.class); router.addMapping("/extrac...
java
private void resetJcsegTaskConfig(JcsegTaskConfig config, JSONObject json) { if ( json.has("jcseg_maxlen") ) { config.setMaxLength(json.getInt("jcseg_maxlen")); } if ( json.has("jcseg_icnname") ) { config.setICnName(json.getBoolean("jcseg_icnname")); } ...
java
private void compact() { int from = 0; int to = 0; while (from < this.capacity) { Object key = this.list[from]; long usage = age(this.ticks[from]); if (usage > 0) { this.ticks[to] = usage; this.list[to] = key; th...
java
public int find(Object key) { Object o = this.map.get(key); return o instanceof Integer ? ((Integer) o).intValue() : none; }
java
public void register(Object value) { if (JSONzip.probe) { int integer = find(value); if (integer >= 0) { JSONzip.log("\nDuplicate key " + value); } } if (this.length >= this.capacity) { compact(); } this.list[this.le...
java
public static IChunk[] getMaximumMatchChunks(IChunk[] chunks) { int maxLength = chunks[0].getLength(); int j; //find the maximum word length for ( j = 1; j < chunks.length; j++ ) { if ( chunks[j].getLength() > maxLength ) maxLength = chunks[j].getLength(...
java
public static IChunk[] getLargestAverageWordLengthChunks(IChunk[] chunks) { double largetAverage = chunks[0].getAverageWordsLength(); int j; //find the largest average word length for ( j = 1; j < chunks.length; j++ ) { if ( chunks[j].getAverageWordsLength() > l...
java
public static IChunk[] getSmallestVarianceWordLengthChunks(IChunk[] chunks) { double smallestVariance = chunks[0].getWordsVariance(); int j; //find the smallest variance word length for ( j = 1; j < chunks.length; j++ ) { if ( chunks[j].getWordsVariance() < smal...
java
public static IChunk[] getLargestSingleMorphemicFreedomChunks(IChunk[] chunks) { double largestFreedom = chunks[0].getSingleWordsMorphemicFreedom(); int j; //find the maximum sum of single morphemic freedom for ( j = 1; j < chunks.length; j++ ) { if ( chunks[j]....
java
public static String implode(String glue, Object[] pieces) { if ( pieces == null ) { return null; } StringBuffer sb = new StringBuffer(); for ( Object o : pieces ) { if ( sb.length() > 0 ) { sb.append(glue); } ...
java
public static int indexOf(String ele, String[] arr) { if ( arr == null ) { return -1; } for ( int i = 0; i < arr.length; i++ ) { if ( arr[i].equals(ele) ) { return i; } } return -1; }
java
public static int startsWith(String str, String[] arr) { if ( arr == null ) { return -1; } for ( int i = 0; i < arr.length; i++ ) { if ( arr[i].startsWith(str) ) { return i; } } return -1; }
java
public static int endsWith(String str, String[] arr) { if ( arr == null ) { return -1; } for ( int i = 0; i < arr.length; i++ ) { if ( arr[i].endsWith(str) ) { return i; } } return -1; }
java
public static int contains(String str, String[] arr) { if ( arr == null ) { return -1; } for ( int i = 0; i < arr.length; i++ ) { if ( arr[i].contains(str) ) { return i; } } return -1; }
java
public static String toJsonObject(String[] arr) { if ( arr == null ) { return null; } StringBuffer sb = new StringBuffer(); sb.append('{'); for ( String ele : arr ) { if ( sb.length() == 1 ) { sb.append('"').append(ele).append(...
java
List<Sentence> textToSentence(Reader reader) throws IOException { List<Sentence> sentence = new ArrayList<Sentence>(); Sentence sen = null; sentenceSeg.reset(reader); while ( (sen = sentenceSeg.next()) != null ) { sentence.add(sen); } ret...
java
List<List<IWord>> sentenceTokenize(List<Sentence> sentence) throws IOException { List<List<IWord>> senWords = new ArrayList<List<IWord>>(); for ( Sentence sen : sentence ) { List<IWord> words = new ArrayList<IWord>(); wordSeg.reset(new StringReader(sen.getValue())); ...
java
protected Document[] textRankSortedDocuments( List<Sentence> sentence, List<List<IWord>> senWords) throws IOException { int docNum = sentence.size(); //documents relevance matrix build double[][] relevance = BM25RelevanceMatixBuild(sentence, senWords); //org.lionsoul...
java
public static final IWord[] createDateTimePool() { return new IWord[]{ null, //year null, //month null, //day null, //timing method null, //hour null, //minute null, //seconds }; }
java
public static final int fillDateTimePool(IWord[] wPool, IWord word) { int pIdx = getDateTimeIndex(word.getEntity(0)); if ( pIdx == DATETIME_NONE ) { return DATETIME_NONE; } if ( wPool[pIdx] == null ) { wPool[pIdx] = word; return pIdx; ...
java
public static final void fillDateTimePool( IWord[] wPool, int pIdx, IWord word) { if ( wPool[pIdx] == null ) { wPool[pIdx] = word; } }
java
public static final String getTimeKey(String entity) { if ( entity == null ) { return null; } int sIdx = entity.indexOf('.'); if ( sIdx == -1 ) { return null; } return entity.substring(sIdx + 1); }
java
protected void readUntil(char echar) throws IOException { int ch, i = 0; IStringBuffer sb = new IStringBuffer(); while ( (ch = readNext()) != -1 ) { if ( ++i >= MAX_QUOTE_LENGTH ) { /* * push back the readed chars * and reset the ...
java
public boolean enQueue( int data ) { Entry o = new Entry(data, tail.prev, tail); tail.prev.next = o; tail.prev = o; //set the size size++; return true; }
java
public boolean add( T word ) { Entry<T> o = new Entry<T>(word, tail.prev, tail); tail.prev.next = o; tail.prev = o; //set the size and set the index size++; index.put(word.getValue(), word); return true; }
java
public String getSummaryFromString(String doc, int length) throws IOException { return getSummary(new StringReader(doc), length); }
java
public String getSummaryFromFile(String file, int length) throws IOException { return getSummary(new FileReader(file), length); }
java
public final static boolean isMailAddress(String str) { int atIndex = str.indexOf('@'); if ( atIndex == -1 ) { return false; } if ( ! StringUtil.isLetterOrNumeric(str, 0, atIndex) ) { return false; } int ptIndex, ptStart = atI...
java
public final static boolean isUrlAddress(String str, ADictionary dic) { int prIndex = str.indexOf("://"); if ( prIndex > -1 && ! StringUtil.isLatin(str, 0, prIndex) ) { return false; } int sIdx = prIndex > -1 ? prIndex + 3 : 0; int slIndex = str.indexOf('...
java
public static final boolean isMobileNumber(String str) { if ( str.length() != 11 ) { return false; } if ( str.charAt(0) != '1' ) { return false; } if ( "34578".indexOf(str.charAt(1)) == -1 ) { return false; } ...
java
public static boolean isCJKChar( int c ) { /* * @Note: added at 2015-11-25 * for foreign country translated name recognize * add '·' as CJK chars */ if ( c == 183 || Character.getType(c) == Character.OTHER_LETTER ) return true; ...
java
public static boolean isEnPunctuation( int c ) { return ( (c > 32 && c < 48) || ( c > 57 && c < 65 ) || ( c > 90 && c < 97 ) || ( c > 122 && c < 127 ) ); }
java
public static boolean isDigit(String str, int beginIndex, int endIndex) { char c; for ( int j = beginIndex; j < endIndex; j++ ) { c = str.charAt(j); //make full-width char half-width if ( c > 65280 ) c -= 65248; if ( c < 48 || c > 57 ) { ...
java
public static boolean isDecimal(String str, int beginIndex, int endIndex) { if ( str.charAt(str.length() - 1) == '.' || str.charAt(0) == '.' ) { return false; } char c; int p= 0; //number of point for ( int j = 1; j < str.length(); j++ ) { ...
java
public static boolean isLatin(String str, int beginIndex, int endIndex) { for ( int j = beginIndex; j < endIndex; j++ ) { if ( ! isEnChar(str.charAt(j)) ) { return false; } } return true; }
java
public static boolean isCJK(String str, int beginIndex, int endIndex) { for ( int j = beginIndex; j < endIndex; j++ ) { if ( ! isCJKChar(str.charAt(j)) ) { return false; } } return true; }
java
public static boolean isLetterOrNumeric(String str, int beginIndex, int endIndex) { for ( int i = beginIndex; i < endIndex; i++ ) { char chr = str.charAt(i); if ( ! StringUtil.isEnLetter(chr) && ! StringUtil.isEnNumeric(chr) ) { return false; ...
java
public static boolean isLetter(String str, int beginIndex, int endIndex) { for ( int i = beginIndex; i < endIndex; i++ ) { char chr = str.charAt(i); if ( ! StringUtil.isEnLetter(chr) ) { return false; } } return true; }
java
public static boolean isNumeric(String str, int beginIndex, int endIndex) { for ( int i = beginIndex; i < endIndex; i++ ) { char chr = str.charAt(i); if ( ! StringUtil.isEnNumeric(chr) ) { return false; } } return true; }
java
public static int latinIndexOf(String str, int offset) { for ( int j = offset; j < str.length(); j++ ) { if ( isEnChar(str.charAt(j)) ) { return j; } } return -1; }
java
public static int CJKIndexOf(String str, int offset) { for ( int j = offset; j < str.length(); j++ ) { if ( isCJKChar(str.charAt(j)) ) { return j; } } return -1; }
java
public static String hwsTofws( String str ) { char[] chars = str.toCharArray(); for ( int j = 0; j < chars.length; j++ ) { if ( chars[j] == '\u0020' ) { chars[j] = '\u3000'; } else if ( chars[j] < '\177' ) { chars[j] = (char)(chars[j] + 65248);...
java
public void pad(int width) throws JSONException { try { this.bitwriter.pad(width); } catch (Throwable e) { throw new JSONException(e); } }
java
private void write(int integer, int width) throws JSONException { try { this.bitwriter.write(integer, width); if (probe) { log(integer, width); } } catch (Throwable e) { throw new JSONException(e); } }
java
private void write(Kim kim, Huff huff, Huff ext) throws JSONException { for (int at = 0; at < kim.length; at += 1) { int c = kim.get(at); write(c, huff); while ((c & 128) == 128) { at += 1; c = kim.get(at); write(c, ext); ...
java
private void write(int integer, Keep keep) throws JSONException { int width = keep.bitsize(); keep.tick(integer); if (probe) { log("\"" + keep.value(integer) + "\""); } write(integer, width); }
java
private void write(JSONArray jsonarray) throws JSONException { // JSONzip has three encodings for arrays: // The array is empty (zipEmptyArray). // First value in the array is a string (zipArrayString). // First value in the array is not a string (zipArrayValue). boolean stringy = false; int length = ...
java
@SuppressWarnings({ "rawtypes", "unchecked" }) private void writeJSON(Object value) throws JSONException { if (JSONObject.NULL.equals(value)) { write(zipNull, 3); } else if (Boolean.FALSE.equals(value)) { write(zipFalse, 3); } else if (Boolean.TRUE.equals(value)) { ...
java
private void writeName(String name) throws JSONException { // If this name has already been registered, then emit its integer and // increment its usage count. Kim kim = new Kim(name); int integer = this.namekeep.find(kim); if (integer != none) { one(); write(integer, t...
java
private void write(JSONObject jsonobject) throws JSONException { // JSONzip has two encodings for objects: Empty Objects (zipEmptyObject) and // non-empty objects (zipObject). boolean first = true; Iterator<String> keys = jsonobject.keys(); while (keys.hasNext()) { if (probe) { ...
java
private void writeValue(Object value) throws JSONException { if (value instanceof Number) { String string = JSONObject.numberToString((Number) value); int integer = this.valuekeep.find(string); if (integer != none) { write(2, 2); write(integer,...
java
protected boolean filter(IWord word) { /* * normally word with length less than 2 will * be something, well could be ignored */ if ( word.getValue().length() < 2 ) { return false; } //type check switch ( word.getType() ) { ...
java
private void init() { //request.setCharacterEncoding(setting.getCharset()); response.setCharacterEncoding(config.getCharset()); response.setContentType("text/html;charset="+config.getCharset()); response.setStatus(HttpServletResponse.SC_OK); }
java
public int getInt(String name) { int val = 0; try { val = Integer.valueOf(request.getParameter(name)); } catch (NumberFormatException e) {} return val; }
java
public float getFloat(String name) { float fval = 0F; try { fval = Float.valueOf(request.getParameter(name)); } catch (NumberFormatException e) {} return fval; }
java
public long getLong(String name) { long val = 0; try { val = Long.valueOf(request.getParameter(name)); } catch (NumberFormatException e) {} return val; }
java
public double getDouble(String name) { double val = 0; try { val = Double.valueOf(request.getParameter(name)); } catch (NumberFormatException e) {} return val; }
java
public boolean getBoolean(String name) { boolean val = false; try { val = Boolean.valueOf(request.getParameter(name)); } catch (NumberFormatException e) {} return val; }
java
public byte[] getRawData() throws IOException { int contentLength = request.getContentLength(); if( contentLength<0 ) { return null; } byte[] buffer = new byte[contentLength]; ServletInputStream is = request.getInputStream(); for (int i = 0; i < c...
java
public String getRawDataAsString() throws IOException { byte[] buffer = getRawData(); if ( buffer == null ) { return null; } String encoding = request.getCharacterEncoding(); if ( encoding == null ) { encoding = "utf-8"; } ...
java
public JSONObject getRawDataAsJson() throws IOException { String input = getRawDataAsString(); if ( input == null ) { return null; } return new JSONObject(input); }
java
static void logchar(int integer, int width) { if (integer > ' ' && integer <= '}') { log("'" + (char) integer + "':" + width + " "); } else { log(integer, width); } }
java
public boolean postMortem(PostMortem pm) { JSONzip that = (JSONzip) pm; return this.namehuff.postMortem(that.namehuff) && this.namekeep.postMortem(that.namekeep) && this.stringkeep.postMortem(that.stringkeep) && this.stringhuff.postMortem(that.stringhuff) ...
java
public boolean postMortem(PostMortem pm) { // Go through every integer in the domain, generating its bit sequence, and // then prove that that bit sequence produces the same integer. for (int integer = 0; integer < this.domain; integer += 1) { if (!postMortem(integer)) { JSONzip.lo...
java
public int read(BitReader bitreader) throws JSONException { try { this.width = 0; Symbol symbol = this.table; while (symbol.integer == none) { this.width += 1; symbol = bitreader.bit() ? symbol.one : symbol.zero; } tick(...
java
private void write(Symbol symbol, BitWriter bitwriter) throws JSONException { try { Symbol back = symbol.back; if (back != null) { this.width += 1; write(back, bitwriter); if (back.zero == symbol) { bitwriter...
java
public void write(int value, BitWriter bitwriter) throws JSONException { this.width = 0; write(this.symbols[value], bitwriter); tick(value); if (JSONzip.probe) { JSONzip.logchar(value, this.width); } }
java
private boolean bit() throws JSONException { boolean value; try { value = this.bitreader.bit(); if (probe) { log(value ? 1 : 0); } return value; } catch (Throwable e) { throw new JSONException(e); } }
java
private Object getAndTick(Keep keep, BitReader bitreader) throws JSONException { try { int width = keep.bitsize(); int integer = bitreader.read(width); Object value = keep.value(integer); if (JSONzip.probe) { JSONzip.log("\"" + value + ...
java
private int read(int width) throws JSONException { try { int value = this.bitreader.read(width); if (probe) { log(value, width); } return value; } catch (Throwable e) { throw new JSONException(e); } }
java
private String read(Huff huff, Huff ext, Keep keep) throws JSONException { Kim kim; int at = 0; int allocation = 256; byte[] bytes = new byte[allocation]; if (bit()) { return getAndTick(keep, this.bitreader).toString(); } while (true) { if ...
java
private JSONArray readArray(boolean stringy) throws JSONException { JSONArray jsonarray = new JSONArray(); jsonarray.put(stringy ? read(this.stringhuff, this.stringhuffext, this.stringkeep) : readValue()); while (true) { if (probe) { lo...
java
private Object readJSON() throws JSONException { switch (read(3)) { case zipObject: return readObject(); case zipArrayString: return readArray(true); case zipArrayValue: return readArray(false); case zipEmptyObject: return new JSONO...
java
public void add( int val ) { if ( size == items.length ) resize( items.length * 2 + 1 ); items[size++] = val; }
java
public void remove( int idx ) { if ( idx < 0 || idx > size ) throw new IndexOutOfBoundsException(); int numMove = size - idx - 1; if ( numMove > 0 ) System.arraycopy(items, idx + 1, items, idx, numMove); size--; }
java
public JSONArray put(int index, Map<String, Object> value) throws JSONException { this.put(index, new JSONObject(value)); return this; }
java
public boolean similar(Object other) { if (!(other instanceof JSONArray)) { return false; } int len = this.length(); if (len != ((JSONArray)other).length()) { return false; } for (int i = 0; i < len; i += 1) { Object valueThis = this.ge...
java
public int copy(byte[] bytes, int at) { System.arraycopy(this.bytes, 0, bytes, at, this.length); return at + this.length; }
java
public int get(int at) throws JSONException { if (at < 0 || at > this.length) { throw new JSONException("Bad character at " + at); } return ((int) this.bytes[at]) & 0xFF; }
java
public void reset( Reader input ) throws IOException { if ( input != null ) { reader = new IPushbackReader(new BufferedReader(input)); } idx = -1; }
java
protected void pushBack(String str) { char[] chars = str.toCharArray(); for ( int j = chars.length - 1; j >= 0; j-- ) { reader.unread(chars[j]); } idx -= chars.length; }
java
protected IWord getNextLatinWord(int c, int pos) throws IOException { /* * clear or just return the English punctuation as * a single word with PUNCTUATION type and part of speech */ if ( StringUtil.isEnPunctuation( c ) ) { String str = String.valueOf((char)c);...
java
protected IWord getNextMixedWord(char[] chars, int cjkidx) throws IOException { IStringBuffer buff = new IStringBuffer(); buff.clear().append(chars, cjkidx); String tstring = buff.toString(); if ( ! dic.match(ILexicon.MIX_ASSIST_WORD, tstring) ) { return null; } ...
java
protected IWord getNextPunctuationPairWord(int c, int pos) throws IOException { IWord w = null, w2 = null; String text = getPairPunctuationText(c); //handle the punctuation. String str = String.valueOf((char)c); if ( ! ( config.CLEAR_STOPWORD && dic....
java
protected void appendWordFeatures( IWord word ) { //add the pinyin to the pool if ( config.APPEND_CJK_PINYIN && config.LOAD_CJK_PINYIN && word.getPinyin() != null ) { IWord pinyin = new Word(word.getPinyin(), IWord.T_CJK_PINYIN); pinyin.setPosition(word.getPo...
java
protected void appendLatinSyn( IWord w ) { IWord ew; /* * @added 2014-07-07 * w maybe EC_MIX_WORD, so check its syn first * and make sure it is not a EC_MIX_WORD then check the EN_WORD */ if ( w.getSyn() == null ) { ew = dic.get(ILexic...
java
protected IWord[] getNextMatch(char[] chars, int index) { ArrayList<IWord> mList = new ArrayList<IWord>(8); //StringBuilder isb = new StringBuilder(); isb.clear(); char c = chars[index]; isb.append(c); String temp = isb.toString(); if ( dic.match(ILexico...
java
protected char[] nextCJKSentence( int c ) throws IOException { isb.clear(); int ch; isb.append((char)c); //reset the CE check mask. ctrlMask &= ~ISegment.CHECK_CE_MASk; while ( (ch = readNext()) != -1 ) { if ( StringUtil.isWhitespace(ch)...
java
protected String nextLatinString(int c) throws IOException { isb.clear(); if ( c > 65280 ) c -= 65248; if ( c >= 65 && c <= 90 ) c += 32; isb.append((char)c); int ch; int _ctype = 0; ctrlMask &= ~ISegment.CHECK_EC_MASK; while ( (ch =...
java
protected String nextLetterNumber( int c ) throws IOException { //StringBuilder isb = new StringBuilder(); isb.clear(); isb.append((char)c); int ch; while ( (ch = readNext()) != -1 ) { if ( StringUtil.isWhitespace(ch) ) { pushBack(ch); ...
java
protected String nextOtherNumber( int c ) throws IOException { //StringBuilder isb = new StringBuilder(); isb.clear(); isb.append((char)c); int ch; while ( (ch = readNext()) != -1 ) { if ( StringUtil.isWhitespace(ch) ) { pushBack(ch); ...
java
protected String nextCNNumeric( char[] chars, int index ) throws IOException { //StringBuilder isb = new StringBuilder(); isb.clear(); isb.append( chars[ index ]); ctrlMask &= ~ISegment.CHECK_CF_MASK; //reset the fraction check mask. for ( int j = index + 1; ...
java
@Override protected IWord getNextCJKWord(int c, int pos) throws IOException { String key = null; char[] chars = nextCJKSentence(c); int cjkidx = 0, ignidx = 0, mnum = 0; IWord word = null; ArrayList<IWord> mList = new ArrayList<IWord>(8); while ( cjkidx ...
java
private void process() { if (requestUri.length() > 1) { parts = new ArrayList<String>(10); for ( int i = 1; i < requestUri.length(); ) { int sIdx = i; int eIdx = requestUri.indexOf('/', sIdx + 1); //not matched or reach...
java