### Setup Dictionaries Source: https://github.com/hrishikeshrt/pycdsl/blob/master/USAGE.rst Explains how to setup default dictionaries using the `setup()` method. Optionally, specific dictionaries can be loaded and updated. ```python # Note: Any additional dictionaries that are installed will also be loaded. CDSL.setup() ``` ```python # For loading specific dictionaries only, # a list of dictionary IDs can be passed to the setup function # e.g. CDSL.setup(["VCP"]) ``` ```python # If `update` flag is True, update check is performed for every dictionary # in `dict_ids` and if available, the updated version is installed # e.g. CDSL.setup(["MW"], update=True) ``` -------------------------------- ### Setup CDSL Dictionaries Source: https://github.com/hrishikeshrt/pycdsl/blob/master/docs/pycdsl.md Initializes and sets up CDSL dictionaries in bulk. It connects to databases and installs updated versions if specified. Accepts optional parameters for dictionary IDs, update flags, and model mappings. ```python corpus = CDSLCorpus() success = corpus.setup(dict_ids=['dict1', 'dict2'], update=True) ``` -------------------------------- ### REPL Session Example (Console) Source: https://github.com/hrishikeshrt/pycdsl/blob/master/USAGE.rst This is an example session inside the REPL where commands such as `available`, `dicts`, `info`, `search`, `show`, `stats`, and `update` can be used to interact with the CDSL dictionaries. This showcases the functionality available within the REPL environment. ```Console Cologne Sanskrit Digital Lexicon (CDSL) --------------------------------------- Install or load dictionaries by typing `use [DICT_IDS..]` e.g. `use MW`. Type any keyword to search in the selected dictionaries. (help or ? for list of options) Loaded 4 dictionaries. (CDSL::None) help -v Documented commands (use 'help -v' for verbose/'help ' for details): Core ===================================================================================================== available Display a list of dictionaries available in CDSL dicts Display a list of dictionaries available locally info Display information about active dictionaries search Search in the active dictionaries show Show a specific entry by ID stats Display statistics about active dictionaries update Update loaded dictionaries ``` -------------------------------- ### Install PyCDSL using pip Source: https://github.com/hrishikeshrt/pycdsl/blob/master/docs/readme.md This command installs the PyCDSL package from the Python Package Index (PyPI). It is the standard way to get the latest stable version of the library for use in your projects. ```console pip install PyCDSL ``` -------------------------------- ### Get Installed Dictionaries Source: https://github.com/hrishikeshrt/pycdsl/blob/master/docs/pycdsl.md Retrieves a list of dictionaries that are currently installed locally and available for use. ```python installed_dicts = corpus.get_installed_dicts() ``` -------------------------------- ### Start PyCDSL REPL Interface (Console) Source: https://github.com/hrishikeshrt/pycdsl/blob/master/docs/readme.md Command to launch the PyCDSL library in interactive REPL (Read-Eval-Print Loop) mode, enabling command-line interaction with the Sanskrit lexicon. ```console $ cdsl -i ``` -------------------------------- ### Setup Dictionaries in CDSLCorpus Source: https://github.com/hrishikeshrt/pycdsl/blob/master/docs/usage.md Shows how to set up default dictionaries or specific dictionaries for the CDSLCorpus. It also includes an option to update dictionaries if newer versions are available. ```python # Note: Any additional dictionaries that are installed will also be loaded. CDSL.setup() # For loading specific dictionaries only, # a list of dictionary IDs can be passed to the setup function # e.g. CDSL.setup(["VCP"]) # If `update` flag is True, update check is performed for every dictionary # in `dict_ids` and if available, the updated version is installed # e.g. CDSL.setup(["MW"], update=True) ``` -------------------------------- ### PyCDSL Console Interface Usage (Console) Source: https://github.com/hrishikeshrt/pycdsl/blob/master/USAGE.rst This example shows the usage of the PyCDSL console interface, including various command-line options for searching, specifying dictionaries, and controlling behavior. It outlines the syntax for invoking the tool with different parameters. ```Console cdsl [-h] [-i] [-s SEARCH] [-p PATH] [-d DICTS [DICTS ...]] [-sm SEARCH_MODE] [-is INPUT_SCHEME] [-os OUTPUT_SCHEME] [-hf HISTORY_FILE] [-sc STARTUP_SCRIPT] [-u] [-dbg] [-v] $ cdsl -d MW AP90 -s हृषीकेश ``` -------------------------------- ### Iterate Over CDSL Corpus and Dictionary (Python) Source: https://github.com/hrishikeshrt/pycdsl/blob/master/docs/readme.md Provides examples of iterating through a CDSLCorpus to get dictionary instances and iterating through a CDSLDict to get individual entries. This demonstrates how to access multiple dictionaries and their contents programmatically. ```python from pycdsl import CDSL # Iterate over CDSLCorpus for cdsl_dict in CDSL: print(type(cdsl_dict)) print(cdsl_dict) break # Iterate over a CDSLDict instance for entry in CDSL.MW: print(type(entry)) print(entry) break ``` -------------------------------- ### Get Available Dictionaries Source: https://github.com/hrishikeshrt/pycdsl/blob/master/docs/pycdsl.md Fetches a list of dictionaries available for download from the CDSL project server by parsing the homepage. ```python available_dicts = corpus.get_available_dicts() ``` -------------------------------- ### PyCDSL Console Interface Common Usage (Console) Source: https://github.com/hrishikeshrt/pycdsl/blob/master/docs/readme.md An example of a common command-line usage for the PyCDSL tool, specifying dictionaries and a search term. This demonstrates a typical non-interactive query. ```console $ cdsl -d MW AP90 -s हृषीकेश ``` -------------------------------- ### Bash: pycdsl Command-Line Interface Usage Source: https://context7.com/hrishikeshrt/pycdsl/llms.txt Provides examples of using the pycdsl command-line interface (CLI) for searching Sanskrit dictionaries without writing Python code. It covers basic searches, specifying dictionaries, updating data, setting custom paths, using different search modes, and checking the version. Assumes pycdsl is installed. ```bash # Install and search in default dictionaries cdsl -s "राम" # Search specific dictionaries with custom transliteration cdsl -d MW AP90 -s "kRRiShNa" -is itrans -os iast # Update dictionaries before searching cdsl -d MW -u -s "yoga" # Search with custom installation path cdsl -p /path/to/sanskrit/data -d MW -s "dharma" # Search with value mode (search in definitions) cdsl -d MW -s "lord of the universe" -sm value # Check version cdsl -v # Interactive REPL mode cdsl -i # Interactive mode with specific dictionaries cdsl -i -d MW VCP -is iast -os devanagari ``` -------------------------------- ### Fetch and Transliterate Dictionary Entry (Python) Source: https://github.com/hrishikeshrt/pycdsl/blob/master/docs/readme.md Demonstrates how to fetch a dictionary entry by its ID and then transliterate it to a specified scheme. This requires the CDSL library to be installed and accessible. ```python from pycdsl import CDSL # Fetch an entry and transliterate to iast scheme entry_iast = CDSL.MW.entry("263938", output_scheme="iast") print(entry_iast) # Fetch an entry and transliterate to slp1 scheme after creation entry_slp1 = CDSL.MW.entry("263938").transliterate("slp1") print(entry_slp1) ``` -------------------------------- ### Bash: Interactive REPL Shell Operations with pycdsl Source: https://context7.com/hrishikeshrt/pycdsl/llms.txt Illustrates interactive usage of the pycdsl command-line interface (CLI) for exploratory Sanskrit lexicon research. It shows commands for loading dictionaries, searching in different scripts, changing schemes, viewing entries, statistics, and managing the shell environment. Requires pycdsl to be installed. ```bash $ cdsl -i # Load dictionaries (CDSL::None) use MW AP90 # Search with Devanagari (CDSL::MW,AP90) हृषीकेश # Search with ITRANS (CDSL::MW,AP90) set input_scheme itrans (CDSL::MW,AP90) hRRiShIkesha # Change output scheme (CDSL::MW,AP90) set output_scheme iast # Show specific entry by ID (CDSL::MW,AP90) show 263938 # Show entry with raw XML data (CDSL::MW,AP90) show 263938 --show-data # Limit search results (CDSL::MW,AP90) set limit 5 (CDSL::MW,AP90) yoga # Search in values (definitions) (CDSL::MW,AP90) set search_mode value (CDSL::MW,AP90) lord # Get dictionary statistics (CDSL::MW,AP90) stats # View available dictionaries online (CDSL::MW,AP90) available # Install and load new dictionary (CDSL::MW,AP90) use WIL # Output redirection to file (CDSL::MW,AP90) show 263938 > output.txt # Copy output to clipboard (CDSL::MW,AP90) show 263938 > # Execute shell command (CDSL::MW,AP90) !cat output.txt # View command history (CDSL::MW,AP90) history # Create alias (CDSL::MW,AP90) alias rāma hRRiShIkesha # Exit shell (CDSL::MW,AP90) quit ``` -------------------------------- ### Iterate CDSL Dictionary (Python) Source: https://github.com/hrishikeshrt/pycdsl/blob/master/USAGE.rst This snippet shows how to iterate through the entries of a specific CDSL dictionary (MW) and print the type and content of each entry. It's similar to the previous example but focuses on a dictionary instance. ```Python for entry in CDSL.MW: print(type(entry)) print(entry) break ``` -------------------------------- ### Search in CDSL Dictionaries Source: https://github.com/hrishikeshrt/pycdsl/blob/master/docs/usage.md Provides examples of searching within loaded dictionaries using both attribute and item access. It demonstrates specifying transliteration schemes, using wildcards, limiting/offsetting results, and applying different search modes. ```python # Any loaded dictionary is accessible using `[]` operator and dictionary ID # e.g. CDSL["MW"] results = CDSL["MW"].search("राम") # Alternatively, they are also accessible like an attribute # e.g. CDSL.MW, CDSL.MWE etc. results = CDSL.MW.search("राम") # Note: Attribute access and Item access both use the `dicts` property # under the hood to access the dictionaries. # >>> CDSL.MW is CDSL.dicts["MW"] # True # >>> CDSL["MW"] is CDSL.dicts["MW"] # True # `input_scheme` and `output_scheme` can be specified to the search function. CDSL.MW.search("kṛṣṇa", input_scheme="iast", output_scheme="itrans")[0] # # Search using wildcard (i.e. `*`) # e.g. To search all etnries starting with kRRi (i.e. कृ) CDSL.MW.search("kRRi*", input_scheme="itrans") # Limit and/or Offset the number of search results, e.g. # Show the first 10 results CDSL.MW.search("kṛ*", input_scheme="iast", limit=10) # Show the next 10 results CDSL.MW.search("kṛ*", input_scheme="iast", limit=10, offset=10) # Search using a different search mode CDSL.MW.search("हृषीकेश", mode=pycdsl.SEARCH_MODE_VALUE) ``` -------------------------------- ### Create CDSLCorpus Instance Source: https://github.com/hrishikeshrt/pycdsl/blob/master/USAGE.rst Shows how to create a `CDSLCorpus` instance, specifying parameters like `data_dir`, `input_scheme`, `output_scheme`, and `search_mode`. ```python # Default installation at ~/cdsl_data CDSL = pycdsl.CDSLCorpus() ``` ```python # Custom installation path can be specified with argument `data_dir` # e.g. CDSL = pycdsl.CDSLCorpus(data_dir="custom-installation-path") ``` ```python # Custom transliteration schemes for input and output can be specified # with arguments `input_scheme` and `output_scheme`. # Values should be valid names of the schemes from `indic-transliteration` # If unspecified, `DEFAULT_SCHEME` (`devanagari`) would be used. # e.g. CDSL = pycdsl.CDSLCorpus(input_scheme="hk", output_scheme="iast") ``` ```python # Search mode can be specified to search values by key or value or both. # Valid options for `search_mode` are "key", "value", "both". # These are also stored in convenience variables, and it is recommended # to use these instead of string literals. # The variables are, SEARCH_MODE_KEY, SEARCH_MODE_VALUE, SEARCH_MODE_BOTH. # The variable SEARCH_MODES will always hold the list of all valid modes. # The variable DEFAULT_SEARCH_MODE will alway point to the default mode. # e.g. CDSL = pycdsl.CDSLCorpus(search_mode=pycdsl.SEARCH_MODE_VALUE) ``` -------------------------------- ### CDSLShell Initialization Source: https://github.com/hrishikeshrt/pycdsl/blob/master/docs/pycdsl.md Initializes the CDSLShell, allowing configuration of data directory, dictionary IDs, search mode, input/output schemes, history file, and startup scripts. ```APIDOC ## CDSLShell ### Description REPL Interface to CDSL. Creates an instance of CDSLCorpus with provided parameters. CDSLCorpus.setup() is called after the command-loop starts. ### Method `__init__` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **data_dir** (str or None) - Optional - Load a CDSL installation instance at the location data_dir. Passed to CDSLCorpus instance as a keyword argument data_dir. - **dict_ids** (list or None) - Optional - List of dictionary IDs to setup. Passed to a CDSLCorpus.setup() as a keyword argument dict_ids. - **search_mode** (str or None) - Optional - Search mode to query by key, value or both. The default is None. - **input_scheme** (str or None) - Optional - Transliteration scheme for input. If None, DEFAULT_SCHEME is used. The default is None. - **output_scheme** (str or None) - Optional - Transliteration scheme for output. If None, DEFAULT_SCHEME is used. The default is None. - **history_file** (str or None) - Optional - Path to the history file to keep a persistent history. If None, the history does not persist across sessions. The default is None. - **startup_script** (str or None) - Optional - Path to the startup script with a list of startup commands to be executed after initialization. If None, no startup commands are run. The default is None. ### Request Example ```json { "data_dir": "/path/to/data", "dict_ids": ["MW", "IAST"], "search_mode": "both", "input_scheme": "iast", "output_scheme": "devanagari", "history_file": "~/.cdsl_history", "startup_script": "./startup.cdsl" } ``` ### Response This is a constructor, it does not return a value directly but initializes the object. #### Success Response (None) None #### Response Example None ``` -------------------------------- ### PyCDSL Console Interface Help (Console) Source: https://github.com/hrishikeshrt/pycdsl/blob/master/docs/readme.md Displays the help message for the PyCDSL console interface, outlining available command-line arguments for searching, specifying dictionaries, setting modes, and managing the application. ```console cdsl -h ``` -------------------------------- ### Initialize CDSLCorpus Instance Source: https://github.com/hrishikeshrt/pycdsl/blob/master/docs/usage.md Demonstrates how to create an instance of the CDSLCorpus class. It covers default initialization, specifying a custom data directory, and configuring input/output transliteration schemes and search modes. ```python # Default installation at ~/cdsl_data CDSL = pycdsl.CDSLCorpus() # Custom installation path can be specified with argument `data_dir` # e.g. CDSL = pycdsl.CDSLCorpus(data_dir="custom-installation-path") # Custom transliteration schemes for input and output can be specified # with arguments `input_scheme` and `output_scheme`. # Values should be valid names of the schemes from `indic-transliteration` # If unspecified, `DEFAULT_SCHEME` (`devanagari`) would be used. # e.g. CDSL = pycdsl.CDSLCorpus(input_scheme="hk", output_scheme="iast") # Search mode can be specified to search values by key or value or both. # Valid options for `search_mode` are "key", "value", "both". # These are also stored in convenience variables, and it is recommended # to use these instead of string literals. # The variables are, SEARCH_MODE_KEY, SEARCH_MODE_VALUE, SEARCH_MODE_BOTH. # The variable SEARCH_MODES will always hold the list of all valid modes. # The variable DEFAULT_SEARCH_MODE will alway point to the default mode. # e.g. CDSL = pycdsl.CDSLCorpus(search_mode=pycdsl.SEARCH_MODE_VALUE) ``` -------------------------------- ### Initialize and manage CDSLCorpus for multi-dictionary operations Source: https://context7.com/hrishikeshrt/pycdsl/llms.txt Demonstrates creating a CDSLCorpus instance with custom configuration, setting up dictionaries, performing a search across them, and iterating over loaded dictionaries. Requires the pycdsl library and appropriate data directory. ```python import pycdsl # Initialize corpus with custom configuration corpus = pycdsl.CDSLCorpus( data_dir="~/my_sanskrit_data", input_scheme="iast", output_scheme="devanagari", search_mode=pycdsl.SEARCH_MODE_KEY ) # Setup and load default dictionaries (MW, AP90, MWE, AE) corpus.setup() # Setup specific dictionaries with update check corpus.setup(dict_ids=["MW", "VCP"], update=True) # Search across multiple dictionaries results = corpus.search( pattern="kṛṣṇa", input_scheme="iast", output_scheme="devanagari", limit=10 ) # Process results from each dictionary for dict_id, entries in results.items(): print(f"\n{dict_id}: Found {len(entries)} entries") for entry in entries: print(f" {entry.key}: {entry.meaning()}") # Get available dictionaries from CDSL server available = corpus.get_available_dicts() print(f"Available dictionaries: {list(available.keys())}") # Get locally installed dictionaries installed = corpus.get_installed_dicts() print(f"Installed: {list(installed.keys())}") # Iterate over loaded dictionaries for dictionary in corpus: print(f"Dictionary: {dictionary.id} - {dictionary.name}") ``` -------------------------------- ### Python: Advanced Search Patterns and Modes with pycdsl Source: https://context7.com/hrishikeshrt/pycdsl/llms.txt Illustrates advanced search capabilities in pycdsl, including wildcard patterns (prefix, suffix, contains), case-insensitive searches, and multi-dictionary searches with different modes. It requires the pycdsl library and configured dictionaries. ```python import pycdsl corpus = pycdsl.CDSLCorpus( input_scheme="iast", output_scheme="iast" ) corpus.setup(dict_ids=["MW", "AP90", "MWE"]) # Wildcard patterns prefix_results = corpus.MW.search("kṛṣṇa*") # Words starting with kṛṣṇa suffix_results = corpus.MW.search("*kṛṣṇa") # Words ending with kṛṣṇa contains_results = corpus.MW.search("*kṛṣṇa*") # Words containing kṛṣṇa # Case-insensitive search results = corpus.MW.search( pattern="krishna", input_scheme="iast", ignore_case=True ) # Multi-dictionary search with different modes results_by_dict = corpus.search( pattern="viṣṇu", dict_ids=["MW", "AP90"], mode=pycdsl.SEARCH_MODE_BOTH, limit=50 ) for dict_id, entries in results_by_dict.items(): print(f"\n=== {dict_id} ===") for entry in entries[:3]: # Show first 3 from each dictionary print(f"{entry.key}: {entry.meaning()[:100]}...") ``` -------------------------------- ### Custom ORM Model and Database Operations with PyCDSL Source: https://context7.com/hrishikeshrt/pycdsl/llms.txt Demonstrates advanced PyCDSL usage with custom ORM models and database connections. Includes setting up custom models, accessing the database, dynamically constructing models, and performing direct Peewee ORM queries. ```python import pycdsl from pycdsl.models import Lexicon, Entry, lexicon_constructor, entry_constructor # Create corpus with default models corpus = pycdsl.CDSLCorpus() # Custom model map for specific dictionaries from pycdsl.models import MWLexicon, MWEntry, AP90Lexicon, AP90Entry custom_model_map = { "MW": (MWLexicon, MWEntry), "AP90": (AP90Lexicon, AP90Entry) } # Setup with custom models corpus.setup(dict_ids=["MW", "AP90"], model_map=custom_model_map) # Access underlying database connection mw_dict = corpus.MW print(f"Database path: {mw_dict.db}") # Dynamically construct models for any dictionary dict_id = "VCP" VCPLexicon = lexicon_constructor(dict_id) VCPEntry = entry_constructor(dict_id) # Connect dictionary with custom models corpus.setup(dict_ids=["VCP"]) c_corpus.VCP.connect(lexicon_model=VCPLexicon, entry_model=VCPEntry) # Direct database query using Peewee ORM from peewee import fn lexicon_model = corpus.MW._lexicon query = ( lexicon_model .select(lexicon_model.key, fn.COUNT(lexicon_model.key).alias('count')) .group_by(lexicon_model.key) .order_by(fn.COUNT(lexicon_model.key).desc()) .limit(10) ) print("Top 10 most frequent words:") for item in query: print(f" {item.key}: {item.count}") ``` -------------------------------- ### Set Search Mode and Search (Python) Source: https://github.com/hrishikeshrt/pycdsl/blob/master/docs/readme.md Illustrates how to change the search mode to 'value' and then perform a search. This affects how the search query is interpreted against the dictionary entries. ```python from pycdsl import CDSL # Set search mode to value and search CDSL.MW.set_search_mode(mode="value") results = CDSL.MW.search("hRRiShIkesha") print(results) ``` -------------------------------- ### Perform flexible searches using CDSLDict.search() Source: https://context7.com/hrishikeshrt/pycdsl/llms.txt Shows various search patterns including basic Devanagari search, IAST input with ITRANS output, wildcard queries, pagination, and mode selection for key/value/both searches. Utilizes the CDSLDict.search method from a CDSLCorpus instance. ```python import pycdsl corpus = pycdsl.CDSLCorpus() corpus.setup(dict_ids=["MW"]) # Basic search with Devanagari results = corpus.MW.search("राम") print(f"Found {len(results)} results") # Search with IAST input and ITRANS output results = corpus.MW.search( pattern="kṛṣṇa", input_scheme="iast", output_scheme="itrans" ) for entry in results: print(entry) # Output: # Wildcard search - all words starting with 'kṛ' results = corpus.MW.search("kṛ*", input_scheme="iast", limit=20) # Paginated search with offset page1 = corpus.MW.search("yoga", input_scheme="iast", limit=10, offset=0) page2 = corpus.MW.search("yoga", input_scheme="iast", limit=10, offset=10) # Search by value (definition) instead of key (headword) results = corpus.MW.search( "lord of the senses", mode=pycdsl.SEARCH_MODE_VALUE, input_scheme="iast" ) # Search both keys and values results = corpus.MW.search( "viṣṇu", mode=pycdsl.SEARCH_MODE_BOTH, input_scheme="iast", ignore_case=True ) ``` -------------------------------- ### Iterating over CDSL Objects Source: https://github.com/hrishikeshrt/pycdsl/blob/master/USAGE.rst Explains how to iterate through dictionaries and entries in the corpus and dictionary. ```python # * Iterating over :code:`CDSLCorpus` yields loaded dictionary instances. # * Iterating over :code:`CDSLDict` yields entries in that dictionary. ``` -------------------------------- ### Transliterate a Single Entry Source: https://github.com/hrishikeshrt/pycdsl/blob/master/USAGE.rst Demonstrates how to transliterate a single dictionary entry using a specified scheme. ```python CDSL.MW.entry("263938").transliterate("slp1") ``` -------------------------------- ### Search in a Dictionary Source: https://github.com/hrishikeshrt/pycdsl/blob/master/USAGE.rst Demonstrates how to search within a dictionary using both attribute and item access, including options for specifying transliteration schemes and wildcards. ```python # Any loaded dictionary is accessible using `[]` operator and dictionary ID # e.g. CDSL["MW"] results = CDSL["MW"].search("राम") ``` ```python # Alternatively, they are also accessible like an attribute # e.g. CDSL.MW, CDSL.MWE etc. results = CDSL.MW.search("राम") ``` ```python # `input_scheme` and `output_scheme` can be specified to the search function. CDSL.MW.search("kṛṣṇa", input_scheme="iast", output_scheme="itrans")[0] ``` ```python # Search using wildcard (i.e. `*`) # e.g. To search all etnries starting with kRRi (i.e. कृ) CDSL.MW.search("kRRi*", input_scheme="itrans") ``` ```python # Limit and/or Offset the number of search results, e.g. # Show the first 10 results CDSL.MW.search("kṛ*", input_scheme="iast", limit=10) ``` ```python # Show the next 10 results CDSL.MW.search("kṛ*", input_scheme="iast", limit=10, offset=10) ``` ```python # Search using a different search mode CDSL.MW.search("हृषीकेश", mode=pycdsl.SEARCH_MODE_VALUE) ``` -------------------------------- ### CDSL Shell Commands Source: https://github.com/hrishikeshrt/pycdsl/blob/master/docs/pycdsl.md Provides functionality to manage and query dictionaries within the CDSL. ```APIDOC ## CDSL Shell Commands ### Description Commands to interact with the CDSL, including displaying dictionary information, managing dictionaries, and searching entries. ### Methods #### `do_info` ##### Description Display information about active dictionaries. ##### Endpoint `info` #### `do_stats` ##### Description Display statistics about active dictionaries. ##### Endpoint `stats` #### `do_dicts` ##### Description Display a list of dictionaries available locally. ##### Endpoint `dicts` #### `do_available` ##### Description Display a list of dictionaries available in CDSL. ##### Endpoint `available` #### `do_update` ##### Description Update loaded dictionaries. ##### Endpoint `update` #### `do_use` ##### Description Load the specified dictionaries from CDSL. If not available locally, they will be installed first. ##### Endpoint `use [DICT_IDS..]` ##### Parameters - **DICT_IDS** (list) - Required - List of dictionary IDs to load. ##### Request Example ```bash use MW IAST ``` #### `do_show` ##### Description Show a specific entry by ID. ##### Endpoint `show [ENTRY_ID]` ##### Parameters - **ENTRY_ID** (str) - Required - The ID of the entry to show. ##### Request Example ```bash show 12345 ``` #### `do_search` ##### Description Search in the active dictionaries. ##### Endpoint `search [QUERY]` ##### Parameters - **QUERY** (str) - Required - The search query string. ##### Request Example ```bash search *agni* ``` ``` -------------------------------- ### Search Dictionary Entries in PyCDSL Source: https://github.com/hrishikeshrt/pycdsl/blob/master/docs/readme.md This Python code illustrates how to search for entries within a loaded CDSL dictionary. It shows searching by key using attribute or item access, specifying transliteration schemes, using wildcards, and applying limits and offsets to the results. It also demonstrates searching by value. ```python # Any loaded dictionary is accessible using `[]` operator and dictionary ID # e.g. CDSL["MW"] results = CDSL["MW"].search("राम") # Alternatively, they are also accessible like an attribute # e.g. CDSL.MW, CDSL.MWE etc. results = CDSL.MW.search("राम") # Note: Attribute access and Item access both use the `dicts` property # under the hood to access the dictionaries. # >>> CDSL.MW is CDSL.dicts["MW"] # True # >>> CDSL["MW"] is CDSL.dicts["MW"] # True # `input_scheme` and `output_scheme` can be specified to the search function. CDSL.MW.search("kṛṣṇa", input_scheme="iast", output_scheme="itrans")[0] # # Search using wildcard (i.e. `*`) # e.g. To search all etnries starting with kRRi (i.e. कृ) CDSL.MW.search("kRRi*", input_scheme="itrans") # Limit and/or Offset the number of search results, e.g. # Show the first 10 results CDSL.MW.search("kṛ*", input_scheme="iast", limit=10) # Show the next 10 results CDSL.MW.search("kṛ*", input_scheme="iast", limit=10, offset=10) # Search using a different search mode CDSL.MW.search("हृषीकेश", mode=pycdsl.SEARCH_MODE_VALUE) ``` -------------------------------- ### Access Entry by ID Source: https://github.com/hrishikeshrt/pycdsl/blob/master/USAGE.rst Shows how to access a dictionary entry by its ID using both item access and the `entry()` function. ```python # Access entry by `entry_id` using `[]` operator entry = CDSL.MW["263938"] ``` ```python # Alternatively, use `CDSLDict.entry` function entry = CDSL.MW.entry("263938") ``` ```python # Output transliteration scheme can also be provided CDSL.MW.entry("263938", output_scheme="iast") ``` -------------------------------- ### Iterate CDSL Corpus (Python) Source: https://github.com/hrishikeshrt/pycdsl/blob/master/USAGE.rst This snippet demonstrates how to iterate through a `CDSLCorpus` instance and print the type and content of each element, stopping after the first iteration. It uses a basic Python for loop. ```Python for cdsl_dict in CDSL: print(type(cdsl_dict)) print(cdsl_dict) break ``` -------------------------------- ### Python: Transliterate Sanskrit Dictionary Entries with pycdsl Source: https://context7.com/hrishikeshrt/pycdsl/llms.txt Demonstrates how to dynamically transliterate Sanskrit dictionary entries using the pycdsl library. It covers retrieving entries, changing transliteration schemes, and performing searches with different input and output formats. Dependencies include the pycdsl library. ```python import pycdsl corpus = pycdsl.CDSLCorpus() corpus.setup(dict_ids=["MW"]) # Get entry in default scheme entry = corpus.MW.entry("263938") print(entry) # Devanagari output # Transliterate single entry after retrieval entry_slp1 = entry.transliterate("slp1") print(entry_slp1) # entry_iast = entry.transliterate("iast", transliterate_keys=True) print(entry_iast) # # Change dictionary's default transliteration scheme corpus.MW.set_scheme( input_scheme="itrans", output_scheme="iast" ) # Now all searches use new scheme results = corpus.MW.search("rAma") # Input in ITRANS for entry in results: print(entry.key) # Output in IAST: rāma # Change search mode for dictionary corpus.MW.set_search_mode(mode=pycdsl.SEARCH_MODE_VALUE) results = corpus.MW.search("hRRiShIkesha") # Searches in definitions ``` -------------------------------- ### Retrieve dictionary entries by unique ID Source: https://context7.com/hrishikeshrt/pycdsl/llms.txt Illustrates accessing entries directly using the dictionary's indexing operator and the entry() method, handling missing IDs, and converting entries to dictionaries. Requires a previously set up corpus with the desired dictionary loaded. ```python import pycdsl corpus = pycdsl.CDSLCorpus() corpus.setup(dict_ids=["MW"]) # Access entry by ID using dictionary syntax entry = corpus.MW["263938"] print(entry) # # Alternative: use entry() method with error handling entry = corpus.MW.entry("263938", output_scheme="iast") if entry: print(f"Key: {entry.key}") print(f"ID: {entry.id}") print(f"Meaning: {entry.meaning()}") print(f"Raw data: {entry.data}") # Convert entry to dictionary entry_dict = entry.to_dict() print(entry_dict) # Output: { # 'lexicon': 'MW', # 'id': '263938', # 'key': 'hṛṣīkeśa', # 'data': '......', # 'text': 'lord of the senses (said of Manas), BhP.' # } # Invalid entry ID returns None (with entry method) result = corpus.MW.entry("999999") if result is None: print("Entry not found") # Invalid entry ID raises KeyError (with [] operator) try: entry = corpus.MW["999999"] except KeyError as e: print(f"Error: {e}") ``` -------------------------------- ### Set Transliteration Scheme and Search (Python) Source: https://github.com/hrishikeshrt/pycdsl/blob/master/docs/readme.md Shows how to change the input transliteration scheme for dictionary searches and then perform a search. This is useful when dealing with different transliteration formats. ```python from pycdsl import CDSL # Set input scheme to itrans and search CDSL.MW.set_scheme(input_scheme="itrans") results = CDSL.MW.search("rAma") print(results) ``` -------------------------------- ### Import PyCDSL Library Source: https://github.com/hrishikeshrt/pycdsl/blob/master/docs/usage.md This snippet shows the basic import statement required to use the PyCDSL library in a Python project. It is the first step before initializing any PyCDSL functionalities. ```python import pycdsl ``` -------------------------------- ### Python: Dictionary Statistics and Iteration with pycdsl Source: https://context7.com/hrishikeshrt/pycdsl/llms.txt Shows how to obtain statistics for Sanskrit dictionaries and iterate over their entries using the pycdsl library. This includes fetching total counts, distinct headwords, top frequent words, and dumping dictionary content to JSON. Requires the pycdsl library. ```python import pycdsl corpus = pycdsl.CDSLCorpus() corpus.setup(dict_ids=["MW", "AP90"]) # Get statistics for a dictionary stats = corpus.MW.stats(top=15, output_scheme="iast") print(f"Total entries: {stats['total']}") print(f"Distinct headwords: {stats['distinct']}") print("Top 15 words by frequency:") for word, count in stats['top']: print(f" {word}: {count} entries") # Iterate over all entries in a dictionary (warning: may be very large) entry_count = 0 for entry in corpus.MW: if entry_count < 5: # Show first 5 entries only print(f"{entry.id}: {entry.key} = {entry.meaning()}") entry_count += 1 if entry_count >= 5: break print(f"Total entries in MW: {entry_count}") # Dump entire dictionary to JSON data = corpus.MW.dump( output_path="mw_dictionary.json", output_scheme="iast" ) print(f"Exported {len(data)} entries to JSON") ``` -------------------------------- ### Iterate over CDSLCorpus and CDSLDict Source: https://github.com/hrishikeshrt/pycdsl/blob/master/docs/usage.md Illustrates how both CDSLCorpus and CDSLDict objects are iterable. Iterating over CDSLCorpus yields loaded dictionary instances, while iterating over CDSLDict yields individual entries within that dictionary. ```python # Iteration over a `CDSLCorpus` instance for cdsl_dict in CDSL: print(type(cdsl_dict)) print(cdsl_dict) break # # CDSLDict(id='MW', date='1899', name='Monier-Williams Sanskrit-English Dictionary') # Iteration over a `CDSLDict` isntance for entry in CDSL.MW: print(type(entry)) print(entry) break # ``` -------------------------------- ### Search In CDSL Corpus Source: https://github.com/hrishikeshrt/pycdsl/blob/master/docs/pycdsl.md Performs a search across multiple dictionaries within the CDSL corpus. Supports pattern matching with wildcards, transliteration schemes, and configurable search parameters like case sensitivity and result limits. ```python results = corpus.search(pattern='*deva*', dict_ids=['dict1'], ignore_case=True, limit=10) ``` -------------------------------- ### English to Sanskrit Reverse Lookup using PyCDSL Source: https://context7.com/hrishikeshrt/pycdsl/llms.txt Performs a reverse lookup for an English word in the corpus, translating it to Sanskrit. Outputs the top 5 Sanskrit entries in Devanagari script. Requires the PyCDSL library. ```python import pycdsl corpus = pycdsl.CDSLCorpus() results = corpus.MWE.search( pattern="love", input_scheme="iast", output_scheme="devanagari" ) print("English 'love' translates to:") for entry in results[:5]: print(f" {entry.key}") ``` -------------------------------- ### Access Dictionary Entry by ID in PyCDSL Source: https://github.com/hrishikeshrt/pycdsl/blob/master/docs/readme.md This Python code shows how to retrieve a specific dictionary entry using its unique identifier. It presents two methods: using the item access operator `[]` and the `entry()` method, highlighting the difference in error handling when an ID is not found. ```python # Access entry by `entry_id` using `[]` operator entry = CDSL.MW["263938"] # Alternatively, use `CDSLDict.entry` function entry = CDSL.MW.entry("263938") # Note: Access using `[]` operator calls the `CDSLDict.entry` function. # The difference is that, in case an `entry_id` is absent, # `[]` based access will raise a `KeyError` # `CDSLDict.entry` will return None and log a `logging.ERROR` level message # >>> entry ``` -------------------------------- ### Access Entry by ID in CDSLDict Source: https://github.com/hrishikeshrt/pycdsl/blob/master/docs/usage.md Illustrates how to retrieve a specific dictionary entry using its unique ID. It shows access via the square bracket operator and the `entry` method, highlighting the difference in error handling when an ID is not found. ```python # Access entry by `entry_id` using `[]` operator entry = CDSL.MW["263938"] # Alternatively, use `CDSLDict.entry` function entry = CDSL.MW.entry("263938") # Note: Access using `[]` operator calls the `CDSLDict.entry` function. # The difference is that, in case an `entry_id` is absent, # `[]` based access will raise a `KeyError` # `CDSLDict.entry` will return None and log a `logging.ERROR` level message # >>> entry # # Output transliteration scheme can also be provided CDSL.MW.entry("263938", output_scheme="iast") # ``` -------------------------------- ### Transliterate a Single Entry Source: https://github.com/hrishikeshrt/pycdsl/blob/master/docs/usage.md Demonstrates the ability to transliterate a dictionary entry after it has been fetched. This allows for changing the representation of the entry's content to a different transliteration scheme. ```python CDSL.MW.entry("263938").transliterate("slp1") # ``` -------------------------------- ### Change Transliteration Scheme for a Dictionary Source: https://github.com/hrishikeshrt/pycdsl/blob/master/docs/usage.md Explains how to permanently change the input or output transliteration scheme for a specific dictionary instance. Subsequent searches on that dictionary will use the newly set scheme. ```python CDSL.MW.set_scheme(input_scheme="itrans") CDSL.MW.search("rAma") ``` -------------------------------- ### Change Search Mode for a Dictionary Source: https://github.com/hrishikeshrt/pycdsl/blob/master/docs/usage.md Shows how to modify the search mode (e.g., 'key', 'value', 'both') for a dictionary instance. This change affects how future search queries on that dictionary are interpreted. ```python CDSL.MW.set_search_mode(mode="value") CDSL.MW.search("hRRiShIkesha") ```