add --shared
[pylucene.git] / lucene-java-3.4.0 / lucene / contrib / analyzers / smartcn / src / java / org / apache / lucene / analysis / cn / smart / hhmm / SegToken.java
1 /**
2  * Licensed to the Apache Software Foundation (ASF) under one or more
3  * contributor license agreements.  See the NOTICE file distributed with
4  * this work for additional information regarding copyright ownership.
5  * The ASF licenses this file to You under the Apache License, Version 2.0
6  * (the "License"); you may not use this file except in compliance with
7  * the License.  You may obtain a copy of the License at
8  *
9  *     http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */
17
18 package org.apache.lucene.analysis.cn.smart.hhmm;
19
20 import java.util.Arrays;
21
22 import org.apache.lucene.analysis.cn.smart.WordType; // for javadocs
23
24 /**
25  * SmartChineseAnalyzer internal token
26  * @lucene.experimental
27  */
28 public class SegToken {
29   /**
30    * Character array containing token text
31    */
32   public char[] charArray;
33
34   /**
35    * start offset into original sentence
36    */
37   public int startOffset;
38
39   /**
40    * end offset into original sentence
41    */
42   public int endOffset;
43
44   /**
45    * {@link WordType} of the text 
46    */
47   public int wordType;
48
49   /**
50    * word frequency
51    */
52   public int weight;
53
54   /**
55    * during segmentation, this is used to store the index of the token in the token list table
56    */
57   public int index;
58
59   /**
60    * Create a new SegToken from a character array.
61    * 
62    * @param idArray character array containing text
63    * @param start start offset of SegToken in original sentence
64    * @param end end offset of SegToken in original sentence
65    * @param wordType {@link WordType} of the text
66    * @param weight word frequency
67    */
68   public SegToken(char[] idArray, int start, int end, int wordType, int weight) {
69     this.charArray = idArray;
70     this.startOffset = start;
71     this.endOffset = end;
72     this.wordType = wordType;
73     this.weight = weight;
74   }
75
76   /**
77    * @see java.lang.Object#hashCode()
78    */
79   @Override
80   public int hashCode() {
81     final int prime = 31;
82     int result = 1;
83     for(int i=0;i<charArray.length;i++) {
84       result = prime * result + charArray[i];
85     }
86     result = prime * result + endOffset;
87     result = prime * result + index;
88     result = prime * result + startOffset;
89     result = prime * result + weight;
90     result = prime * result + wordType;
91     return result;
92   }
93
94   /**
95    * @see java.lang.Object#equals(java.lang.Object)
96    */
97   @Override
98   public boolean equals(Object obj) {
99     if (this == obj)
100       return true;
101     if (obj == null)
102       return false;
103     if (getClass() != obj.getClass())
104       return false;
105     SegToken other = (SegToken) obj;
106     if (!Arrays.equals(charArray, other.charArray))
107       return false;
108     if (endOffset != other.endOffset)
109       return false;
110     if (index != other.index)
111       return false;
112     if (startOffset != other.startOffset)
113       return false;
114     if (weight != other.weight)
115       return false;
116     if (wordType != other.wordType)
117       return false;
118     return true;
119   }
120
121 }