1 package org.apache.lucene.search.highlight; 2 import org.apache.lucene.analysis.Token; 3 4 8 public class TokenGroup 9 { 10 11 private static final int MAX_NUM_TOKENS_PER_GROUP=50; 12 Token [] tokens=new Token[MAX_NUM_TOKENS_PER_GROUP]; 13 float [] scores=new float[MAX_NUM_TOKENS_PER_GROUP]; 14 int numTokens=0; 15 int startOffset=0; 16 int endOffset=0; 17 18 19 void addToken(Token token, float score) 20 { 21 if(numTokens==0) 22 { 23 startOffset=token.startOffset(); 24 endOffset=token.endOffset(); 25 } 26 else 27 { 28 startOffset=Math.min(startOffset,token.startOffset()); 29 endOffset=Math.max(endOffset,token.endOffset()); 30 } 31 tokens[numTokens]=token; 32 scores[numTokens]=score; 33 numTokens++; 34 } 35 36 boolean isDistinct(Token token) 37 { 38 return token.startOffset()>endOffset; 39 } 40 41 42 void clear() 43 { 44 numTokens=0; 45 } 46 47 52 public Token getToken(int index) 53 { 54 return tokens[index]; 55 } 56 57 62 public float getScore(int index) 63 { 64 return scores[index]; 65 } 66 67 71 public int getEndOffset() 72 { 73 return endOffset; 74 } 75 76 80 public int getNumTokens() 81 { 82 return numTokens; 83 } 84 85 89 public int getStartOffset() 90 { 91 return startOffset; 92 } 93 94 97 public float getTotalScore() 98 { 99 float total=0; 100 for (int i = 0; i < numTokens; i++) 101 { 102 total+=scores[i]; 103 } 104 return total; 105 } 106 107 } 108 | Popular Tags |