打标签
来源:互联网 发布:自学编程先学什么 编辑:程序博客网 时间:2024/06/11 22:07
import java.io.*;import java.util.HashMap;import java.util.Map;import java.util.Properties;public class SQLCacheFile { //stone库导出的地点X智能数据, 实例:江苏省南京市卫生局:0 public static HashMap<String,int[]> SQLCacheMap; public void loadSQLFile (String path) { String encoding = "utf-8"; File file = new File(path); try { long now = System.currentTimeMillis(); if(file.isFile() && file.exists()) { InputStreamReader read = new InputStreamReader( new FileInputStream(file),encoding ); BufferedReader bufferedReader = new BufferedReader(read); String lineText = ""; while((lineText=bufferedReader.readLine()) != null) { String[] parts = lineText.split(":"); SQLCacheMap.put(parts[0],new int[]{Integer.parseInt(parts[1]),0}); } System.out.println("读取文件完毕,耗费:"+(System.currentTimeMillis()-now)+"ms!"); } else { System.out.println("读取文件失败!"); } } catch (FileNotFoundException e) { System.out.println(e); } catch (UnsupportedEncodingException e) { System.out.println(e); } catch (IOException e) { System.out.println(e); } catch (Exception e) { System.out.println(e); } } /* 从kafka上接入消息 要接入分词功能,对传入的文章进行切词处理 */ public void getTitleAndTextWordCut(String title,String text) { while(true) { //text为从kafka上取得的文章正文和标题// String[] titleWord = getWordCut(title);// String[] textWord = getWordCut(text);// for(int i =0; i<titleWord.length; i++) {// checkIfExistsInSQLCache(titleWord[i]);// }// for(int i =0; i<textWord.length; i++) {// checkIfExistsInSQLCache(textWord[i]);// } } } public void checkIfExistsInSQLCache(String word) { if(SQLCacheMap.containsKey(word)) { //如果词在词典中存在的话,则赋值为1 SQLCacheMap.get(word)[1] = 1; } } public void writeSQLCacheIntoFile(String path) { try { FileOutputStream fos = new FileOutputStream(path); OutputStreamWriter osw = new OutputStreamWriter(fos,"utf-8"); for(Map.Entry<String,int[]> entry : SQLCacheMap.entrySet()) { String govName = ""; //判断文件出现位是否为1,1代表出现过,0代表没有出现过 if(entry.getValue()[1] == 1) { //判断政府前缀为是否为1,1代表有前缀中共 if(entry.getValue()[0] == 1) { govName = "中共"+ entry.getKey(); }else { govName = entry.getKey(); } } osw.write(govName+System.getProperty("line.separator")); } osw.close(); } catch (FileNotFoundException e) { System.out.println(e); } catch (UnsupportedEncodingException e) { System.out.println(e); } catch (IOException e) { System.out.println(e); } } public static void main(String[] args) { try { Properties properties = new Properties(); FileInputStream fis = new FileInputStream("config.properties"); properties.load(fis); String SQLCacheFilePath = properties.getProperty("SQLCacheFilePath"); String FileSavePath = properties.getProperty("FileSavePath"); SQLCacheFile sqlCacheFile = new SQLCacheFile(); sqlCacheFile.loadSQLFile(SQLCacheFilePath); fis.close(); } catch (FileNotFoundException e) { System.out.println(e); } catch (IOException e) { System.out.println(e); } }}
SQLCacheFilePath=/User/cross/PractiseProject/sql.txtFileSavePath=/User/cross/PractiseProject/save.txtFileSaveInterval=1000
阅读全文
0 0
- 打标签
- ClearCase如何打标签
- CVS打标签
- git 打标签
- Git 基础 - 打标签
- git 打标签
- git - 打标签
- 打标签批处理脚本
- git 打标签操作
- git tag 打标签
- Git 基础 - 打标签
- git tag打标签
- Git打标签tag
- git打标签
- Git tag 打标签
- 仿nice打标签
- ViewPager相片打标签
- 【vim】编辑时打标签
- 如何实现用户的历史记录功能(最多n条)
- eclipse取消validation验证
- jenkins Error performing command: git ls-remote -h
- 向梦想出发
- android 5.0和6.0后新增的控件总结
- 打标签
- 数据库锁
- HDU 2159 Fate(二维完全背包)
- java中的继承
- 6文本的属性
- 前m大的数
- Python 二维数组操作
- C++ 修改文件名
- 回归