### Set up Python Versions and Run Tests with tox Source: https://pykakasi.readthedocs.io/en/latest/devguide.html Install specific Python versions using pyenv, set them as local versions, and then run tests using tox for cross-environment compatibility. ```bash pyenv install 2.7.13 pyenv install 3.5.5 pyenv install 3.6.4 pyenv local 2.7.13, 3.5.5, 3.6.4 tox ``` -------------------------------- ### Install Pykakasi Library Source: https://pykakasi.readthedocs.io/en/latest/api.html Installs the pykakasi library using pip. Ensure you have pip installed and configured. ```bash pip install pykakasi ``` -------------------------------- ### Run Local Tests with pytest Source: https://pykakasi.readthedocs.io/en/latest/devguide.html Execute the project's tests using the pytest framework. Ensure pytest is installed in your environment. ```bash pytest ``` -------------------------------- ### Configure and Convert Japanese Text to Romanized Output Source: https://pykakasi.readthedocs.io/en/latest/api.html Configures conversion modes for Hiragana, Katakana, and Japanese text to ASCII (romanized) output with Hepburn romanization, spaces, and capitalization. This is a comprehensive example for general text conversion. ```python from pykakasi import kakasi, wakati text = u"かな漢字交じり文" kakasi = kakasi() kakasi.setMode("H","a") # Hiragana to ascii, default: no conversion kakasi.setMode("K","a") # Katakana to ascii, default: no conversion kakasi.setMode("J","a") # Japanese to ascii, default: no conversion kakasi.setMode("r","Hepburn") # default: use Hepburn Roman table kakasi.setMode("s", True) # add space, default: no separator kakasi.setMode("C", True) # capitalize, default: no capitalize conv = kakasi.getConverter() result = conv.do(text) print(result) ``` -------------------------------- ### Transliterate Japanese text to rōmaji with specific modes Source: https://pykakasi.readthedocs.io/en/latest/api.html Demonstrates transliterating Japanese text to rōmaji using specific `setMode` configurations for Hiragana, Katakana, Japanese to ASCII, Hepburn romanization, spacing, and capitalization. This example is useful for understanding the effect of each mode. ```python >>> import pykakasi >>> >>> text = u"かな漢字交じり文" >>> kakasi = pykakasi.kakasi() >>> kakasi.setMode("H","a") # Hiragana to ascii, default: no conversion >>> kakasi.setMode("K","a") # Katakana to ascii, default: no conversion >>> kakasi.setMode("J","a") # Japanese to ascii, default: no conversion >>> kakasi.setMode("r","Hepburn") # default: use Hepburn Roman table >>> kakasi.setMode("s", True) # add space, default: no separator >>> kakasi.setMode("C", True) # capitalize, default: no capitalize >>> conv = kakasi.getConverter() >>> result = conv.do(text) >>> print(result) kana Kanji Majiri Bun ``` -------------------------------- ### Run Local Tests with setup.py Source: https://pykakasi.readthedocs.io/en/latest/devguide.html Execute the project's tests using the setup.py script. This is a standard way to run tests for Python packages. ```bash python setup.py test ``` -------------------------------- ### Display Help Text Source: https://pykakasi.readthedocs.io/en/latest/cli.html Use --help or -h to display the help text for pykakasi. ```bash --help, -h ``` -------------------------------- ### Enable Wakati Gaki Mode Source: https://pykakasi.readthedocs.io/en/latest/cli.html Use --wakati or -w to enable the wakati gaki mode for processing. ```bash --wakati, -w ``` -------------------------------- ### Display Version Source: https://pykakasi.readthedocs.io/en/latest/cli.html Use --version or -v to display the current version of pykakasi. ```bash --version, -v ``` -------------------------------- ### Specify Input File Source: https://pykakasi.readthedocs.io/en/latest/cli.html Use --input or -i followed by a filename to specify the input file for processing. ```bash --input, -i ``` -------------------------------- ### Kakasi Command Options (Original) Source: https://pykakasi.readthedocs.io/en/latest/changes.html These options replicate the behavior of the original kakasi command. ```bash -J{aKH} -K{aH} -H{aK} -E{a} -rk -rh -w -s -S -C ``` -------------------------------- ### Specify Output File Source: https://pykakasi.readthedocs.io/en/latest/cli.html Use --output or -o followed by a filename to specify the output file for results. ```bash --output, -o ``` -------------------------------- ### Convert Kanji to ASCII, Hiragana, Katakana, or None Source: https://pykakasi.readthedocs.io/en/latest/cli.html Use the -J option to specify how Kanji should be converted: 'a' for ASCII, 'H' for Hiragana, 'K' for Katakana, or 'None'. ```bash -J ``` -------------------------------- ### Kakasi Command Options (Additional) Source: https://pykakasi.readthedocs.io/en/latest/changes.html These are additional options supported by the PyKakasi implementation of the kakasi command. ```bash -v --version -h --help -O --output: output file -I --input: input file ``` -------------------------------- ### Convert Japanese Text to Romanized Output with Furigana Source: https://pykakasi.readthedocs.io/en/latest/api.html Configures conversion modes to output Japanese text with furigana (pronunciation aid) in romaji. Useful for displaying pronunciation alongside text. ```python import pykakasi text = u"かな漢字交じり文" kakasi = pykakasi.kakasi() kakasi.setMode("J","aF") # Japanese to furigana kakasi.setMode("H","aF") # Japanese to furigana conv = kakasi.getConverter() result = conv.do(text) print(result) ``` -------------------------------- ### convert method Source: https://pykakasi.readthedocs.io/en/latest/api.html The 'convert' method returns a dictionary with original text, kana, hiragana, Hepburn, Kunrei, and passport romanization. ```APIDOC ## convert method ### Description Returns the conversion result as a dictionary. The dictionary contains keys for the original text ('orig'), kana ('kana'), hiragana ('hira'), Hepburn romanization ('hepburn'), Kunrei romanization ('kunrei'), and passport romanization ('passport'). ### Method ``` kks = pykakasi.kakasi() result = kks.convert(text) ``` ### Parameters * **text** (string) - The Japanese text to convert. ### Response * **result** (list of dict) - A list of dictionaries, where each dictionary represents a converted segment of the text and contains the following keys: * **orig** (string) - The original character or word. * **kana** (string) - The Katakana representation. * **hira** (string) - The Hiragana representation. * **hepburn** (string) - The Hepburn romanization. * **kunrei** (string) - The Kunrei-shiki romanization. * **passport** (string) - The Passport romanization. ### Request Example ```python kks = pykakasi.kakasi() text = 'かな漢字' result = kks.convert(text) for item in result: print("{}: kana '{}', hiragana '{}', romaji: '{}'".format(item['orig'], item['kana'], item['hira'], item['hepburn'])) ``` ### Response Example ``` かな: kana 'カナ', hiragana: 'かな', romaji: 'kana' 漢字: kana 'カンジ', hiragana: 'かんじ', romaji: 'kanji' ``` ``` -------------------------------- ### Enable Furigana Mode Source: https://pykakasi.readthedocs.io/en/latest/cli.html Use the -f flag to enable furigana mode for processing. ```bash -f ``` -------------------------------- ### Conversion Options (Old API) Source: https://pykakasi.readthedocs.io/en/latest/api.html Details on conversion options for the older v1.2 API, including Katakana, Hiragana, Kanji, and Roman conversion settings. ```APIDOC ## Conversion Options (Old API v1.2) ### Description These options control the conversion process for Japanese text. They are derived from the original Kakasi tool and allow customization of how different character types (Katakana, Hiragana, Kanji) are converted, as well as the romanization style. ### Options Table | Option | Description | Values | Note | |---|---|---|---| | K | Katakana conversion | a,H,None | roman, Hiragana or non conversion | | H | Hiragana conversion | a,K,None | roman, Katakana or non conversion | | J | Kanji conversion | a,H,K,None | roman or Hiragana, Katakana or noconv | | a | Roman conversion | E,None | JIS ROMAN or non conversion | | E | JIS ROMAN conversion | a,None | ascii roman or non conversion | ### Character Sets * **a**: ascii * **j**: jisroman * **g**: graphic * **k**: kana (defined in jisx0201) * **E**: kigou * **K**: katakana * **H**: hiragana * **J**: kanji (defined in jisx0208) ### API Usage Example (Old API) ```python from pykakasi import kakasi text = u"かな漢字交じり文" kks = kakasi() kks.setMode("H","a") # Hiragana to ascii kks.setMode("K","a") # Katakana to ascii kks.setMode("J","a") # Japanese to ascii kks.setMode("r","Hepburn") # Romanisation table kks.setMode("s", True) # Add space separator kks.setMode("C", True) # Capitalize first letter of each word conv = kks.getConverter() result = conv.do(text) print(result) ``` ### Output Mode Values * **H**: Hiragana * **K**: Katakana * **a**: Alphabet / Romaji * **aF**: Furigana in Romaji ### Other `setMode` Switches * **r**: Romanisation table (`Hepburn`, `Kunrei`, `Passport`) * **s**: Separator (`True` adds spaces, `False` does not) * **C**: Capitalize (`True` capitalizes words, `False` does not) ``` -------------------------------- ### Convert Hiragana to ASCII, Katakana, or None Source: https://pykakasi.readthedocs.io/en/latest/cli.html Use the -H option to specify how Hiragana should be converted: 'a' for ASCII, 'K' for Katakana, or 'None'. ```bash -H ``` -------------------------------- ### Add furigana (pronounciation aid) in rōmaji to text Source: https://pykakasi.readthedocs.io/en/latest/api.html Shows how to add furigana in romaji to Japanese text using specific `setMode` configurations for Japanese and Hiragana to furigana output. This is useful for displaying pronunciation aids. ```python >>> kakasi = pykakasi.kakasi() >>> kakasi.setMode("J","aF") # Japanese to furigana >>> kakasi.setMode("H","aF") # Japanese to furigana >>> conv = kakasi.getConverter() >>> result = conv.do(text) >>> print(result) かな[kana] 漢字[Kanji] 交じり[Majiri] 文[Bun] ``` -------------------------------- ### Convert Katakana to ASCII, Hepburn Roman, or None Source: https://pykakasi.readthedocs.io/en/latest/cli.html Use the -K option to specify how Katakana should be converted: 'a' for ASCII, 'H' for Hepburn Roman, or 'None'. ```bash -K ``` -------------------------------- ### Convert Japanese Text to Dictionary Format Source: https://pykakasi.readthedocs.io/en/latest/api.html Uses the `convert` method to return a dictionary with original and converted text components. Useful for detailed analysis of converted text. ```python import pykakasi kks = pykakasi.kakasi() text = 'かな漢字' result = kks.convert(text) for item in result: print("{}: kana '{}', hiragana '{}', romaji: '{}'".format(item['orig'], item['kana'], item['hira'], item['hepburn'])) ``` -------------------------------- ### Output Uppercase Characters Source: https://pykakasi.readthedocs.io/en/latest/cli.html Use the -U option to output all characters in uppercase. ```bash -U ``` -------------------------------- ### Tokenize Japanese Text using wakati Source: https://pykakasi.readthedocs.io/en/latest/api.html Uses the `wakati` class to tokenize Japanese text, splitting it into word boundaries. This is equivalent to the `wakati` gaki option. ```python from pykakasi import kakasi, wakati text = u"かな漢字交じり文" wakati = wakati() conv = wakati.getConverter() result = conv.do(text) print(result) ``` -------------------------------- ### Convert ASCII Roman to ASCII or None Source: https://pykakasi.readthedocs.io/en/latest/cli.html Use the -a option to specify how ASCII Roman characters should be converted: 'E' for Kigou (symbols) or 'None'. ```bash -a ``` -------------------------------- ### Character Set Definitions Source: https://pykakasi.readthedocs.io/en/latest/cli.html Defines the character sets used for conversion: 'a' for ascii, 'j' for jisroman, 'g' for graphic, 'k' for kana, 'E' for kigou, 'K' for katakana, 'H' for hiragana, 'J' for kanji. ```text Character Sets a: ascii j: jisroman g: graphic k: kana (j,k defined in jisx0201) E: kigou K: katakana H: hiragana J: kanji (E,K,H,J defined in jisx0208) ``` -------------------------------- ### Successful Conversion Return Code Source: https://pykakasi.readthedocs.io/en/latest/cli.html A return code of 0 indicates that the conversion process was successful. ```text 0. convert successful ``` -------------------------------- ### Capitalize First Roman Character of Each Word Source: https://pykakasi.readthedocs.io/en/latest/cli.html Use the -C option to capitalize the first Roman character of each word. ```bash -C ``` -------------------------------- ### Convert JIS Roman to ASCII or None Source: https://pykakasi.readthedocs.io/en/latest/cli.html Use the -E option to specify how JIS Roman characters should be converted: 'a' for ASCII or 'None'. ```bash -E ``` -------------------------------- ### Specify Roman Word Conversion Rule Source: https://pykakasi.readthedocs.io/en/latest/cli.html Use --roman or -r followed by 'h' (hepburn), 'k' (kunrei), or 'p' (passport) to specify the Roman word conversion rule. ```bash --roman, -r ``` -------------------------------- ### Insert Space Between Words Source: https://pykakasi.readthedocs.io/en/latest/cli.html Use --space or -s to insert a space character between words in the output. ```bash --space, -s ``` -------------------------------- ### Specify Separator Character Source: https://pykakasi.readthedocs.io/en/latest/cli.html Use --separator or -S followed by a character to specify the separator character inserted between words. ```bash --separator, -S ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.