其他

StringStore

class

通过64位哈希值查找字符串。从v2.0开始,spaCy使用哈希值替代整数ID。这确保了字符串始终映射到相同的ID,即使来自不同的StringStores

StringStore.__init__ 方法

创建StringStore

名称描述
stringsA sequence of strings to add to the store. Optional[Iterable[str]]

StringStore.__len__ 方法

获取存储中的字符串数量。

名称描述

StringStore.__getitem__ 方法

从给定哈希中检索字符串,反之亦然。

名称描述
string_or_idThe value to encode. Union[bytes, str, int]

StringStore.__contains__ 方法

检查字符串是否存在于存储中。

名称描述
stringThe string to check. str

StringStore.__iter__ 方法

按顺序遍历存储中的字符串。请注意,新初始化的存储始终会在位置0包含一个空字符串""

名称描述

StringStore.add 方法

StringStore添加一个字符串。

名称描述
stringThe string to add. str

StringStore.to_disk 方法

将当前状态保存到目录中。

名称描述
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]

StringStore.from_disk 方法

从目录加载状态。就地修改对象并返回它。

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

StringStore.to_bytes 方法

将当前状态序列化为二进制字符串。

名称描述

StringStore.from_bytes 方法

从二进制字符串加载状态。

名称描述
bytes_dataThe data to load from. bytes

实用工具

strings.hash_string 函数

获取给定字符串的64位哈希值。

名称描述
stringThe string to hash. str