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
9 * http://www.apache.org/licenses/LICENSE-2.0
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.
18 package org.apache.lucene.analysis.cn.smart;
21 import java.io.FileInputStream;
22 import java.io.IOException;
23 import java.util.Properties;
26 * Manages analysis data configuration for SmartChineseAnalyzer
28 * SmartChineseAnalyzer has a built-in dictionary and stopword list out-of-box.
30 * @lucene.experimental
32 public class AnalyzerProfile {
35 * Global indicating the configured analysis data directory
37 public static String ANALYSIS_DATA_DIR = "";
43 private static void init() {
44 String dirName = "analysis-data";
45 String propName = "analysis.properties";
47 // Try the system property:-Danalysis.data.dir=/path/to/analysis-data
48 ANALYSIS_DATA_DIR = System.getProperty("analysis.data.dir", "");
49 if (ANALYSIS_DATA_DIR.length() != 0)
52 File[] cadidateFiles = new File[] { new File("./" + dirName),
53 new File("./lib/" + dirName), new File("./" + propName),
54 new File("./lib/" + propName) };
55 for (int i = 0; i < cadidateFiles.length; i++) {
56 File file = cadidateFiles[i];
58 if (file.isDirectory()) {
59 ANALYSIS_DATA_DIR = file.getAbsolutePath();
60 } else if (file.isFile() && getAnalysisDataDir(file).length() != 0) {
61 ANALYSIS_DATA_DIR = getAnalysisDataDir(file);
67 if (ANALYSIS_DATA_DIR.length() == 0) {
68 // Dictionary directory cannot be found.
70 .println("WARNING: Can not find lexical dictionary directory!");
72 .println("WARNING: This will cause unpredictable exceptions in your application!");
74 .println("WARNING: Please refer to the manual to download the dictionaries.");
79 private static String getAnalysisDataDir(File propFile) {
80 Properties prop = new Properties();
82 FileInputStream input = new FileInputStream(propFile);
84 String dir = prop.getProperty("analysis.data.dir", "");
87 } catch (IOException e) {