From 26638249120e37a2c7e72be5bfcfcccfd419d793 Mon Sep 17 00:00:00 2001 From: David Huggins-Daines Date: Fri, 16 Aug 2024 16:10:17 -0400 Subject: [PATCH] fix(docs): fix all the docstrings. Up-to-date versions of mkdocstrings now are stricter about dostring syntax and *require* blank lines between sections. See: https://mkdocstrings.github.io/griffe/reference/docstrings/#google-syntax --- rustfst-python/rustfst/algorithms/__init__.py | 9 ++++ rustfst-python/rustfst/algorithms/compose.py | 4 ++ rustfst-python/rustfst/algorithms/concat.py | 3 ++ .../rustfst/algorithms/determinize.py | 5 ++ .../rustfst/algorithms/isomorphic.py | 2 + rustfst-python/rustfst/algorithms/minimize.py | 4 ++ rustfst-python/rustfst/algorithms/optimize.py | 2 + rustfst-python/rustfst/algorithms/project.py | 2 + rustfst-python/rustfst/algorithms/reverse.py | 2 + .../rustfst/algorithms/rm_epsilon.py | 2 + .../rustfst/algorithms/shortest_path.py | 4 ++ rustfst-python/rustfst/algorithms/top_sort.py | 1 + .../rustfst/algorithms/tr_unique.py | 1 + rustfst-python/rustfst/algorithms/union.py | 5 +- rustfst-python/rustfst/fst/__init__.py | 27 ++++++++++ rustfst-python/rustfst/fst/const_fst.py | 14 +++++ rustfst-python/rustfst/fst/vector_fst.py | 53 +++++++++++++++++++ .../rustfst/string_paths_iterator.py | 1 + rustfst-python/rustfst/symbol_table.py | 25 +++++++++ rustfst-python/rustfst/tr.py | 1 + rustfst-python/rustfst/trs.py | 2 + rustfst-python/rustfst/weight.py | 2 + 22 files changed, 170 insertions(+), 1 deletion(-) diff --git a/rustfst-python/rustfst/algorithms/__init__.py b/rustfst-python/rustfst/algorithms/__init__.py index 3a1b3336b..ab246a8dd 100644 --- a/rustfst-python/rustfst/algorithms/__init__.py +++ b/rustfst-python/rustfst/algorithms/__init__.py @@ -18,13 +18,16 @@ def acceptor( ) -> VectorFst: """ Creates an acceptor from a string. + This function creates a FST which accepts its input with a fixed weight (defaulting to semiring One). + Args: astring: The input string. weight: A Weight or weight string indicating the desired path weight. If omitted or null, the path weight is set to semiring One. symbol_table: SymbolTable to be used to encode the string. + Returns: An FST acceptor. """ @@ -52,14 +55,17 @@ def transducer( ) -> VectorFst: """ Creates a transducer from a pair of strings or acceptor FSTs. + This function creates a FST which transduces from the first string to the second with a fixed weight (defaulting to semiring One). + Args: istring: The input string ostring: The output string weight: A Weight as float. isymt: SymbolTable to be used to encode the string. osymt: SymbolTable to be used to encode the string. + Returns: An FST transducer. """ @@ -85,10 +91,13 @@ def transducer( def epsilon_machine(weight: Optional[float] = None) -> VectorFst: """ Constructs a single-state, no-arc FST accepting epsilon. + This function creates an unweighted FST with a single state which is both initial and final. + Args: weight: A Weight. Default semiring One. + Returns: An FST. """ diff --git a/rustfst-python/rustfst/algorithms/compose.py b/rustfst-python/rustfst/algorithms/compose.py index c145d5071..80161da9b 100644 --- a/rustfst-python/rustfst/algorithms/compose.py +++ b/rustfst-python/rustfst/algorithms/compose.py @@ -110,9 +110,11 @@ def __del__(self): def compose(fst: VectorFst, other_fst: VectorFst) -> VectorFst: """ Compute the composition of two FSTs. + Args: fst: Left fst. other_fst: Right fst. + Returns: Resulting fst. """ @@ -130,10 +132,12 @@ def compose_with_config( ) -> VectorFst: """ Compute the composition of two FSTs parametrized with a config. + Args: fst: Left fst. other_fst: Right fst. config: Config parameters of the composition. + Returns: Resulting fst. """ diff --git a/rustfst-python/rustfst/algorithms/concat.py b/rustfst-python/rustfst/algorithms/concat.py index 592a74a67..718c652a6 100644 --- a/rustfst-python/rustfst/algorithms/concat.py +++ b/rustfst-python/rustfst/algorithms/concat.py @@ -13,9 +13,11 @@ def concat(fst: VectorFst, other_fst: VectorFst) -> VectorFst: """ Compute the concatenation of two Fsts. + Args: fst: Left fst. other_fst: Right fst. + Returns: Resulting fst. """ @@ -30,6 +32,7 @@ def concat(fst: VectorFst, other_fst: VectorFst) -> VectorFst: def concat_list(fsts: List[VectorFst]) -> VectorFst: """ Compute the concatenation of a list of Fsts. + Args: fsts: List of Fsts to concatenated diff --git a/rustfst-python/rustfst/algorithms/determinize.py b/rustfst-python/rustfst/algorithms/determinize.py index caa52b230..cc0084628 100644 --- a/rustfst-python/rustfst/algorithms/determinize.py +++ b/rustfst-python/rustfst/algorithms/determinize.py @@ -41,6 +41,7 @@ class DeterminizeConfig: def __init__(self, det_type: DeterminizeType, delta: Optional[float] = None): """ Creates the configuration object. + Args: det_type: Type of determinization to perform. delta: @@ -62,8 +63,10 @@ def __init__(self, det_type: DeterminizeType, delta: Optional[float] = None): def determinize(fst: VectorFst) -> VectorFst: """ Make an Fst deterministic + Args: fst: The Fst to make deterministic. + Returns: The resulting Fst. """ @@ -78,9 +81,11 @@ def determinize(fst: VectorFst) -> VectorFst: def determinize_with_config(fst: VectorFst, config: DeterminizeConfig) -> VectorFst: """ Make an Fst deterministic + Args: fst: The Fst to make deterministic. config: Configuration of the determinization algorithm to use. + Returns: The resulting Fst. """ diff --git a/rustfst-python/rustfst/algorithms/isomorphic.py b/rustfst-python/rustfst/algorithms/isomorphic.py index 29a7d5e56..e666bf2b5 100644 --- a/rustfst-python/rustfst/algorithms/isomorphic.py +++ b/rustfst-python/rustfst/algorithms/isomorphic.py @@ -11,9 +11,11 @@ def isomorphic(fst: VectorFst, other_fst: VectorFst) -> bool: """ Check if two Fsts are isomorphic. + Args: fst: First Fst. other_fst: Second Fst. + Returns: Whether both Fsts are equal. """ diff --git a/rustfst-python/rustfst/algorithms/minimize.py b/rustfst-python/rustfst/algorithms/minimize.py index c04297d87..0a751930f 100644 --- a/rustfst-python/rustfst/algorithms/minimize.py +++ b/rustfst-python/rustfst/algorithms/minimize.py @@ -32,8 +32,10 @@ def __init__(self, delta=None, allow_nondet=False): def minimize(fst: VectorFst) -> VectorFst: """ Minimize an FST in-place + Params: fst: Fst + Returns: fst """ @@ -47,9 +49,11 @@ def minimize(fst: VectorFst) -> VectorFst: def minimize_with_config(fst: VectorFst, config: MinimizeConfig) -> VectorFst: """ Minimize an FST in-place + Params: fst: Fst config: Configuration + Returns: fst """ diff --git a/rustfst-python/rustfst/algorithms/optimize.py b/rustfst-python/rustfst/algorithms/optimize.py index 13b8bd168..bd0a51545 100644 --- a/rustfst-python/rustfst/algorithms/optimize.py +++ b/rustfst-python/rustfst/algorithms/optimize.py @@ -13,6 +13,7 @@ def optimize(fst: VectorFst): """ Optimize an fst in-place + Args: fst: Fst to optimize. """ @@ -24,6 +25,7 @@ def optimize(fst: VectorFst): def optimize_in_log(fst: VectorFst): """ Optimize an fst in-place in the log semiring. + Args: fst: Fst to optimize. """ diff --git a/rustfst-python/rustfst/algorithms/project.py b/rustfst-python/rustfst/algorithms/project.py index 75926cb49..f7e00d30d 100644 --- a/rustfst-python/rustfst/algorithms/project.py +++ b/rustfst-python/rustfst/algorithms/project.py @@ -27,9 +27,11 @@ class ProjectType(Enum): def project(fst: VectorFst, proj_type: ProjectType) -> VectorFst: """ Convert a Fst to an acceptor using input or output labels. + Args: fst: Fst on which to apply the algorithm. proj_type: Whether to replace input labels or output labels. + Returns: The resulting Fst. """ diff --git a/rustfst-python/rustfst/algorithms/reverse.py b/rustfst-python/rustfst/algorithms/reverse.py index ba6ddee90..fa944f698 100644 --- a/rustfst-python/rustfst/algorithms/reverse.py +++ b/rustfst-python/rustfst/algorithms/reverse.py @@ -15,8 +15,10 @@ def reverse(fst: VectorFst) -> VectorFst: Not to be confused with `inverse`, which does something totally different! + Args: fst: Fst to reverse + Returns: Newly created, reversed Fst. """ diff --git a/rustfst-python/rustfst/algorithms/rm_epsilon.py b/rustfst-python/rustfst/algorithms/rm_epsilon.py index f619ab185..226c277aa 100644 --- a/rustfst-python/rustfst/algorithms/rm_epsilon.py +++ b/rustfst-python/rustfst/algorithms/rm_epsilon.py @@ -11,8 +11,10 @@ def rm_epsilon(fst: VectorFst) -> VectorFst: """ Return an equivalent FST with epsilon transitions removed. + Args: fst: Fst + Returns: Newly created FST with epsilon transitions removed. """ diff --git a/rustfst-python/rustfst/algorithms/shortest_path.py b/rustfst-python/rustfst/algorithms/shortest_path.py index ac8d4561d..c3ca8f4de 100644 --- a/rustfst-python/rustfst/algorithms/shortest_path.py +++ b/rustfst-python/rustfst/algorithms/shortest_path.py @@ -41,8 +41,10 @@ def __init__( def shortestpath(fst: VectorFst) -> VectorFst: """ Construct a FST containing the shortest path of the input FST + Args: fst: Fst + Returns: Newly-created FST containing only the shortest path of the input FST. """ @@ -58,9 +60,11 @@ def shortestpath(fst: VectorFst) -> VectorFst: def shortestpath_with_config(fst: VectorFst, config: ShortestPathConfig) -> VectorFst: """ Construct a FST containing the shortest path of the input FST + Args: fst: Fst config: Configuration for shortest-path operation. + Returns: Newly-created FST containing only the shortest path of the input FST. """ diff --git a/rustfst-python/rustfst/algorithms/top_sort.py b/rustfst-python/rustfst/algorithms/top_sort.py index cdbf1c368..46d8bfa4e 100644 --- a/rustfst-python/rustfst/algorithms/top_sort.py +++ b/rustfst-python/rustfst/algorithms/top_sort.py @@ -24,6 +24,7 @@ def top_sort(fst: VectorFst) -> VectorFst: Args: fst: Fst to top_sort. + Returns: Equivalent top sorted Fst. Modification also happens in-place. """ diff --git a/rustfst-python/rustfst/algorithms/tr_unique.py b/rustfst-python/rustfst/algorithms/tr_unique.py index a7d3c210d..836fba708 100644 --- a/rustfst-python/rustfst/algorithms/tr_unique.py +++ b/rustfst-python/rustfst/algorithms/tr_unique.py @@ -11,6 +11,7 @@ def tr_unique(fst: VectorFst): """ Keep a single instance of trs leaving the same state, going to the same state and with the same input labels, output labels and weight. + Args: fst: Fst to modify """ diff --git a/rustfst-python/rustfst/algorithms/union.py b/rustfst-python/rustfst/algorithms/union.py index e3407d28e..5431dc103 100644 --- a/rustfst-python/rustfst/algorithms/union.py +++ b/rustfst-python/rustfst/algorithms/union.py @@ -12,7 +12,9 @@ def union(fst: VectorFst, other_fst: VectorFst) -> VectorFst: """ - Performs the union of two wFSTs. If A transduces string `x` to `y` with weight `a` + Performs the union of two wFSTs. + + If A transduces string `x` to `y` with weight `a` and `B` transduces string `w` to `v` with weight `b`, then their union transduces `x` to `y` with weight `a` and `w` to `v` with weight `b`. @@ -32,6 +34,7 @@ def union(fst: VectorFst, other_fst: VectorFst) -> VectorFst: Args: fst: other_fst: + Returns: The resulting Fst. diff --git a/rustfst-python/rustfst/fst/__init__.py b/rustfst-python/rustfst/fst/__init__.py index 9a05b8b45..ac25a2b56 100644 --- a/rustfst-python/rustfst/fst/__init__.py +++ b/rustfst-python/rustfst/fst/__init__.py @@ -23,6 +23,7 @@ def __init__(self, ptr, isymt=None, osymt=None): def start(self) -> Optional[int]: """ Returns the start state. + Returns : The start state or None. """ @@ -38,10 +39,13 @@ def start(self) -> Optional[int]: def final(self, state: int) -> Optional[float]: """ Returns the final weight of a state. + Args: state: The integer index of a state. + Returns: The final Weight of that state. + Raises: Exception: If State index out of range. """ @@ -60,12 +64,16 @@ def final(self, state: int) -> Optional[float]: def num_trs(self, state: int) -> int: """ Returns the number of trs leaving a state. + Args: state: The integer index of a state. + Returns: The number of trs leaving that state. + Raises: Exception: If State index out of range. + See also: `num_states`. """ num_trs = ctypes.c_size_t() @@ -79,10 +87,13 @@ def num_trs(self, state: int) -> int: def trs(self, state: int) -> TrsIterator: """ Returns an iterator over trs leaving the specified state. + Args: state: The source state ID. + Returns: An TrsIterator. + See also: `mutable_trs`, `states`. """ return TrsIterator(self, state) @@ -90,8 +101,10 @@ def trs(self, state: int) -> TrsIterator: def is_final(self, state_id: int) -> bool: """ Check if a state is final + Args : state_id: + Returns : bool """ @@ -107,8 +120,10 @@ def is_final(self, state_id: int) -> bool: def is_start(self, state_id: int) -> bool: """ Check if a state is a start state. + Args : state_id: Integer index of the state. + Returns : bool """ @@ -124,8 +139,10 @@ def is_start(self, state_id: int) -> bool: def input_symbols(self) -> Optional[SymbolTable]: """ Returns the Fst's input symbol table, or None if none is present. + Returns : The Fst's input symbol table, or None if none is present. + See also: `output_symbols`. """ if self._input_symbols: @@ -143,8 +160,10 @@ def input_symbols(self) -> Optional[SymbolTable]: def output_symbols(self) -> Optional[SymbolTable]: """ Returns the Fst's output symbol table, or None if none is present. + Returns : The Fst's output symbol table, or None if none is present. + See also: `input_symbols`. """ if self._output_symbols: @@ -164,10 +183,13 @@ def set_input_symbols(self, syms: Optional[SymbolTable]) -> Fst: """ Sets the input symbol table. Passing None as a value will delete the input symbol table. + Args: syms: A SymbolTable. + Returns: self. + See also: `set_output_symbols`. """ if syms is None: @@ -192,10 +214,13 @@ def set_output_symbols(self, syms: Optional[SymbolTable]) -> Fst: """ Sets the output symbol table. Passing None as a value will delete the output symbol table. + Args: syms: A SymbolTable. + Returns: self. + See also: `set_input_symbols`. """ if syms is None: @@ -221,6 +246,7 @@ def remove_input_symbols(self, symbols: list[int]) -> Fst: """ Args: symbols: List[int] + Returns: self. """ @@ -236,6 +262,7 @@ def remove_output_symbols(self, symbols: list[int]) -> Fst: """ Args: symbols: List[int] + Returns: self. """ diff --git a/rustfst-python/rustfst/fst/const_fst.py b/rustfst-python/rustfst/fst/const_fst.py index d4607a666..8a1690630 100644 --- a/rustfst-python/rustfst/fst/const_fst.py +++ b/rustfst-python/rustfst/fst/const_fst.py @@ -32,13 +32,16 @@ def draw( ): """ Writes out the FST in Graphviz text format. + This method writes out the FST in the dot graph description language. The graph can be rendered using the `dot` executable provided by Graphviz. + Args: filename: The string location of the output dot/Graphviz file. isymbols: An optional symbol table used to label input symbols. osymbols: An optional symbol table used to label output symbols. drawing_config: Drawing configuration to use. + See also: `text`. """ @@ -90,10 +93,13 @@ def draw( def read(cls, filename: Union[str, Path]) -> ConstFst: """ Read a Fst at a given path. + Args: filename: The string location of the input file. + Returns: An FST. + Raises: ValueError: Read failed. """ @@ -110,10 +116,13 @@ def read(cls, filename: Union[str, Path]) -> ConstFst: def from_vector_fst(cls, fst: VectorFst) -> ConstFst: """ Converts a given `VectorFst` to `ConstFst` + Args: fst: The `VectorFst` that should be converted + Returns: A `ConstFst` + Raises: ValueError: Conversion failed """ @@ -127,9 +136,12 @@ def from_vector_fst(cls, fst: VectorFst) -> ConstFst: def write(self, filename: Union[str, Path]): """ Serializes FST to a file. + This method writes the FST to a file in binary format. + Args: filename: The string location of the output file. + Raises: ValueError: Write failed. """ @@ -140,8 +152,10 @@ def write(self, filename: Union[str, Path]): def equals(self, other: Fst) -> bool: """ Check if this Fst is equal to the other + Args : other: Fst instance + Returns: bool """ diff --git a/rustfst-python/rustfst/fst/vector_fst.py b/rustfst-python/rustfst/fst/vector_fst.py index 06f5b5919..77ed90f42 100644 --- a/rustfst-python/rustfst/fst/vector_fst.py +++ b/rustfst-python/rustfst/fst/vector_fst.py @@ -67,13 +67,17 @@ def add_tr(self, state: int, tr: Tr) -> Fst: """ Adds a new tr to the FST and return self. Note the tr should be considered consumed and is not safe to use it after. + Args: state: The integer index of the source state. tr: The tr to add. + Returns: self. + Raises: SnipsFstException: If State index out of range. + See also: `add_state`. """ ret_code = lib.vec_fst_add_tr(self.ptr, ctypes.c_size_t(state), tr.ptr) @@ -85,8 +89,10 @@ def add_tr(self, state: int, tr: Tr) -> Fst: def add_state(self) -> int: """ Adds a new state to the FST and returns the state ID. + Returns: The integer index of the new state. + See also: `add_tr`, `set_start`, `set_final`. """ state_id = ctypes.c_size_t() @@ -100,12 +106,15 @@ def add_state(self) -> int: def set_final(self, state: int, weight: Union[float, None] = None): """ Sets the final weight for a state. + Args: state: The integer index of a state. weight: A float indicating the desired final weight; if omitted, it is set to semiring One. + Raises: ValueError: State index out of range or Incompatible or invalid weight. + See also: `set_start`. """ if weight is None: @@ -121,8 +130,10 @@ def set_final(self, state: int, weight: Union[float, None] = None): def unset_final(self, state: int): """ Unset the final weight of a state. As a result, the state is no longer final. + Args: state: The integer index of a state + Raises: ValueError: State index out of range. """ @@ -134,10 +145,13 @@ def unset_final(self, state: int): def mutable_trs(self, state: int) -> MutableTrsIterator: """ Returns a mutable iterator over trs leaving the specified state. + Args: state: The source state ID. + Returns: A MutableTrsIterator. + See also: `trs`, `states`. """ return MutableTrsIterator(self, state) @@ -153,6 +167,7 @@ def delete_states(self): def num_states(self) -> int: """ Returns the number of states. + Returns: Number of states present in the Fst. """ @@ -166,10 +181,13 @@ def num_states(self) -> int: def set_start(self, state: int): """ Sets a state to be the initial state state. + Args: state: The integer index of a state. + Raises: ValueError: If State index out of range. + See also: `set_final`. """ state_id = ctypes.c_size_t(state) @@ -180,8 +198,10 @@ def set_start(self, state: int): def states(self) -> StateIterator: """ Returns an iterator over all states in the FST. + Returns: A StateIterator object for the FST. + See also: `trs`, `mutable_trs`. """ return StateIterator(self) @@ -253,13 +273,16 @@ def draw( ): """ Writes out the FST in Graphviz text format. + This method writes out the FST in the dot graph description language. The graph can be rendered using the `dot` executable provided by Graphviz. + Args: filename: The string location of the output dot/Graphviz file. isymbols: An optional symbol table used to label input symbols. osymbols: An optional symbol table used to label output symbols. drawing_config: Drawing configuration to use. + See also: `text`. """ @@ -311,10 +334,13 @@ def draw( def read(cls, filename: Union[str, Path]) -> VectorFst: """ Read a Fst at a given path. + Args: filename: The string location of the input file. + Returns: An Fst. + Raises: ValueError: Read failed. """ @@ -330,9 +356,12 @@ def read(cls, filename: Union[str, Path]) -> VectorFst: def write(self, filename: Union[str, Path]): """ Serializes FST to a file. + This method writes the FST to a file in vector binary format. + Args: filename: The string location of the output file. + Raises: ValueError: Write failed. """ @@ -344,6 +373,7 @@ def write(self, filename: Union[str, Path]): def from_bytes(cls, data: bytes) -> VectorFst: """ Load a `VectorFst` from a sequence of bytes. + Args: data: Sequence of bytes. @@ -367,6 +397,7 @@ class BytesArray(ctypes.Structure): def to_bytes(self) -> bytes: """ Turns the `VectorFst` into bytes. + Returns: Sequence of bytes. """ @@ -390,8 +421,10 @@ class BytesArray(ctypes.Structure): def equals(self, other: Fst) -> bool: """ Check if this Fst is equal to the other. + Args: other: Fst instance + Returns: Whether both Fst are equals. """ @@ -421,9 +454,11 @@ def compose( """ Compute composition of this Fst with another Fst, returning the resulting Fst. + Args: other: Fst to compose with. config: Config parameters of the composition. + Returns: The composed Fst. """ @@ -438,6 +473,7 @@ def concat(self, other: VectorFst) -> VectorFst: """ Compute Fst Concatenation of this Fst with another Fst, returning the resulting Fst. + Args: other: Fst to concatenate with. @@ -496,8 +532,10 @@ def top_sort(self) -> VectorFst: def determinize(self, config: Union[DeterminizeConfig, None] = None) -> VectorFst: """ Make an Fst deterministic + Args: config: Configuration for the determinization operation. + Returns: The resulting Fst. """ @@ -510,8 +548,10 @@ def determinize(self, config: Union[DeterminizeConfig, None] = None) -> VectorFs def minimize(self, config: Union[MinimizeConfig, None] = None) -> VectorFst: """ Minimize an FST in place + Args: config: Configuration for the minimization operation. + Returns: self """ @@ -524,8 +564,10 @@ def minimize(self, config: Union[MinimizeConfig, None] = None) -> VectorFst: def project(self, proj_type: Union[ProjectType, None] = None) -> VectorFst: """ Convert a Fst to an acceptor using input or output labels. + Args: proj_type: Whether to replace input labels or output labels. + Returns: self """ @@ -610,6 +652,7 @@ def reverse(self) -> VectorFst: def rm_epsilon(self) -> VectorFst: """ Return an equivalent FST with epsilon transitions removed. + Returns: Newly created FST with epsilon transitions removed. """ @@ -622,8 +665,10 @@ def shortest_path( ) -> VectorFst: """ Construct a FST containing the shortest path of the input FST + Args: config: Configuration for shortest-path operation. + Returns: Newly-created FST containing only the shortest path of the input FST. """ @@ -657,6 +702,7 @@ def union(self, other_fst: VectorFst) -> VectorFst: Args: other_fst: Fst to perform union with this one. + Returns: The resulting newly-created Fst. @@ -668,6 +714,7 @@ def union(self, other_fst: VectorFst) -> VectorFst: def optimize(self) -> VectorFst: """ Optimize an FST in-place. + Returns: self """ @@ -679,6 +726,7 @@ def optimize(self) -> VectorFst: def optimize_in_log(self) -> VectorFst: """ Optimize an fst in-place in the log semiring. + Returns: self """ @@ -714,8 +762,10 @@ def tr_unique(self): def isomorphic(self, other: VectorFst) -> bool: """ Check if this Fst is isomorphic with another + Args: other: Other Fst. + Returns: Whether both Fsts are equal. """ @@ -726,6 +776,7 @@ def isomorphic(self, other: VectorFst) -> bool: def __add__(self, other: VectorFst) -> VectorFst: """ `fst_1 + fst_2` is a shortcut to perform the concatenation of `fst_1` and `fst_2`. + Args: other: VectorFst to concatenate after the current Fst. @@ -739,6 +790,7 @@ def __add__(self, other: VectorFst) -> VectorFst: def __mul__(self, other: VectorFst) -> VectorFst: """ `fst_1 * fst_2` is a shortcut to perform the composition of `fst_1` and `fst_2`. + Args: other: VectorFst to compose with. @@ -751,6 +803,7 @@ def __mul__(self, other: VectorFst) -> VectorFst: def __or__(self, other: VectorFst) -> VectorFst: """ `fst_1 | fst_2` is a shortcut to perform the union of `fst_1` and `fst_2`. + Args: other: VectorFst to perform the union with. diff --git a/rustfst-python/rustfst/string_paths_iterator.py b/rustfst-python/rustfst/string_paths_iterator.py index 4d49b3b7b..53b9b0ac3 100644 --- a/rustfst-python/rustfst/string_paths_iterator.py +++ b/rustfst-python/rustfst/string_paths_iterator.py @@ -51,6 +51,7 @@ def __next__(self) -> StringPath: def done(self) -> bool: """ Returns whether we're at the end of the Iterator. + Returns: True or False """ diff --git a/rustfst-python/rustfst/symbol_table.py b/rustfst-python/rustfst/symbol_table.py index bf8a74c15..7936b436d 100644 --- a/rustfst-python/rustfst/symbol_table.py +++ b/rustfst-python/rustfst/symbol_table.py @@ -32,6 +32,7 @@ def add_symbol(self, symbol: str) -> int: Args: symbol: A symbol unicode string. + Returns: The integer key of the new symbol. """ @@ -51,6 +52,7 @@ def add_table(self, syms: SymbolTable): """ This method merges another symbol table into the current table. All key values will be offset by the current available key. + Args: syms: A `SymbolTable` to be merged with the current table. """ @@ -74,13 +76,17 @@ def copy(self) -> SymbolTable: def find(self, 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. + Args: key: Either a string or an index. + Returns: If key is a string, the associated index; if key is an integer, the associated symbol. + Raises: KeyError: Key not found. """ @@ -114,8 +120,10 @@ def member(self, key: Union[int, str]) -> bool: 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. + Args: key: Either a string or an index. + Returns: Whether or not the key is present (as a string or a index) in the table. """ @@ -156,10 +164,13 @@ def read(cls, filename: Union[str, Path]) -> SymbolTable: """ Reads symbol table from binary file. This class method creates a new SymbolTable from a symbol table binary file. + Args: filename: The string location of the input binary file. + Returns: A new SymbolTable instance. + See also: `SymbolTable.read_fst`, `SymbolTable.read_text`. """ symt = ctypes.pointer(ctypes.c_void_p()) @@ -176,12 +187,15 @@ def read(cls, filename: Union[str, Path]) -> SymbolTable: def read_text(cls, filename: Union[str, Path]) -> SymbolTable: """ Reads symbol table from text file. + This class method creates a new SymbolTable from a symbol table text file. + Args: filename: The string location of the input text file. Returns: A new SymbolTable instance. + See also: `SymbolTable.read`, `SymbolTable.read_fst`. """ symt = ctypes.pointer(ctypes.c_void_p()) @@ -197,9 +211,12 @@ def read_text(cls, filename: Union[str, Path]) -> SymbolTable: def write(self, filename: Union[str, Path]): """ Serializes symbol table to a file. + This methods writes the SymbolTable to a file in binary format. + Args: filename: The string location of the output file. + Raises: FstIOError: Write failed. """ @@ -213,9 +230,12 @@ def write(self, filename: Union[str, Path]): def write_text(self, filename: Union[str, Path]): """ Writes symbol table to text file. + This method writes the SymbolTable to a file in human-readable format. + Args: filename: The string location of the output file. + Raises: FstIOError: Write failed. """ @@ -232,6 +252,7 @@ def equals(self, other: SymbolTable) -> bool: Params: other: SymbolTable instance + Returns: bool """ @@ -249,6 +270,7 @@ def __eq__(self, other: SymbolTable) -> bool: Params: other: SymbolTable instance + Returns: bool """ @@ -257,6 +279,7 @@ def __eq__(self, other: SymbolTable) -> bool: def __iter__(self) -> SymbolTableIterator: """ Returns an Iterator over the SymbolTable. + Returns: An iterator over the SymbolTable. """ @@ -292,6 +315,7 @@ class SymbolTableIterator: def __init__(self, symbol_table: SymbolTable): """ Constructs an iterator from the `Symboltable`. + Args: symbol_table: """ @@ -302,6 +326,7 @@ def __init__(self, symbol_table: SymbolTable): def __next__(self) -> Tuple[int, str]: """ Iterator over the symbols in the `SymbolTable`. + Returns: A pair label (int) and symbol (str). """ diff --git a/rustfst-python/rustfst/tr.py b/rustfst-python/rustfst/tr.py index f91b21647..b0380d518 100644 --- a/rustfst-python/rustfst/tr.py +++ b/rustfst-python/rustfst/tr.py @@ -17,6 +17,7 @@ class Tr: """ Structure representing a transition from a state to another state in a FST. + Attributes: ilabel: The input label. olabel: The output label. diff --git a/rustfst-python/rustfst/trs.py b/rustfst-python/rustfst/trs.py index f9ee3867d..ad0cb7c6d 100755 --- a/rustfst-python/rustfst/trs.py +++ b/rustfst-python/rustfst/trs.py @@ -26,6 +26,7 @@ def __init__(self, ptr=None) -> Trs: def push(self, tr: Tr): """ Add a new transition to the list. + Args: tr: The transition to add. """ @@ -45,6 +46,7 @@ def remove(self, index: int) -> Tr: def len(self) -> int: """ Compute the number of transitions in the list. + Returns: The number of transitions. diff --git a/rustfst-python/rustfst/weight.py b/rustfst-python/rustfst/weight.py index baeaea1a4..f56345594 100644 --- a/rustfst-python/rustfst/weight.py +++ b/rustfst-python/rustfst/weight.py @@ -8,6 +8,7 @@ def weight_one() -> float: """ Compute One() in the Tropical Semiring. + Returns: Float value corresponding to One() in the Tropical Semiring. """ @@ -21,6 +22,7 @@ def weight_one() -> float: def weight_zero() -> float: """ Compute Zero() in the Tropical Semiring. + Returns: Float value corresponding to Zero() in the Tropical Semiring. """