CandidateFilter.java revision 7b3b414976b6b3d6d85459de79e843d5ab35ed06
1/*
2 * Copyright (C) 2008,2009  OMRON SOFTWARE Co., Ltd.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 *      http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16package jp.co.omronsoft.openwnn;
17
18import java.util.regex.Matcher;
19import java.util.regex.Pattern;
20
21/**
22 * This class is used for filtering candidates by {@code WnnEngine}.
23 *
24 * @author Copyright (C) 2009, OMRON SOFTWARE CO., LTD.  All Rights Reserved.
25 *
26 */
27public class CandidateFilter {
28	public static final int FILTER_NONE = 0x0;
29	public static final int FILTER_EMOJI = 0x1;
30
31    /** Regular expression pattern for emoji */
32    private static final Pattern PATTERN_EMOJI = Pattern.compile("[\uDBB8\uDBB9\uDBBA\uDBBB]");
33
34	private int mFilter = 0;
35
36	public void setFilter(int filter) {
37		mFilter = filter;
38	}
39
40	public boolean isAllowed(WnnWord word) {
41		if (mFilter == 0) {
42			return true;
43		}
44		if ((mFilter & FILTER_EMOJI) != 0) {
45			Matcher m = PATTERN_EMOJI.matcher(word.candidate);
46			if (m.matches()) {
47				return false;
48			}
49		}
50		return true;
51	}
52
53}
54