narrative


Namenarrative JSON
Version 1.1.2 PyPI version JSON
download
home_pagehttps://github.com/prosegrinder/python-narrative
SummaryA small Python package for splitting text into dialogue and narrative.
upload_time2022-12-19 20:07:30
maintainer
docs_urlNone
authorDavid L. Day
requires_python>=3.7.2,<4.0.0
licenseGPLv3
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # narrative

[![Latest PyPI version](https://img.shields.io/pypi/v/narrative.svg)](https://pypi.python.org/pypi/narrative)
[![GitHub Workflow Status](https://github.com/prosegrinder/python-narrative/workflows/Python%20CI/badge.svg?branch=main)](https://github.com/prosegrinder/python-narrative/actions?query=workflow%3A%22Python+CI%22+branch%3Amain)

A small Python package for splitting text into dialogue and narrative.

## Installation

`narrative` is available on PyPI. Simply install it with `pip`:

```bash
pip install narrative
```

## Usage

`narrative` splits a piece of prose into narrative and dialogue components. The
main function `split()` will return a dict containing both `narrative` and
`dialogue` components:

```python
>>> import narrative
>>> text = '"Hello," he said. "How are you today?"'
>>> narrative.split(text)
{'dialogue': ['"Hello,"', '"How are you today?"'], 'narrative': ['', ' he said. ', '']}
```

There are two other helper functions as well.

`get_dialogue()` returns only the dialogue components:

```python
>>> narrative.get_dialogue(text)
['"Hello,"', '"How are you today?"']
```

`get_narrative()` returns only the narrative components:

```python
>>> narrative.get_narrative(text)
['', ' he said. ', '']
```

Note: The empty strings are a feature of Python's `split()` function. See
[Why are empty strings returned in split() results?](https://stackoverflow.com/questions/2197451/why-are-empty-strings-returned-in-split-results#2197493)
for an explanation.

### British Style

Each function accepts a second parameter of a regular expression used to parse
out the dialogue. This defaults to `narrative.DIALOGUE_RE`, which follows the
American standard of using double quotes for initial quotes. `narrative` now
includes a second regular expression, `narrative.BRITISH_DIALOGUE_RE`, which
follows the British style of using single quotes for initial quotes. Simply use
it as the second parameter for any function:

```python
>>> import narrative
>>> narrative.split(text, narrative.BRITISH_DIALOGUE_RE)
>>> …
>>> narrative.get_dialogue(text, narrative.BRITISH_DIALOGUE_RE)
>>> …
>>> narrative.get_narrative(text, narrative.BRITISH_DIALOGUE_RE)
>>> …
```

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/prosegrinder/python-narrative",
    "name": "narrative",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.7.2,<4.0.0",
    "maintainer_email": "",
    "keywords": "",
    "author": "David L. Day",
    "author_email": "david@davidlday.com",
    "download_url": "https://files.pythonhosted.org/packages/24/04/43bda243e7570c1948883f1193f79657409a0ff2833e4ad750525f753f88/narrative-1.1.2.tar.gz",
    "platform": null,
    "description": "# narrative\n\n[![Latest PyPI version](https://img.shields.io/pypi/v/narrative.svg)](https://pypi.python.org/pypi/narrative)\n[![GitHub Workflow Status](https://github.com/prosegrinder/python-narrative/workflows/Python%20CI/badge.svg?branch=main)](https://github.com/prosegrinder/python-narrative/actions?query=workflow%3A%22Python+CI%22+branch%3Amain)\n\nA small Python package for splitting text into dialogue and narrative.\n\n## Installation\n\n`narrative` is available on PyPI. Simply install it with `pip`:\n\n```bash\npip install narrative\n```\n\n## Usage\n\n`narrative` splits a piece of prose into narrative and dialogue components. The\nmain function `split()` will return a dict containing both `narrative` and\n`dialogue` components:\n\n```python\n>>> import narrative\n>>> text = '\"Hello,\" he said. \"How are you today?\"'\n>>> narrative.split(text)\n{'dialogue': ['\"Hello,\"', '\"How are you today?\"'], 'narrative': ['', ' he said. ', '']}\n```\n\nThere are two other helper functions as well.\n\n`get_dialogue()` returns only the dialogue components:\n\n```python\n>>> narrative.get_dialogue(text)\n['\"Hello,\"', '\"How are you today?\"']\n```\n\n`get_narrative()` returns only the narrative components:\n\n```python\n>>> narrative.get_narrative(text)\n['', ' he said. ', '']\n```\n\nNote: The empty strings are a feature of Python's `split()` function. See\n[Why are empty strings returned in split() results?](https://stackoverflow.com/questions/2197451/why-are-empty-strings-returned-in-split-results#2197493)\nfor an explanation.\n\n### British Style\n\nEach function accepts a second parameter of a regular expression used to parse\nout the dialogue. This defaults to `narrative.DIALOGUE_RE`, which follows the\nAmerican standard of using double quotes for initial quotes. `narrative` now\nincludes a second regular expression, `narrative.BRITISH_DIALOGUE_RE`, which\nfollows the British style of using single quotes for initial quotes. Simply use\nit as the second parameter for any function:\n\n```python\n>>> import narrative\n>>> narrative.split(text, narrative.BRITISH_DIALOGUE_RE)\n>>> \u2026\n>>> narrative.get_dialogue(text, narrative.BRITISH_DIALOGUE_RE)\n>>> \u2026\n>>> narrative.get_narrative(text, narrative.BRITISH_DIALOGUE_RE)\n>>> \u2026\n```\n",
    "bugtrack_url": null,
    "license": "GPLv3",
    "summary": "A small Python package for splitting text into dialogue and narrative.",
    "version": "1.1.2",
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "md5": "9ac0989f2ee2e9a5abee099b6e732f09",
                "sha256": "cfce47fd206f6bb894f18a2abbade631e44c4c1888342095bf75aba295e61bf0"
            },
            "downloads": -1,
            "filename": "narrative-1.1.2-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "9ac0989f2ee2e9a5abee099b6e732f09",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.7.2,<4.0.0",
            "size": 15412,
            "upload_time": "2022-12-19T20:07:28",
            "upload_time_iso_8601": "2022-12-19T20:07:28.577215Z",
            "url": "https://files.pythonhosted.org/packages/3e/0d/b04a022fa65469d2f2f13b8ed29bdc6ffe6efd48ed2c6646973266414e4e/narrative-1.1.2-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "md5": "855c2f89e4b3bab90b5745f7f5439364",
                "sha256": "9c5dbb5d8373df4792560533684ff899f005f0dbdd50f8672f4a2c73f969dc66"
            },
            "downloads": -1,
            "filename": "narrative-1.1.2.tar.gz",
            "has_sig": false,
            "md5_digest": "855c2f89e4b3bab90b5745f7f5439364",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.7.2,<4.0.0",
            "size": 15429,
            "upload_time": "2022-12-19T20:07:30",
            "upload_time_iso_8601": "2022-12-19T20:07:30.139118Z",
            "url": "https://files.pythonhosted.org/packages/24/04/43bda243e7570c1948883f1193f79657409a0ff2833e4ad750525f753f88/narrative-1.1.2.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2022-12-19 20:07:30",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "github_user": "prosegrinder",
    "github_project": "python-narrative",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "narrative"
}
        
Elapsed time: 0.03479s