• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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  */
16 
17 package jp.co.omronsoft.openwnn;
18 
19 /**
20  * The filter class for candidates.
21  * This class is used for filtering candidates by {link WnnEngine}.
22  *
23  * @author Copyright (C) 2009 OMRON SOFTWARE CO., LTD.  All Rights Reserved.
24  *
25  */
26 public class CandidateFilter {
27     /** Filtering pattern (No filter) */
28     public static final int FILTER_NONE = 0x0;
29     /** Filtering pattern (Non ASCII) */
30     public static final int FILTER_NON_ASCII = 0x2;
31 
32     /** Current filter type */
33     public int filter = 0;
34 
35     /**
36      * Checking whether a specified word is filtered.
37      *
38      * @param word      A word
39      * @return          {@code true} if the word is allowed; {@code false} if the word is denied.
40      */
isAllowed(WnnWord word)41     public boolean isAllowed(WnnWord word) {
42         if (filter == 0) {
43             return true;
44         }
45         if ((filter & FILTER_NON_ASCII) != 0) {
46             String str = word.candidate;
47             for (int i = 0; i < str.length(); i++) {
48                 if (str.charAt(i) < 0x20 || 0x7E < str.charAt(i)) {
49                     return false;
50                 }
51             }
52         }
53         return true;
54     }
55 }
56