Skip to main content

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

Project description

narrative

Latest PyPI version GitHub Workflow Status

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

Installation

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

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:

>>> 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:

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

get_narrative() returns only the narrative components:

>>> 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? 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:

>>> 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)
>>> 

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

narrative-1.1.2.tar.gz (15.4 kB view details)

Uploaded Source

Built Distribution

narrative-1.1.2-py3-none-any.whl (15.4 kB view details)

Uploaded Python 3

File details

Details for the file narrative-1.1.2.tar.gz.

File metadata

  • Download URL: narrative-1.1.2.tar.gz
  • Upload date:
  • Size: 15.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.3.1 CPython/3.10.6 Linux/5.15.0-1024-azure

File hashes

Hashes for narrative-1.1.2.tar.gz
Algorithm Hash digest
SHA256 9c5dbb5d8373df4792560533684ff899f005f0dbdd50f8672f4a2c73f969dc66
MD5 855c2f89e4b3bab90b5745f7f5439364
BLAKE2b-256 240443bda243e7570c1948883f1193f79657409a0ff2833e4ad750525f753f88

See more details on using hashes here.

File details

Details for the file narrative-1.1.2-py3-none-any.whl.

File metadata

  • Download URL: narrative-1.1.2-py3-none-any.whl
  • Upload date:
  • Size: 15.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.3.1 CPython/3.10.6 Linux/5.15.0-1024-azure

File hashes

Hashes for narrative-1.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 cfce47fd206f6bb894f18a2abbade631e44c4c1888342095bf75aba295e61bf0
MD5 9ac0989f2ee2e9a5abee099b6e732f09
BLAKE2b-256 3e0db04a022fa65469d2f2f13b8ed29bdc6ffe6efd48ed2c6646973266414e4e

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page