打标签

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.txt
FileSavePath=/User/cross/PractiseProject/save.txt
FileSaveInterval=1000

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值