python包实现基于字符串匹配的实体消歧
disamb的Python项目详细描述
分解
- 自由软件:麻省理工学院许可证
- 文档:https://disamby.readthedocs.io。
disamby是一个python包,用于执行基于fuzzy的实体消歧 字符串匹配。
它最适用于那些具有非常相似字符串的实体。 这种消歧算法很好地工作的情况的例子是 公司名称和地址,有排印、替换拼写或复合名称。 其他用例包括识别数据库中可能拼写错误的人。
该算法的工作原理是利用给定单词/令牌的信息量,基于 在整个弦乐语料库中观察到的频率。例如 公司名称的案例信息量不大,但是“所罗门”是,因为前者出现了 重复而第二次很少。
使用这些频率,算法计算给定的一对实例的相似程度 它们是,如果它们高于任意阈值,则它们连接在 “别名图”(即一个实体连接到另一个实体的有向网络 如果它足够相似)。以这种方式连接所有记录之后 返回强连接的实体集[2]。强连接手段 在这种情况下,存在从所有节点到组件内的所有节点的路径。
示例
在项目中使用分解:
import pandas as pd import disamby.preprocessors as pre form disamby import Disamby # create a dataframe with the fields you intend to match on as columns df = pd.DataFrame({ 'name': ['Luca Georger', 'Luca Geroger', 'Adrian Sulzer'], 'address': ['Mira, 34, Augsburg', 'Miri, 34, Augsburg', 'Milano, 34']}, index= ['L1', 'L2', 'O1'] ) # define the pipeline to process the strings, note that the last step must return # a tuple of strings pipeline = [ pre.normalize_whitespace, pre.remove_punctuation, lambda x: pre.trigram(x) + pre.split_words(x) # any python function is allowed ] # instantiate the disamby object, it applies the given pre-processing pipeline and # computes their frequency. dis = Disamby(df, pipeline) # let disamby compute disambiguated sets. Node that a threshold must be given or it # defaults to 0. dis.disambiguated_sets(threshold=0.5) [{'L2', 'L1'}, {'O1'}] # output # To check if the sets are accurate you can get the rows from the # pandas dataframe like so: df.loc[['L2', 'L1']]
安装
要安装disamby,请在终端中运行此命令:
$ pip install disamby
这是安装disamby的首选方法,因为它总是安装最新的稳定版本。 如果您没有安装pip,这个Python installation guide可以指导您 你完成了整个过程。
您也可以从源代码安装它,如下所示 可从Github repo下载要分解的源代码。 您可以克隆公共存储库:
$ git clone git://github.com/verginer/disamby
或者下载tarball:
$ curl -OL https://github.com/verginer/disamby/tarball/master
一旦您有了源代码的副本,就可以使用以下命令安装它:
$ python setup.py install
学分
我从“搜索引擎-一个 根据模糊标准进行匹配”作者:Thorsten Doherr,来自CISS[1]暑期学校,2017年
[1] | http://www.euro-ciss.eu/ciss/home.html |
[2] | https://en.wikipedia.org/wiki/Strongly_connected_component |
历史记录
0.2.3(2017-07-01)
- 修复了破坏pypi显示的格式设置
0.2.2(2017-06-30)
- 使用最少文档的工作版本
- 使用多字段匹配
- 自动执行从字符串预处理到 识别强连接组件
0.1.0(2017-06-24)
- pypi上的第一个版本。