Skip to main content

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

Project description

narrative

Latest PyPI version Python Poetry CI

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.2.1.tar.gz (14.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

narrative-1.2.1-py3-none-any.whl (15.5 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: narrative-1.2.1.tar.gz
  • Upload date:
  • Size: 14.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.1.3 CPython/3.12.3 Linux/6.11.0-1018-azure

File hashes

Hashes for narrative-1.2.1.tar.gz
Algorithm Hash digest
SHA256 dc746a97fdc5dc0dd3d9e1de8e526be7ddd02f9c6e71e26213f6a78c249467af
MD5 6ced0fa799813c540625654df90d2d1f
BLAKE2b-256 471878c82e186efb79461382cfca73e89e166c0d50cab0f391c83a7558cc1e1d

See more details on using hashes here.

File details

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

File metadata

  • Download URL: narrative-1.2.1-py3-none-any.whl
  • Upload date:
  • Size: 15.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.1.3 CPython/3.12.3 Linux/6.11.0-1018-azure

File hashes

Hashes for narrative-1.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 882097e9983d5ed2c33f88060e7a28b51ecbacbad68d44da8a0436f0832cec8d
MD5 39e751c4112d6e67957944006a54efd7
BLAKE2b-256 aa8aa794fd30c3e92ecb65860fd82ec7f5b7132aa09a7a2a2fb0a2b13b668775

See more details on using hashes here.

Supported by

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