⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 dicttreetest.java

📁 这是关于中文分词的有关程序
💻 JAVA
字号:
/*
 * Created on 2005-12-29
 * author 谢骋超
 * 
 */
package cn.edu.zju.dartsplitter.impl;

import java.util.List;
import java.util.Set;

import junit.framework.TestCase;

import org.apache.log4j.Logger;

import cn.edu.zju.dartsplitter.DictTree;
import cn.edu.zju.dartsplitter.appcontext.AppContextFactory;
import cn.edu.zju.dartsplitter.data.DictNode;
import cn.edu.zju.dartsplitter.data.DictValue;

public class DictTreeTest extends TestCase{
    /**
     * Logger for this class
     */
    private static final Logger logger = Logger.getLogger(DictTreeTest.class);

    private DictTree dictTree;

    public void setUp() {
        dictTree=(DictTree)AppContextFactory.getContext().getBean("dictTree");
    }
    
    public void testGetAllPrefixes() {
        Set<String> prefixSet=dictTree.getAllPrefixes();
        assertTrue(prefixSet.contains("感"));
    }
    
    public void testBuildAndGetSubList() {
        DictNode dictNode=dictTree.buildSubNodes("感");
        logger.debug(dictNode);
              
        int i=0;
        for (DictNode curNode:dictNode.getChildNodes().values()){
            i++;
            logger.debug("node "+i+curNode);
        }
        
        DictNode dictNode2=dictTree.buildOrGetSubNodes("冒",dictNode);
        logger.debug(dictNode2);
       // logger.debug("token value "+ dictNode2.getTokenValue());
        
        for (DictNode curNode:dictNode2.getChildNodes().values()){
            i++;
            logger.debug("node "+i+curNode);
            //logger.debug("token value "+ curNode.getTokenValue());
        }     
    }
    
    
    public void testGetSubList() {
        DictNode dictNode=dictTree.buildOrGetSubNodes("感",DictNode.EMPTY_NODE);
        logger.debug(dictNode);
              
        int i=0;
        for (DictNode curNode:dictNode.getChildNodes().values()){
            i++;
            logger.debug("node "+i+curNode);
        }
        
        DictNode dictNode2=dictTree.buildOrGetSubNodes("冒",dictNode);
        logger.debug(dictNode2);
       // logger.debug("token value "+ dictNode2.getTokenValue());
        
        for (DictNode curNode:dictNode2.getChildNodes().values()){
            i++;
            logger.debug("node "+i+curNode);
            //logger.debug("token value "+ curNode.getTokenValue());
        }     
    }    
    
    public void testGetDictValues() {   
        Set<String> allPrefixes=dictTree.getAllPrefixes();
        logger.debug("allPrefix size is "+allPrefixes.size());
//        for (String prefix:allPrefixes){
//            System.out.print(prefix+" ");
//        }
//        System.out.println();
        List<DictValue> dictValues=dictTree.getDictValues("感");
        int i=0;
        for (DictValue dictValue:dictValues){
            i++;
            logger.debug("dict Value "+i+":"+dictValue);
        }
    }
    
    public void testBuildSubNodes() {   
        DictNode dictNode=dictTree.buildSubNodes("感");
        logger.debug(dictNode);
        DictNode childNode1=dictNode.getChildNode("冒");
        logger.debug(childNode1);
        DictNode childNode2=childNode1.getChildNode("清");
        logger.debug(childNode2);
    }
    
    
    
    public void testSaveDictMap() {
        logger.debug("start save dict ");
        dictTree.saveDictMap();
        logger.debug("finish save dict ");
    }
}

⌨️ 快捷键说明

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