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

📄 commondictdao.java

📁 这是关于中文分词的有关程序
💻 JAVA
字号:
/*
 * Copyright 2002-2005 the original author or authors.
 * 
 * Licensed 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 cn.edu.zju.dartsplitter.dao;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Types;
import java.util.List;

import javax.sql.DataSource;

import org.springframework.jdbc.core.SqlParameter;
import org.springframework.jdbc.object.MappingSqlQuery;

import cn.edu.zju.dartsplitter.data.DictValue;

/**
 *  对一个通用词库进行操作,目前这个实现是针对Access的
 *  词库数据库的配置在 etc/dictJdbc.properties
 * @author xiecc
 * @email xieccy@gmail.com xieccy@yahoo.com
 * homepage:  http://blog.itpub.net/xiecc
 * projectpage: http://ccnt.zju.edu.cn/projects
 */
public class CommonDictDAO implements DictDAO {
	private DataSource dataSource;

	private String tableName;

	public DataSource getDataSource() {
		return dataSource;
	}

	public void setDataSource(DataSource dataSource) {
		this.dataSource = dataSource;
	}

	public String getTableName() {
		return tableName;
	}

	public void setTableName(String tableName) {
		this.tableName = tableName;
	}

	public List<DictValue> getDictValues(String strPrefix) {
	       DictMappingQuery dictMappingQuery=new DictMappingQuery(getDataSource());
	        Object[] parameters = new Object[1];
	        parameters[0]=strPrefix+"%";
	        return dictMappingQuery.execute(parameters);
	}
	
    private class DictMappingQuery extends MappingSqlQuery {
        public DictMappingQuery(DataSource ds) {
            super(ds, "select WORD from "+getTableName()+" where WORD like ?");
            declareParameter(
                    new SqlParameter("WORD", Types.VARCHAR));
            compile();
        }

        public Object mapRow(ResultSet rs, int rowNumber) throws SQLException {
            DictValue dictValue=new DictValue(rs.getString("WORD"));
           // dictValue.setUseCount(rs.getInt("USECOUNT")); 
            return dictValue;         
        }
    }	

	public List<String> getAllPrefixes() {
        DictPrefixMappingQuery prefixQuery=new DictPrefixMappingQuery(getDataSource());
        return prefixQuery.execute();
	}
	
	/**
	 * 这个类是不通用的,在access里用left,oracle里用的是substr
	 * @author xiecc
	 *
	 */
    private class DictPrefixMappingQuery extends MappingSqlQuery {
        public DictPrefixMappingQuery(DataSource ds) {
            super(ds, "select Left(WORD,1) as wordPrefix from "+getTableName()+" group by Left(WORD,1)");
            compile();
        }

        public Object mapRow(ResultSet rs, int rowNumber) throws SQLException {
            return rs.getString("wordPrefix");         
        }
    }	

}

⌨️ 快捷键说明

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