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

####第一步,难受,查找四级英语单词大纲。。
找了半天最后都是混杂着其他信息的,只好用R提取了。。提取成果如下。(称为cet)

abandon
ability
abnormal
aboard
abroad
absence
absent
absolute
absolutely
absorb
abstract

然后找了几篇四级阅读,格式如下(称为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);
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值