freepeople性欧美熟妇, 色戒完整版无删减158分钟hd, 无码精品国产vα在线观看DVD, 丰满少妇伦精品无码专区在线观看,艾栗栗与纹身男宾馆3p50分钟,国产AV片在线观看,黑人与美女高潮,18岁女RAPPERDISSSUBS,国产手机在机看影片

正文內(nèi)容

[計(jì)算機(jī)]lucene代碼分析(編輯修改稿)

2024-09-13 04:26 本頁(yè)面
 

【文章內(nèi)容簡(jiǎn)介】 break。 else return null。 } else c = ioBuffer[bufferIndex++]。 if (isTokenChar(c)) { // if it39。s a token char if (length == 0) // start of token start = offset 1。 buffer[length++] = normalize(c)。 // buffer it, normalized if (length == MAX_WORD_LEN) // buffer overflow! break。 } else if (length 0) // at nonLetter w/ chars break。 // return 39。em } return new Token(new String(buffer, 0, length), start, start + length)。} 看起來(lái)很長(zhǎng),其實(shí)很簡(jiǎn)單,至少讀起來(lái)很簡(jiǎn)單,其中isTokenChar就是我們剛才在LetterTokenizer中看到的,代碼中用start記錄一個(gè)token的起始位置,用length記錄它的長(zhǎng)度,如果不是字符的話,就break。,我們看到一個(gè)新的類Token,這里它的構(gòu)造參數(shù)有字符串,起始位置,結(jié)束位置。 看一下Token的源代碼:String termText。 // the text of the termint startOffset。 // start in source textint endOffset。 // end in source textString type = word。 // lexical typeprivate int positionIncrement = 1。/** Constructs a Token with the given term text, and start amp。 end offsets. The type defaults to word. */public Token(String text, int start, int end) { termText = text。 startOffset = start。 endOffset = end。}/** Constructs a Token with the given text, start and end offsets, amp。 type. */public Token(String text, int start, int end, String typ) { termText = text。 startOffset = start。 endOffset = end。 type = typ。} 和我們剛才用到的構(gòu)造函數(shù)對(duì)應(yīng)一下,就知道三個(gè)成員變量的意思了,type和positionIncrement我還是引用一下別的人話,Type主要用來(lái)表示文本編碼和語(yǔ)言類型,single表示單個(gè)ASCII字符,double表示nonASCII字符,Word是默認(rèn)的不區(qū)分的字符類型。而positionIncrement表示位置增量,用于處理拼音之類的情況(拼音就在那個(gè)詞的上方)。3. Lucene源代碼分析[3]關(guān)于TokenFilter我們先看一個(gè)最簡(jiǎn)單的LowerCaseFilter,它的next函數(shù)如下:public final Token next() throws IOException { Token t = ()。 if (t == null) return null。 = ()。 return t。} 沒什么意思,就是把Token對(duì)象中的字符串換成了小寫,你想看有意思的可以看PortStemFilter,劍橋大學(xué)出的那本Introduction to information retrieval中也提到過這種方法,34頁(yè)。 再看一個(gè)稍有一點(diǎn)意義的TokenFilter,StopFilter,我們看一下public static final Set makeStopSet(String[] stopWords) { return makeStopSet(stopWords, false)。}public static final Set makeStopSet(String[] stopWords, boolean ignoreCase) { HashSet stopTable = new HashSet()。 for (int i = 0。 i 。 i++) (ignoreCase ? stopWords[i].toLowerCase() : stopWords[i])。 return stopTable。}public final Token next() throws IOException { // return the first nonstop word found for (Token token = ()。 token != null。 token = ()) { String termText = ignoreCase ? () : 。 if (!(termText)) return token。 } // reached EOS return null return null。} makeStopSet是把所有要過濾的詞加到stopTable中去(不清楚為什么不用HashSet呢),在next函數(shù)中,它過濾掉stopTable有的字符串。 再來(lái)看一個(gè)簡(jiǎn)單的Analyzer,StopAnalyzer的next函數(shù):public TokenStream tokenStream(String fieldName, Reader reader) { return new StopFilter(new LowerCaseTokenizer(reader), stopWords)。} 記得這句話嗎?Lucene中一個(gè)Analyzer通常由Tokenizer和TokenFilter組成,這里就是這句話的證據(jù),我們先對(duì)reader傳進(jìn)來(lái)的字符串進(jìn)行分詞,再對(duì)它進(jìn)行過濾。而其中的tokenStream當(dāng)然就是我們?cè)诜衷~時(shí)要調(diào)用的那個(gè)函數(shù)了。4. Lucene源代碼分析[4] 寫一個(gè)略有一點(diǎn)意義的例子,我
點(diǎn)擊復(fù)制文檔內(nèi)容
環(huán)評(píng)公示相關(guān)推薦
文庫(kù)吧 www.dybbs8.com
備案圖片鄂ICP備17016276號(hào)-1