idx int64 0 41.2k | question stringlengths 74 4.04k | target stringlengths 7 750 |
|---|---|---|
32,700 | public static ADictionary createDefaultDictionary ( JcsegTaskConfig config , boolean loadDic ) { return createDefaultDictionary ( config , config . isAutoload ( ) , loadDic ) ; } | create the ADictionary according to the JcsegTaskConfig |
32,701 | public static ADictionary createSingletonDictionary ( JcsegTaskConfig config , boolean loadDic ) { synchronized ( LOCK ) { if ( singletonDic == null ) { singletonDic = createDefaultDictionary ( config , loadDic ) ; } } return singletonDic ; } | create a singleton ADictionary object according to the JcsegTaskConfig |
32,702 | 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 { sb . append ( str . charAt ( j ) ) ; } } return sb . toString ( ) ; } | convert the traditional words to simplified words of the specified string . |
32,703 | 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 ( Exception e ) { e . printStackTrace ( ) ; System . out . println ( "can't load the ISegment implements class " + "with path [" + _class . getName ( ) + "] " ) ; } return seg ; } | load the ISegment class with the given path |
32,704 | 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 : _clsname = ComplexSeg . class ; break ; case JcsegTaskConfig . DETECT_MODE : _clsname = DetectSeg . class ; break ; case JcsegTaskConfig . SEARCH_MODE : _clsname = SearchSeg . class ; break ; case JcsegTaskConfig . DELIMITER_MODE : _clsname = DelimiterSeg . class ; break ; case JcsegTaskConfig . NLP_MODE : _clsname = NLPSeg . class ; break ; default : throw new JcsegException ( "No Such Algorithm Excpetion" ) ; } Class < ? > [ ] _paramtype = null ; if ( args . length == 2 ) { _paramtype = new Class [ ] { JcsegTaskConfig . class , ADictionary . class } ; } else if ( args . length == 3 ) { _paramtype = new Class [ ] { Reader . class , JcsegTaskConfig . class , ADictionary . class } ; } else { throw new JcsegException ( "length of the arguments should be 2 or 3" ) ; } return createSegment ( _clsname , _paramtype , args ) ; } | create the specified mode Jcseg instance |
32,705 | private void init ( ) { QueuedThreadPool threadPool = new QueuedThreadPool ( ) ; threadPool . setMaxThreads ( config . getMaxThreadPoolSize ( ) ) ; threadPool . setIdleTimeout ( config . getThreadIdleTimeout ( ) ) ; server = new Server ( threadPool ) ; HttpConfiguration http_config = new HttpConfiguration ( ) ; http_config . setOutputBufferSize ( config . getOutputBufferSize ( ) ) ; http_config . setRequestHeaderSize ( config . getRequestHeaderSize ( ) ) ; http_config . setResponseHeaderSize ( config . getResponseHeaderSize ( ) ) ; http_config . setSendServerVersion ( false ) ; http_config . setSendDateHeader ( false ) ; ServerConnector connector = new ServerConnector ( server , new HttpConnectionFactory ( http_config ) ) ; connector . setPort ( config . getPort ( ) ) ; connector . setHost ( config . getHost ( ) ) ; connector . setIdleTimeout ( config . getHttpIdleTimeout ( ) ) ; server . addConnector ( connector ) ; } | initialize the server and register the basic context handler |
32,706 | 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 ( "/extractor/keyphrase" , KeyphraseController . class ) ; router . addMapping ( "/extractor/sentence" , SentenceController . class ) ; router . addMapping ( "/extractor/summary" , SummaryController . class ) ; router . addMapping ( "/tokenizer/default" , TokenizerController . class ) ; StandardHandler stdHandler = new StandardHandler ( config , resourcePool , router ) ; JcsegResourceHandler resourceHandler = new JcsegResourceHandler ( ) ; GzipHandler gzipHandler = new GzipHandler ( ) ; HandlerList handlers = new HandlerList ( ) ; handlers . setHandlers ( new Handler [ ] { stdHandler , resourceHandler } ) ; gzipHandler . setHandler ( handlers ) ; server . setHandler ( gzipHandler ) ; return this ; } | register handler service |
32,707 | 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" ) ) ; } if ( json . has ( "jcseg_pptmaxlen" ) ) { config . setPPT_MAX_LENGTH ( json . getInt ( "jcseg_pptmaxlen" ) ) ; } if ( json . has ( "jcseg_cnmaxlnadron" ) ) { config . setMaxCnLnadron ( json . getInt ( "jcseg_cnmaxlnadron" ) ) ; } if ( json . has ( "jcseg_clearstopword" ) ) { config . setClearStopwords ( json . getBoolean ( "jcseg_clearstopword" ) ) ; } if ( json . has ( "jcseg_cnnumtoarabic" ) ) { config . setCnNumToArabic ( json . getBoolean ( "jcseg_cnnumtoarabic" ) ) ; } if ( json . has ( "jcseg_cnfratoarabic" ) ) { config . setCnFactionToArabic ( json . getBoolean ( "jcseg_cnfratoarabic" ) ) ; } if ( json . has ( "jcseg_keepunregword" ) ) { config . setKeepUnregWords ( json . getBoolean ( "jcseg_keepunregword" ) ) ; } if ( json . has ( "jcseg_ensencondseg" ) ) { config . setEnSecondSeg ( json . getBoolean ( "jcseg_ensencondseg" ) ) ; } if ( json . has ( "jcseg_stokenminlen" ) ) { config . setSTokenMinLen ( json . getInt ( "jcseg_stokenminlen" ) ) ; } if ( json . has ( "jcseg_nsthreshold" ) ) { config . setNameSingleThreshold ( json . getInt ( "jcseg_nsthreshold" ) ) ; } if ( json . has ( "jcseg_keeppunctuations" ) ) { config . setKeepPunctuations ( json . getString ( "jcseg_keeppunctuations" ) ) ; } } | reset a JcsegTaskConfig from a JSONObject |
32,708 | 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 ; this . map . put ( key , to ) ; to += 1 ; } else { this . map . remove ( key ) ; } from += 1 ; } if ( to < this . capacity ) { this . length = to ; } else { this . map . clear ( ) ; this . length = 0 ; } this . power = 0 ; } | Compact the keep . A keep may contain at most this . capacity elements . The keep contents can be reduced by deleting all elements with low use counts and by reducing the use counts of the survivors . |
32,709 | public int find ( Object key ) { Object o = this . map . get ( key ) ; return o instanceof Integer ? ( ( Integer ) o ) . intValue ( ) : none ; } | Find the integer value associated with this key or nothing if this key is not in the keep . |
32,710 | 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 . length ] = value ; this . map . put ( value , this . length ) ; this . ticks [ this . length ] = 1 ; if ( JSONzip . probe ) { JSONzip . log ( "<" + this . length + " " + value + "> " ) ; } this . length += 1 ; } | Register a value in the keep . Compact the keep if it is full . The next time this value is encountered its integer can be sent instead . |
32,711 | public static IChunk [ ] getMaximumMatchChunks ( IChunk [ ] chunks ) { int maxLength = chunks [ 0 ] . getLength ( ) ; int j ; for ( j = 1 ; j < chunks . length ; j ++ ) { if ( chunks [ j ] . getLength ( ) > maxLength ) maxLength = chunks [ j ] . getLength ( ) ; } ArrayList < IChunk > chunkArr = new ArrayList < IChunk > ( chunks . length ) ; for ( j = 0 ; j < chunks . length ; j ++ ) { if ( chunks [ j ] . getLength ( ) == maxLength ) { chunkArr . add ( chunks [ j ] ) ; } } IChunk [ ] lchunk = new IChunk [ chunkArr . size ( ) ] ; chunkArr . toArray ( lchunk ) ; chunkArr . clear ( ) ; return lchunk ; } | 1 . the maximum match rule this rule will return the chunks that own the largest word length |
32,712 | public static IChunk [ ] getLargestAverageWordLengthChunks ( IChunk [ ] chunks ) { double largetAverage = chunks [ 0 ] . getAverageWordsLength ( ) ; int j ; for ( j = 1 ; j < chunks . length ; j ++ ) { if ( chunks [ j ] . getAverageWordsLength ( ) > largetAverage ) { largetAverage = chunks [ j ] . getAverageWordsLength ( ) ; } } ArrayList < IChunk > chunkArr = new ArrayList < IChunk > ( chunks . length ) ; for ( j = 0 ; j < chunks . length ; j ++ ) { if ( chunks [ j ] . getAverageWordsLength ( ) == largetAverage ) { chunkArr . add ( chunks [ j ] ) ; } } IChunk [ ] lchunk = new IChunk [ chunkArr . size ( ) ] ; chunkArr . toArray ( lchunk ) ; chunkArr . clear ( ) ; return lchunk ; } | 2 . largest average word length this rule will return the chunks that own the largest average word length |
32,713 | public static IChunk [ ] getSmallestVarianceWordLengthChunks ( IChunk [ ] chunks ) { double smallestVariance = chunks [ 0 ] . getWordsVariance ( ) ; int j ; for ( j = 1 ; j < chunks . length ; j ++ ) { if ( chunks [ j ] . getWordsVariance ( ) < smallestVariance ) { smallestVariance = chunks [ j ] . getWordsVariance ( ) ; } } ArrayList < IChunk > chunkArr = new ArrayList < IChunk > ( chunks . length ) ; for ( j = 0 ; j < chunks . length ; j ++ ) { if ( chunks [ j ] . getWordsVariance ( ) == smallestVariance ) { chunkArr . add ( chunks [ j ] ) ; } } IChunk [ ] lchunk = new IChunk [ chunkArr . size ( ) ] ; chunkArr . toArray ( lchunk ) ; chunkArr . clear ( ) ; return lchunk ; } | the smallest variance word length this rule will the chunks that one the smallest variance word length |
32,714 | public static IChunk [ ] getLargestSingleMorphemicFreedomChunks ( IChunk [ ] chunks ) { double largestFreedom = chunks [ 0 ] . getSingleWordsMorphemicFreedom ( ) ; int j ; for ( j = 1 ; j < chunks . length ; j ++ ) { if ( chunks [ j ] . getSingleWordsMorphemicFreedom ( ) > largestFreedom ) { largestFreedom = chunks [ j ] . getSingleWordsMorphemicFreedom ( ) ; } } ArrayList < IChunk > chunkArr = new ArrayList < IChunk > ( chunks . length ) ; for ( j = 0 ; j < chunks . length ; j ++ ) { if ( chunks [ j ] . getSingleWordsMorphemicFreedom ( ) == largestFreedom ) { chunkArr . add ( chunks [ j ] ) ; } } IChunk [ ] lchunk = new IChunk [ chunkArr . size ( ) ] ; chunkArr . toArray ( lchunk ) ; chunkArr . clear ( ) ; return lchunk ; } | the largest sum of degree of morphemic freedom of one - character words this rule will return the chunks that own the largest sum of degree of morphemic freedom of one - character |
32,715 | 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 ) ; } sb . append ( o . toString ( ) ) ; } return sb . toString ( ) ; } | String array implode internal method |
32,716 | 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 ; } | check and search the specified element in the Array |
32,717 | 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 ; } | check if there is an element that starts with the specified string |
32,718 | 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 ; } | check if there is an element that ends with the specified string |
32,719 | 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 ; } | check if there is an element that contains the specified string |
32,720 | 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 ( "\":true" ) ; } else { sb . append ( ",\"" ) . append ( ele ) . append ( "\":true" ) ; } } sb . append ( '}' ) ; return sb . toString ( ) ; } | implode the array elements as a Json array string |
32,721 | 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 ) ; } return sentence ; } | text doc to sentence |
32,722 | 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 ( ) ) ) ; IWord word = null ; while ( ( word = wordSeg . next ( ) ) != null ) { words . add ( word ) ; } senWords . add ( words ) ; } return senWords ; } | sentence to words |
32,723 | protected Document [ ] textRankSortedDocuments ( List < Sentence > sentence , List < List < IWord > > senWords ) throws IOException { int docNum = sentence . size ( ) ; double [ ] [ ] relevance = BM25RelevanceMatixBuild ( sentence , senWords ) ; double [ ] score = new double [ docNum ] ; double [ ] weight_sum = new double [ docNum ] ; for ( int i = 0 ; i < docNum ; i ++ ) { weight_sum [ i ] = sum ( relevance [ i ] ) - relevance [ i ] [ i ] ; score [ i ] = 0 ; } for ( int c = 0 ; c < maxIterateNum ; c ++ ) { for ( int i = 0 ; i < docNum ; i ++ ) { double sigema = 0D ; for ( int j = 0 ; j < docNum ; j ++ ) { if ( i == j || weight_sum [ j ] == 0 ) continue ; sigema += relevance [ j ] [ i ] / weight_sum [ j ] * score [ j ] ; } score [ i ] = 1 - D + D * sigema ; } } Document [ ] docs = new Document [ docNum ] ; for ( int i = 0 ; i < docNum ; i ++ ) { docs [ i ] = new Document ( i , sentence . get ( i ) , senWords . get ( i ) , score [ i ] ) ; } Sort . shellSort ( docs ) ; relevance = null ; score = null ; weight_sum = null ; return docs ; } | get the documents order by relevance score . |
32,724 | public static final IWord [ ] createDateTimePool ( ) { return new IWord [ ] { null , null , null , null , null , null , null , } ; } | create and return a date - time pool |
32,725 | 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 ; } return DATETIME_NONE ; } | fill the date - time pool specified part through the specified time entity string . |
32,726 | public static final void fillDateTimePool ( IWord [ ] wPool , int pIdx , IWord word ) { if ( wPool [ pIdx ] == null ) { wPool [ pIdx ] = word ; } } | fill the date - time pool specified part with part index constant |
32,727 | 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 ) ; } | get and return the time key part of the specified entity string |
32,728 | protected void readUntil ( char echar ) throws IOException { int ch , i = 0 ; IStringBuffer sb = new IStringBuffer ( ) ; while ( ( ch = readNext ( ) ) != - 1 ) { if ( ++ i >= MAX_QUOTE_LENGTH ) { for ( int j = sb . length ( ) - 1 ; j >= 0 ; j -- ) { reader . unread ( sb . charAt ( j ) ) ; } idx -= sb . length ( ) ; break ; } sb . append ( ( char ) ch ) ; if ( ch == echar ) { gisb . append ( sb . toString ( ) ) ; break ; } } sb = null ; } | loop the reader until the specifield char is found . |
32,729 | public boolean enQueue ( int data ) { Entry o = new Entry ( data , tail . prev , tail ) ; tail . prev . next = o ; tail . prev = o ; size ++ ; return true ; } | append a int from the tail |
32,730 | public boolean add ( T word ) { Entry < T > o = new Entry < T > ( word , tail . prev , tail ) ; tail . prev . next = o ; tail . prev = o ; size ++ ; index . put ( word . getValue ( ) , word ) ; return true ; } | append a item from the tail |
32,731 | public String getSummaryFromString ( String doc , int length ) throws IOException { return getSummary ( new StringReader ( doc ) , length ) ; } | get document summary from a string |
32,732 | public String getSummaryFromFile ( String file , int length ) throws IOException { return getSummary ( new FileReader ( file ) , length ) ; } | get document summary from a file |
32,733 | 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 = atIndex + 1 ; while ( ( ptIndex = str . indexOf ( '.' , ptStart ) ) > 0 ) { if ( ptIndex == ptStart ) { return false ; } if ( ! StringUtil . isLetterOrNumeric ( str , ptStart , ptIndex ) ) { return false ; } ptStart = ptIndex + 1 ; } if ( ptStart < str . length ( ) && ! StringUtil . isLetterOrNumeric ( str , ptStart , str . length ( ) ) ) { return false ; } return true ; } | check if the specified string is an email address or not |
32,734 | 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 ( '/' , sIdx ) , sgIndex = str . indexOf ( '?' , sIdx ) ; int eIdx = slIndex > - 1 ? slIndex : ( sgIndex > - 1 ? sgIndex : str . length ( ) ) ; int lpIndex = - 1 ; for ( int i = sIdx ; i < eIdx ; i ++ ) { char chr = str . charAt ( i ) ; if ( chr == '.' ) { if ( lpIndex == - 1 ) { lpIndex = i ; continue ; } if ( ( i - lpIndex ) == 1 || i == ( eIdx - 1 ) ) { return false ; } lpIndex = i ; } else if ( ! StringUtil . isEnLetter ( chr ) && ! StringUtil . isEnNumeric ( chr ) ) { return false ; } } if ( dic != null && ! dic . match ( ILexicon . DOMAIN_SUFFIX , str . substring ( lpIndex + 1 , eIdx ) ) ) { return false ; } if ( slIndex > - 1 ) { sIdx = slIndex ; eIdx = sgIndex > - 1 ? sgIndex : str . length ( ) ; lpIndex = - 1 ; for ( int i = sIdx ; i < eIdx ; i ++ ) { char chr = str . charAt ( i ) ; if ( "./-_" . indexOf ( chr ) > - 1 ) { if ( lpIndex == - 1 ) { lpIndex = i ; continue ; } if ( i - lpIndex == 1 || ( chr == '.' && i == ( eIdx - 1 ) ) ) { return false ; } lpIndex = i ; } else if ( ! StringUtil . isEnLetter ( chr ) && ! StringUtil . isEnNumeric ( chr ) ) { return false ; } } } return true ; } | check if the specified string is an URL address or not |
32,735 | 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 ; } return StringUtil . isNumeric ( str , 2 , str . length ( ) ) ; } | check if the specified string is a mobile number |
32,736 | public static boolean isCJKChar ( int c ) { if ( c == 183 || Character . getType ( c ) == Character . OTHER_LETTER ) return true ; return false ; } | check the specified char is CJK Thai ... char true will be return if it is or return false |
32,737 | public static boolean isEnPunctuation ( int c ) { return ( ( c > 32 && c < 48 ) || ( c > 57 && c < 65 ) || ( c > 90 && c < 97 ) || ( c > 122 && c < 127 ) ) ; } | check the given char is half - width punctuation |
32,738 | public static boolean isDigit ( String str , int beginIndex , int endIndex ) { char c ; for ( int j = beginIndex ; j < endIndex ; j ++ ) { c = str . charAt ( j ) ; if ( c > 65280 ) c -= 65248 ; if ( c < 48 || c > 57 ) { return false ; } } return true ; } | check the specified char is a digit or not true will return if it is or return false this method can recognize full - with char |
32,739 | 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 ; for ( int j = 1 ; j < str . length ( ) ; j ++ ) { c = str . charAt ( j ) ; if ( c == '.' ) { p ++ ; } else { if ( c > 65280 ) c -= 65248 ; if ( c < 48 || c > 57 ) return false ; } } return ( p == 1 ) ; } | check the specified char is a decimal including the full - width char |
32,740 | 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 ; } | check if the specified string is all Latin chars |
32,741 | 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 ; } | check if the specified string is all CJK chars |
32,742 | 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 ; } } return true ; } | check if the specified string is Latin numeric or letter |
32,743 | 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 ; } | check if the specified string is Latin letter |
32,744 | 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 ; } | check if the specified string it Latin numeric |
32,745 | 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 ; } | get the index of the first Latin char of the specified string |
32,746 | 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 ; } | get the index of the first CJK char of the specified string |
32,747 | 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 ) ; } } return new String ( chars ) ; } | a static method to replace the half - width char to the full - width char in a given string |
32,748 | public void pad ( int width ) throws JSONException { try { this . bitwriter . pad ( width ) ; } catch ( Throwable e ) { throw new JSONException ( e ) ; } } | Pad the output to fill an allotment of bits . |
32,749 | 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 ) ; } } | Write a number using the number of bits necessary to hold the number . |
32,750 | 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 ) ; } } } | Write each of the bytes in a kim with Huffman encoding . |
32,751 | 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 ) ; } | Write an integer using the number of bits necessary to hold the number as determined by its keep and increment its usage count in the keep . |
32,752 | private void write ( JSONArray jsonarray ) throws JSONException { boolean stringy = false ; int length = jsonarray . length ( ) ; if ( length == 0 ) { write ( zipEmptyArray , 3 ) ; } else { Object value = jsonarray . get ( 0 ) ; if ( value == null ) { value = JSONObject . NULL ; } if ( value instanceof String ) { stringy = true ; write ( zipArrayString , 3 ) ; writeString ( ( String ) value ) ; } else { write ( zipArrayValue , 3 ) ; writeValue ( value ) ; } for ( int i = 1 ; i < length ; i += 1 ) { if ( probe ) { log ( ) ; } value = jsonarray . get ( i ) ; if ( value == null ) { value = JSONObject . NULL ; } if ( value instanceof String != stringy ) { zero ( ) ; } one ( ) ; if ( value instanceof String ) { writeString ( ( String ) value ) ; } else { writeValue ( value ) ; } } zero ( ) ; zero ( ) ; } } | Write a JSON Array . |
32,753 | @ 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 ) ) { write ( zipTrue , 3 ) ; } else { if ( value instanceof Map ) { value = new JSONObject ( ( Map ) value ) ; } else if ( value instanceof Collection ) { value = new JSONArray ( ( Collection ) value ) ; } else if ( value . getClass ( ) . isArray ( ) ) { value = new JSONArray ( value ) ; } if ( value instanceof JSONObject ) { write ( ( JSONObject ) value ) ; } else if ( value instanceof JSONArray ) { write ( ( JSONArray ) value ) ; } else { throw new JSONException ( "Unrecognized object" ) ; } } } | Write a JSON value . |
32,754 | private void writeName ( String name ) throws JSONException { Kim kim = new Kim ( name ) ; int integer = this . namekeep . find ( kim ) ; if ( integer != none ) { one ( ) ; write ( integer , this . namekeep ) ; } else { zero ( ) ; write ( kim , this . namehuff , this . namehuffext ) ; write ( end , namehuff ) ; this . namekeep . register ( kim ) ; } } | Write the name of an object property . Names have their own Keep and Huffman encoder because they are expected to be a more restricted set . |
32,755 | private void write ( JSONObject jsonobject ) throws JSONException { boolean first = true ; Iterator < String > keys = jsonobject . keys ( ) ; while ( keys . hasNext ( ) ) { if ( probe ) { log ( ) ; } Object key = keys . next ( ) ; if ( key instanceof String ) { if ( first ) { first = false ; write ( zipObject , 3 ) ; } else { one ( ) ; } writeName ( ( String ) key ) ; Object value = jsonobject . get ( ( String ) key ) ; if ( value instanceof String ) { zero ( ) ; writeString ( ( String ) value ) ; } else { one ( ) ; writeValue ( value ) ; } } } if ( first ) { write ( zipEmptyObject , 3 ) ; } else { zero ( ) ; } } | Write a JSON object . |
32,756 | 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 , this . valuekeep ) ; return ; } if ( value instanceof Integer || value instanceof Long ) { long longer = ( ( Number ) value ) . longValue ( ) ; if ( longer >= 0 && longer < int14 ) { write ( 0 , 2 ) ; if ( longer < int4 ) { zero ( ) ; write ( ( int ) longer , 4 ) ; return ; } one ( ) ; if ( longer < int7 ) { zero ( ) ; write ( ( int ) ( longer - int4 ) , 7 ) ; return ; } one ( ) ; write ( ( int ) ( longer - int7 ) , 14 ) ; return ; } } write ( 1 , 2 ) ; for ( int i = 0 ; i < string . length ( ) ; i += 1 ) { write ( bcd ( string . charAt ( i ) ) , 4 ) ; } write ( endOfNumber , 4 ) ; this . valuekeep . register ( string ) ; } else { write ( 3 , 2 ) ; writeJSON ( value ) ; } } | Write a value . |
32,757 | protected boolean filter ( IWord word ) { if ( word . getValue ( ) . length ( ) < 2 ) { return false ; } switch ( word . getType ( ) ) { case IWord . T_LETTER_NUMBER : case IWord . T_OTHER_NUMBER : case IWord . T_CJK_PINYIN : case IWord . T_PUNCTUATION : case IWord . T_UNRECOGNIZE_WORD : { return false ; } } String [ ] poss = word . getPartSpeech ( ) ; if ( poss == null ) return true ; char pos = poss [ 0 ] . charAt ( 0 ) ; switch ( pos ) { case 'e' : { if ( poss [ 0 ] . equals ( "en" ) ) return true ; return false ; } case 'm' : { if ( poss [ 0 ] . equals ( "mix" ) ) return true ; return false ; } case 'q' : case 'b' : case 'r' : case 'z' : case 'p' : case 'c' : case 'u' : case 'y' : case 'd' : case 'o' : case 'h' : case 'k' : case 'g' : case 'x' : case 'w' : { return false ; } } return true ; } | word item filter |
32,758 | private void init ( ) { response . setCharacterEncoding ( config . getCharset ( ) ) ; response . setContentType ( "text/html;charset=" + config . getCharset ( ) ) ; response . setStatus ( HttpServletResponse . SC_OK ) ; } | request initialize work |
32,759 | public int getInt ( String name ) { int val = 0 ; try { val = Integer . valueOf ( request . getParameter ( name ) ) ; } catch ( NumberFormatException e ) { } return val ; } | get a integer arguments |
32,760 | public float getFloat ( String name ) { float fval = 0F ; try { fval = Float . valueOf ( request . getParameter ( name ) ) ; } catch ( NumberFormatException e ) { } return fval ; } | get a float arguments |
32,761 | public long getLong ( String name ) { long val = 0 ; try { val = Long . valueOf ( request . getParameter ( name ) ) ; } catch ( NumberFormatException e ) { } return val ; } | get a long argument |
32,762 | public double getDouble ( String name ) { double val = 0 ; try { val = Double . valueOf ( request . getParameter ( name ) ) ; } catch ( NumberFormatException e ) { } return val ; } | get a double argument |
32,763 | public boolean getBoolean ( String name ) { boolean val = false ; try { val = Boolean . valueOf ( request . getParameter ( name ) ) ; } catch ( NumberFormatException e ) { } return val ; } | get a boolean argument |
32,764 | 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 < contentLength ; ) { int rLen = is . read ( buffer , i , contentLength - i ) ; if ( rLen == - 1 ) { break ; } i += rLen ; } return buffer ; } | get the original raw data |
32,765 | public String getRawDataAsString ( ) throws IOException { byte [ ] buffer = getRawData ( ) ; if ( buffer == null ) { return null ; } String encoding = request . getCharacterEncoding ( ) ; if ( encoding == null ) { encoding = "utf-8" ; } return new String ( buffer , encoding ) ; } | get the original request raw data as String |
32,766 | public JSONObject getRawDataAsJson ( ) throws IOException { String input = getRawDataAsString ( ) ; if ( input == null ) { return null ; } return new JSONObject ( input ) ; } | get the original request raw data as json |
32,767 | static void logchar ( int integer , int width ) { if ( integer > ' ' && integer <= '}' ) { log ( "'" + ( char ) integer + "':" + width + " " ) ; } else { log ( integer , width ) ; } } | Write a character or its code to the console . |
32,768 | 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 ) && this . valuekeep . postMortem ( that . valuekeep ) ; } | This method is used for testing the implementation of JSONzip . It is not suitable for any other purpose . It is used to compare a Compressor and a Decompressor verifying that the data structures that were built during zipping and unzipping were the same . |
32,769 | public boolean postMortem ( PostMortem pm ) { for ( int integer = 0 ; integer < this . domain ; integer += 1 ) { if ( ! postMortem ( integer ) ) { JSONzip . log ( "\nBad huff " ) ; JSONzip . logchar ( integer , integer ) ; return false ; } } return this . table . postMortem ( ( ( Huff ) pm ) . table ) ; } | Compare two Huffman tables . |
32,770 | 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 ( symbol . integer ) ; if ( JSONzip . probe ) { JSONzip . logchar ( symbol . integer , this . width ) ; } return symbol . integer ; } catch ( Throwable e ) { throw new JSONException ( e ) ; } } | Read bits until a symbol can be identified . The weight of the read symbol will be incremented . |
32,771 | 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 . zero ( ) ; } else { bitwriter . one ( ) ; } } } catch ( Throwable e ) { throw new JSONException ( e ) ; } } | Recur from a symbol back emitting bits . We recur before emitting to make the bits come out in the right order . |
32,772 | 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 ) ; } } | Write the bits corresponding to a symbol . The weight of the symbol will be incremented . |
32,773 | 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 ) ; } } | Read one bit . |
32,774 | 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 + "\"" ) ; JSONzip . log ( integer , width ) ; } if ( integer >= keep . length ) { throw new JSONException ( "Deep error." ) ; } keep . tick ( integer ) ; return value ; } catch ( Throwable e ) { throw new JSONException ( e ) ; } } | Read enough bits to obtain an integer from the keep and increase that integer s weight . |
32,775 | 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 ) ; } } | Read an integer specifying its width in bits . |
32,776 | 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 ( at >= allocation ) { allocation *= 2 ; bytes = java . util . Arrays . copyOf ( bytes , allocation ) ; } int c = huff . read ( this . bitreader ) ; if ( c == end ) { break ; } while ( ( c & 128 ) == 128 ) { bytes [ at ] = ( byte ) c ; at += 1 ; c = ext . read ( this . bitreader ) ; } bytes [ at ] = ( byte ) c ; at += 1 ; } if ( at == 0 ) { return "" ; } kim = new Kim ( bytes , at ) ; keep . register ( kim ) ; return kim . toString ( ) ; } | Read Huffman encoded characters into a keep . |
32,777 | 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 ) { log ( ) ; } if ( ! bit ( ) ) { if ( ! bit ( ) ) { return jsonarray ; } jsonarray . put ( stringy ? readValue ( ) : read ( this . stringhuff , this . stringhuffext , this . stringkeep ) ) ; } else { jsonarray . put ( stringy ? read ( this . stringhuff , this . stringhuffext , this . stringkeep ) : readValue ( ) ) ; } } } | Read a JSONArray . |
32,778 | 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 JSONObject ( ) ; case zipEmptyArray : return new JSONArray ( ) ; case zipTrue : return Boolean . TRUE ; case zipFalse : return Boolean . FALSE ; default : return JSONObject . NULL ; } } | Read a JSON value . The type of value is determined by the next 3 bits . |
32,779 | public void add ( int val ) { if ( size == items . length ) resize ( items . length * 2 + 1 ) ; items [ size ++ ] = val ; } | Append a new Integer to the end . |
32,780 | 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 -- ; } | remove the element at the specified position use System . arraycopy instead of a loop may be more efficient |
32,781 | public JSONArray put ( int index , Map < String , Object > value ) throws JSONException { this . put ( index , new JSONObject ( value ) ) ; return this ; } | Put a value in the JSONArray where the value will be a JSONObject that is produced from a Map . |
32,782 | 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 . get ( i ) ; Object valueOther = ( ( JSONArray ) other ) . get ( i ) ; if ( valueThis instanceof JSONObject ) { if ( ! ( ( JSONObject ) valueThis ) . similar ( valueOther ) ) { return false ; } } else if ( valueThis instanceof JSONArray ) { if ( ! ( ( JSONArray ) valueThis ) . similar ( valueOther ) ) { return false ; } } else if ( ! valueThis . equals ( valueOther ) ) { return false ; } } return true ; } | Determine if two JSONArrays are similar . They must contain similar sequences . |
32,783 | public int copy ( byte [ ] bytes , int at ) { System . arraycopy ( this . bytes , 0 , bytes , at , this . length ) ; return at + this . length ; } | Copy the contents of this kim to a byte array . |
32,784 | 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 ; } | Get a byte from a kim . |
32,785 | public void reset ( Reader input ) throws IOException { if ( input != null ) { reader = new IPushbackReader ( new BufferedReader ( input ) ) ; } idx = - 1 ; } | input stream and reader reset . |
32,786 | 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 ; } | push back a string to the stream |
32,787 | protected IWord getNextLatinWord ( int c , int pos ) throws IOException { if ( StringUtil . isEnPunctuation ( c ) ) { String str = String . valueOf ( ( char ) c ) ; if ( config . CLEAR_STOPWORD && dic . match ( ILexicon . STOP_WORD , str ) ) { return null ; } IWord w = new Word ( str , IWord . T_PUNCTUATION ) ; w . setPosition ( pos ) ; w . setPartSpeech ( IWord . PUNCTUATION ) ; return w ; } IWord w = nextLatinWord ( c , pos ) ; w . setPosition ( pos ) ; if ( config . EN_SECOND_SEG && ( ctrlMask & ISegment . START_SS_MASK ) != 0 ) { enSecondSeg ( w , false ) ; } if ( config . CLEAR_STOPWORD && dic . match ( ILexicon . STOP_WORD , w . getValue ( ) ) ) { w = null ; return null ; } if ( config . APPEND_CJK_SYN ) { appendLatinSyn ( w ) ; } return w ; } | get the next Latin word from the current position of the input stream |
32,788 | 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 ; } if ( behindLatin == null ) { behindLatin = nextLatinString ( readNext ( ) ) ; } IWord wd = null ; buff . append ( behindLatin ) ; tstring = buff . toString ( ) ; if ( dic . match ( ILexicon . CJK_WORD , tstring ) ) { wd = dic . get ( ILexicon . CJK_WORD , tstring ) ; } if ( ( ctrlMask & ISegment . CHECK_EC_MASK ) != 0 || dic . match ( ILexicon . MIX_ASSIST_WORD , tstring ) ) { ialist . clear ( ) ; int chr = - 1 , j , mc = 0 ; for ( j = 0 ; j < dic . mixSuffixLength && ( chr = readNext ( ) ) != - 1 ; j ++ ) { buff . append ( ( char ) chr ) ; ialist . add ( chr ) ; tstring = buff . toString ( ) ; if ( dic . match ( ILexicon . CJK_WORD , tstring ) ) { wd = dic . get ( ILexicon . CJK_WORD , tstring ) ; mc = j + 1 ; } } for ( int i = j - 1 ; i >= mc ; i -- ) { pushBack ( ialist . get ( i ) ) ; } } buff . clear ( ) ; buff = null ; if ( wd != null ) { behindLatin = null ; } return wd ; } | get the next mixed word CJK - English or CJK - English - CJK or whatever |
32,789 | protected IWord getNextPunctuationPairWord ( int c , int pos ) throws IOException { IWord w = null , w2 = null ; String text = getPairPunctuationText ( c ) ; String str = String . valueOf ( ( char ) c ) ; if ( ! ( config . CLEAR_STOPWORD && dic . match ( ILexicon . STOP_WORD , str ) ) ) { w = new Word ( str , IWord . T_PUNCTUATION ) ; w . setPartSpeech ( IWord . PUNCTUATION ) ; w . setPosition ( pos ) ; } if ( text != null && text . length ( ) > 0 && ! ( config . CLEAR_STOPWORD && dic . match ( ILexicon . STOP_WORD , text ) ) ) { w2 = new Word ( text , ILexicon . CJK_WORD ) ; w2 . setPartSpeech ( IWord . PPT_POSPEECH ) ; w2 . setPosition ( pos + 1 ) ; if ( w == null ) w = w2 ; else wordPool . add ( w2 ) ; } if ( w == null && w2 == null ) { return null ; } return w ; } | get the next punctuation pair word from the current position of the input stream . |
32,790 | protected void appendWordFeatures ( IWord word ) { 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 . getPosition ( ) ) ; pinyin . setEntity ( word . getEntity ( ) ) ; wordPool . add ( pinyin ) ; } if ( config . APPEND_CJK_SYN && config . LOAD_CJK_SYN && word . getSyn ( ) != null ) { SegKit . appendSynonyms ( wordPool , word ) ; } } | check and append the pinyin and the synonyms words of the specified word |
32,791 | protected void appendLatinSyn ( IWord w ) { IWord ew ; if ( w . getSyn ( ) == null ) { ew = dic . get ( ILexicon . CJK_WORD , w . getValue ( ) ) ; } else { ew = w ; } if ( ew != null && ew . getSyn ( ) != null ) { ew . setPosition ( w . getPosition ( ) ) ; SegKit . appendSynonyms ( wordPool , ew ) ; } } | Check and append the synonyms words of specified word included the CJK and basic Latin words All the synonyms words share the same position part of speech word type with the primitive word |
32,792 | protected IWord [ ] getNextMatch ( char [ ] chars , int index ) { ArrayList < IWord > mList = new ArrayList < IWord > ( 8 ) ; isb . clear ( ) ; char c = chars [ index ] ; isb . append ( c ) ; String temp = isb . toString ( ) ; if ( dic . match ( ILexicon . CJK_WORD , temp ) ) { mList . add ( dic . get ( ILexicon . CJK_WORD , temp ) ) ; } String _key = null ; for ( int j = 1 ; j < config . MAX_LENGTH && ( ( j + index ) < chars . length ) ; j ++ ) { isb . append ( chars [ j + index ] ) ; _key = isb . toString ( ) ; if ( dic . match ( ILexicon . CJK_WORD , _key ) ) { mList . add ( dic . get ( ILexicon . CJK_WORD , _key ) ) ; } } if ( mList . isEmpty ( ) ) { mList . add ( new Word ( temp , ILexicon . UNMATCH_CJK_WORD ) ) ; } IWord [ ] words = new IWord [ mList . size ( ) ] ; mList . toArray ( words ) ; mList . clear ( ) ; return words ; } | match the next CJK word in the dictionary |
32,793 | protected char [ ] nextCJKSentence ( int c ) throws IOException { isb . clear ( ) ; int ch ; isb . append ( ( char ) c ) ; ctrlMask &= ~ ISegment . CHECK_CE_MASk ; while ( ( ch = readNext ( ) ) != - 1 ) { if ( StringUtil . isWhitespace ( ch ) ) { pushBack ( ch ) ; break ; } if ( ! StringUtil . isCJKChar ( ch ) ) { pushBack ( ch ) ; if ( StringUtil . isEnLetter ( ch ) || StringUtil . isEnNumeric ( ch ) ) { ctrlMask |= ISegment . CHECK_CE_MASk ; } break ; } isb . append ( ( char ) ch ) ; } return isb . toString ( ) . toCharArray ( ) ; } | load a CJK char list from the stream start from the current position till the char is not a CJK char |
32,794 | 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 = readNext ( ) ) != - 1 ) { if ( ch > 65280 ) ch -= 65248 ; _ctype = StringUtil . getEnCharType ( ch ) ; if ( _ctype == StringUtil . EN_WHITESPACE ) { break ; } if ( _ctype == StringUtil . EN_PUNCTUATION ) { if ( ! config . isKeepPunctuation ( ( char ) ch ) ) { pushBack ( ch ) ; break ; } } if ( _ctype == StringUtil . EN_UNKNOW ) { pushBack ( ch ) ; if ( StringUtil . isCJKChar ( ch ) ) { ctrlMask |= ISegment . CHECK_EC_MASK ; } break ; } if ( ch >= 65 && ch <= 90 ) ch += 32 ; isb . append ( ( char ) ch ) ; if ( isb . length ( ) > config . MAX_LATIN_LENGTH ) { break ; } } for ( int j = isb . length ( ) - 1 ; j > 0 ; j -- ) { if ( isb . charAt ( j ) == '.' ) { isb . deleteCharAt ( j ) ; } } return isb . toString ( ) ; } | the simple version of the next basic Latin fetch logic Just return the next Latin string with the keep punctuation after it |
32,795 | protected String nextLetterNumber ( int c ) throws IOException { isb . clear ( ) ; isb . append ( ( char ) c ) ; int ch ; while ( ( ch = readNext ( ) ) != - 1 ) { if ( StringUtil . isWhitespace ( ch ) ) { pushBack ( ch ) ; break ; } if ( ! StringUtil . isLetterNumber ( ch ) ) { pushBack ( ch ) ; break ; } isb . append ( ( char ) ch ) ; } return isb . toString ( ) ; } | find the next other letter from the current position find the letter number from the current position count until the char in the specified position is not a letter number or whitespace |
32,796 | protected String nextOtherNumber ( int c ) throws IOException { isb . clear ( ) ; isb . append ( ( char ) c ) ; int ch ; while ( ( ch = readNext ( ) ) != - 1 ) { if ( StringUtil . isWhitespace ( ch ) ) { pushBack ( ch ) ; break ; } if ( ! StringUtil . isOtherNumber ( ch ) ) { pushBack ( ch ) ; break ; } isb . append ( ( char ) ch ) ; } return isb . toString ( ) ; } | find the other number from the current position count until the char in the specified position is not a other number or whitespace |
32,797 | protected String nextCNNumeric ( char [ ] chars , int index ) throws IOException { isb . clear ( ) ; isb . append ( chars [ index ] ) ; ctrlMask &= ~ ISegment . CHECK_CF_MASK ; for ( int j = index + 1 ; j < chars . length ; j ++ ) { if ( NumericUtil . isCNNumeric ( chars [ j ] ) == - 1 ) { if ( j + 2 < chars . length && chars [ j ] == '分' && chars [ j + 1 ] == '之' && NumericUtil . isCNNumeric ( chars [ j + 2 ] ) != - 1 ) { isb . append ( chars [ j ++ ] ) ; isb . append ( chars [ j ++ ] ) ; isb . append ( chars [ j ] ) ; ctrlMask |= ISegment . CHECK_CF_MASK ; continue ; } else { break ; } } isb . append ( chars [ j ] ) ; } return isb . toString ( ) ; } | find the Chinese number from the current position count until the char in the specified position is not a other number or whitespace |
32,798 | 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 < chars . length ) { String sstr = String . valueOf ( chars [ cjkidx ] ) ; if ( dic . match ( ILexicon . CJK_WORD , sstr ) ) { IWord sWord = dic . get ( ILexicon . CJK_WORD , sstr ) . clone ( ) ; sWord . setPosition ( pos + cjkidx ) ; mList . add ( sWord ) ; } mnum = 0 ; isb . clear ( ) . append ( chars [ cjkidx ] ) ; for ( int j = 1 ; j < config . MAX_LENGTH && ( cjkidx + j ) < chars . length ; j ++ ) { isb . append ( chars [ cjkidx + j ] ) ; key = isb . toString ( ) ; if ( dic . match ( ILexicon . CJK_WORD , key ) ) { mnum = 1 ; ignidx = Math . max ( ignidx , cjkidx + j ) ; word = dic . get ( ILexicon . CJK_WORD , key ) . clone ( ) ; word . setPosition ( pos + cjkidx ) ; mList . add ( word ) ; } } if ( mnum == 0 && ( cjkidx == 0 || cjkidx > ignidx ) ) { String temp = String . valueOf ( chars [ cjkidx ] ) ; if ( ! dic . match ( ILexicon . CJK_WORD , temp ) ) { word = new Word ( temp , ILexicon . UNMATCH_CJK_WORD ) ; word . setPosition ( pos + cjkidx ) ; mList . add ( word ) ; } } cjkidx ++ ; } for ( IWord w : mList ) { key = w . getValue ( ) ; if ( config . CLEAR_STOPWORD && dic . match ( ILexicon . STOP_WORD , key ) ) { continue ; } wordPool . add ( w ) ; appendWordFeatures ( w ) ; } mList . clear ( ) ; mList = null ; return wordPool . size ( ) == 0 ? null : wordPool . remove ( ) ; } | get the next CJK word from the current position of the input stream and this function is the core part the most segmentation implements |
32,799 | 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 ) ; if ( eIdx == - 1 ) { parts . add ( requestUri . substring ( sIdx ) ) ; break ; } parts . add ( requestUri . substring ( sIdx , eIdx ) ) ; i = eIdx + 1 ; } if ( requestUri . charAt ( requestUri . length ( ) - 1 ) == '/' ) { parts . add ( "" ) ; } int length = parts . size ( ) ; if ( length > 1 ) { IStringBuffer sb = new IStringBuffer ( ) ; for ( int i = 0 ; i < length - 1 ; i ++ ) { int l = sb . length ( ) ; sb . append ( parts . get ( i ) ) ; char chr = sb . charAt ( l ) ; if ( chr >= 90 ) { chr -= 32 ; sb . set ( l , chr ) ; } } controller = sb . toString ( ) ; } method = parts . get ( length - 1 ) ; } } | do the request uri process |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.