### Install mlconjug3 from source Source: https://mlconjug3.readthedocs.io/en/latest/readme.html After cloning the repository or downloading the source, navigate to the source directory and install mlconjug3 using setup.py. ```bash $ python setup.py install ``` -------------------------------- ### Install MLConjug3 from source Source: https://mlconjug3.readthedocs.io/en/latest/installation.html Methods for cloning or downloading the repository and installing via setup.py or poetry. ```bash $ git clone git://github.com/Ars-Linguistica/mlconjug3 ``` ```bash $ curl -OL https://github.com/Ars-Linguistica/mlconjug3/tarball/master ``` ```bash $ python setup.py install ``` ```bash $ pip install poetry $ poetry install ``` -------------------------------- ### Install mlconjug3 using poetry Source: https://mlconjug3.readthedocs.io/en/latest/readme.html Install poetry and then use it to install mlconjug3 from the source. These commands should be run in your terminal. ```bash $ pip install poetry $ poetry install ``` -------------------------------- ### Install Dependencies with Poetry Source: https://mlconjug3.readthedocs.io/en/latest/contributing.html Install project dependencies using poetry, the recommended build manager. Ensure poetry is installed before running this command. ```bash $ cd mlconjug3 $ poetry install ``` -------------------------------- ### Initialize pre-commit hooks Source: https://mlconjug3.readthedocs.io/en/latest/contributing.html Install the git hooks defined in the repository configuration. ```bash $ pre-commit install ``` -------------------------------- ### Install pre-commit Source: https://mlconjug3.readthedocs.io/en/latest/contributing.html Add the pre-commit tool to the project dependencies. ```bash $ poetry add pre-commitand ``` -------------------------------- ### Install MLConjug3 with pip Source: https://mlconjug3.readthedocs.io/en/latest/installation.html The preferred method for installing the most recent stable release. ```bash $ pip install mlconjug3 ``` -------------------------------- ### Configuration File Formats Source: https://mlconjug3.readthedocs.io/en/latest/usage.html Examples of TOML and YAML configuration files for setting default conjugation parameters and themes. ```toml language = "en" subject = "abbrev" output = "conjugation_table.json" file_format = "json" [theme] header_style = "bold #0D47A1" mood_style = "bold #F9A825" tense_style = "bold bright_magenta" person_style = "bold cyan" conjugation_style = "bold #4CAF50" ``` ```yaml language: fr subject: pronoun output: conjugation_table.json file_format: json theme: header_style: bold blue mood_style: bold yellow tense_style: bold green person_style: bold bright_cyan conjugation_style: bold bright_magenta ``` -------------------------------- ### Conjugate Verbs via CLI Source: https://mlconjug3.readthedocs.io/en/latest/usage.html Examples of common conjugation commands using different languages, formats, and output options. ```bash $ mlconjug3 -l en -s abbrev 'have' ``` ```bash $ mlconjug3 -l fr -s pronoun 'aimer' 'être' 'aller' ``` ```bash $ mlconjug3 -l es -s pronoun -f json 'hablar' -o 'conjugation_table.json' ``` ```bash $ mlconjug3 -l it -s abbrev -f csv 'parlare' 'avere' 'essere' -o 'conjugation_table.csv' ``` -------------------------------- ### Install MLConjug3 with pipx Source: https://mlconjug3.readthedocs.io/en/latest/installation.html Recommended for isolating the package from other Python environments. ```bash $ pipx install mlconjug3 ``` -------------------------------- ### Install MLConjug3 with conda Source: https://mlconjug3.readthedocs.io/en/latest/installation.html Recommended for Apple M1/M2 processors to ensure pre-compiled dependencies. ```bash $ conda config --add channels conda-forge $ conda config --set channel_priority strict $ conda install mlconjug3 ``` ```bash $ conda install -c conda-forge mlconjug3 ``` -------------------------------- ### Install mlconjug3 using conda (alternative) Source: https://mlconjug3.readthedocs.io/en/latest/readme.html If you already have Anaconda or Miniconda available on your system, you can use this command to install mlconjug3 from the conda-forge channel. ```bash $ conda install -c conda-forge mlconjug3 ``` -------------------------------- ### MLConjug3 Command Line Interface Source: https://mlconjug3.readthedocs.io/en/latest/usage.html This section covers the usage of the MLConjug3 command-line tool, including its options and examples for conjugating verbs in different languages. ```APIDOC ## MLConjug3 CLI Usage ### Description MLConjug3 provides a command-line interface for conjugating verbs. You can specify the language, subject format, output file, and file format. ### Method CLI Command ### Endpoint mlconjug3 ### Parameters #### Command Line Options - **-l, --language** (TEXT) - Optional - The language for the conjugation pipeline. Supported values: 'fr', 'en', 'es', 'it', 'pt', 'ro'. Defaults to 'fr'. - **-o, --output** (TEXT) - Optional - Path of the filename for storing the conjugation tables. - **-s, --subject** (TEXT) - Optional - The subject format type for the conjugated forms. Supported values: 'abbrev', 'pronoun'. Defaults to 'abbrev'. - **-f, --file_format** (TEXT) - Optional - The output format for storing the conjugation tables. Supported values: 'json', 'csv'. Defaults to 'json'. - **-c, --config** (FILE) - Optional - Path of the configuration file for specifying language, subject, output file name and format, as well as theme settings. Supported file formats: toml, yaml. - **-h, --help** - Optional - Show this message and exit. #### Verbs [VERBS]... - The verbs to conjugate. ### Request Example ```bash $ mlconjug3 -l en -s abbrev 'have' $ mlconjug3 -l fr -s pronoun 'aimer' 'être' 'aller' $ mlconjug3 -l es -s pronoun -f json 'hablar' -o 'conjugation_table.json' $ mlconjug3 -l it -s abbrev -f csv 'parlare' 'avere' 'essere' -o 'conjugation_table.csv' ``` ### Response #### Success Response (200) Outputs the conjugation table in the specified format (JSON or CSV) to the console or a file. #### Response Example (Output depends on the verb and specified format. Example for JSON output): ```json { "have": { "indicative": { "present": { "1s": "I have", "2s": "you have", "3s": "he/she/it has", "1p": "we have", "2p": "you have", "3p": "they have" } } } } ``` ``` -------------------------------- ### Install mlconjug3 using conda Source: https://mlconjug3.readthedocs.io/en/latest/readme.html Install mlconjug3 using Anaconda or Miniconda. Run this command in your terminal after configuring conda channels. ```bash $ conda install mlconjug3 ``` -------------------------------- ### Clone mlconjug3 repository from GitHub Source: https://mlconjug3.readthedocs.io/en/latest/readme.html Clone the public repository of mlconjug3 from GitHub to get the source code. Use this command in your terminal. ```bash $ git clone git://github.com/Ars-Linguistica/mlconjug3 ``` -------------------------------- ### Install MLConjug3 on Apple M1 via Conda Source: https://mlconjug3.readthedocs.io/en/latest/history.html Use this command to install MLConjug3 on an Apple M1 processor, especially when using conda environments. ```bash conda install -c conda-forge mlconjug3 ``` -------------------------------- ### Configure conda channels for mlconjug3 Source: https://mlconjug3.readthedocs.io/en/latest/readme.html These commands configure conda to use the conda-forge channel, which is necessary for installing mlconjug3. Run these commands in your terminal. ```bash $ conda config --add channels conda-forge $ conda config --set channel_priority strict ``` -------------------------------- ### GET /get_verb_info Source: https://mlconjug3.readthedocs.io/en/latest/_modules/mlconjug3/conjug_manager/conjug_manager.html Retrieves detailed information about a specific verb, including its root and template. ```APIDOC ## GET /get_verb_info ### Description Retrieves verb information and returns a VerbInfo instance for a given verb. ### Parameters #### Query Parameters - **verb** (string) - Required - The verb to conjugate. ### Response #### Success Response (200) - **VerbInfo** (object) - A VerbInfo object containing infinitive, root, and template, or None if the verb is not found. ``` -------------------------------- ### Display CLI Help Source: https://mlconjug3.readthedocs.io/en/latest/usage.html View available commands and options for the mlconjug3 tool. ```bash $ mlconjug3 -h Usage: mlconjug3 [OPTIONS] [VERBS]... Examples of how to use mlconjug3 from the terminal To conjugate a verb in English, abbreviated subject format : $ mlconjug3 -l en -s abbrev 'have' To conjugate multiple verbs in French, full subject format : $ mlconjug3 -l fr -s pronoun 'aimer' 'être' 'aller' To conjugate a verb in Spanish, full subject format and save the conjugation table in a json file: $ mlconjug3 -l es -s pronoun -f json 'hablar' -o 'conjugation_table.json' To conjugate multiple verbs in Italian, abbreviated subject format and save the conjugation table in a csv file: $ mlconjug3 -l it -s abbrev -f json 'parlare' 'avere' 'essere' -o 'conjugation_table.json' Examples of how to use mlconjug3 from the terminal with a config file: To use a config file in your home directory: $ mlconjug3 -c have To use a specific config file: $ mlconjug3 -c /path/to/config.toml have be eat To use a specific config file and override some of the settings: $ mlconjug3 -c /path/to/config.toml -l en -s pronoun -o conjugation_table.json -f json have fly Options: -l, --language TEXT The language for the conjugation pipeline. The values can be 'fr', 'en', 'es', 'it', 'pt' or 'ro'. The default value is fr. -o, --output TEXT Path of the filename for storing the conjugation tables. -s, --subject TEXT The subject format type for the conjugated forms. The values can be 'abbrev' or 'pronoun'. The default value is 'abbrev'. -f, --file_format TEXT The output format for storing the conjugation tables. The values can be 'json', 'csv'. The default value is 'json'. -c, --config FILE Path of the configuration file for specifying language, subject, output file name and format, as well as theme settings for the conjugation table columns. Supported file formats: toml, yaml -h, --help Show this message and exit. ``` -------------------------------- ### Main Execution Block Source: https://mlconjug3.readthedocs.io/en/latest/_modules/mlconjug3/mlconjug.html Standard entry point for script execution. ```python if __name__ == "__main__": pass ``` -------------------------------- ### Using Configuration Files Source: https://mlconjug3.readthedocs.io/en/latest/usage.html Details on how to use configuration files (TOML or YAML) to set MLConjug3 parameters, overriding command-line options. ```APIDOC ## Using Configuration Files ### Description MLConjug3 supports configuration files in TOML or YAML format to manage settings like language, subject format, output file, and theme. These files can be placed in a default directory or specified via the `-c` option. ### Method CLI Command with Configuration File ### Endpoint mlconjug3 ### Parameters #### Command Line Options - **-c, --config** (FILE) - Required - Path to the configuration file. #### Configuration File Parameters (TOML/YAML) - **language** (TEXT) - Optional - The language for the conjugation pipeline. Supported values: 'fr', 'en', 'es', 'it', 'pt', 'ro'. - **subject** (TEXT) - Optional - The subject format type for the conjugated forms. Supported values: 'abbrev', 'pronoun'. - **output** (TEXT) - Optional - Path of the filename for storing the conjugation tables. - **file_format** (TEXT) - Optional - The output format for storing the conjugation tables. Supported values: 'json', 'csv'. - **theme** (TABLE) - Optional - Settings for theme customization of the conjugation table columns. - **header_style** (TEXT) - Style for the table header. - **mood_style** (TEXT) - Style for mood sections. - **tense_style** (TEXT) - Style for tense sections. - **person_style** (TEXT) - Style for person sections. - **conjugation_style** (TEXT) - Style for conjugation values. ### Request Example ```bash # Using a default config file in ~/.mlconjug3/ $ mlconjug3 -c # Using a specific config file and overriding settings $ mlconjug3 -c /path/to/config.toml -l en -s pronoun -o conjugation_table.json -f json have fly ``` ### Request Body Example (config.toml) ```toml language = "en" subject = "abbrev" output = "conjugation_table.json" file_format = "json" [theme] header_style = "bold #0D47A1" mood_style = "bold #F9A825" tense_style = "bold bright_magenta" person_style = "bold cyan" conjugation_style = "bold #4CAF50" ``` ### Request Body Example (config.yaml) ```yaml language: fr subject: pronoun output: conjugation_table.json file_format: json theme: header_style: bold blue mood_style: bold yellow tense_style: bold green person_style: bold bright_cyan conjugation_style: bold bright_magenta ``` ### Response #### Success Response (200) Outputs the conjugation table based on the configuration file settings and any command-line overrides. #### Response Example (Output depends on the configuration and verbs provided. Refer to the CLI Usage section for example output formats.) ``` -------------------------------- ### GET /get_conjug_info Source: https://mlconjug3.readthedocs.io/en/latest/_modules/mlconjug3/conjug_manager/conjug_manager.html Retrieves the conjugation suffixes associated with a specific verb template. ```APIDOC ## GET /get_conjug_info ### Description Gets conjugation information corresponding to the given template name. ### Parameters #### Query Parameters - **template** (string) - Required - The name of the verb ending pattern. ### Response #### Success Response (200) - **inflected_forms** (OrderedDict) - An OrderedDict containing the conjugated suffixes of the template, or None if the template is not found. ``` -------------------------------- ### Use Configuration Files with CLI Source: https://mlconjug3.readthedocs.io/en/latest/usage.html Commands to execute conjugation using local or specific configuration files. ```bash $ mlconjug3 -c hablar ``` ```bash $ mlconjug3 -c /path/to/config.toml manger parler ``` ```bash $ mlconjug3 -c /path/to/config.toml -l en -s pronoun -o conjugation_table.json -f json have ``` -------------------------------- ### PyVerbiste Class Initialization Source: https://mlconjug3.readthedocs.io/en/latest/_modules/mlconjug3/PyVerbiste/PyVerbiste.html The Verbiste class handles Verbiste XML files for a specified language. It loads and parses verbs and their conjugation patterns. ```APIDOC ## Class Verbiste ### Description This is the class handling the Verbiste xml files. ### Parameters - **language** (string) - Optional - The language of the conjugator. The default value is fr for French. The allowed values are: fr, en, es, it, pt, ro. ### Attributes - **language** (Language of the conjugator) - **verbs** (Dictionary where the keys are verbs and the values are conjugation patterns) - **conjugations** (Dictionary where the keys are conjugation patterns and the values are inflected forms) - **_allowed_endings** (A set containing the allowed endings of verbs in the target language) - **templates** (List of strings: List of the conjugation patterns.) ``` -------------------------------- ### DataSet Initialization Source: https://mlconjug3.readthedocs.io/en/latest/_modules/mlconjug3/dataset/dataset.html Initializes the DataSet object with a dictionary of verbs and their conjugation templates. ```APIDOC ## Constructor: DataSet(verbs_dict) ### Description Initializes the dataset management object. It processes the input dictionary to extract verbs and templates, and prepares internal structures for machine learning tasks. ### Parameters #### Request Body - **verbs_dict** (dict) - Required - A dictionary where keys are verbs and values are objects containing the "template" key. ``` -------------------------------- ### Run flake8 linting Source: https://mlconjug3.readthedocs.io/en/latest/contributing.html Check the codebase for style issues using the flake8 linter. ```bash $ poetry run flake8 mlconjug3 ``` -------------------------------- ### Getting the Total Number of Conjugated Forms Source: https://mlconjug3.readthedocs.io/en/latest/_modules/mlconjug3/verbs/verbs.html Calculates and returns the total count of all available conjugated forms for the verb. Accounts for different structures of tense/person data. ```python def __len__(self): """ Returns the number of conjugated forms of the verb """ count = 0 for mood, tenses in self.conjug_info.items(): for tense, persons in tenses.items(): if isinstance(persons, str): count += 1 else: count += len(persons) return count ``` -------------------------------- ### Initialize DataSet Class Source: https://mlconjug3.readthedocs.io/en/latest/_modules/mlconjug3/dataset/dataset.html Initializes the DataSet object with a dictionary of verbs and their conjugation information. It sets up internal lists and dictionaries for managing the data. ```python class DataSet: """ | This class holds and manages the data set. | Defines helper methodss for managing Machine Learning tasks like constructing a training and testing set. :param verbs_dict: A dictionary of verbs and their corresponding conjugation class. :ivar verbs_dict: A dictionary of verbs and their corresponding conjugation class. :ivar verbs: A list of all the verbs in the data set. :ivar templates: A list of all the templates in the data set. :ivar verbs_list: A list of all the verbs in the data set, shuffled randomly. :ivar templates_list: A list of the template index of each verb in the shuffled verbs_list. :ivar dict_conjug: A dictionary where the keys are conjugation templates and the values are the verbs that belong to that template. :ivar min_threshold: The minimum number of verbs in a conjugation class for it to be split into a training and testing set. :ivar split_proportion: The proportion of the data set that should be used as the training set. :ivar train_input: A list of the verbs in the training set. :ivar train_labels: A list of the template index of each verb in the training set. :ivar test_input: A list of the verbs in the testing set. :ivar test_labels: A list of the template index of each verb in the testing set. """ def __init__(self, verbs_dict): self.verbs_dict = verbs_dict self.verbs = self.verbs_dict.keys() self.templates = sorted({verb["template"] for verb in self.verbs_dict.values()}) self.verbs_list = [] self.templates_list = [] self.dict_conjug = None self.min_threshold = 8 self.split_proportion = 0.5 self.train_input = [] self.train_labels = [] self.test_input = [] self.test_labels = [] self.construct_dict_conjug() return ``` -------------------------------- ### Get Inflected Forms from Tense Source: https://mlconjug3.readthedocs.io/en/latest/_modules/mlconjug3/PyVerbiste/PyVerbiste.html Extracts inflected forms for each person from a tense object. Returns None if no persons are present or if a person's form cannot be found. Handles single and multiple persons. ```python def get_inflected_forms(tense): """ List of inflected forms. """ persons = list(tense) if not persons: return None elif len(persons) == 1: if persons[0].find("i") is None: return None conjug = persons[0].find("i").text else: conjug = [] for pers, term in enumerate(persons): if term.find("i") is not None: if term.find("i").text is not None: conjug.append((pers, term.find("i").text)) else: conjug.append((pers, "")) else: conjug.append((pers, None)) return conjug ``` -------------------------------- ### Helper Methods Source: https://mlconjug3.readthedocs.io/en/latest/_modules/mlconjug3/PyVerbiste/PyVerbiste.html Utility methods for loading tense information and managing cache files. ```APIDOC ## Helper Methods ### `_load_cache(file)` #### Description Loads data from a cache file if available and up-to-date. #### Parameters - **file** (string) - Path to the XML file for which to check the cache. #### Returns - **file_dic** (dict or None) - The cached dictionary if found, otherwise None. #### Error Handling - Raises a `ValueError` if the provided file path does not end with ".xml". ### `_load_tense(tense)` #### Description Load and parses the inflected forms of the tense from an XML tag. #### Parameters - **tense** (list of xml tags) - The list of inflected forms for the current tense being processed. #### Returns - **inflected_forms** (list) - A list of inflected forms. ``` -------------------------------- ### Run tests with coverage Source: https://mlconjug3.readthedocs.io/en/latest/contributing.html Execute the test suite while measuring code coverage for the mlconjug3 package. ```bash $ poetry run pytest --cov=mlconjug3 ``` -------------------------------- ### Verify mlconjug3 Release with Custom Paths Source: https://mlconjug3.readthedocs.io/en/latest/readme.html Specify explicit paths for the certificate and signature files if they are not in the same directory as the release file. This command verifies only one file at a time. ```bash $ python -m sigstore verify identity mlconjug3-3.10.tar.gz \ --certificate some/other/path/mlconjug3-3.10.crt \ --signature some/other/path/mlconjug3-3.10.sig \ --cert-identity 'diao.sekou.nlp@gmail.com' \ --cert-oidc-issuer 'https://github.com/login/oauth' ``` -------------------------------- ### ConjugatorTrainer Class Initialization Source: https://mlconjug3.readthedocs.io/en/latest/modules.html Initializes a new instance of the ConjugatorTrainer class with the specified language, output directory, and model parameters. ```APIDOC ## Constructor: ConjugatorTrainer ### Description Initializes a ConjugatorTrainer instance for training a conjugation model. ### Parameters - **lang** (str) - Required - The language for which the model will be trained. - **output_folder** (str) - Required - The directory where the trained model will be saved. - **split_proportion** (float) - Required - The proportion of the data set to use for training. - **dataset** (class) - Required - The DataSet class from the mlconjug3 library. - **model** (obj) - Required - The model to be trained. ``` -------------------------------- ### Verify Multiple mlconjug3 Release Signatures Source: https://mlconjug3.readthedocs.io/en/latest/readme.html Verify multiple mlconjug3 release files simultaneously by listing them after the verify command. This is useful when downloading several package formats. ```bash $ python -m sigstore verify identity mlconjug3-3.10.tar.gz mlconjug3-3.10.0-py3-none-any.whl \ --cert-identity 'diao.sekou.nlp@gmail.com' \ --cert-oidc-issuer 'https://github.com/login/oauth' ``` -------------------------------- ### Italian Verb Conjugation Logic (VerbIt) Source: https://mlconjug3.readthedocs.io/en/latest/_modules/mlconjug3/verbs/verbs.html The `VerbIt` class customizes the `_load_conjug` method for Italian verbs. It handles the addition of personal pronouns to inflected verb forms, considering specific rules for imperative and negative tenses. ```python class VerbIt(Verb): """ This class defines the Italian Verb Object. """ __slots__ = () language = "it" def _load_conjug(self, subject): """ | Populates the inflected forms of the verb. | Adds personal pronouns to the inflected verbs. """ for mood, tense in self.conjug_info.items(): for tense_name, persons in tense.items(): if isinstance(persons, list): persons_dict = OrderedDict() for pers, term in persons: if len(persons) == 6 and not tense_name.startswith( "Imperativo" ): key = PRONOUNS[self.language][subject][pers] elif tense_name.startswith("Imperativo"): key = PRONOUNS[self.language]["abbrev"][pers] else: key = pers if term is not None and term != "-": if tense_name == "Imperativo non": persons_dict[key] = " ".join( ( NEGATION[self.language], self.verb_info.root + term, ) ) else: self.conjugate_person(key, persons_dict, term) else: persons_dict[key] = None self.conjug_info[mood][tense_name] = persons_dict elif isinstance(persons, str): if not persons.startswith(self.verb_info.root): self.conjug_info[mood][tense_name] = ( self.verb_info.root + persons ) return ``` -------------------------------- ### Download mlconjug3 source tarball Source: https://mlconjug3.readthedocs.io/en/latest/readme.html Download the master tarball of the mlconjug3 source code. Use this command in your terminal. ```bash $ curl -OL https://github.com/Ars-Linguistica/mlconjug3/tarball/master ``` -------------------------------- ### Portuguese Verb Conjugation Logic (VerbPt) Source: https://mlconjug3.readthedocs.io/en/latest/_modules/mlconjug3/verbs/verbs.html The `VerbPt` class extends the `Verb` class for Portuguese. Its `_load_conjug` method customizes conjugation by incorporating personal pronouns and handling specific tense constructions, such as the negative imperative. ```python class VerbPt(Verb): """ This class defines the Portuguese Verb Object. """ __slots__ = () language = "pt" def _load_conjug(self, subject): """ | Populates the inflected forms of the verb. | Adds personal pronouns to the inflected verbs. """ for mood, tense in self.conjug_info.items(): for tense_name, persons in tense.items(): if isinstance(persons, list): persons_dict = OrderedDict() for pers, term in persons: if len(persons) == 6 and not tense_name.startswith( "Imperativo" ): key = PRONOUNS[self.language][subject][pers] elif tense_name.startswith("Imperativo"): key = PRONOUNS[self.language]["abbrev"][pers] else: key = pers if term is not None and term != "-": if tense_name == "Imperativo Negativo": persons_dict[key] = " ".join( ( NEGATION[self.language], self.verb_info.root + term, ) ) else: ``` -------------------------------- ### PyVerbiste API Reference Source: https://mlconjug3.readthedocs.io/en/latest/modules.html API documentation for the PyVerbiste.Verbiste class, which manages Verbiste XML files for verb conjugations. ```APIDOC ## Class: PyVerbiste.Verbiste This is the class handling the Verbiste xml files. ### Parameters - **language** (string) - Optional - The language of the conjugator. The default value is fr for French. The allowed values are: fr, en, es, it, pt, ro. ### Variables - **language** (string) - Language of the conjugator. - **verbs** (dict) - Dictionary where the keys are verbs and the values are conjugation patterns. - **conjugations** (dict) - Dictionary where the keys are conjugation patterns and the values are inflected forms. - **_allowed_endings** (set) - A set containing the allowed endings of verbs in the target language. - **templates** (list) - List of the conjugation patterns. ### Methods #### _load_verbs(_verbs_file_) Load and parses the verbs from the xml file. Parameters: - **verbs_file** (string or path object) - Path to the verbs xml file. #### _parse_verbs(_file_) Parses the XML file. Parameters: - **file** (FileObject) - XML file containing the verbs. Return: - verb_templates (OrderedDict) - An OrderedDict containing the verb and its template for all verbs in the file. #### _load_conjugations(_conjugations_file_) Load and parses the conjugations from the xml file. Parameters: - **conjugations_file** (string or path object) - Path to the conjugation xml file. #### _detect_allowed_endings() Detects the allowed endings for verbs in the supported languages. Return: - allowed_endings (set) - A set containing the allowed endings of verbs in the target language. #### _parse_conjugations(_file_) Parses the XML file. Parameters: - **file** (FileObject) - XML file containing the conjugation templates. Return: - conjugations (OrderedDict) - An OrderedDict containing all the conjugation templates in the file. #### get_conjug_info(_template_) Gets conjugation information corresponding to the given template. Parameters: - **template** (string) - Name of the verb ending pattern. Return: - inflected_forms (OrderedDict or None) - OrderedDict containing the conjugated suffixes of the template. #### get_verb_info(_verb_) Gets verb information and returns a VerbInfo instance. Parameters: - **verb** (string) - Verb to conjugate. Return: - VerbInfo (VerbInfo object or None) - VerbInfo object or None. #### is_valid_verb(_verb_) Checks if the verb is a valid verb in the given language. Parameters: - **verb** (string) - The verb to conjugate. Return: - is_allowed (bool) - True if the verb is a valid verb in the language. False otherwise. #### _static __load_tense(_tense_) Load and parses the inflected forms of the tense from xml file. Parameters: - **tense** (list) - List of xml tags containing inflected forms. Return: - inflected_forms (list) - List of inflected forms. ``` -------------------------------- ### Clone MLConjug3 Repository Source: https://mlconjug3.readthedocs.io/en/latest/contributing.html Clone the MLConjug3 repository locally to begin development. This command is used after forking the repository on GitHub. ```bash $ git clone git@github.com:Ars-Linguistica/mlconjug3.git ``` -------------------------------- ### Commit and Push Changes Source: https://mlconjug3.readthedocs.io/en/latest/contributing.html Commit your changes with a descriptive message and push the branch to your GitHub fork. This prepares your changes for a pull request. ```bash $ git add . $ git commit -m "Your detailed description of your changes." $ git push origin name-of-your-bugfix-or-feature ``` -------------------------------- ### ConjugManager Initialization Source: https://mlconjug3.readthedocs.io/en/latest/_modules/mlconjug3/conjug_manager/conjug_manager.html Initializes the ConjugManager instance for a specific language, loading the corresponding verb and conjugation data. ```APIDOC ## Constructor: ConjugManager(language="default") ### Description Initializes the ConjugManager with the specified language. Loads verb and conjugation data from internal resources. ### Parameters #### Request Body - **language** (string) - Optional - The language of the conjugator. Allowed values: fr, en, es, it, pt, ro. Defaults to 'fr'. ``` -------------------------------- ### Loading and Parsing Verbs Source: https://mlconjug3.readthedocs.io/en/latest/_modules/mlconjug3/PyVerbiste/PyVerbiste.html Methods for loading and parsing verb data from XML files, with caching mechanisms. ```APIDOC ## Load and Parse Verbs ### `_load_verbs(verbs_file)` #### Description Load and parses the verbs from the xml file. #### Parameters - **verbs_file** (string or path object) - Path to the verbs xml file. ### `_parse_verbs(file)` #### Description Parses the XML file containing verb data. #### Parameters - **file** (FileObject) - XML file containing the verbs. #### Returns - **verb_templates** (OrderedDict) - An OrderedDict containing the verb and its template for all verbs in the file. #### Caching This method utilizes a caching mechanism. If a corresponding `.pkl` file exists and is up-to-date, it will load the data from the cache instead of parsing the XML file. ``` -------------------------------- ### Format code with black Source: https://mlconjug3.readthedocs.io/en/latest/contributing.html Automatically format the source code according to black's standards. ```bash $ poetry run black mlconjug3 ``` -------------------------------- ### Verify mlconjug3 Release Signature Source: https://mlconjug3.readthedocs.io/en/latest/readme.html Use this command to verify the signature of a single mlconjug3 release file. Ensure the certificate identity and issuer match the release details. ```bash $ python -m sigstore verify identity mlconjug3-3.10.tar.gz \ --cert-identity 'diao.sekou.nlp@gmail.com' \ --cert-oidc-issuer 'https://github.com/login/oauth' ``` -------------------------------- ### Construct Conjugation Dictionary Source: https://mlconjug3.readthedocs.io/en/latest/_modules/mlconjug3/dataset/dataset.html Populates the dictionary mapping conjugation templates to lists of verbs and shuffles the verbs. This method is called during initialization. ```python def construct_dict_conjug(self): """ | Populates the dictionary containing the conjugation templates. | Populates the lists containing the verbs and their templates. """ conjug = defaultdict(list) verb_items = list(self.verbs_dict.items()) Random(42).shuffle(verb_items) for verb, info_verb in verb_items: self.verbs_list.append(verb) self.templates_list.append(self.templates.index(info_verb["template"])) conjug[info_verb["template"]].append(verb) self.dict_conjug = conjug return ``` -------------------------------- ### Load Cache or JSON Data Source: https://mlconjug3.readthedocs.io/en/latest/_modules/mlconjug3/conjug_manager/conjug_manager.html Loads data from a .pkl cache file if it exists and is more recent than the source JSON file. Otherwise, it returns None, indicating that the JSON file should be loaded. ```python def _load_cache(self, file): file_path = os.path.abspath(file) if not file_path.endswith(".json"): raise ValueError(f"Invalid file path, expected .json file, got {file_path}") pkl_file = file_path + ".pkl" if os.path.isfile(pkl_file): last_modified_time_file = os.path.getmtime(file_path) last_modified_time_pkl = os.path.getmtime(pkl_file) if last_modified_time_file <= last_modified_time_pkl: file_dic = joblib.load(pkl_file) return file_dic else: return None ``` -------------------------------- ### Run mypy type checks Source: https://mlconjug3.readthedocs.io/en/latest/contributing.html Perform static type checking on the mlconjug3 source code. ```bash $ poetry run mypy mlconjug3 ``` -------------------------------- ### Split Data into Training and Testing Sets Source: https://mlconjug3.readthedocs.io/en/latest/_modules/mlconjug3/dataset/dataset.html Splits the verb data into training and testing sets based on a minimum threshold for conjugation classes and a specified proportion for the training set. Raises a ValueError if the proportion is invalid. ```python def split_data(self, threshold=8, proportion=0.5): """ Splits the data into a training and a testing set. :param threshold: int. Minimum size of conjugation class to be split. :param proportion: float. Proportion of samples in the training set. Must be between 0 and 1. :raises: ValueError. """ if proportion <= 0 or proportion > 1: raise ValueError(_("The split proportion must be between 0 and 1.")) self.min_threshold = threshold self.split_proportion = proportion train_set = [] test_set = [] for template, lverbs in self.dict_conjug.items(): if len(lverbs) <= threshold: for verbe in lverbs: train_set.append((verbe, template)) else: index = round(len(lverbs) * proportion) for verbe in lverbs[:index]: train_set.append((verbe, template)) for verbe in lverbs[index:]: test_set.append((verbe, template)) Random(42).shuffle(train_set) Random(42).shuffle(test_set) self.train_input = [elmt[0] for elmt in train_set] self.train_labels = [self.templates.index(elmt[1]) for elmt in train_set] self.test_input = [elmt[0] for elmt in test_set] self.test_labels = [self.templates.index(elmt[1]) for elmt in test_set] return ``` -------------------------------- ### Internal Method: _load_conjug (VerbIt) Source: https://mlconjug3.readthedocs.io/en/latest/_modules/mlconjug3/verbs/verbs.html Populates the inflected forms of an Italian verb object and adds personal pronouns. ```APIDOC ## _load_conjug (VerbIt) ### Description Populates the inflected forms of the Italian verb object and adds personal pronouns to the inflected verbs based on the provided subject. ### Parameters #### Path Parameters - **subject** (string) - Required - The subject pronoun context used to determine the correct personal pronouns for conjugation. ``` -------------------------------- ### Retrieve Verb Information Source: https://mlconjug3.readthedocs.io/en/latest/_modules/mlconjug3/conjug_manager/conjug_manager.html Returns a VerbInfo object containing the infinitive, root, and template for a given verb string. ```python def get_verb_info(self, verb): """ Gets verb information and returns a VerbInfo instance. :param verb: string. Verb to conjugate. :return VerbInfo: VerbInfo object or None. """ if verb not in self.verbs.keys(): return None infinitive = verb root = self.verbs[verb]["root"] template = self.verbs[verb]["template"] return VerbInfo(infinitive, root, template) ``` -------------------------------- ### Define model configuration in YAML Source: https://mlconjug3.readthedocs.io/en/latest/usage.html Provides a template for storing model settings in a YAML file, which can be loaded using libraries like PyYaml or Hydra. ```yaml # config.yaml language: fr output_folder: models split_proportion: 0.8 vectorizer: type: mlconjug3.CountVectorizer kwargs: analyzer: type: functools.partial kwargs: func: mlconjug3.feature_extractor.extract_verb_features lang: fr ngram_range: [2, 7] binary: true lowercase: false feature_selector: type: mlconjug3.SelectFromModel kwargs: estimator: type: mlconjug3.LinearSVC kwargs: penalty: l1 max_iter: 12000 dual: false verbose: 0 classifier: type: mlconjug3.SGDClassifier kwargs: loss: log penalty: elasticnet l1_ratio: 0.15 max_iter: 40000 alpha: 1e-5 verbose: 0 ``` -------------------------------- ### Verify mlconjug3 Release from GitHub Actions Source: https://mlconjug3.readthedocs.io/en/latest/readme.html Verify a mlconjug3 release signed within GitHub Actions. This command uses specific paths for the certificate and signature files generated by the workflow. ```bash $ python -m sigstore verify github mlconjug3-3.10.tar.gz \ --certificate mlconjug3-3.10.tar.gz.crt \ --signature mlconjug3-3.10.tar.gz.sig \ --cert-identity https://github.com/diao.sekou.nlp/mlconjug3/.github/workflows/sign_and_publish.yml@refs/tags/v3.10.0 ``` -------------------------------- ### Generic Verb Conjugation Logic Source: https://mlconjug3.readthedocs.io/en/latest/_modules/mlconjug3/verbs/verbs.html This snippet illustrates a generic verb conjugation logic, likely from a base `Verb` class, that handles various tenses and moods. It includes logic for imperative pronouns, negation, gerunds, and infinitives, determining the conjugation key based on tense and person. ```python key = IMPERATIVE_PRONOUNS[self.language][subject][pers] elif tense_name == "Imperativo non": key = " ".join( ( IMPERATIVE_PRONOUNS[self.language][subject][pers], NEGATION[self.language], ) ) elif tense_name == "Gerundio Gerondio": if term.endswith("ndo"): key = "" else: continue elif tense_name == "Infinitivo Infinitivo": if term.endswith("r"): key = "" else: continue else: key = pers if term is not None and term != "-": self.conjugate_person(key, persons_dict, term) else: persons_dict[key] = None self.conjug_info[mood][tense_name] = persons_dict elif isinstance(persons, str): if not persons.startswith(self.verb_info.root): self.conjug_info[mood][tense_name] = ( self.verb_info.root + persons ) return ``` -------------------------------- ### Initialize Conjugator and Conjugate Verbs Source: https://mlconjug3.readthedocs.io/en/latest/usage.html Basic usage of the Conjugator class to conjugate a verb and iterate through its forms. ```python from mlconjug3 import Conjugator # initialize the conjugator conjugator = Conjugator() # conjugate the verb "parler" verb = conjugator.conjugate("parler") # print all the conjugated forms as a list of tuples. print(verb.iterate()) ``` -------------------------------- ### Update project dependencies Source: https://mlconjug3.readthedocs.io/en/latest/contributing.html Update the project's dependencies and lock files to the latest compatible versions. ```bash $ poetry update ``` -------------------------------- ### Conjugator Class Initialization Source: https://mlconjug3.readthedocs.io/en/latest/modules.html Initializes the Conjugator class with a specified language and optional custom machine learning model. ```APIDOC ## Class: Conjugator ### Description The main class for managing the Verbiste data set and interfacing with scikit-learn pipelines for verb conjugation. ### Parameters - **language** (string) - Optional - Language of the conjugator. Defaults to 'fr'. - **model** (mlconjug3.Model or scikit-learn Pipeline) - Optional - A user-provided pipeline for training or custom conjugation models. ``` -------------------------------- ### Initialize ConjugManager Source: https://mlconjug3.readthedocs.io/en/latest/_modules/mlconjug3/conjug_manager/conjug_manager.html Initializes the ConjugManager with a specified language. Loads verbs and conjugations from JSON files, with support for caching. Raises ValueError for unsupported languages. ```python def __init__(self, language="default"): if language not in LANGUAGES: raise ValueError( _( "Unsupported language.\n The allowed languages are fr, en, es, it, pt, ro." ) ) self.language = "fr" if language == "default" else language self.verbs = {} self.conjugations = OrderedDict() verbs_file = pkg_resources.resource_filename( RESOURCE_PACKAGE, VERBS_RESOURCE_PATH[self.language] ) self._load_verbs(verbs_file) self._allowed_endings = self._detect_allowed_endings() conjugations_file = pkg_resources.resource_filename( RESOURCE_PACKAGE, CONJUGATIONS_RESOURCE_PATH[self.language] ) self._load_conjugations(conjugations_file) self.templates = sorted(self.conjugations.keys()) return ``` -------------------------------- ### Spanish Verb Conjugation Logic Source: https://mlconjug3.readthedocs.io/en/latest/_modules/mlconjug3/verbs/verbs.html The `_load_conjug` method in `VerbEs` handles Spanish verb conjugations. It includes logic to skip certain conjugations based on the number of persons and tense name, and determines the pronoun key for regular conjugations. ```python def _load_conjug(self, subject): """ | Populates the inflected forms of the verb. | Adds personal pronouns to the inflected verbs. """ for mood, tense in self.conjug_info.items(): for tense_name, persons in tense.items(): if isinstance(persons, list): persons_dict = OrderedDict() for pers, term in persons: if len(persons) == 5 and not tense_name.startswith( "Imperativo" ): continue if len(persons) == 6: key = PRONOUNS[self.language][subject][pers] elif tense_name == "Imperativo Afirmativo": ``` -------------------------------- ### DataSet Class Methods Source: https://mlconjug3.readthedocs.io/en/latest/modules.html Methods for managing and splitting datasets for machine learning tasks. ```APIDOC ## DataSet Methods ### construct_dict_conjug() - **Description**: Populates the dictionary containing conjugation templates and lists of verbs. ### split_data(threshold, proportion) - **Description**: Splits the data into training and testing sets. - **Parameters**: - **threshold** (int) - Optional - Minimum size of conjugation class to be split (default 8). - **proportion** (float) - Optional - Proportion of samples in the training set (default 0.5). - **Errors**: Raises ValueError if parameters are invalid. ``` -------------------------------- ### Loading and Parsing Conjugations Source: https://mlconjug3.readthedocs.io/en/latest/_modules/mlconjug3/PyVerbiste/PyVerbiste.html Methods for loading and parsing conjugation data from XML files, including support for caching. ```APIDOC ## Load and Parse Conjugations ### `_load_conjugations(conjugations_file)` #### Description Load and parses the conjugations from the xml file. #### Parameters - **conjugations_file** (string or path object) - Path to the conjugation xml file. ### `_parse_conjugations(file)` #### Description Parses the XML file containing conjugation templates. #### Parameters - **file** (FileObject) - XML file containing the conjugation templates. #### Returns - **conjugations** (OrderedDict) - An OrderedDict containing all the conjugation templates in the file. #### Caching This method utilizes a caching mechanism. If a corresponding `.pkl` file exists and is up-to-date, it will load the data from the cache instead of parsing the XML file. ```