|
| 1 | +narrative |
| 2 | +=========== |
| 3 | + |
| 4 | +.. image:: https://img.shields.io/pypi/v/narrative.svg |
| 5 | + :target: https://pypi.python.org/pypi/narrative |
| 6 | + :alt: Latest PyPI version |
| 7 | + |
| 8 | +.. image:: https://travis-ci.org/prosegrinder/python-narrative.svg?branch=master |
| 9 | + :target: https://travis-ci.org/prosegrinder/python-narrative |
| 10 | + :alt: Latest Travis CI build status |
| 11 | + |
| 12 | +.. image:: https://api.codacy.com/project/badge/Grade/199d8dcecc4345249c704325bec9cf7c |
| 13 | + :target: https://www.codacy.com/app/ProseGrinder/python-narrative?utm_source=github.com&utm_medium=referral&utm_content=prosegrinder/python-narrative&utm_campaign=Badge_Grade |
| 14 | + :alt: Latest Codacy Coverage Report |
| 15 | + |
| 16 | +A Python small package for splitting text into dialogue and narrative. |
| 17 | + |
| 18 | +Installation |
| 19 | +------------ |
| 20 | + |
| 21 | +``narrative`` is available on PyPI. Simply install it with ``pip``:: |
| 22 | + |
| 23 | + $ pip install narrative |
| 24 | + |
| 25 | +You can also install it from source:: |
| 26 | + |
| 27 | + $ git clone https://github.com/prosegrinder/python-narrative.git |
| 28 | + Cloning into 'python-narrative'... |
| 29 | + ... |
| 30 | + |
| 31 | + $ cd python-narrative |
| 32 | + $ python setup.py install |
| 33 | + ... |
| 34 | + |
| 35 | +Usage |
| 36 | +----- |
| 37 | + |
| 38 | +``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:: |
| 39 | + |
| 40 | + >>> import narrative |
| 41 | + >>> text = '"Hello," he said. "How are you today?"' |
| 42 | + >>> narrative.split(text) |
| 43 | + {'dialogue': ['"Hello,"', '"How are you today?"'], 'narrative': ['', ' he said. ', '']} |
| 44 | + |
| 45 | +There are two other helper functions as well. |
| 46 | + |
| 47 | +``get_dialogue()`` returns only the dialogue components:: |
| 48 | + |
| 49 | + >>> narrative.get_dialogue(text) |
| 50 | + ['"Hello,"', '"How are you today?"'] |
| 51 | + |
| 52 | +``get_narrative()`` returns a dict containing all first, second, and third person pov words:: |
| 53 | + |
| 54 | + >>> narrative.get_dialogue(text) |
| 55 | + ['', ' he said. ', ''] |
| 56 | + |
| 57 | +Note: The empty strings are a feature of Python's ``split()`` function. See `Why are empty strings returned in split() results?`_ for an explanation. |
| 58 | + |
| 59 | +Authors |
| 60 | +------- |
| 61 | + |
| 62 | +`` narrative`` was written by ` David L. Day < [email protected]>`_. |
| 63 | + |
| 64 | +.. _`Why are empty strings returned in split() results?`: https://stackoverflow.com/questions/2197451/why-are-empty-strings-returned-in-split-results#2197493 |
0 commit comments