文档比较去重

public class ReadArticle {

    public static List createData(String filename, ArrayList<String> list) throws IOException {
        //读取段落
        String r;
        String[] rs;

        //读取文章内容
        BufferedReader file1 = new BufferedReader(new FileReader(new File(filename).getAbsoluteFile()));
        try {
            while ((r = file1.readLine()) != null) {
                //消除不必要的标点符号
                r = r.replaceAll("\\s+ |“|\\[|‘|《| *|", "").trim();
                //留下” , 。  。”  ”。 ”, ? 》 -等作为划分句子的分割符标示
                rs = r.split(",|(。”|”(。|,)|。)|(\\])|”|’|?|:|》|-");

                for(String s1: rs){
//                    System.out.println(s1);
                    list.add(s1);
                }
            }
        }finally {
            file1.close();
        }
        return list;
    }


    public static void CompareDoc(List<String> list1, List<String> list2){
        System.out.println("222111222");
        Collection exists = new ArrayList(list2);
        Collection notexists = new ArrayList(list2);
        exists.removeAll(list1);
        notexists.removeAll(exists);
        System.out.println(notexists);

    }


    public static void main(String[] args) throws IOException {
        String filename1 = "C:\\Users\\Administrator\\Desktop\\222.txt";
        String filename2 = "C:\\Users\\Administrator\\Desktop\\lll.txt";
        ArrayList<String> list1= new ArrayList<>();
        ArrayList<String> list2= new ArrayList<>();
        Set set = new HashSet();
        CompareDoc(createData(filename1, list1),createData(filename2, list2)) ;

        Iterator i = set.iterator();
        if(i.hasNext()){
            System.out.println("sss:" + i.next());
        }
    }
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值