StringStore
通过64位哈希值查找字符串。从v2.0开始,spaCy使用哈希值替代整数ID。这确保了字符串始终映射到相同的ID,即使来自不同的StringStores。
StringStore.__init__ 方法
创建StringStore。
| 名称 | 描述 |
|---|---|
strings | A sequence of strings to add to the store. Optional[Iterable[str]] |
StringStore.__len__ 方法
获取存储中的字符串数量。
| 名称 | 描述 |
|---|---|
| 返回值 | 存储中的字符串数量。int |
StringStore.__getitem__ 方法
从给定哈希中检索字符串,反之亦然。
| 名称 | 描述 |
|---|---|
string_or_id | The value to encode. Union[bytes, str, int] |
| 返回值 | 要获取的值。Union[str, int] |
StringStore.__contains__ 方法
检查字符串是否存在于存储中。
| 名称 | 描述 |
|---|---|
string | The string to check. str |
| 返回值 | 存储是否包含该字符串。bool |
StringStore.__iter__ 方法
按顺序遍历存储中的字符串。请注意,新初始化的存储始终会在位置0包含一个空字符串""。
| 名称 | 描述 |
|---|---|
| YIELDS | 存储中的一个字符串。str |
StringStore.add 方法
向StringStore添加一个字符串。
| 名称 | 描述 |
|---|---|
string | The string to add. str |
| 返回值 | 字符串的哈希值。int |
StringStore.to_disk 方法
将当前状态保存到目录中。
| 名称 | 描述 |
|---|---|
path | A 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 方法
从目录加载状态。就地修改对象并返回它。
| 名称 | 描述 |
|---|---|
path | A path to a directory. Paths may be either strings or Path-like objects. Union[str,Path] |
| RETURNS | The modified StringStore object. StringStore |
StringStore.to_bytes 方法
将当前状态序列化为二进制字符串。
| 名称 | 描述 |
|---|---|
| RETURNS | The serialized form of the StringStore object. bytes |
StringStore.from_bytes 方法
从二进制字符串加载状态。
| 名称 | 描述 |
|---|---|
bytes_data | The data to load from. bytes |
| RETURNS | The StringStore object. StringStore |
实用工具
strings.hash_string 函数
获取给定字符串的64位哈希值。
| 名称 | 描述 |
|---|---|
string | The string to hash. str |
| 返回值 | 哈希值。int |