KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > lucene > index > SegmentTermPositionVector


1 package org.apache.lucene.index;
2
3 /**
4  * Copyright 2004 The Apache Software Foundation
5  *
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  */

18
19 public class SegmentTermPositionVector extends SegmentTermVector implements TermPositionVector {
20   protected int[][] positions;
21   protected TermVectorOffsetInfo[][] offsets;
22   public static final int[] EMPTY_TERM_POS = new int[0];
23   
24   public SegmentTermPositionVector(String JavaDoc field, String JavaDoc terms[], int termFreqs[], int[][] positions, TermVectorOffsetInfo[][] offsets) {
25     super(field, terms, termFreqs);
26     this.offsets = offsets;
27     this.positions = positions;
28   }
29
30   /**
31    * Returns an array of TermVectorOffsetInfo in which the term is found.
32    *
33    * @param index The position in the array to get the offsets from
34    * @return An array of TermVectorOffsetInfo objects or the empty list
35    * @see org.apache.lucene.analysis.Token
36    */

37   public TermVectorOffsetInfo[] getOffsets(int index) {
38     TermVectorOffsetInfo[] result = TermVectorOffsetInfo.EMPTY_OFFSET_INFO;
39     if(offsets == null)
40       return null;
41     if (index >=0 && index < offsets.length)
42     {
43       result = offsets[index];
44     }
45     return result;
46   }
47   
48   /**
49    * Returns an array of positions in which the term is found.
50    * Terms are identified by the index at which its number appears in the
51    * term String array obtained from the <code>indexOf</code> method.
52    */

53   public int[] getTermPositions(int index) {
54     int[] result = EMPTY_TERM_POS;
55     if(positions == null)
56       return null;
57     if (index >=0 && index < positions.length)
58     {
59       result = positions[index];
60     }
61     
62     return result;
63   }
64 }
Popular Tags