Skip to content

Commit

Permalink
SetPropertiesFilePath
Browse files Browse the repository at this point in the history
添加指定PropertiesFile文件路径的方法
  • Loading branch information
YangliAtGitHub committed Nov 22, 2015
1 parent 915d3ee commit c2418b4
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion src/main/java/com/hankcs/hanlp/HanLP.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import com.hankcs.hanlp.tokenizer.StandardTokenizer;

import java.io.File;
import java.io.FileInputStream;
import java.io.InputStreamReader;
import java.util.List;
import java.util.Properties;
Expand All @@ -43,11 +44,21 @@
*/
public class HanLP
{
public static String PropertiesFilePath;
/**
* 指定properties文件位置
*/
public static void SetPropertiesFile(String sPath)
{
PropertiesFilePath = sPath;
}

/**
* 库的全局配置,既可以用代码修改,也可以通过hanlp.properties配置(按照 变量名=值 的形式)
*/
public static final class Config
{

/**
* 开发模式
*/
Expand Down Expand Up @@ -175,7 +186,15 @@ public static final class Config
Properties p = new Properties();
try
{
p.load(new InputStreamReader(Thread.currentThread().getContextClassLoader().getResourceAsStream("hanlp.properties"), "UTF-8"));
if( HanLP.PropertiesFilePath != null)
{
File file = new File( HanLP.PropertiesFilePath );
FileInputStream fIn = new FileInputStream(file);
InputStreamReader isr = new InputStreamReader(fIn);
p.load( isr );
} else {
p.load(new InputStreamReader(Thread.currentThread().getContextClassLoader().getResourceAsStream("hanlp.properties"), "UTF-8"));
}
String root = p.getProperty("root", "").replaceAll("\\\\", "/");
if (!root.endsWith("/")) root += "/";
CoreDictionaryPath = root + p.getProperty("CoreDictionaryPath", CoreDictionaryPath);
Expand Down Expand Up @@ -256,6 +275,8 @@ public static void enableDebug()
{
enableDebug(true);
}



/**
* 开启调试模式(会降低性能)
Expand Down

0 comments on commit c2418b4

Please sign in to comment.