symbol_table
Classes
SymbolTable
SymbolTable
class. This class wraps the SymbolTable
struct.
Source code in rustfst/symbol_table.py
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 |
|
Functions
__init__(ptr = None)
Creates an empty SymbolTable
.
Source code in rustfst/symbol_table.py
15 16 17 18 19 20 21 22 23 24 25 26 27 |
|
add_symbol(symbol: str) -> int
Adds a symbol to the table and returns the index.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
symbol |
str
|
A symbol unicode string. |
required |
Returns:
Type | Description |
---|---|
int
|
The integer key of the new symbol. |
Source code in rustfst/symbol_table.py
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
|
add_table(syms: SymbolTable)
This method merges another symbol table into the current table. All key values will be offset by the current available key.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
syms |
SymbolTable
|
A |
required |
Source code in rustfst/symbol_table.py
50 51 52 53 54 55 56 57 58 59 |
|
copy() -> SymbolTable
Returns:
Type | Description |
---|---|
SymbolTable
|
A mutable copy of the |
Source code in rustfst/symbol_table.py
61 62 63 64 65 66 67 68 69 70 71 72 |
|
find(key: Union[int, str]) -> Union[int, str]
Given a symbol or index, finds the other one. This method returns the index associated with a symbol key, or the symbol associated with a index key.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
key |
Union[int, str]
|
Either a string or an index. |
required |
Returns:
Type | Description |
---|---|
Union[int, str]
|
If key is a string, the associated index; if key is an integer, the associated symbol. |
Raises:
Type | Description |
---|---|
KeyError
|
Key not found. |
Source code in rustfst/symbol_table.py
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
|
member(key: Union[int, str]) -> bool
Given a symbol or index, returns whether it is found in the table. This method returns a boolean indicating whether the given symbol or index is present in the table. If one intends to perform subsequent lookup, it is better to simply call the find method, catching the KeyError.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
key |
Union[int, str]
|
Either a string or an index. |
required |
Returns:
Type | Description |
---|---|
bool
|
Whether or not the key is present (as a string or a index) in the table. |
Source code in rustfst/symbol_table.py
111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 |
|
num_symbols() -> int
Returns:
Type | Description |
---|---|
int
|
The number of symbols in the symbol table. |
Source code in rustfst/symbol_table.py
142 143 144 145 146 147 148 149 150 151 152 |
|
read(filename: Union[str, Path]) -> SymbolTable
classmethod
Reads symbol table from binary file. This class method creates a new SymbolTable from a symbol table binary file.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
filename |
Union[str, Path]
|
The string location of the input binary file. |
required |
Returns:
Type | Description |
---|---|
SymbolTable
|
A new SymbolTable instance. |
See also: SymbolTable.read_fst
, SymbolTable.read_text
.
Source code in rustfst/symbol_table.py
154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 |
|
read_text(filename: Union[str, Path]) -> SymbolTable
classmethod
Reads symbol table from text file. This class method creates a new SymbolTable from a symbol table text file.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
filename |
Union[str, Path]
|
The string location of the input text file. |
required |
Returns:
Type | Description |
---|---|
SymbolTable
|
A new SymbolTable instance. |
See also: SymbolTable.read
, SymbolTable.read_fst
.
Source code in rustfst/symbol_table.py
175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 |
|
write(filename: Union[str, Path])
Serializes symbol table to a file. This methods writes the SymbolTable to a file in binary format.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
filename |
Union[str, Path]
|
The string location of the output file. |
required |
Raises:
Type | Description |
---|---|
FstIOError
|
Write failed. |
Source code in rustfst/symbol_table.py
197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 |
|
write_text(filename: Union[str, Path])
Writes symbol table to text file. This method writes the SymbolTable to a file in human-readable format.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
filename |
Union[str, Path]
|
The string location of the output file. |
required |
Raises:
Type | Description |
---|---|
FstIOError
|
Write failed. |
Source code in rustfst/symbol_table.py
213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 |
|
equals(other: SymbolTable) -> bool
Check if this SymbolTable is equal to the other
Parameters:
Name | Type | Description | Default |
---|---|---|---|
other |
SymbolTable
|
SymbolTable instance |
required |
Returns:
Type | Description |
---|---|
bool
|
bool |
Source code in rustfst/symbol_table.py
229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 |
|
__eq__(other: SymbolTable) -> bool
Check if this SymbolTable
is equal to the other
Parameters:
Name | Type | Description | Default |
---|---|---|---|
other |
SymbolTable
|
SymbolTable instance |
required |
Returns:
Type | Description |
---|---|
bool
|
bool |
Source code in rustfst/symbol_table.py
246 247 248 249 250 251 252 253 254 255 |
|
__iter__() -> SymbolTableIterator
Returns an Iterator over the SymbolTable.
Returns:
Type | Description |
---|---|
SymbolTableIterator
|
An iterator over the SymbolTable. |
Source code in rustfst/symbol_table.py
257 258 259 260 261 262 263 |
|
from_symbols(symbols: List[str]) -> SymbolTable
classmethod
Constructs a SymbolTable from list of strings.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
symbols |
List[str]
|
List of symbols |
required |
Returns:
Type | Description |
---|---|
SymbolTable
|
A new |
Source code in rustfst/symbol_table.py
265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 |
|
SymbolTableIterator
Iterator on a SymbolTable. Allows retrieving all the symbols along with their corresponding labels.
Source code in rustfst/symbol_table.py
287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 |
|
Functions
__init__(symbol_table: SymbolTable)
Constructs an iterator from the Symboltable
.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
symbol_table |
SymbolTable
|
required |
Source code in rustfst/symbol_table.py
292 293 294 295 296 297 298 299 300 |
|
__next__() -> Tuple[int, str]
Iterator over the symbols in the SymbolTable
.
Returns:
Type | Description |
---|---|
Tuple[int, str]
|
A pair label (int) and symbol (str). |
Source code in rustfst/symbol_table.py
302 303 304 305 306 307 308 309 310 311 312 |
|