其他

查找表

class
用于存储大型查找表和字典的容器

该类提供了便捷访问大型查找表和字典的功能,例如利用布隆过滤器处理词形还原数据或分词器例外列表。查找操作可通过Vocab中的vocab.lookups实现,因此既能在管道组件应用前(如分词器和词形还原器中)使用,也能通过doc.vocab.lookups在管道组件内部访问。

Lookups.__init__ 方法

创建一个Lookups对象。

Lookups.__len__ 方法

获取查找表中当前的表格数量。

名称描述

Lookups.__contains__ 方法

检查查找表是否包含指定名称的表格。委托给 Lookups.has_table

名称描述
nameName of the table. str

Lookups.tables 属性

获取lookups中所有表的名称。

名称描述

Lookups.add_table 方法

向查找表添加一个带有可选数据的新表。如果表已存在,则会引发错误。

名称描述
nameUnique name of the table. str
dataOptional data to add to the table. dict

Lookups.get_table 方法

从查找表中获取一个表。如果表不存在则引发错误。

名称描述
nameName of the table. str

Lookups.remove_table 方法

从查找表中移除一个表格。如果表格不存在,将引发错误。

名称描述
nameName of the table to remove. str

Lookups.has_table 方法

检查查找表是否包含指定名称的表格。等同于Lookups.__contains__

名称描述
nameName of the table. str

Lookups.to_bytes 方法

将查找表序列化为字节串。

名称描述

Lookups.from_bytes 方法

从字节串加载查找表。

名称描述
bytes_dataThe data to load from. bytes

Lookups.to_disk 方法

将查找表保存到目录中,文件名为lookups.bin。需要一个目录路径作为参数,如果该目录不存在将会被自动创建。

名称描述
pathA path to a directory, which will be created if it doesn’t exist. Paths may be either strings or Path-like objects. Union[str,Path]

Lookups.from_disk 方法

从包含lookups.bin文件的目录加载查找表。如果文件不存在,将跳过加载。

名称描述
pathA path to a directory. Paths may be either strings or Path-like objects. Union[str,Path]

表格 classordererddict

查找表中的一个表。作为OrderedDict的子类,它实现了更一致和统一的API,并包含布隆过滤器以加速未命中的查找。支持OrderedDict/dict所有其他方法和属性,以及此处列出的自定义方法。获取或设置键的方法同时接受整数和字符串(在添加到表之前会被哈希处理)。

Table.__init__ 方法

初始化一个新表格。

名称描述
nameOptional table name for reference. str

Table.from_dict 类方法

从字典初始化一个新表格。

名称描述
dataThe dictionary. dict
nameOptional table name for reference. str

Table.set 方法

设置一个新的键/值对。字符串键会被哈希处理。等同于table[key] = value

名称描述
keyThe key. Union[str, int]
valueThe value.

Table.to_bytes 方法

将表格序列化为字节串。

名称描述

Table.from_bytes 方法

从字节字符串加载表格。

名称描述
bytes_dataThe data to load. bytes

属性

名称描述
nameTable name. str
default_sizeDefault size of bloom filters if no data is provided. int
bloomThe bloom filters. preshed.BloomFilter