身份证号码编码规则及校验位校验算法

算法地址:http://jingyan.baidu.com/article/7f41ececff944a593d095c8c.html

简单验证长度

         /// <summary>
/// 检查身份证基本信息
/// </summary>
/// <returns>结果</returns>
private string CheckAndParse()
{
if (string.IsNullOrWhiteSpace(this.Id))
{
return "身份证号码不能为空";
}
if (this.Id.Length == )
{
return this.ParseCardInfo15();
}
if (this.Id.Length == )
{
return this.ParseCardInfo18();
}
return "身份证号码必须为15位或18位";
}

简单验证

身份证分为2中 18位 OR 15位

验证先用正则表达式进行初步验证 并且取出 身份证上面包含的信息(地区 生日 随机码 性别 尾号)

18位身份证

        /// <summary>
/// 18位身份证
/// </summary>
/// <returns>结果</returns>
private string ParseCardInfo18()
{
const string CardIdParttern = @"(\d{6})(\d{4})(\d{2})(\d{2})(\d{2})(\d{1})([\d,x,X]{1})";
Match match = Regex.Match(this.Id, CardIdParttern);
if (match.Success)
{
this.areaCode = match.Groups[].Value;
string year = match.Groups[].Value;
string month = match.Groups[].Value;
string day = match.Groups[].Value;
this.birthCode = year + month + day;
this.randomCode = match.Groups[].Value;
this.sexCode = char.Parse(match.Groups[].Value);
string verifyCode = match.Groups[].Value.ToUpper(); if (this.ValidateVerifyCode(this.Id.Substring(, ), char.Parse(verifyCode)))
{
try
{
this.Birth = BirthDate.GetBirthDate(year, month, day);
this.Area = AreaCodeMapping.GetArea(this.areaCode);
Sex = GetSex(this.sexCode);
}
catch (System.Exception ex)
{
return ex.Message;
}
return string.Empty;
}
}
return "身份证号码格式错误";
}

18位

15位身份证

         /// <summary>
/// 15位身份证
/// </summary>
/// <returns>结果</returns>
private string ParseCardInfo15()
{
const string CardIdParttern = @"(\d{6})(\d{2})(\d{2})(\d{2})(\d{2})(\d{1})";
Match match = Regex.Match(this.Id, CardIdParttern);
if (match.Success)
{
this.areaCode = match.Groups[].Value;
string year = match.Groups[].Value;
string month = match.Groups[].Value;
string day = match.Groups[].Value;
this.birthCode = year + month + day;
this.randomCode = match.Groups[].Value;
this.sexCode = char.Parse(match.Groups[].Value); try
{
this.Area = AreaCodeMapping.GetArea(this.areaCode);
this.Birth = BirthDate.GetBirthDate(year, month, day);
Sex = GetSex(this.sexCode);
}
catch (System.Exception ex)
{
return ex.Message;
}
return string.Empty;
}
return "身份证号码格式错误";
}

15位

校验代码

 namespace Notify.Solution.Code.IdentityCard
{
/// <summary>
/// 验证类
/// </summary>
public class Validator
{
/// <summary>
/// 验证码
/// </summary>
private readonly char[] verifyCodeMapping = { '', '', 'X', '', '', '', '', '', '', '', '' }; /// <summary>
/// 地区代码
/// </summary>
private string areaCode; /// <summary>
/// 生日
/// </summary>
private string birthCode; /// <summary>
/// 随机
/// </summary>
private string randomCode; /// <summary>
/// 性别
/// </summary>
private char sexCode; /// <summary>
/// Initializes a new instance of the <see cref="Validator"/> class.
/// </summary>
/// <param name="id">Id</param>
public Validator(string id)
{
this.Id = id;
this.Success = false;
this.ErrorMessage = string.Empty;
this.Area = null;
this.Birth = BirthDate.Empty;
this.Sex = Sex.Male;
} /// <summary>
/// 身份证ID
/// </summary>
public string Id { get; private set; } /// <summary>
/// 结果
/// </summary>
public bool Success { get; private set; } /// <summary>
/// 错误信息
/// </summary>
public string ErrorMessage { get; private set; } /// <summary>
/// 区域信息
/// </summary>
public AreaInformation Area { get; private set; } /// <summary>
/// 生日
/// </summary>
public BirthDate Birth { get; private set; } /// <summary>
/// 性别
/// </summary>
public Sex Sex { get; private set; } /// <summary>
/// 执行比较结果
/// </summary>
/// <returns>结果</returns>
public bool Execute()
{
string msg = this.CheckAndParse();
if (string.IsNullOrWhiteSpace(msg))
{
this.ErrorMessage = string.Empty;
this.Success = true;
}
else
{
this.ErrorMessage = msg;
this.Success = false;
}
return this.Success;
} /// <summary>
/// IdentityCard18
/// </summary>
public string IdentityCard18
{
get
{
if (string.IsNullOrWhiteSpace(this.Id))
{
return "身份证号码不能为空";
}
if (this.Success && this.Id.Length == )
{
return this.ToCardInfo18();
}
return this.Id;
}
} /// <summary>
/// ToCardInfo18
/// </summary>
/// <returns>结果</returns>
private string ToCardInfo18()
{
string bodyCode = GetBodyCode(this.areaCode, "" + this.birthCode, this.randomCode, this.sexCode);
char verifyCode = this.GetVerifyCode(bodyCode);
return bodyCode + verifyCode;
} /// <summary>
/// 获取bodyCode
/// </summary>
/// <param name="areaCode">areaCode</param>
/// <param name="birthCode">birthCode</param>
/// <param name="randomCode">randomCode</param>
/// <param name="sexCode">sexCode</param>
/// <returns></returns>
private static string GetBodyCode(string areaCode, string birthCode, string randomCode, char sexCode)
{
return areaCode + birthCode + randomCode + sexCode.ToString();
} /// <summary>
/// 检查身份证基本信息
/// </summary>
/// <returns>结果</returns>
private string CheckAndParse()
{
if (string.IsNullOrWhiteSpace(this.Id))
{
return "身份证号码不能为空";
}
if (this.Id.Length == )
{
return this.ParseCardInfo15();
}
if (this.Id.Length == )
{
return this.ParseCardInfo18();
}
return "身份证号码必须为15位或18位";
} /// <summary>
/// 18位身份证
/// </summary>
/// <returns>结果</returns>
private string ParseCardInfo18()
{
const string CardIdParttern = @"(\d{6})(\d{4})(\d{2})(\d{2})(\d{2})(\d{1})([\d,x,X]{1})";
Match match = Regex.Match(this.Id, CardIdParttern);
if (match.Success)
{
this.areaCode = match.Groups[].Value;
string year = match.Groups[].Value;
string month = match.Groups[].Value;
string day = match.Groups[].Value;
this.birthCode = year + month + day;
this.randomCode = match.Groups[].Value;
this.sexCode = char.Parse(match.Groups[].Value);
string verifyCode = match.Groups[].Value.ToUpper(); if (this.ValidateVerifyCode(this.Id.Substring(, ), char.Parse(verifyCode)))
{
try
{
this.Birth = BirthDate.GetBirthDate(year, month, day);
this.Area = AreaCodeMapping.GetArea(this.areaCode);
Sex = GetSex(this.sexCode);
}
catch (System.Exception ex)
{
return ex.Message;
}
return string.Empty;
}
}
return "身份证号码格式错误";
} /// <summary>
/// 验证验证码
/// </summary>
/// <param name="bodyCode">bodyCode</param>
/// <param name="verifyCode">verifyCode</param>
/// <returns>结果</returns>
private bool ValidateVerifyCode(string bodyCode, char verifyCode)
{
char calculatedVerifyCode = this.GetVerifyCode(bodyCode);
return calculatedVerifyCode == verifyCode;
} /// <summary>
/// 15位身份证
/// </summary>
/// <returns>结果</returns>
private string ParseCardInfo15()
{
const string CardIdParttern = @"(\d{6})(\d{2})(\d{2})(\d{2})(\d{2})(\d{1})";
Match match = Regex.Match(this.Id, CardIdParttern);
if (match.Success)
{
this.areaCode = match.Groups[].Value;
string year = match.Groups[].Value;
string month = match.Groups[].Value;
string day = match.Groups[].Value;
this.birthCode = year + month + day;
this.randomCode = match.Groups[].Value;
this.sexCode = char.Parse(match.Groups[].Value); try
{
this.Area = AreaCodeMapping.GetArea(this.areaCode);
this.Birth = BirthDate.GetBirthDate(year, month, day);
Sex = GetSex(this.sexCode);
}
catch (System.Exception ex)
{
return ex.Message;
}
return string.Empty;
}
return "身份证号码格式错误";
} /// <summary>
/// 获取验证码
/// </summary>
/// <param name="bodyCode">bodyCode</param>
/// <returns>结果</returns>
private char GetVerifyCode(string bodyCode)
{
char[] bodyCodeArray = bodyCode.ToCharArray();
////int sum = 0;
////for (int index = 0; index < bodyCodeArray.Length; index++)
////{
//// sum += int.Parse(bodyCodeArray[index].ToString()) * GetWeight(index);
////}
////return this.verifyCodeMapping[sum % 11];
int sum = bodyCodeArray.Select((t, index) => int.Parse(t.ToString()) * GetWeight(index)).Sum();
return this.verifyCodeMapping[sum % ];
} /// <summary>
/// GetWeight
/// </summary>
/// <param name="index">index</param>
/// <returns>index</returns>
private static int GetWeight(int index)
{
return ( << ( - index)) % ;
} /// <summary>
/// 获取性别
/// </summary>
/// <param name="sexCode">性别代码</param>
/// <returns>性别</returns>
private static Sex GetSex(char sexCode)
{
return ((int)sexCode) % == ? Sex.Female : Sex.Male;
}
} /// <summary>
/// 生日
/// </summary>
public struct BirthDate
{
/// <summary>
/// 年
/// </summary>
private readonly string year; /// <summary>
/// 月
/// </summary>
private readonly string month; /// <summary>
/// 日
/// </summary>
private readonly string day; /// <summary>
/// 默认
/// </summary>
public static BirthDate Empty
{
get { return new BirthDate("", "", ""); }
} /// <summary>
/// Initializes a new instance of the <see cref="BirthDate"/> struct.
/// </summary>
/// <param name="year">年</param>
/// <param name="month">月</param>
/// <param name="day">日</param>
public BirthDate(string year, string month, string day)
{
this.year = year;
this.month = month;
this.day = day;
} /// <summary>
/// 获取生日
/// </summary>
/// <param name="year">年</param>
/// <param name="month">月</param>
/// <param name="day">日</param>
/// <returns>结果</returns>
public static BirthDate GetBirthDate(string year, string month, string day)
{
DateTime date;
if (DateTime.TryParse(string.Format("{0}-{1}-{2}", year, month, day), out date))
{
return new BirthDate(year, month, day);
}
throw new System.Exception("日期不存在");
} /// <summary>
/// 年
/// </summary>
public string Year
{
get { return this.year; }
} /// <summary>
/// 年
/// </summary>
public string Month
{
get { return this.month; }
} /// <summary>
/// 日
/// </summary>
public string Day
{
get { return this.day; }
} /// <summary>
/// 重写ToString
/// </summary>
/// <returns>结果</returns>
public override string ToString()
{
return string.Format("{0}年{1}月{2}日", this.year, this.month, this.day);
} /// <summary>
/// 重写ToString
/// </summary>
/// <param name="separator">separator</param>
/// <returns>结果</returns>
public string ToString(string separator)
{
return string.Format("{1}{0}{2}{0}{3}", separator, this.year, this.month, this.day);
}
} /// <summary>
/// 性别
/// </summary>
public enum Sex
{
/// <summary>
/// 男
/// </summary>
Male, /// <summary>
/// 女
/// </summary>
Female
}
}

读取地区代码

 namespace Notify.Solution.Code.IdentityCard
{
/// <summary>
/// 区域配置
/// </summary>
public class AreaCodeMapping
{
/// <summary>
/// 区域字典
/// </summary>
private static readonly Dictionary<string, Area> areas; /// <summary>
/// Initializes static members of the <see cref="AreaCodeMapping"/> class.
/// </summary>
static AreaCodeMapping()
{
areas = LoadAreaInfo();
} /// <summary>
/// 加载信息
/// </summary>
/// <returns>区域信息</returns>
private static Dictionary<string, Area> LoadAreaInfo()
{
XmlDocument doc = LoadXmlDocument("AreaCodes.xml");
XmlNode areasNode = doc.SelectSingleNode("AreaCode");
if (areasNode != null)
{
XmlNodeList provinceNodeList = areasNode.ChildNodes;
return LoadProvinces(provinceNodeList);
} return null;
} /// <summary>
/// 加载XML
/// </summary>
/// <param name="fileName">文件名</param>
/// <returns>XmlDocument</returns>
private static XmlDocument LoadXmlDocument(string fileName)
{
var declaringType = MethodBase.GetCurrentMethod().DeclaringType;
if (declaringType != null)
{
string resourceName = declaringType.Namespace + "." + fileName;
Assembly assembly = Assembly.GetExecutingAssembly();
Stream stream = assembly.GetManifestResourceStream(resourceName);
XmlDocument result = new XmlDocument();
if (stream != null)
{
result.Load(stream);
}
return result;
}
return null;
} /// <summary>
/// 解析XML节点
/// </summary>
/// <param name="provinceNodeList">provinceNodeList</param>
/// <returns>结果</returns>
private static Dictionary<string, Area> LoadProvinces(XmlNodeList provinceNodeList)
{
Dictionary<string, Area> result = new Dictionary<string, Area>();
foreach (XmlNode provinceNode in provinceNodeList)
{
string code = GetAttribute(provinceNode, "code");
string name = GetAttribute(provinceNode, "name");
Area province = new Area(code, name, null);
var cities = LoadCities(province, provinceNode.ChildNodes);
foreach (var city in cities)
{
province.AppendChild(city);
}
result.Add(code, province);
}
return result;
} /// <summary>
/// 加载城市
/// </summary>
/// <param name="province">省</param>
/// <param name="cityNodeList">节点</param>
/// <returns>结果</returns>
private static IEnumerable<Area> LoadCities(Area province, XmlNodeList cityNodeList)
{
List<Area> result = new List<Area>();
if (cityNodeList != null)
{
foreach (XmlNode cityNode in cityNodeList)
{
string code = GetAttribute(cityNode, "code");
string name = GetAttribute(cityNode, "name");
Area city = new Area(code, name, province);
var counties = loadCounties(city, cityNode.ChildNodes);
foreach (var county in counties)
{
city.AppendChild(county);
}
result.Add(city);
}
}
return result;
} /// <summary>
/// 加载区域
/// </summary>
/// <param name="city">市</param>
/// <param name="countyNodeList">节点</param>
/// <returns>结果</returns>
private static IEnumerable<Area> loadCounties(Area city, XmlNodeList countyNodeList)
{
List<Area> result = new List<Area>();
if (countyNodeList != null)
{
foreach (XmlNode countyNode in countyNodeList)
{
string code = GetAttribute(countyNode, "code");
string name = GetAttribute(countyNode, "name");
Area county = new Area(code, name, city);
result.Add(county);
}
}
return result;
} /// <summary>
/// 获取节点属性
/// </summary>
/// <param name="node">node</param>
/// <param name="attributeName">attributeName</param>
/// <returns>结果</returns>
private static string GetAttribute(XmlNode node, string attributeName)
{
if (node.Attributes != null)
{
XmlAttribute attribute = node.Attributes[attributeName];
return attribute == null ? string.Empty : attribute.Value;
}
return string.Empty;
} /// <summary>
/// 获取区域信息
/// </summary>
/// <param name="areaCode">区域代码</param>
/// <returns>结果</returns>
public static AreaInformation GetArea(string areaCode)
{
Area targetArea = null;
if (!string.IsNullOrWhiteSpace(areaCode) && areaCode.Length == )
{
string provinceCode = areaCode.Substring(, );
if (areas.ContainsKey(provinceCode))
{
var province = areas[provinceCode];
string cityCode = areaCode.Substring(, );
if (province.ContainsChild(cityCode))
{
var city = province.GetChild(cityCode);
string countyCode = areaCode.Substring();
if (city.ContainsChild(countyCode))
{
targetArea = city.GetChild(countyCode);
}
else
{
targetArea = city;
}
}
else if (province.ContainsChild(areaCode.Substring()))
{
targetArea = province.GetChild(areaCode.Substring());
}
else
{
targetArea = province;
}
}
}
return targetArea == null ? null : targetArea.ToAreaInformation();
}
} /// <summary>
/// 区域
/// </summary>
public class Area
{
/// <summary>
/// 子区域
/// </summary>
private readonly Dictionary<string, Area> childrenDic; /// <summary>
/// 区域集
/// </summary>
private readonly List<Area> childrenList; /// <summary>
/// Initializes a new instance of the <see cref="Area"/> class.
/// </summary>
/// <param name="code">代码</param>
/// <param name="name">名称</param>
/// <param name="parent">父区域</param>
internal Area(string code, string name, Area parent)
{
this.Info = new CodeNameMapping(code, name);
this.Parent = parent;
this.childrenDic = new Dictionary<string, Area>();
this.childrenList = new List<Area>();
} /// <summary>
/// 代码名称映射信息
/// </summary>
public CodeNameMapping Info
{
get;
private set;
} /// <summary>
/// 父区域
/// </summary>
public Area Parent
{
get;
private set;
} /// <summary>
/// 子区域
/// </summary>
public ReadOnlyCollection<Area> Children
{
get
{
return this.childrenList.AsReadOnly();
}
} /// <summary>
/// 区域集是否包含
/// </summary>
/// <param name="code">代码</param>
/// <returns>结果</returns>
internal bool ContainsChild(string code)
{
return this.childrenDic.ContainsKey(code);
} /// <summary>
/// 获取区域
/// </summary>
/// <param name="code">代码</param>
/// <returns>区域</returns>
internal Area GetChild(string code)
{
return this.childrenDic[code];
} /// <summary>
/// 父亲区域
/// </summary>
internal Area TopParent
{
get
{
return this.Parent == null ? this : this.Parent.TopParent;
}
} /// <summary>
/// 添加子区域
/// </summary>
/// <param name="child">子节点</param>
internal void AppendChild(Area child)
{
if (!this.childrenDic.ContainsKey(child.Info.Code))
{
this.childrenDic.Add(child.Info.Code, child);
this.childrenList.Add(child);
}
} /// <summary>
/// 区域信息转化
/// </summary>
/// <returns>区域信息</returns>
internal AreaInformation ToAreaInformation()
{
CodeNameMapping province = this.TopParent.Info;
CodeNameMapping city = default(CodeNameMapping);
CodeNameMapping county = default(CodeNameMapping);
if (this.Parent != null)
{
if (this.Parent.Info == province)
{
city = this.Info;
}
else
{
city = this.Parent.Info;
county = this.Info;
}
}
return new AreaInformation(province, city, county);
}
} /// <summary>
/// 区域信息
/// </summary>
public class AreaInformation
{
/// <summary>
/// Initializes a new instance of the <see cref="AreaInformation"/> class.
/// </summary>
/// <param name="province">省</param>
/// <param name="city">市</param>
/// <param name="county">区</param>
public AreaInformation(CodeNameMapping province, CodeNameMapping city, CodeNameMapping county)
{
this.Province = province;
this.City = city;
this.County = county;
} /// <summary>
/// 代码
/// </summary>
public string Code
{
get
{
return this.Province.Code + this.City.Code + this.County.Code;
}
} /// <summary>
/// 省
/// </summary>
public CodeNameMapping Province
{
get;
private set;
} /// <summary>
/// 市
/// </summary>
public CodeNameMapping City
{
get;
private set;
} /// <summary>
/// 区
/// </summary>
public CodeNameMapping County
{
get;
private set;
} /// <summary>
/// 名称
/// </summary>
public string FullName
{
get
{
return this.Province.Name + this.City.Name + this.County.Name;
}
} /// <summary>
/// 重写ToString
/// </summary>
/// <returns>结果</returns>
public override string ToString()
{
return this.FullName;
}
} /// <summary>
/// 代码名称映射
/// </summary>
public struct CodeNameMapping
{
/// <summary>
/// 代码
/// </summary>
private readonly string code; /// <summary>
/// 名称
/// </summary>
private readonly string name; /// <summary>
/// Initializes a new instance of the <see cref="CodeNameMapping"/> struct.
/// </summary>
/// <param name="code">代码</param>
/// <param name="name">名称</param>
internal CodeNameMapping(string code, string name)
{
this.code = code;
this.name = name;
} /// <summary>
/// 代码
/// </summary>
public string Code
{
get { return this.code; }
} /// <summary>
/// 名称
/// </summary>
public string Name
{
get { return this.name; }
} /// <summary>
/// 重写比较
/// </summary>
/// <param name="obj">对象</param>
/// <returns>结果</returns>
public override bool Equals(object obj)
{
if (obj != null && obj is CodeNameMapping)
{
return ((CodeNameMapping)obj).Code == this.Code;
}
return false;
} /// <summary>
/// GetHashCode
/// </summary>
/// <returns>HashCode</returns>
public override int GetHashCode()
{
return this.Code.GetHashCode();
} /// <summary>
/// 相等比较器
/// </summary>
/// <param name="left">left</param>
/// <param name="right">right</param>
/// <returns>结果</returns>
public static bool operator ==(CodeNameMapping left, CodeNameMapping right)
{
return left.Code != right.Code;
} /// <summary>
/// 不相等比较器
/// </summary>
/// <param name="left">left</param>
/// <param name="right">right</param>
/// <returns>结果</returns>
public static bool operator !=(CodeNameMapping left, CodeNameMapping right)
{
return left.Code != right.Code;
}
}
}

xml配置文件

下载地址

测试方法

         private static void Validator()
{
// 正确的
Validator v = new Validator("");
var rel = v.Execute(); // 错误的 更改第5位数
Validator v1 = new Validator("");
var rel1 = v1.Execute();
}

js验证点这里

.NET身份证验证的更多相关文章

  1. 身份证验证JS代码

    身份证验证JS程序function checkidcardfun(code) { var city = {11: "北京", 12: "天津", 13: &qu ...

  2. java身份证验证

    import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Calendar; impor ...

  3. jQuery身份证验证插件

    jQuery身份证验证插件 /*! * jQuery isIDCard Plugin v1.0.0 * http://www.cnblogs.com/cssfirefly/p/5629561.html ...

  4. java对身份证验证及正则表达式解析

    原文地址:http://www.cnblogs.com/zhongshengzhen/ java对身份证验证及正则表达式解析 package service; import java.text.Par ...

  5. Jsp注册页面身份证验证

    <!--身份证验证 --><script type="text/javascript">function isCardNo(Idcardnumber) { ...

  6. C#实现中国身份证验证问题

    C#中国身份证验证,包括省份验证和校验码验证,符合GB11643-1999标准...   今天写的 C#中国身份证验证,包括省份验证和校验码验证,符合GB11643-1999标准... 理论部分: 1 ...

  7. 【NumberValidators】大陆身份证验证

    需要说明的是这里的大陆身份证识别并不是公安局联网的识别,而是按国标GB 11643进行的验证,所以其验证结果只能说符合国标规范,但不能保证该身份证一定真实存在,如果你实际需求是希望身份证一定真实存在, ...

  8. Java正则表达式实现港、澳、台身份证验证

    最近由于业务的要求,需要进行港.澳.台人员身份证验证,现在直接上代码,经供参考学习,也为自己积累一些工具类: package com.qiu.validate; public class regexV ...

  9. js邮箱验证,身份证验证,正则表达式

    邮箱验证: html部分: 邮箱验证:<input type="text" id="mail" value="" / onkeyup= ...

  10. Java基础之身份证验证

    //简约版package test; import java.util.Scanner; public class ID { /** * 匹配算法 : 1) 得到17位身份证号码与下面给出的17位 2 ...

随机推荐

  1. python 读取配置文件总是报错 configparser.NoSectionError: No section:

    本文为作者原创,禁止转载,违者必究法律责任!!! python 读取配置文件总是报错 configparser.NoSectionError: No section: 无论是 python2的版本,还 ...

  2. 消息 8101,级别 16,状态 1,第 1 行 仅当使用了列列表并且 IDENTITY_INSERT 为 ON 时,才能为表'ResourceInfo'中的标识列指定显式值。

    问题分析: 意思是你的主键是自动编号类型的,所以不能向该列插入数据. 解决办法: 执行 语句 :SET IDENTITY_INSERT CUSTOMER_TBL ON 然后在向表中插入数据,如inse ...

  3. 去n的第一个出现的1

    实例十八:去n的第一个出现的1 方法:result=n & (n-1) 与实例十七 思路类似.实例十七是不断取1,本例只去最低位. 解释:n 0000 1111n-1 0000 1110&am ...

  4. 概率检索模型:BIM+BM25+BM25F

    1. 概率排序原理 以往的向量空间模型是将query和文档使用向量表示然后计算其内容相似性来进行相关性估计的,而概率检索模型是一种直接对用户需求进行相关性的建模方法,一个query进来,将所有的文档分 ...

  5. KM算法模板

    大白书P248有证明,此处贴出两种复杂度的方案, n^4 大白书P350 n^3 #include <algorithm> #include <string.h> #inclu ...

  6. Python: 从字典中提取子集--字典推导

    问题: 构造一个字典,它是另外一个字典的子集 answer: 最简单的方式是使用字典推导 eg1: 1. >>>prices = {'ACME': 45.23, 'AAPL': 61 ...

  7. emoj表情过滤

    用法:  isEmojiCharacter(input_value)   //  提交时候校验.true:emoj表情   undefined:无   if(isEmojiCharacter(val) ...

  8. Filter过滤器与Session会话跟踪技术

    Filter过滤器 适用场景 1.为web应用程序的新功能建立模型(可被添加到web应用程序中或者从web应用程序中删除而不需要重写基层应用程序代码)2.用户授权Filter:负责检查用户请求,根据请 ...

  9. 20165207 Exp1 PC平台逆向破解

    20165207 Exp1 PC平台逆向破解 0.写在最前面 在做三个实验的前两个的时候,我还没有到博客里去看作业的要求.当时我的主机名是kali5207也就是用我的学号命名的,要求的是姓名全拼命名k ...

  10. sqlserver 判断各种不存在

    判断数据库是否存在 if exists (select * from dbo.sysobjects where name = '数据库名') --drop database [数据库名] 判断表是否存 ...