gliner.decoding.trie.python_labels_trie module¶

class gliner.decoding.trie.python_labels_trie.Node(key, permanent)[source]¶

Bases: object

__init__(key, permanent)[source]¶
get_key()[source]¶
is_permanent()[source]¶
add_child(child)[source]¶
get_child(child_key)[source]¶
get_children()[source]¶
has_children()[source]¶
delete_child(child_key)[source]¶
class gliner.decoding.trie.python_labels_trie.Trie(init_value=None)[source]¶

Bases: object

__init__(init_value=None)[source]¶
add_batch(entities, permanent)[source]¶
add(entity, permanent)[source]¶
get_possible_next_keys(entity)[source]¶
get_branch(entity)[source]¶
remove_batch(entities)[source]¶
remove_entity(entity)[source]¶
class gliner.decoding.trie.python_labels_trie.LabelsTrie(entities=None)[source]¶

Bases: object

Initialize the trie.

Parameters:

entities (List[List[int]] | None) – Optional initial list of token sequences to add to the trie. If None or empty, creates an empty trie.

__init__(entities=None)[source]¶

Initialize the trie.

Parameters:

entities (List[List[int]] | None) – Optional initial list of token sequences to add to the trie. If None or empty, creates an empty trie.

add_batch(entities)[source]¶

Add multiple token sequences to the trie.

Parameters:

entities (List[List[int]]) – List of token sequences to add.

add(tokens)[source]¶

Add a single token sequence to the trie.

Parameters:

tokens (List[int]) – Token sequence to add.

get(prefix)[source]¶

Get possible next tokens after a given prefix.

Parameters:

prefix (List[int]) – The token sequence to search for.

Returns:

List of possible next token IDs.

Return type:

List[int]

remove_batch(entities)[source]¶

Remove multiple token sequences from the trie.

Parameters:

entities (List[List[int]]) – List of token sequences to remove.

remove_entity(tokens)[source]¶

Remove a single token sequence from the trie.

Parameters:

tokens (List[int]) – Token sequence to remove.