Home » lucene-3.0.1-src » org.apache.lucene.analysis.cn.smart.hhmm » [javadoc | source]

    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    * <p><font color="#FF0000">
   27    * WARNING: The status of the analyzers/smartcn <b>analysis.cn.smart</b> package is experimental. 
   28    * The APIs and file formats introduced here might change in the future and will not be 
   29    * supported anymore in such a case.</font>
   30    * </p>
   31    */
   32   public class SegToken {
   33     /**
   34      * Character array containing token text
   35      */
   36     public char[] charArray;
   37   
   38     /**
   39      * start offset into original sentence
   40      */
   41     public int startOffset;
   42   
   43     /**
   44      * end offset into original sentence
   45      */
   46     public int endOffset;
   47   
   48     /**
   49      * {@link WordType} of the text 
   50      */
   51     public int wordType;
   52   
   53     /**
   54      * word frequency
   55      */
   56     public int weight;
   57   
   58     /**
   59      * during segmentation, this is used to store the index of the token in the token list table
   60      */
   61     public int index;
   62   
   63     /**
   64      * Create a new SegToken from a character array.
   65      * 
   66      * @param idArray character array containing text
   67      * @param start start offset of SegToken in original sentence
   68      * @param end end offset of SegToken in original sentence
   69      * @param wordType {@link WordType} of the text
   70      * @param weight word frequency
   71      */
   72     public SegToken(char[] idArray, int start, int end, int wordType, int weight) {
   73       this.charArray = idArray;
   74       this.startOffset = start;
   75       this.endOffset = end;
   76       this.wordType = wordType;
   77       this.weight = weight;
   78     }
   79   
   80     /**
   81      * @see java.lang.Object#hashCode()
   82      */
   83     @Override
   84     public int hashCode() {
   85       final int prime = 31;
   86       int result = 1;
   87       for(int i=0;i<charArray.length;i++) {
   88         result = prime * result + charArray[i];
   89       }
   90       result = prime * result + endOffset;
   91       result = prime * result + index;
   92       result = prime * result + startOffset;
   93       result = prime * result + weight;
   94       result = prime * result + wordType;
   95       return result;
   96     }
   97   
   98     /**
   99      * @see java.lang.Object#equals(java.lang.Object)
  100      */
  101     @Override
  102     public boolean equals(Object obj) {
  103       if (this == obj)
  104         return true;
  105       if (obj == null)
  106         return false;
  107       if (getClass() != obj.getClass())
  108         return false;
  109       SegToken other = (SegToken) obj;
  110       if (!Arrays.equals(charArray, other.charArray))
  111         return false;
  112       if (endOffset != other.endOffset)
  113         return false;
  114       if (index != other.index)
  115         return false;
  116       if (startOffset != other.startOffset)
  117         return false;
  118       if (weight != other.weight)
  119         return false;
  120       if (wordType != other.wordType)
  121         return false;
  122       return true;
  123     }
  124   
  125   }

Home » lucene-3.0.1-src » org.apache.lucene.analysis.cn.smart.hhmm » [javadoc | source]