同义词词林图转树
2015-06-04 11:08
211 查看
HIT同义词此林的上下位词关系不是树状结构,从图转到树型结构
算法:
1.察看word是否有下为词,得到下位词childlist
2.若第一步childlist为空,在entity表中查找该概念对应的实体,否则对于childlist中的每个word若之前没访问过,执行第一步
3.结果合并生成树型结构
缺点:
1.忽略了此的层次关系
2.对于结构较大的概念,效率较慢
算法:
1.察看word是否有下为词,得到下位词childlist
2.若第一步childlist为空,在entity表中查找该概念对应的实体,否则对于childlist中的每个word若之前没访问过,执行第一步
3.结果合并生成树型结构
缺点:
1.忽略了此的层次关系
2.对于结构较大的概念,效率较慢
package cn.dataprocess; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.UnsupportedEncodingException; import java.sql.*; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; import org.codehaus.jettison.json.JSONArray; import org.codehaus.jettison.json.JSONException; import org.codehaus.jettison.json.JSONObject; public class WordTree { public static Map<String,String> iMap = new HashMap<String,String>(); public static List<String> findDown(String word) throws ClassNotFoundException, SQLException{ String driver = "com.mysql.jdbc.Driver"; String url = "jdbc:mysql://localhost:3306/maya"; String user = "root"; String password = "root"; Class.forName(driver); Connection conn = DriverManager.getConnection(url,user,password); //if(!conn.isClosed()) System.out.println("Succeeded connecting to the Database!"); Statement statement = conn.createStatement(); String sql = "select * from hpy_hpy where parent = '" + word + "'"; ResultSet rs = statement.executeQuery(sql); List<String> res = new ArrayList<String>(); while(rs.next()){ res.add(rs.getString("child")); } return res; } public static List<String> findEntity(String word) throws ClassNotFoundException, SQLException{ String driver = "com.mysql.jdbc.Driver"; String url = "jdbc:mysql://localhost:3306/maya"; String user = "root"; String password = "root"; Class.forName(driver); Connection conn = DriverManager.getConnection(url,user,password); //if(!conn.isClosed()) System.out.println("Succeeded connecting to the Database!"); Statement statement = conn.createStatement(); String sql = "select * from ent_hpy where hpy = '" + word + "'"; ResultSet rs = statement.executeQuery(sql); List<String> res = new ArrayList<String>(); while(rs.next()){ res.add(rs.getString("ent")); } return res; } public static JSONObject solve(String word) throws ClassNotFoundException, SQLException, JSONException{ if(iMap.containsKey(word))return null; iMap.put(word, "has"); //System.out.println("word:" + word); JSONObject res = new JSONObject(); List<String> word_down = findDown(word); if(word_down.size() == 0){ List<String> ent_down = findEntity(word); //res.add(ent_down); //return ; JSONArray tem = new JSONArray(); for(int i = 0;i < ent_down.size();i ++){ tem.put(i,ent_down.get(i)); } res.put(word, tem); return res; } JSONArray tem = new JSONArray(); for(String key : word_down){ //System.out.println("key:" + key); tem.put(solve(key)); //System.out.println("tem:" + tem.toString()); } res.put(word,tem); return res; } public static JSONObject getTree(String tem) throws IOException, ClassNotFoundException, SQLException, JSONException { // TODO Auto-generated method stub //List<List<String>> res = new ArrayList<List<String>>(); iMap.clear(); JSONObject res = solve(tem); return res; } }
相关文章推荐
- UIImageView、UIView、拉伸像素点
- android webview用法小结1
- hdu - 1113 Word Amalgamation (stl)
- IIS - HTTP 错误 500.21 - Internal Server Error 处理程序“WebServiceHandlerFactory-Integrated”在其模块列表中有一个错误模块“ManagedPipelineHandler”
- STL中使用reserve()提升效率
- 关于dos-formatted/unix-formatted 文件转换
- Nginx学习笔记--负载均衡配置
- iOS中使用 Reachability 检测网络
- 如何在vp中使用cout
- 为什么很少见工资高的程序员炫富?
- How to use C++ in Go?
- ORACLE中查询拥有某字段的表
- 假设检验
- 第二次冲刺第四天
- Win8.1系统任务管理器不能用显示灰色怎么解决?
- [Erlang]Erlang与C的节点通信
- linux 修改时间
- hadoop安全之hftp
- 操作系统--并发进程死锁
- windows下mongodb安装与使用整理