pylucene 3.5.0-3
[pylucene.git] / lucene-java-3.5.0 / lucene / contrib / analyzers / common / src / java / org / apache / lucene / analysis / hunspell / HunspellAffix.java
1 package org.apache.lucene.analysis.hunspell;
2
3 /**
4  * Licensed to the Apache Software Foundation (ASF) under one or more
5  * contributor license agreements.  See the NOTICE file distributed with
6  * this work for additional information regarding copyright ownership.
7  * The ASF licenses this file to You under the Apache License, Version 2.0
8  * (the "License"); you may not use this file except in compliance with
9  * the License.  You may obtain a copy of the License at
10  *
11  *     http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  */
19
20 import java.util.regex.Pattern;
21
22 /**
23  * Wrapper class representing a hunspell affix
24  */
25 public class HunspellAffix {
26
27   private String append; // the affix itself, what is appended
28   private char appendFlags[]; // continuation class flags
29   private String strip;
30   
31   private String condition;
32   private Pattern conditionPattern;
33   
34   private char flag;
35
36   private boolean crossProduct;
37
38   /**
39    * Checks whether the given text matches the conditional pattern on this affix
40    *
41    * @param text Text to check if it matches the affix's conditional pattern
42    * @return {@code true} if the text meets the condition, {@code false} otherwise
43    */
44   public boolean checkCondition(CharSequence text) {
45     return conditionPattern.matcher(text).matches();
46   }
47
48   /**
49    * Returns the append defined for the affix
50    *
51    * @return Defined append
52    */
53   public String getAppend() {
54     return append;
55   }
56
57   /**
58    * Sets the append defined for the affix
59    *
60    * @param append Defined append for the affix
61    */
62   public void setAppend(String append) {
63     this.append = append;
64   }
65
66   /**
67    * Returns the flags defined for the affix append
68    *
69    * @return Flags defined for the affix append
70    */
71   public char[] getAppendFlags() {
72     return appendFlags;
73   }
74
75   /**
76    * Sets the flags defined for the affix append
77    *
78    * @param appendFlags Flags defined for the affix append
79    */
80   public void setAppendFlags(char[] appendFlags) {
81     this.appendFlags = appendFlags;
82   }
83
84   /**
85    * Returns the stripping characters defined for the affix
86    *
87    * @return Stripping characters defined for the affix
88    */
89   public String getStrip() {
90     return strip;
91   }
92
93   /**
94    * Sets the stripping characters defined for the affix
95    *
96    * @param strip Stripping characters defined for the affix
97    */
98   public void setStrip(String strip) {
99     this.strip = strip;
100   }
101
102   /**
103    * Returns the condition that must be met before the affix can be applied
104    *
105    * @return Condition that must be met before the affix can be applied
106    */
107   public String getCondition() {
108     return condition;
109   }
110
111   /**
112    * Sets the condition that must be met before the affix can be applied
113    *
114    * @param condition Condition to be met before affix application
115    * @param pattern Condition as a regular expression pattern
116    */
117   public void setCondition(String condition, String pattern) {
118     this.condition = condition;
119     this.conditionPattern = Pattern.compile(pattern);
120   }
121
122   /**
123    * Returns the affix flag
124    *
125    * @return Affix flag
126    */
127   public char getFlag() {
128     return flag;
129   }
130
131   /**
132    * Sets the affix flag
133    *
134    * @param flag Affix flag
135    */
136   public void setFlag(char flag) {
137     this.flag = flag;
138   }
139
140   /**
141    * Returns whether the affix is defined as cross product
142    *
143    * @return {@code true} if the affix is cross product, {@code false} otherwise
144    */
145   public boolean isCrossProduct() {
146     return crossProduct;
147   }
148
149   /**
150    * Sets whether the affix is defined as cross product
151    *
152    * @param crossProduct Whether the affix is defined as cross product
153    */
154   public void setCrossProduct(boolean crossProduct) {
155     this.crossProduct = crossProduct;
156   }
157 }