今天工作进展顺利,各个人的任务都完成了预期效果:
(1)陈伯雄:search部分的框架更改已经设计出来,之前的框架问题百出,不适合查询,现在是优化了框架;
(2)刘宇翔:找出了800多个match部分用的测试文档;给我优化后的代码找出了一些bug和不足;
(3)张孝祖:上传功能Upload部分已经基本完成,能够把文件上传到服务器了,下面就是积分的处理了;
(4)潘学:下载功能还有一些问题,积分功能差不多完成了;
(5)李忠:今天给刘宇翔的match进行了优化,提高了容错率,我加入了比较两个字符串的编辑距离的方法,并将半角标点符号统一转化为全角处理;
明天将继续今天的工作,张孝祖和潘学明天就能完成了,剩下的就是search和match
我的设计的编辑距离的代码和半角标点符号转全角标点符号的代码
//编写一个求两个字符串编辑距离的方法,提高容错率
static public int editDistance(string x , string y) {
//定义三个常量分别表示插入、删除和修改一个字符所消耗的编辑次数
const int COSTINDEL = 1;
const int COSTININS = 1;
const int COSTINSUB = 1;
int xLength = x.Length, yLength = y.Length;
//二维数组distance用于存储动态规划过程中每一步的编辑距离
int row = xLength + 1, low = yLength + 1;
int[][] distance=new int[row][];
for (int i = 0; i < row; i++) {
distance[i] = new int[low];
}
//初始化距离distance二维表的行和列
distance[0][0] = 0;
for (int i = 1; i < row; i++) {
distance[i][0] = distance[i - 1][0] + COSTINDEL;
}
for (int j = 1; j < low; j++) {
distance[0][j] = distance[0][j - 1] + COSTININS;
}
//利用动态规划算法求x和y的编辑距离
for (int i = 1; i < row; i++) {
for (int j = 1; j < low; j++) {
//分别用delDistance、insDistance和subDistance暂存要编辑到distance[i][j]的各种方式的编辑次数
int delDistance = distance[i - 1][j] + COSTINDEL;
int insDistance = distance[i][j - 1] + COSTININS;
int subDistance = distance[i - 1][j - 1] + (x[i - 1] == y[j - 1] ? 0 : COSTINSUB);
int temp;
distance[i][j] = subDistance < (temp = (delDistance < insDistance ? delDistance : insDistance)) ? subDistance : temp; //选择一个编辑次数最少的值附给distance[i][j]
}
}
return distance[xLength][yLength]; //返回两个数的编辑距离的
}
//将标点符号进行更改的从半角转化为全角的方法
static string half_to_whole(string s) {
int sLength=s.Length;
char[] c=s.ToCharArray();
for (int i = 0; i < sLength; i++) {
byte[] b = System.Text.Encoding.Unicode.GetBytes(c,i,1);
if (b.Length == 2) {
if (b[1] == 0 && !(c[i] >= 'a' && c[i] <= 'z' || c[i] >= 'A' && c[i] <= 'Z' || c[i] >= '0' && c[i] <= '9'))
{
b[0] = (byte)(b[0] - 32);
b[1] = 255;
c[i] = System.Text.Encoding.Unicode.GetChars(b)[0];
}
}
}
string news = new string(c);
return news;
}