/// <summary> /// 自定义比较函数,用以排序等工作 /// </summary> /// <param name="obj"></param> /// <returns></returns> public int CompareTo(object obj) { int res = 0; try { AnsData ansobj = (AnsData)obj; if (this.memory > ansobj.memory) { res = 1; } else if (this.memory < ansobj.memory) { res = -1; } else { if (this.size > ansobj.size) { res = 1; } else if (this.size < ansobj.size) { res = -1; } } } catch (Exception e) { throw new Exception("compare error", e.InnerException); } return(res); }
/// <summary> /// 自定义文件遍历方法,根据筛选器进行筛选,并生成自定义数据类型列表 /// </summary> /// <param name="folder">文件夹位置</param> /// <returns>遍历得到的文件列表</returns> public static List <AnsData> GetAllFiles(string folder) { DirectoryInfo myfolder = new DirectoryInfo(folder); FileInfo[] files = myfolder.GetFiles(); List <AnsData> ans = new List <AnsData>(); foreach (FileInfo file in files) { AnsData now = new AnsData(file.Name, file.Length, file.FullName); bool flag = true; foreach (string key in Consts.KEYWORDS) { if (!now.fullfilename.Contains(key)) { flag = false; break; } } if (flag) { ans.Add(now); } } return(ans); }
/// <summary> /// 相似度计算方法,代码核心 /// 综合两种文本相似度计算方法,召回率更高 /// </summary> /// <param name="other">另一个自定义类型</param> /// <returns>计算得到的相似度,在[0..1]范围内</returns> public double calsim(AnsData other) { if (language != other.language) { return(0); } double memsim = (double)Math.Min(other.memory, memory) / (double)Math.Max(other.memory, memory); double timesim = (double)Math.Min(other.time, time) / (double)Math.Max(other.time, time); if (memsim < Consts.MEMTHRESHOLD || timesim < Consts.TIMETHRESHOLD) { return(memsim * timesim * 0.5); } double textsim = Math.Max(StringFunctions.calstringsim2(other.text, text), StringFunctions.calstringsim(other.text, text)); return(textsim * memsim * timesim); }
/// <summary> /// 相似度计算方法,代码核心,调参数的理想之地 /// </summary> /// <param name="other">另一个自定义类型</param> /// <returns>计算得到的相似度,在[0..1]范围内</returns> public double calsim(AnsData other) { if (language != other.language) return 0; double memsim = (double)Math.Min(other.memory, memory) / (double)Math.Max(other.memory, memory); double timesim = (double)Math.Min(other.time, time) / (double)Math.Max(other.time, time); if (memsim < Consts.MEMTHRESHOLD || timesim < Consts.TIMETHRESHOLD) return memsim * timesim * 0.5; double textsim = StringFunctions.calstringsim(other.text, text); return textsim * memsim * timesim; }
/// <summary> /// 自定义文件遍历方法,根据筛选器进行筛选,并生成自定义数据类型列表 /// </summary> /// <param name="folder">文件夹位置</param> /// <returns>遍历得到的文件列表</returns> public static List<AnsData> GetAllFiles(string folder) { DirectoryInfo myfolder = new DirectoryInfo(folder); FileInfo[] files = myfolder.GetFiles(); List<AnsData> ans = new List<AnsData>(); foreach (FileInfo file in files) { AnsData now = new AnsData(file.Name, file.Length, file.FullName); bool flag = true; foreach (string key in Consts.KEYWORDS) { if (!now.fullfilename.Contains(key)) { flag = false; break; } } if (flag) ans.Add(now); } return ans; }