dictionarypropertyeditor.java

来自「基于词典的最大分词算法 达到很好的分词准确率」· Java 代码 · 共 51 行

JAVA
51
字号
/*
 * @作者:Hades , 创建日期:2006-12-25
 *
 * 汕头大学03计算机本科
 * 
 */
package edu.stu.cn.segment.spring.ioc;

import java.beans.PropertyEditorSupport;

import edu.stu.cn.segment.matching.dictionary.DictionaryImpl;
import edu.stu.cn.segment.matching.util.DictionaryUtil;

/**
 * @author Hades Guan 将字符串描述转换为相应字典类型
 */
public class DictionaryPropertyEditor<T extends DictionaryImpl> extends
        PropertyEditorSupport
{
    @SuppressWarnings("unused")
    private Class<T> classType = null;

    /**
     * 默认构造函数
     * 
     * @param classType
     *            指定所使用泛型的Class类型
     */
    public DictionaryPropertyEditor(Class<T> classType)
    {
        this.classType = classType;
    }

    /*
     * (非 Javadoc)
     * 
     * @see java.beans.PropertyEditorSupport#setAsText(java.lang.String)
     */
    @Override
    public void setAsText(String text) throws IllegalArgumentException
    {
        // 初始化字典工具
        DictionaryUtil<T> tool = new DictionaryUtil<T>();
        // 根据指定的文件路径初始化字典实例
        T dic = tool.readDictionary(text);
        // 设置访问值
        this.setValue(dic);
    }

}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?