chirptext


Namechirptext JSON
Version 0.1.2 PyPI version JSON
download
home_pagehttps://github.com/letuananh/chirptext/
SummaryA minimalist collection of text processing tools for Python 3
upload_time2021-05-20 03:19:39
maintainer
docs_urlNone
authorLe Tuan Anh
requires_python>=3.5
licenseMIT License
keywords nlp mecab language linguistics vietnamese japanese chinese kanji radical
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            ChirpText is a collection of text processing tools for Python 3.

[![Documentation Status](https://readthedocs.org/projects/chirptext/badge/?version=latest)](https://chirptext.readthedocs.io/en/latest/?badge=latest)
[![Total alerts](https://img.shields.io/lgtm/alerts/g/letuananh/chirptext.svg?logo=lgtm&logoWidth=18)](https://lgtm.com/projects/g/letuananh/chirptext/alerts/)
[![Language grade: Python](https://img.shields.io/lgtm/grade/python/g/letuananh/chirptext.svg?logo=lgtm&logoWidth=18)](https://lgtm.com/projects/g/letuananh/chirptext/context:python)

It is not meant to be a powerful tank like the popular NTLK but a small package which you can pip-install anywhere and write a few lines of code to process textual data.

# Main features

* Simple file data manipulation using an enhanced `open()` function (txt, gz, binary, etc.)
* CSV helper functions
* Parse Japanese text with mecab library (Does not require `mecab-python3` package even on Windows, only a binary release (i.e. `mecab.exe`) is required)
* Built-in "lite" [text annotation formats](https://pypi.org/project/texttaglib/) (`texttaglib` TTL/CSV and TTL/JSON)
* Helper functions and useful data for processing English, Japanese, Chinese and Vietnamese.
* Application configuration files management which can make educated guess about config files' whereabouts
* Quick text-based report generation

# Installation

`chirptext` is available on [PyPI](https://pypi.org/project/chirptext/) and can be installed using pip

```bash
pip install chirptext
```

**Note**: chirptext library does not support Python 2 anymore. Please update to Python 3 to use this package.

# Sample codes

## Using MeCab on Windows
You can download mecab binary package from [http://taku910.github.io/mecab/#download](http://taku910.github.io/mecab/#download) and install it.
After installed you can try:
```python
>>> from chirptext import deko
>>> sent = deko.parse('猫が好きです。')
>>> sent.tokens
[[猫(名詞-一般/*/*|猫|ネコ|ネコ)], [が(助詞-格助詞/一般/*|が|ガ|ガ)], [好き(名詞-形容動詞語幹/*/*|好き|スキ|スキ)], [です(助動詞-*/*/*|です|デス|デス)], [。(記号-句点/*/*|。|。|。)], [EOS(-//|||)]]
>>> sent.words
['猫', 'が', '好き', 'です', '。']
>>> sent[0].pos
'名詞'
>>> sent[0].root
'猫'
>>> sent[0].reading
'ネコ'
```

If you installed MeCab to a custom location, for example `C:\mecab\bin\mecab.exe`, try
```python
>>> deko.set_mecab_bin("C:\\mecab\\bin\\mecab.exe")
>>> deko.get_mecab_bin()
'C:\\mecab\\bin\\mecab.exe'

# Just that & now you can use mecab
>>> deko.parse('雨が降る。').words
['雨', 'が', '降る', '。']
```

## Convenient IO APIs

```python
>>> from chirptext import chio
>>> chio.write_tsv('data/test.tsv', [['a', 'b'], ['c', 'd']])
>>> chio.read_tsv('data/tes.tsv')
[['a', 'b'], ['c', 'd']]

>>> chio.write_file('data/content.tar.gz', 'Support writing to .tar.gz file')
>>> chio.read_file('data/content.tar.gz')
'Support writing to .tar.gz file'

>>> for row in chio.read_tsv_iter('data/test.tsv'):
...     print(row)
... 
['a', 'b']
['c', 'd']
```

## Sample TextReport

```python
# a string report
rp = TextReport()  # by default, TextReport will write to standard output, i.e. terminal
rp = TextReport(TextReport.STDOUT)  # same as above
rp = TextReport('~/tmp/my-report.txt')  # output to a file
rp = TextReport.null()  # ouptut to /dev/null, i.e. nowhere
rp = TextReport.string()  # output to a string. Call rp.content() to get the string
rp = TextReport(TextReport.STRINGIO)  # same as above

# TextReport will close the output stream automatically by using the with statement
with TextReport.string() as rp:
    rp.header("Lorem Ipsum Analysis", level="h0")
    rp.header("Raw", level="h1")
    rp.print(LOREM_IPSUM)
    rp.header("Top 5 most common letters")
    ct.summarise(report=rp, limit=5)
    print(rp.content())
```

### Output
```
+---------------------------------------------------------------------------------- 
| Lorem Ipsum Analysis 
+---------------------------------------------------------------------------------- 
 
Raw 
------------------------------------------------------------ 
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. 
 
Top 5 most common letters
------------------------------------------------------------ 
i: 42 
e: 37 
t: 32 
o: 29 
a: 29 
```

# Useful links

- Documentation: https://chirptext.readthedocs.io
- Source code: https://github.com/letuananh/chirptext/
- PyPI: https://pypi.org/project/chirptext/
            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/letuananh/chirptext/",
    "name": "chirptext",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.5",
    "maintainer_email": "",
    "keywords": "nlp,mecab,language,linguistics,vietnamese,japanese,chinese,kanji,radical",
    "author": "Le Tuan Anh",
    "author_email": "tuananh.ke@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/66/1f/7da1ed147b9d8687283dfea4f8413ab9067242591978db493fe3a8d4b96c/chirptext-0.1.2.tar.gz",
    "platform": "any",
    "description": "ChirpText is a collection of text processing tools for Python 3.\n\n[![Documentation Status](https://readthedocs.org/projects/chirptext/badge/?version=latest)](https://chirptext.readthedocs.io/en/latest/?badge=latest)\n[![Total alerts](https://img.shields.io/lgtm/alerts/g/letuananh/chirptext.svg?logo=lgtm&logoWidth=18)](https://lgtm.com/projects/g/letuananh/chirptext/alerts/)\n[![Language grade: Python](https://img.shields.io/lgtm/grade/python/g/letuananh/chirptext.svg?logo=lgtm&logoWidth=18)](https://lgtm.com/projects/g/letuananh/chirptext/context:python)\n\nIt is not meant to be a powerful tank like the popular NTLK but a small package which you can pip-install anywhere and write a few lines of code to process textual data.\n\n# Main features\n\n* Simple file data manipulation using an enhanced `open()` function (txt, gz, binary, etc.)\n* CSV helper functions\n* Parse Japanese text with mecab library (Does not require `mecab-python3` package even on Windows, only a binary release (i.e. `mecab.exe`) is required)\n* Built-in \"lite\" [text annotation formats](https://pypi.org/project/texttaglib/) (`texttaglib` TTL/CSV and TTL/JSON)\n* Helper functions and useful data for processing English, Japanese, Chinese and Vietnamese.\n* Application configuration files management which can make educated guess about config files' whereabouts\n* Quick text-based report generation\n\n# Installation\n\n`chirptext` is available on [PyPI](https://pypi.org/project/chirptext/) and can be installed using pip\n\n```bash\npip install chirptext\n```\n\n**Note**: chirptext library does not support Python 2 anymore. Please update to Python 3 to use this package.\n\n# Sample codes\n\n## Using MeCab on Windows\nYou can download mecab binary package from [http://taku910.github.io/mecab/#download](http://taku910.github.io/mecab/#download) and install it.\nAfter installed you can try:\n```python\n>>> from chirptext import deko\n>>> sent = deko.parse('\u732b\u304c\u597d\u304d\u3067\u3059\u3002')\n>>> sent.tokens\n[[\u732b(\u540d\u8a5e-\u4e00\u822c/*/*|\u732b|\u30cd\u30b3|\u30cd\u30b3)], [\u304c(\u52a9\u8a5e-\u683c\u52a9\u8a5e/\u4e00\u822c/*|\u304c|\u30ac|\u30ac)], [\u597d\u304d(\u540d\u8a5e-\u5f62\u5bb9\u52d5\u8a5e\u8a9e\u5e79/*/*|\u597d\u304d|\u30b9\u30ad|\u30b9\u30ad)], [\u3067\u3059(\u52a9\u52d5\u8a5e-*/*/*|\u3067\u3059|\u30c7\u30b9|\u30c7\u30b9)], [\u3002(\u8a18\u53f7-\u53e5\u70b9/*/*|\u3002|\u3002|\u3002)], [EOS(-//|||)]]\n>>> sent.words\n['\u732b', '\u304c', '\u597d\u304d', '\u3067\u3059', '\u3002']\n>>> sent[0].pos\n'\u540d\u8a5e'\n>>> sent[0].root\n'\u732b'\n>>> sent[0].reading\n'\u30cd\u30b3'\n```\n\nIf you installed MeCab to a custom location, for example `C:\\mecab\\bin\\mecab.exe`, try\n```python\n>>> deko.set_mecab_bin(\"C:\\\\mecab\\\\bin\\\\mecab.exe\")\n>>> deko.get_mecab_bin()\n'C:\\\\mecab\\\\bin\\\\mecab.exe'\n\n# Just that & now you can use mecab\n>>> deko.parse('\u96e8\u304c\u964d\u308b\u3002').words\n['\u96e8', '\u304c', '\u964d\u308b', '\u3002']\n```\n\n## Convenient IO APIs\n\n```python\n>>> from chirptext import chio\n>>> chio.write_tsv('data/test.tsv', [['a', 'b'], ['c', 'd']])\n>>> chio.read_tsv('data/tes.tsv')\n[['a', 'b'], ['c', 'd']]\n\n>>> chio.write_file('data/content.tar.gz', 'Support writing to .tar.gz file')\n>>> chio.read_file('data/content.tar.gz')\n'Support writing to .tar.gz file'\n\n>>> for row in chio.read_tsv_iter('data/test.tsv'):\n...     print(row)\n... \n['a', 'b']\n['c', 'd']\n```\n\n## Sample TextReport\n\n```python\n# a string report\nrp = TextReport()  # by default, TextReport will write to standard output, i.e. terminal\nrp = TextReport(TextReport.STDOUT)  # same as above\nrp = TextReport('~/tmp/my-report.txt')  # output to a file\nrp = TextReport.null()  # ouptut to /dev/null, i.e. nowhere\nrp = TextReport.string()  # output to a string. Call rp.content() to get the string\nrp = TextReport(TextReport.STRINGIO)  # same as above\n\n# TextReport will close the output stream automatically by using the with statement\nwith TextReport.string() as rp:\n    rp.header(\"Lorem Ipsum Analysis\", level=\"h0\")\n    rp.header(\"Raw\", level=\"h1\")\n    rp.print(LOREM_IPSUM)\n    rp.header(\"Top 5 most common letters\")\n    ct.summarise(report=rp, limit=5)\n    print(rp.content())\n```\n\n### Output\n```\n+---------------------------------------------------------------------------------- \n| Lorem Ipsum Analysis \n+---------------------------------------------------------------------------------- \n \nRaw \n------------------------------------------------------------ \nLorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. \n \nTop 5 most common letters\n------------------------------------------------------------ \ni: 42 \ne: 37 \nt: 32 \no: 29 \na: 29 \n```\n\n# Useful links\n\n- Documentation: https://chirptext.readthedocs.io\n- Source code: https://github.com/letuananh/chirptext/\n- PyPI: https://pypi.org/project/chirptext/",
    "bugtrack_url": null,
    "license": "MIT License",
    "summary": "A minimalist collection of text processing tools for Python 3",
    "version": "0.1.2",
    "project_urls": {
        "Bug Tracker": "https://github.com/letuananh/chirptext/issues",
        "Homepage": "https://github.com/letuananh/chirptext/",
        "Source Code": "https://github.com/letuananh/chirptext/"
    },
    "split_keywords": [
        "nlp",
        "mecab",
        "language",
        "linguistics",
        "vietnamese",
        "japanese",
        "chinese",
        "kanji",
        "radical"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "661f7da1ed147b9d8687283dfea4f8413ab9067242591978db493fe3a8d4b96c",
                "md5": "620afb738e18470d86ce2a2868ad9b75",
                "sha256": "643c9c11508f509b37257e3f3a629a668c0908ae5f582d7b9f131234a7379303"
            },
            "downloads": -1,
            "filename": "chirptext-0.1.2.tar.gz",
            "has_sig": false,
            "md5_digest": "620afb738e18470d86ce2a2868ad9b75",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.5",
            "size": 70576,
            "upload_time": "2021-05-20T03:19:39",
            "upload_time_iso_8601": "2021-05-20T03:19:39.082656Z",
            "url": "https://files.pythonhosted.org/packages/66/1f/7da1ed147b9d8687283dfea4f8413ab9067242591978db493fe3a8d4b96c/chirptext-0.1.2.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2021-05-20 03:19:39",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "letuananh",
    "github_project": "chirptext",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "requirements": [],
    "lcname": "chirptext"
}
        
Elapsed time: 1.56030s