软件工程作业--java实现四级超纲率=(版本1)=

来源:互联网 发布:淘宝客服规范 编辑:程序博客网 时间:2024/06/06 00:53

第一步,难受,查找四级英语单词大纲。。

找了半天最后都是混杂着其他信息的,只好用R提取了。。提取成果如下。(称为cet)

abandonabilityabnormalaboardabroadabsenceabsentabsoluteabsolutelyabsorbabstract

然后找了几篇四级阅读,格式如下(称为eng):

When one looks back upon the fifteen hundred years that are the life span of the English language, he should be able to notice a number of significant truths. The history of our language has always been a history of constant change—at times a slow, almost imperceptible change, at other times a violent collision between two languages. Our language has always been a living growing organism, it has never been static. Another significant truth that emerges from such a study is that language at all times has been the possession not of one class or group but of many. 『At one extreme it has been the property of the common, ignorant folk, who have used it in the daily business of their living, much as they have used their animals or the kitchen pots and pans.』① At the other extreme it has been the treasure of those who have respected it as an instrument and a sign of civilization, and who have struggled by writing it down to give it some permanence, order, dignity, and if possible, a little beauty.

第二步,读文件啊。。

对于cet。这么读的。加\n是为了拆分数组的时候好拆。

public static String    read(String filename) throws IOException{        BufferedReader in = new BufferedReader(                new FileReader(filename)) ;        String s;        StringBuilder sb = new StringBuilder();        while((s = in.readLine())!= null)          sb.append(s + "\n");        in.close();        return sb.toString();    }

对于eng,这么做的。本来就有回车空格,就不需要回车了。

readen(String filename) throws IOException{        BufferedReader in = new BufferedReader(                new FileReader(filename)) ;        String s;        StringBuilder sb = new StringBuilder();        while((s = in.readLine())!= null)          sb.append(s);        in.close();        return sb.toString();    }

当然,两个合并,可以这样,读不同文件,自己定义。。

read(String filename,String sep) throws IOException{        BufferedReader in = new BufferedReader(                new FileReader(filename)) ;        String s;        StringBuilder sb = new StringBuilder();        while((s = in.readLine())!= null)          sb.append(s + sep);        in.close();        return sb.toString();    }

第三步,读入之后,弄成数组之前的处理,先把所有变成小写,再就是,通过正则表达式,拆分成数组。

 cet = cet.toLowerCase() ;               String[] cetarry = Pattern.compile("\n").split(cet); eng = eng.toLowerCase() ;               String[] enarry = Pattern.compile("\\W+").split(eng) ;

第四步,啊里。为了减轻工作负担,对eng去重,接着排序。

rmrep(String[] arr) {        String[] tmpArr = new String[arr.length];        int tmp = 0 ;        for(int i = 0 ; i<arr.length ; i++) {            boolean isTrue = true ;             for(int j=i+1;j<arr.length;j++){                    if(arr[i].equals(arr[j])){                        isTrue = false;                        break;                    }                }                if(isTrue){                    tmpArr[tmp] = arr[i];                    tmp++;                }            }            String[]  newArr = new String[tmp];            arraycopy(tmpArr,0,newArr,0,tmp);            return newArr;    }      String[] noRepeatArr = rmrep(enarry) ;           Arrays.sort(noRepeatArr, String.CASE_INSENSITIVE_ORDER);

第五步,计算超纲率。。

public static double       rCet(String[] arr,String[] cetArr) {        int a1 = arr.length ;        int a2 = cetArr.length ;        int tmp = 0 ;        for(int i = 0; i<a1 ; i++) {            boolean isTrue = true ;            for(int j = 0 ; j<a2 ; j++) {                if(arr[i].equals(cetArr[j])) {                    isTrue = false;                    break;                }            }            if(isTrue) {                tmp++;            }        }        return 1-(double)tmp/a1 ;    }

第六步,输出。

for( String ar:noRepeatArr) {                   out.println(ar);               }                double dd = rCet(noRepeatArr, cetarry);                 out.println("单词超纲率:"+dd);
原创粉丝点击