1 package org.apache.lucene.analysis.hunspell;
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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.
20 import java.util.regex.Pattern;
23 * Wrapper class representing a hunspell affix
25 public class HunspellAffix {
27 private String append; // the affix itself, what is appended
28 private char appendFlags[]; // continuation class flags
31 private String condition;
32 private Pattern conditionPattern;
36 private boolean crossProduct;
39 * Checks whether the given text matches the conditional pattern on this affix
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
44 public boolean checkCondition(CharSequence text) {
45 return conditionPattern.matcher(text).matches();
49 * Returns the append defined for the affix
51 * @return Defined append
53 public String getAppend() {
58 * Sets the append defined for the affix
60 * @param append Defined append for the affix
62 public void setAppend(String append) {
67 * Returns the flags defined for the affix append
69 * @return Flags defined for the affix append
71 public char[] getAppendFlags() {
76 * Sets the flags defined for the affix append
78 * @param appendFlags Flags defined for the affix append
80 public void setAppendFlags(char[] appendFlags) {
81 this.appendFlags = appendFlags;
85 * Returns the stripping characters defined for the affix
87 * @return Stripping characters defined for the affix
89 public String getStrip() {
94 * Sets the stripping characters defined for the affix
96 * @param strip Stripping characters defined for the affix
98 public void setStrip(String strip) {
103 * Returns the condition that must be met before the affix can be applied
105 * @return Condition that must be met before the affix can be applied
107 public String getCondition() {
112 * Sets the condition that must be met before the affix can be applied
114 * @param condition Condition to be met before affix application
115 * @param pattern Condition as a regular expression pattern
117 public void setCondition(String condition, String pattern) {
118 this.condition = condition;
119 this.conditionPattern = Pattern.compile(pattern);
123 * Returns the affix flag
127 public char getFlag() {
132 * Sets the affix flag
134 * @param flag Affix flag
136 public void setFlag(char flag) {
141 * Returns whether the affix is defined as cross product
143 * @return {@code true} if the affix is cross product, {@code false} otherwise
145 public boolean isCrossProduct() {
150 * Sets whether the affix is defined as cross product
152 * @param crossProduct Whether the affix is defined as cross product
154 public void setCrossProduct(boolean crossProduct) {
155 this.crossProduct = crossProduct;