forked from hankcs/HanLP
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
815 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
72 changes: 72 additions & 0 deletions
72
src/main/java/com/hankcs/hanlp/corpus/util/CustomNatureUtility.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
/* | ||
* <summary></summary> | ||
* <author>He Han</author> | ||
* <email>[email protected]</email> | ||
* <create-date>2016/1/4 16:02</create-date> | ||
* | ||
* <copyright file="CustomNatureUtility.java" company="码农场"> | ||
* Copyright (c) 2008-2016, 码农场. All Right Reserved, http://www.hankcs.com/ | ||
* This source is subject to Hankcs. Please contact Hankcs to get more information. | ||
* </copyright> | ||
*/ | ||
package com.hankcs.hanlp.corpus.util; | ||
|
||
import com.hankcs.hanlp.corpus.tag.Nature; | ||
import com.hankcs.hanlp.dictionary.CustomDictionary; | ||
import com.hankcs.hanlp.recognition.nr.PersonRecognition; | ||
import com.hankcs.hanlp.recognition.nt.OrganizationRecognition; | ||
import com.hankcs.hanlp.seg.common.Vertex; | ||
import static com.hankcs.hanlp.utility.Predefine.logger; | ||
|
||
/** | ||
* 运行时动态增加词性工具 | ||
* | ||
* @author hankcs | ||
*/ | ||
public class CustomNatureUtility | ||
{ | ||
static | ||
{ | ||
logger.warning("已激活自定义词性功能,由于采用了反射技术,用户需对本地环境的兼容性和稳定性负责!\n" + | ||
"如果用户代码X.java中有switch(nature)语句,需要调用CustomNatureUtility.registerSwitchClass(X.class)注册X这个类"); | ||
} | ||
|
||
/** | ||
* 动态增加词性工具 | ||
*/ | ||
private static EnumBuster<Nature> enumBuster = new EnumBuster<Nature>(Nature.class, | ||
CustomDictionary.class, | ||
Vertex.class, | ||
PersonRecognition.class, | ||
OrganizationRecognition.class); | ||
|
||
/** | ||
* 增加词性 | ||
* @param name 词性名称 | ||
* @return 词性 | ||
*/ | ||
public static Nature addNature(String name) | ||
{ | ||
Nature customNature = enumBuster.make(name); | ||
enumBuster.addByValue(customNature); | ||
|
||
return customNature; | ||
} | ||
|
||
/** | ||
* 注册switch(nature)语句类 | ||
* @param switchUsers 任何使用了switch(nature)语句的类 | ||
*/ | ||
public static void registerSwitchClass(Class... switchUsers) | ||
{ | ||
enumBuster.registerSwitchClass(switchUsers); | ||
} | ||
|
||
/** | ||
* 还原对词性的全部修改 | ||
*/ | ||
public static void restore() | ||
{ | ||
enumBuster.restore(); | ||
} | ||
} |
Oops, something went wrong.