X-Git-Url: https://git.mdrn.pl/pylucene.git/blobdiff_plain/a2e61f0c04805cfcb8706176758d1283c7e3a55c..aaeed5504b982cf3545252ab528713250aa33eed:/lucene-java-3.5.0/lucene/contrib/analyzers/smartcn/src/java/org/apache/lucene/analysis/cn/smart/AnalyzerProfile.java diff --git a/lucene-java-3.5.0/lucene/contrib/analyzers/smartcn/src/java/org/apache/lucene/analysis/cn/smart/AnalyzerProfile.java b/lucene-java-3.5.0/lucene/contrib/analyzers/smartcn/src/java/org/apache/lucene/analysis/cn/smart/AnalyzerProfile.java new file mode 100644 index 0000000..7612da1 --- /dev/null +++ b/lucene-java-3.5.0/lucene/contrib/analyzers/smartcn/src/java/org/apache/lucene/analysis/cn/smart/AnalyzerProfile.java @@ -0,0 +1,92 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.lucene.analysis.cn.smart; + +import java.io.File; +import java.io.FileInputStream; +import java.io.IOException; +import java.util.Properties; + +/** + * Manages analysis data configuration for SmartChineseAnalyzer + *

+ * SmartChineseAnalyzer has a built-in dictionary and stopword list out-of-box. + *

+ * @lucene.experimental + */ +public class AnalyzerProfile { + + /** + * Global indicating the configured analysis data directory + */ + public static String ANALYSIS_DATA_DIR = ""; + + static { + init(); + } + + private static void init() { + String dirName = "analysis-data"; + String propName = "analysis.properties"; + + // Try the system property:-Danalysis.data.dir=/path/to/analysis-data + ANALYSIS_DATA_DIR = System.getProperty("analysis.data.dir", ""); + if (ANALYSIS_DATA_DIR.length() != 0) + return; + + File[] cadidateFiles = new File[] { new File("./" + dirName), + new File("./lib/" + dirName), new File("./" + propName), + new File("./lib/" + propName) }; + for (int i = 0; i < cadidateFiles.length; i++) { + File file = cadidateFiles[i]; + if (file.exists()) { + if (file.isDirectory()) { + ANALYSIS_DATA_DIR = file.getAbsolutePath(); + } else if (file.isFile() && getAnalysisDataDir(file).length() != 0) { + ANALYSIS_DATA_DIR = getAnalysisDataDir(file); + } + break; + } + } + + if (ANALYSIS_DATA_DIR.length() == 0) { + // Dictionary directory cannot be found. + System.err + .println("WARNING: Can not find lexical dictionary directory!"); + System.err + .println("WARNING: This will cause unpredictable exceptions in your application!"); + System.err + .println("WARNING: Please refer to the manual to download the dictionaries."); + } + + } + + private static String getAnalysisDataDir(File propFile) { + Properties prop = new Properties(); + try { + FileInputStream input = new FileInputStream(propFile); + prop.load(input); + String dir = prop.getProperty("analysis.data.dir", ""); + input.close(); + return dir; + } catch (IOException e) { + } + return ""; + } + +}