idx
int64
0
165k
question
stringlengths
73
4.15k
target
stringlengths
5
918
len_question
int64
21
890
len_target
int64
3
255
32,600
private static void injectIntoFrames ( final WebDriver driver , final String script , final ArrayList < WebElement > parents ) { final JavascriptExecutor js = ( JavascriptExecutor ) driver ; final List < WebElement > frames = driver . findElements ( By . tagName ( "iframe" ) ) ; for ( WebElement frame : frames ) { driver . switchTo ( ) . defaultContent ( ) ; if ( parents != null ) { for ( WebElement parent : parents ) { driver . switchTo ( ) . frame ( parent ) ; } } driver . switchTo ( ) . frame ( frame ) ; js . executeScript ( script ) ; ArrayList < WebElement > localParents = ( ArrayList < WebElement > ) parents . clone ( ) ; localParents . add ( frame ) ; injectIntoFrames ( driver , script , localParents ) ; } }
Recursively find frames and inject a script into them .
182
12
32,601
public static void writeResults ( final String name , final Object output ) { Writer writer = null ; try { writer = new BufferedWriter ( new OutputStreamWriter ( new FileOutputStream ( name + ".json" ) , "utf-8" ) ) ; writer . write ( output . toString ( ) ) ; } catch ( IOException ignored ) { } finally { try { writer . close ( ) ; } catch ( Exception ignored ) { } } }
Writes a raw object out to a JSON file with the specified name .
95
15
32,602
public void add ( IWord word ) { //check and extends the entity from the base word if ( word . getEntity ( ) == null ) { word . setEntity ( rootWord . getEntity ( ) ) ; } //check and extends the part of speech from the base word if ( word . getPartSpeech ( ) == null ) { word . setPartSpeech ( rootWord . getPartSpeech ( ) ) ; } word . setSyn ( this ) ; synsList . add ( word ) ; }
add a new synonyms word and the newly added word will extends the part of speech and the entity from the base word if there are not set
109
29
32,603
public static int isCNNumeric ( char c ) { Integer i = cnNumeric . get ( c ) ; if ( i == null ) return - 1 ; return i . intValue ( ) ; }
check if the given char is a Chinese numeric or not
43
11
32,604
public static boolean isCNNumericString ( String str , int sIdx , int eIdx ) { for ( int i = sIdx ; i < eIdx ; i ++ ) { if ( ! cnNumeric . containsKey ( str . charAt ( i ) ) ) { return false ; } } return true ; }
check if the specified string is a Chinese numeric string
71
10
32,605
protected void response ( int code , String data ) { /* * send the json content type and the charset */ response . setContentType ( "application/json;charset=" + config . getCharset ( ) ) ; JSONWriter json = JSONWriter . create ( ) . put ( "code" , code ) . put ( "data" , data ) ; /*IStringBuffer sb = new IStringBuffer(); sb.append("{\n"); sb.append("\"status\": ").append(status).append(",\n"); sb.append("\"errcode\": ").append(errcode).append(",\n"); sb.append("\"data\": "); if ( data.charAt(0) == '{' || data.charAt(0) == '[' ) { sb.append(data).append('\n'); } else { sb.append('"').append(data).append("\"\n"); } sb.append("}\n");*/ output . println ( json . toString ( ) ) ; output . flush ( ) ; //let the gc do its work json = null ; }
global output protocol
251
3
32,606
protected void response ( int code , List < Object > data ) { response ( code , JSONWriter . list2JsonString ( data ) ) ; }
global list output protocol
32
4
32,607
protected void response ( int code , Map < String , Object > data ) { response ( code , JSONWriter . map2JsonString ( data ) ) ; }
global map output protocol
34
4
32,608
public JSONWriter put ( String key , Object obj ) { data . put ( key , obj ) ; return this ; }
put a new mapping with a string
25
7
32,609
public JSONWriter put ( String key , Object [ ] vector ) { data . put ( key , vector2JsonString ( vector ) ) ; return this ; }
put a new mapping with a vector
34
7
32,610
@ SuppressWarnings ( "unchecked" ) public static String vector2JsonString ( Object [ ] vector ) { IStringBuffer sb = new IStringBuffer ( ) ; sb . append ( ' ' ) ; for ( Object o : vector ) { if ( o instanceof List < ? > ) { sb . append ( list2JsonString ( ( List < Object > ) o ) ) . append ( ' ' ) ; } else if ( o instanceof Object [ ] ) { sb . append ( vector2JsonString ( ( Object [ ] ) o ) ) . append ( ' ' ) ; } else if ( o instanceof Map < ? , ? > ) { sb . append ( map2JsonString ( ( Map < String , Object > ) o ) ) . append ( ' ' ) ; } else if ( ( o instanceof Boolean ) || ( o instanceof Byte ) || ( o instanceof Short ) || ( o instanceof Integer ) || ( o instanceof Long ) || ( o instanceof Float ) || ( o instanceof Double ) ) { sb . append ( o . toString ( ) ) . append ( ' ' ) ; } else { String v = o . toString ( ) ; int last = v . length ( ) - 1 ; // Avoid string like "[Error] there is a problem" treat as a array // and "{error}: there is a problem" treat as object if ( v . length ( ) > 1 && ( ( v . charAt ( 0 ) == ' ' && v . charAt ( last ) == ' ' ) || ( v . charAt ( 0 ) == ' ' && v . charAt ( last ) == ' ' ) ) ) { sb . append ( v ) . append ( ' ' ) ; } else { sb . append ( ' ' ) . append ( v ) . append ( "\"," ) ; } } } if ( sb . length ( ) > 1 ) { sb . deleteCharAt ( sb . length ( ) - 1 ) ; } sb . append ( ' ' ) ; return sb . toString ( ) ; }
vector to json string
453
4
32,611
@ SuppressWarnings ( "unchecked" ) public static String map2JsonString ( Map < String , Object > map ) { IStringBuffer sb = new IStringBuffer ( ) ; sb . append ( ' ' ) ; for ( Map . Entry < String , Object > entry : map . entrySet ( ) ) { sb . append ( ' ' ) . append ( entry . getKey ( ) . toString ( ) ) . append ( "\": " ) ; Object obj = entry . getValue ( ) ; if ( obj instanceof List < ? > ) { sb . append ( list2JsonString ( ( List < Object > ) obj ) ) . append ( ' ' ) ; } else if ( obj instanceof Object [ ] ) { sb . append ( vector2JsonString ( ( Object [ ] ) obj ) ) . append ( ' ' ) ; } else if ( obj instanceof Map < ? , ? > ) { sb . append ( map2JsonString ( ( Map < String , Object > ) obj ) ) . append ( ' ' ) ; } else if ( ( obj instanceof Boolean ) || ( obj instanceof Byte ) || ( obj instanceof Short ) || ( obj instanceof Integer ) || ( obj instanceof Long ) || ( obj instanceof Float ) || ( obj instanceof Double ) ) { sb . append ( obj . toString ( ) ) . append ( ' ' ) ; } else { String v = obj . toString ( ) ; int last = v . length ( ) - 1 ; if ( v . length ( ) > 1 && ( ( v . charAt ( 0 ) == ' ' && v . charAt ( last ) == ' ' ) || ( v . charAt ( 0 ) == ' ' && v . charAt ( last ) == ' ' ) ) ) { sb . append ( v ) . append ( ' ' ) ; } else { sb . append ( ' ' ) . append ( v ) . append ( "\"," ) ; } } } if ( sb . length ( ) > 1 ) { sb . deleteCharAt ( sb . length ( ) - 1 ) ; } sb . append ( ' ' ) ; return sb . toString ( ) ; }
map to json string
480
4
32,612
public static Object stringToValue ( String string ) { if ( "true" . equalsIgnoreCase ( string ) ) { return Boolean . TRUE ; } if ( "false" . equalsIgnoreCase ( string ) ) { return Boolean . FALSE ; } if ( "null" . equalsIgnoreCase ( string ) ) { return JSONObject . NULL ; } // If it might be a number, try converting it, first as a Long, and then as a // Double. If that doesn't work, return the string. try { char initial = string . charAt ( 0 ) ; if ( initial == ' ' || ( initial >= ' ' && initial <= ' ' ) ) { Long value = new Long ( string ) ; if ( value . toString ( ) . equals ( string ) ) { return value ; } } } catch ( Exception ignore ) { try { Double value = new Double ( string ) ; if ( value . toString ( ) . equals ( string ) ) { return value ; } } catch ( Exception ignoreAlso ) { } } return string ; }
Try to convert a string into a number boolean or null . If the string can t be converted return the string . This is much less ambitious than JSONObject . stringToValue especially because it does not attempt to convert plus forms octal forms hex forms or E forms lacking decimal points .
222
57
32,613
public boolean pad ( int width ) throws IOException { boolean result = true ; int gap = ( int ) this . nrBits % width ; if ( gap < 0 ) { gap += width ; } if ( gap != 0 ) { int padding = width - gap ; while ( padding > 0 ) { if ( bit ( ) ) { result = false ; } padding -= 1 ; } } return result ; }
Check that the rest of the block has been padded with zeroes .
86
15
32,614
public int read ( int width ) throws IOException { if ( width == 0 ) { return 0 ; } if ( width < 0 || width > 32 ) { throw new IOException ( "Bad read width." ) ; } int result = 0 ; while ( width > 0 ) { if ( this . available == 0 ) { this . unread = this . in . read ( ) ; if ( this . unread < 0 ) { throw new IOException ( "Attempt to read past end." ) ; } this . available = 8 ; } int take = width ; if ( take > this . available ) { take = this . available ; } result |= ( ( this . unread >>> ( this . available - take ) ) & ( ( 1 << take ) - 1 ) ) << ( width - take ) ; this . nrBits += take ; this . available -= take ; width -= take ; } return result ; }
Read some bits .
193
4
32,615
public int read ( char [ ] cbuf , int off , int len ) throws IOException { //check the buffer queue int size = queue . size ( ) ; if ( size > 0 ) { //TODO //int num = size <= len ? size : len; //System.arraycopy(src, srcPos, dest, destPos, length) throw new IOException ( "Method not implemented yet" ) ; } return reader . read ( cbuf , off , len ) ; }
read the specified block from the stream
103
7
32,616
public void unread ( char [ ] cbuf , int off , int len ) { for ( int i = 0 ; i < len ; i ++ ) { queue . enQueue ( cbuf [ off + i ] ) ; } }
unread a block from a char array to the stream
49
11
32,617
public void load ( File file ) throws NumberFormatException , FileNotFoundException , IOException { loadWords ( config , this , file , synBuffer ) ; }
load all the words from a specified lexicon file
34
10
32,618
public void loadDirectory ( String lexDir ) throws IOException { File path = new File ( lexDir ) ; if ( ! path . exists ( ) ) { throw new IOException ( "Lexicon directory [" + lexDir + "] does'n exists." ) ; } /* * load all the lexicon file under the lexicon path * that start with "lex-" and end with ".lex". */ File [ ] files = path . listFiles ( new FilenameFilter ( ) { @ Override public boolean accept ( File dir , String name ) { return ( name . startsWith ( "lex-" ) && name . endsWith ( ".lex" ) ) ; } } ) ; for ( File file : files ) { load ( file ) ; } }
load the all the words from all the files under a specified lexicon directory
157
15
32,619
public void loadClassPath ( ) throws IOException { Class < ? > dClass = this . getClass ( ) ; CodeSource codeSrc = this . getClass ( ) . getProtectionDomain ( ) . getCodeSource ( ) ; if ( codeSrc == null ) { return ; } String codePath = codeSrc . getLocation ( ) . getPath ( ) ; if ( codePath . toLowerCase ( ) . endsWith ( ".jar" ) ) { ZipInputStream zip = new ZipInputStream ( codeSrc . getLocation ( ) . openStream ( ) ) ; while ( true ) { ZipEntry e = zip . getNextEntry ( ) ; if ( e == null ) { break ; } String fileName = e . getName ( ) ; if ( fileName . endsWith ( ".lex" ) && fileName . startsWith ( "lexicon/lex-" ) ) { load ( dClass . getResourceAsStream ( "/" + fileName ) ) ; } } } else { //now, the classpath is an IDE directory // like eclipse ./bin or maven ./target/classes/ loadDirectory ( codePath + "/lexicon" ) ; } }
load all the words from all the files under the specified class path .
252
14
32,620
public void startAutoload ( ) { if ( autoloadThread != null || config . getLexiconPath ( ) == null ) { return ; } //create and start the lexicon auto load thread autoloadThread = new Thread ( new Runnable ( ) { @ Override public void run ( ) { String [ ] paths = config . getLexiconPath ( ) ; AutoLoadFile [ ] files = new AutoLoadFile [ paths . length ] ; for ( int i = 0 ; i < files . length ; i ++ ) { files [ i ] = new AutoLoadFile ( paths [ i ] + "/" + AL_TODO_FILE ) ; files [ i ] . setLastUpdateTime ( files [ i ] . getFile ( ) . lastModified ( ) ) ; } while ( true ) { //sleep for some time (seconds) try { Thread . sleep ( config . getPollTime ( ) * 1000 ) ; } catch ( InterruptedException e ) { break ; } //check the update of all the reload todo files File f = null ; AutoLoadFile af = null ; for ( int i = 0 ; i < files . length ; i ++ ) { af = files [ i ] ; f = files [ i ] . getFile ( ) ; if ( ! f . exists ( ) ) continue ; if ( f . lastModified ( ) <= af . getLastUpdateTime ( ) ) { continue ; } //load words form the lexicon files try { BufferedReader reader = new BufferedReader ( new FileReader ( f ) ) ; String line = null ; while ( ( line = reader . readLine ( ) ) != null ) { line = line . trim ( ) ; if ( line . indexOf ( ' ' ) != - 1 ) continue ; if ( "" . equals ( line ) ) continue ; load ( paths [ i ] + "/" + line ) ; } reader . close ( ) ; FileWriter fw = new FileWriter ( f ) ; fw . write ( "" ) ; fw . close ( ) ; //update the last update time //@Note: some file system may close the in-time last update time update // in that case, this won't work normally. //but, it will still work!!! af . setLastUpdateTime ( f . lastModified ( ) ) ; //System.out.println("newly added words loaded for path " + f.getParent()); } catch ( IOException e ) { break ; } } //flush the synonyms buffer resetSynonymsNet ( ) ; } } } ) ; autoloadThread . setDaemon ( true ) ; autoloadThread . start ( ) ; }
start the lexicon autoload thread
567
8
32,621
public static int getIndex ( String key ) { if ( key == null ) { return - 1 ; } key = key . toUpperCase ( ) ; if ( key . startsWith ( "CJK_WORD" ) ) { return ILexicon . CJK_WORD ; } else if ( key . startsWith ( "CJK_CHAR" ) ) { return ILexicon . CJK_CHAR ; } else if ( key . startsWith ( "CJK_UNIT" ) ) { return ILexicon . CJK_UNIT ; } else if ( key . startsWith ( "CN_LNAME_ADORN" ) ) { return ILexicon . CN_LNAME_ADORN ; } else if ( key . startsWith ( "CN_LNAME" ) ) { return ILexicon . CN_LNAME ; } else if ( key . startsWith ( "CN_SNAME" ) ) { return ILexicon . CN_SNAME ; } else if ( key . startsWith ( "CN_DNAME_1" ) ) { return ILexicon . CN_DNAME_1 ; } else if ( key . startsWith ( "CN_DNAME_2" ) ) { return ILexicon . CN_DNAME_2 ; } else if ( key . startsWith ( "STOP_WORD" ) ) { return ILexicon . STOP_WORD ; } else if ( key . startsWith ( "DOMAIN_SUFFIX" ) ) { return ILexicon . DOMAIN_SUFFIX ; } else if ( key . startsWith ( "NUMBER_UNIT" ) ) { return ILexicon . NUMBER_UNIT ; } else if ( key . startsWith ( "CJK_SYN" ) ) { return ILexicon . CJK_SYN ; } return ILexicon . CJK_WORD ; }
get the key s type index located in ILexicon interface
411
12
32,622
public static void loadWords ( JcsegTaskConfig config , ADictionary dic , File file , List < String [ ] > buffer ) throws NumberFormatException , FileNotFoundException , IOException { loadWords ( config , dic , new FileInputStream ( file ) , buffer ) ; }
load all the words in the specified lexicon file into the dictionary
63
13
32,623
public final static void appendSynonyms ( LinkedList < IWord > wordPool , IWord wd ) { List < IWord > synList = wd . getSyn ( ) . getList ( ) ; synchronized ( synList ) { for ( int j = 0 ; j < synList . size ( ) ; j ++ ) { IWord curWord = synList . get ( j ) ; if ( curWord . getValue ( ) . equals ( wd . getValue ( ) ) ) { continue ; } IWord synWord = synList . get ( j ) . clone ( ) ; synWord . setPosition ( wd . getPosition ( ) ) ; wordPool . add ( synWord ) ; } } }
quick interface to do the synonyms append word You got check if the specified has any synonyms first
153
20
32,624
public T get ( E key ) { Entry < E , T > entry = null ; synchronized ( this ) { entry = map . get ( key ) ; if ( map . get ( key ) == null ) return null ; entry . prev . next = entry . next ; entry . next . prev = entry . prev ; entry . prev = this . head ; entry . next = this . head . next ; this . head . next . prev = entry ; this . head . next = entry ; } return entry . value ; }
get a element from map with specified key
109
8
32,625
public void set ( E key , T value ) { Entry < E , T > entry = new Entry < E , T > ( key , value , null , null ) ; synchronized ( this ) { if ( map . get ( key ) == null ) { if ( this . length >= this . capacity ) this . removeLeastUsedElements ( ) ; entry . prev = this . head ; entry . next = this . head . next ; this . head . next . prev = entry ; this . head . next = entry ; this . length ++ ; map . put ( key , entry ) ; } else { entry = map . get ( key ) ; entry . value = value ; entry . prev . next = entry . next ; entry . next . prev = entry . prev ; entry . prev = this . head ; entry . next = this . head . next ; this . head . next . prev = entry ; this . head . next = entry ; } } }
set a element to list
201
5
32,626
public synchronized void remove ( E key ) { Entry < E , T > entry = map . get ( key ) ; this . tail . prev = entry . prev ; entry . prev . next = this . tail ; map . remove ( entry . key ) ; this . length -- ; }
remove a element from list
59
5
32,627
public synchronized void removeLeastUsedElements ( ) { int rows = this . removePercent / 100 * this . length ; rows = rows == 0 ? 1 : rows ; while ( rows > 0 && this . length > 0 ) { // remove the last element Entry < E , T > entry = this . tail . prev ; this . tail . prev = entry . prev ; entry . prev . next = this . tail ; map . remove ( entry . key ) ; this . length -- ; rows -- ; } }
remove least used elements
107
4
32,628
public synchronized void printList ( ) { Entry < E , T > entry = this . head . next ; System . out . println ( "\n|----- key list----|" ) ; while ( entry != this . tail ) { System . out . println ( " -> " + entry . key ) ; entry = entry . next ; } System . out . println ( "|------- end --------|\n" ) ; }
print the list
88
3
32,629
public void write ( int bits , int width ) throws IOException { if ( bits == 0 && width == 0 ) { return ; } if ( width <= 0 || width > 32 ) { throw new IOException ( "Bad write width." ) ; } while ( width > 0 ) { int actual = width ; if ( actual > this . vacant ) { actual = this . vacant ; } this . unwritten |= ( ( bits >>> ( width - actual ) ) & ( ( 1 << actual ) - 1 ) ) << ( this . vacant - actual ) ; width -= actual ; nrBits += actual ; this . vacant -= actual ; if ( this . vacant == 0 ) { this . out . write ( this . unwritten ) ; this . unwritten = 0 ; this . vacant = 8 ; } } }
Write some bits . Up to 32 bits can be written at a time .
170
15
32,630
public String __toString ( ) { StringBuilder sb = new StringBuilder ( ) ; sb . append ( value ) ; sb . append ( ' ' ) ; //append the cx if ( partspeech != null ) { for ( int j = 0 ; j < partspeech . length ; j ++ ) { if ( j == 0 ) { sb . append ( partspeech [ j ] ) ; } else { sb . append ( ' ' ) ; sb . append ( partspeech [ j ] ) ; } } } else { sb . append ( "null" ) ; } sb . append ( ' ' ) ; sb . append ( pinyin ) ; sb . append ( ' ' ) ; if ( syn != null ) { List < IWord > synsList = syn . getList ( ) ; synchronized ( synsList ) { for ( int i = 0 ; i < synsList . size ( ) ; i ++ ) { if ( i == 0 ) { sb . append ( synsList . get ( i ) ) ; } else { sb . append ( ' ' ) ; sb . append ( synsList . get ( i ) ) ; } } } } else { sb . append ( "null" ) ; } if ( value . length ( ) == 1 ) { sb . append ( ' ' ) ; sb . append ( fre ) ; } if ( entity != null ) { sb . append ( ' ' ) ; sb . append ( ArrayUtil . implode ( "|" , entity ) ) ; } if ( parameter != null ) { sb . append ( ' ' ) ; sb . append ( parameter ) ; } return sb . toString ( ) ; }
for debug only
375
3
32,631
public static < T extends Comparable < ? super T > > void insertionSort ( T [ ] arr ) { int j ; for ( int i = 1 ; i < arr . length ; i ++ ) { T tmp = arr [ i ] ; for ( j = i ; j > 0 && tmp . compareTo ( arr [ j - 1 ] ) < 0 ; j -- ) { arr [ j ] = arr [ j - 1 ] ; } if ( j < i ) arr [ j ] = tmp ; } }
insert sort method
108
3
32,632
public static < T extends Comparable < ? super T > > void shellSort ( T [ ] arr ) { int j , k = 0 , gap ; for ( ; GAPS [ k ] < arr . length ; k ++ ) ; while ( k -- > 0 ) { gap = GAPS [ k ] ; for ( int i = gap ; i < arr . length ; i ++ ) { T tmp = arr [ i ] ; for ( j = i ; j >= gap && tmp . compareTo ( arr [ j - gap ] ) < 0 ; j -= gap ) { arr [ j ] = arr [ j - gap ] ; } if ( j < i ) arr [ j ] = tmp ; } } }
shell sort algorithm
149
3
32,633
@ SuppressWarnings ( "unchecked" ) public static < T extends Comparable < ? super T > > void mergeSort ( T [ ] arr ) { /*if ( arr.length < 15 ) { insertionSort( arr ); return; }*/ T [ ] tmpArr = ( T [ ] ) new Comparable [ arr . length ] ; mergeSort ( arr , tmpArr , 0 , arr . length - 1 ) ; }
merge sort algorithm
94
4
32,634
private static < T extends Comparable < ? super T > > void mergeSort ( T [ ] arr , T [ ] tmpArr , int left , int right ) { //recursive way if ( left < right ) { int center = ( left + right ) / 2 ; mergeSort ( arr , tmpArr , left , center ) ; mergeSort ( arr , tmpArr , center + 1 , right ) ; merge ( arr , tmpArr , left , center + 1 , right ) ; } //loop instead /* int len = 2, pos; int rpos, offset, cut; while ( len <= right ) { pos = 0; offset = len / 2; while ( pos + len <= right ) { rpos = pos + offset; merge( arr, tmpArr, pos, rpos, rpos + offset - 1 ); pos += len; } //merge the rest cut = pos + offset; if ( cut <= right ) merge( arr, tmpArr, pos, cut, right ); len *= 2; } merge( arr, tmpArr, 0, len / 2, right );*/ }
internal method to make a recursive call
238
7
32,635
private static < T extends Comparable < ? super T > > void merge ( T [ ] arr , T [ ] tmpArr , int lPos , int rPos , int rEnd ) { int lEnd = rPos - 1 ; int tPos = lPos ; int leftTmp = lPos ; while ( lPos <= lEnd && rPos <= rEnd ) { if ( arr [ lPos ] . compareTo ( arr [ rPos ] ) <= 0 ) { tmpArr [ tPos ++ ] = arr [ lPos ++ ] ; } else { tmpArr [ tPos ++ ] = arr [ rPos ++ ] ; } } //copy the rest element of the left half subarray. while ( lPos <= lEnd ) { tmpArr [ tPos ++ ] = arr [ lPos ++ ] ; } //copy the rest elements of the right half subarray. (only one loop will be execute) while ( rPos <= rEnd ) { tmpArr [ tPos ++ ] = arr [ rPos ++ ] ; } //copy the tmpArr back cause we need to change the arr array items. for ( ; rEnd >= leftTmp ; rEnd -- ) { arr [ rEnd ] = tmpArr [ rEnd ] ; } }
internal method to merge the sorted halves of a subarray
270
11
32,636
private static < T > void swapReferences ( T [ ] arr , int idx1 , int idx2 ) { T tmp = arr [ idx1 ] ; arr [ idx1 ] = arr [ idx2 ] ; arr [ idx2 ] = tmp ; }
method to swap elements in an array
59
7
32,637
public static < T extends Comparable < ? super T > > void quicksort ( T [ ] arr ) { quicksort ( arr , 0 , arr . length - 1 ) ; }
quick sort algorithm
40
3
32,638
public static < T extends Comparable < ? super T > > void insertionSort ( T [ ] arr , int start , int end ) { int i ; for ( int j = start + 1 ; j <= end ; j ++ ) { T tmp = arr [ j ] ; for ( i = j ; i > start && tmp . compareTo ( arr [ i - 1 ] ) < 0 ; i -- ) { arr [ i ] = arr [ i - 1 ] ; } if ( i < j ) arr [ i ] = tmp ; } }
method to sort an subarray from start to end with insertion sort algorithm
114
14
32,639
private static < T extends Comparable < ? super T > > void quicksort ( T [ ] arr , int left , int right ) { if ( left + CUTOFF <= right ) { //find the pivot T pivot = median ( arr , left , right ) ; //start partitioning int i = left , j = right - 1 ; for ( ; ; ) { while ( arr [ ++ i ] . compareTo ( pivot ) < 0 ) ; while ( arr [ -- j ] . compareTo ( pivot ) > 0 ) ; if ( i < j ) { swapReferences ( arr , i , j ) ; } else { break ; } } //swap the pivot reference back to the small collection. swapReferences ( arr , i , right - 1 ) ; quicksort ( arr , left , i - 1 ) ; //sort the small collection. quicksort ( arr , i + 1 , right ) ; //sort the large collection. } else { //if the total number is less than CUTOFF we use insertion sort instead. insertionSort ( arr , left , right ) ; } }
internal method to sort the array with quick sort algorithm
230
10
32,640
public static < T extends Comparable < ? super T > > void quickSelect ( T [ ] arr , int k ) { quickSelect ( arr , 0 , arr . length - 1 , k ) ; }
quick select algorithm
43
3
32,641
public static void bucketSort ( int [ ] arr , int m ) { int [ ] count = new int [ m ] ; int j , i = 0 ; //System.out.println(count[0]==0?"true":"false"); for ( j = 0 ; j < arr . length ; j ++ ) { count [ arr [ j ] ] ++ ; } //loop and filter the elements for ( j = 0 ; j < m ; j ++ ) { if ( count [ j ] > 0 ) { while ( count [ j ] -- > 0 ) { arr [ i ++ ] = j ; } } } }
bucket sort algorithm
130
4
32,642
public static String getJarHome ( Object o ) { String path = o . getClass ( ) . getProtectionDomain ( ) . getCodeSource ( ) . getLocation ( ) . getFile ( ) ; File jarFile = new File ( path ) ; return jarFile . getParentFile ( ) . getAbsolutePath ( ) ; }
get the absolute parent path for the jar file .
72
10
32,643
public static void printMatrix ( double [ ] [ ] matrix ) { StringBuffer sb = new StringBuffer ( ) ; sb . append ( ' ' ) . append ( ' ' ) ; for ( double [ ] line : matrix ) { for ( double column : line ) { sb . append ( column ) . append ( ", " ) ; } sb . append ( ' ' ) ; } sb . append ( ' ' ) ; System . out . println ( sb . toString ( ) ) ; }
print the specified matrix
108
4
32,644
public void resetFromFile ( String configFile ) throws IOException { IStringBuffer isb = new IStringBuffer ( ) ; String line = null ; BufferedReader reader = new BufferedReader ( new FileReader ( configFile ) ) ; while ( ( line = reader . readLine ( ) ) != null ) { line = line . trim ( ) ; if ( line . equals ( "" ) ) continue ; if ( line . charAt ( 0 ) == ' ' ) continue ; isb . append ( line ) . append ( ' ' ) ; line = null ; //let gc do its work } globalConfig = new JSONObject ( isb . toString ( ) ) ; //let gc do its work isb = null ; reader . close ( ) ; reader = null ; }
initialize it from the specified config file
166
8
32,645
public boolean enQueue ( int data ) { Entry o = new Entry ( data , head . next ) ; head . next = o ; size ++ ; return true ; }
add a new item to the queue
35
7
32,646
public static ADictionary createDictionary ( Class < ? extends ADictionary > _class , Class < ? > [ ] paramType , Object [ ] args ) { try { Constructor < ? > cons = _class . getConstructor ( paramType ) ; return ( ( ADictionary ) cons . newInstance ( args ) ) ; } catch ( Exception e ) { System . err . println ( "can't create the ADictionary instance " + "with classpath [" + _class . getName ( ) + "]" ) ; e . printStackTrace ( ) ; } return null ; }
create a new ADictionary instance
123
6
32,647
public static ADictionary createDefaultDictionary ( JcsegTaskConfig config , boolean loadDic ) { return createDefaultDictionary ( config , config . isAutoload ( ) , loadDic ) ; }
create the ADictionary according to the JcsegTaskConfig
46
13
32,648
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
66
16
32,649
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 .
119
13
32,650
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
137
10
32,651
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
347
9
32,652
private void init ( ) { //setup thread pool QueuedThreadPool threadPool = new QueuedThreadPool ( ) ; threadPool . setMaxThreads ( config . getMaxThreadPoolSize ( ) ) ; threadPool . setIdleTimeout ( config . getThreadIdleTimeout ( ) ) ; server = new Server ( threadPool ) ; //setup the http configuration 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 ) ; //setup the connector 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
251
10
32,653
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 ) ; /* * the rest of path and dynamic rest checking will handler it */ //router.addMapping("/tokenizer/default", TokenizerController.class); /* * prepare standard handler */ StandardHandler stdHandler = new StandardHandler ( config , resourcePool , router ) ; /* * prepare the resource handler */ JcsegResourceHandler resourceHandler = new JcsegResourceHandler ( ) ; /* * i am going to rewrite the path to handler mapping mechanism * check the Router handler for more info */ 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
330
3
32,654
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
592
12
32,655
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 .
146
40
32,656
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 .
41
19
32,657
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 .
138
29
32,658
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 ( ) ; } //get the items that the word length equals to //the max's length. 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
225
18
32,659
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 ( ) > largetAverage ) { largetAverage = chunks [ j ] . getAverageWordsLength ( ) ; } } //get the items that the average word length equals to //the max's. 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
244
19
32,660
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 ( ) < smallestVariance ) { smallestVariance = chunks [ j ] . getWordsVariance ( ) ; } } //get the items that the variance word length equals to //the max's. 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
244
17
32,661
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 ] . getSingleWordsMorphemicFreedom ( ) > largestFreedom ) { largestFreedom = chunks [ j ] . getSingleWordsMorphemicFreedom ( ) ; } } //get the items that the word length equals to //the max's length. 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
263
37
32,662
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
90
6
32,663
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
67
9
32,664
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
68
12
32,665
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
68
12
32,666
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
66
11
32,667
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
134
11
32,668
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
76
4
32,669
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
134
4
32,670
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.jcseg.util.Util.printMatrix(relevance); 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 ; } //do the textrank score iteration 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 ; /* * ws(vj) * wji / sigma(wjk) with k in Out(Vj) * ws(vj): score[j] the score of document[j] * wji: relevance score bettween document[j] and document[i] * sigema(wjk): weight sum for document[j] */ sigema += relevance [ j ] [ i ] / weight_sum [ j ] * score [ j ] ; } score [ i ] = 1 - D + D * sigema ; } } //build the document set //and sort the documents by scores 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 ) ; //let gc do its works relevance = null ; score = null ; weight_sum = null ; return docs ; }
get the documents order by relevance score .
471
8
32,671
public static final IWord [ ] createDateTimePool ( ) { return new IWord [ ] { null , //year null , //month null , //day null , //timing method null , //hour null , //minute null , //seconds } ; }
create and return a date - time pool
54
8
32,672
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 .
104
15
32,673
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
51
12
32,674
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
65
12
32,675
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 global idx value. */ 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 .
175
12
32,676
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 ; }
append a int from the tail
49
6
32,677
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 ; }
append a item from the tail
72
6
32,678
public String getSummaryFromString ( String doc , int length ) throws IOException { return getSummary ( new StringReader ( doc ) , length ) ; }
get document summary from a string
32
6
32,679
public String getSummaryFromFile ( String file , int length ) throws IOException { return getSummary ( new FileReader ( file ) , length ) ; }
get document summary from a file
32
6
32,680
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
190
11
32,681
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 ; } //check the path part 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
526
11
32,682
public static final boolean isMobileNumber ( String str ) { if ( str . length ( ) != 11 ) { return false ; } if ( str . charAt ( 0 ) != ' ' ) { 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
93
9
32,683
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 ; return false ; }
check the specified char is CJK Thai ... char true will be return if it is or return false
70
20
32,684
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
57
10
32,685
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 ) { 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
91
26
32,686
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 ++ ) { c = str . charAt ( j ) ; if ( c == ' ' ) { p ++ ; } else { //make full-width half-width 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
153
13
32,687
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
61
9
32,688
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
65
10
32,689
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
89
10
32,690
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
72
8
32,691
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
74
8
32,692
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
60
12
32,693
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
62
13
32,694
public static String hwsTofws ( String str ) { char [ ] chars = str . toCharArray ( ) ; for ( int j = 0 ; j < chars . length ; j ++ ) { if ( chars [ j ] == ' ' ) { chars [ j ] = ' ' ; } else if ( chars [ j ] < ' ' ) { 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
103
20
32,695
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 .
41
11
32,696
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 .
59
14
32,697
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 .
92
14
32,698
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 .
63
27
32,699
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 = 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 .
283
5