Skip to content

Commit ac3cf2d

Browse files
authored
Merge pull request #1 from prosegrinder/init
Initial Release v0.1.0
2 parents 0db349a + fc48295 commit ac3cf2d

File tree

11 files changed

+237
-2
lines changed

11 files changed

+237
-2
lines changed

.editorconfig

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# http://editorconfig.org
2+
3+
root = true
4+
5+
[*]
6+
indent_style = space
7+
indent_size = 2
8+
insert_final_newline = true
9+
trim_trailing_whitespace = true
10+
end_of_line = lf
11+
charset = utf-8
12+
13+
# Docstrings and comments use max_line_length = 79
14+
[*.py]
15+
indent_size = 4

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ nosetests.xml
4545
coverage.xml
4646
*.cover
4747
.hypothesis/
48+
.pytest_cache/
4849

4950
# Translations
5051
*.mo

.travis.yml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
language: python
2+
python:
3+
- pypy3
4+
- pypy
5+
- '3.6'
6+
- '3.5'
7+
- '3.4'
8+
- '2.7'
9+
sudo: false
10+
install:
11+
- pip install -U pip
12+
- pip install -U pytest
13+
script:
14+
- python ./setup.py develop
15+
- pytest tests/*
16+
deploy:
17+
provider: pypi
18+
user: davidlday
19+
python: '3.6'
20+
password:
21+
secure: 3/zLhV44lkbEuyT14Y4zFd65ywUwKMWeGqr5Yi8DTzYKYTlCTf/W1Qhm2/WfaYEiFQPyyAbjrf9cAGtSj70lo0xdkjXTteJnY7jtchEh7kcawJDdmuMxa9x2QhhJ2C4p5rl6ec3iBZwxGU6yox4woG9aSAC7D6x/KDPw4qSdb1aXq50WT+ePgBYMkenKdLNX5O/9+MD5nUI7tCbcatKyP2erWK86RbiVO7iOFAUG/g8fJ3OIp2Y+XFqDzLT4AlQBalLI3CQJAKjiVfUEK7SH60sHTkFtFp9MQBnvVWHcElsF4wW7VN9rbgqV0vbPG0wWwgaA04Sea1QOq5JLV2TJ3k1V0dRQQcRNuF+cqXw3bsBitqVnEUuZt+iphi+xeFXEkrY3rZXqcftlxZeF0u4966s3FpvkAK6zjR6zxtH6S2af8at3esoFOZ59j2Rt4+cgrKYfjQnzCsIDcP6+b9NVkLMcNyzy5/syhn3+TjhPcDs8G38IAfguAfIYgH/uZSbO/6fHCTI49mTpA6fFpIeauGTiiqyOJmwulQ/rQncOpmsDlbyLVMIef+AS8Stt2Om0HSSljdMfx+VX2vzwZLbIIOcf8mnPD3yP04FEI9KUUNN5OzQBNh2GaCJfhTcslmaMEN196KWyAaZx0paQzq0IylB6RqVeLY57a1S/1VLzxAk=
22+
distributions: sdist bdist_wheel
23+
on:
24+
tags: true
25+

MANIFEST.in

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
include MANIFEST.in
2+
include README.rst
3+
include LICENSE
4+
graft narrative
5+
graft tests
6+
global-exclude .git
7+
global-exclude __pycache__
8+
global-exclude *.py[co] .DS_Store

README.md

Lines changed: 0 additions & 2 deletions
This file was deleted.

README.rst

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
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

narrative/VERSION

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
0.1.0

narrative/__init__.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# -*- coding: utf-8 -*-
2+
3+
"""narrative - A Python small package for splitting text into dialogue and narrative."""
4+
5+
import re
6+
7+
import pkg_resources
8+
9+
__version__ = pkg_resources.resource_string(
10+
'narrative', 'VERSION').decode('utf-8').strip()
11+
12+
# NOTE: Smart quotes are error prone. I recommend converting
13+
# them to regular quotes first.
14+
#
15+
# RegEx developed from following reference
16+
# http://www.rubular.com/r/mP6IRzteSm
17+
# http://pythex.org/
18+
# http://www.metaltoad.com/blog/regex-quoted-string-escapable-quotes
19+
# DIALOGUE_RE = r'[\"“]((?:.(?![\"“]))*.?)[\"”\\n]'
20+
DIALOGUE_RE = re.compile(r'[\"“](?:.(?![\"“]))*.?[\"”\\n]', re.MULTILINE)
21+
22+
23+
def get_dialogue(text, dialogue_regex=DIALOGUE_RE):
24+
dialogue = dialogue_regex.findall(text)
25+
return dialogue
26+
27+
28+
def get_narrative(text, dialogue_regex=DIALOGUE_RE):
29+
narrative = dialogue_regex.split(text)
30+
return narrative
31+
32+
33+
def split(text, dialogue_regex=DIALOGUE_RE):
34+
dialogue = get_dialogue(text, dialogue_regex)
35+
narrative = get_narrative(text, dialogue_regex)
36+
return {"dialogue": dialogue, "narrative": narrative}

setup.cfg

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
[bdist_wheel]
2+
universal = 1
3+
4+
[metadata]
5+
license_file = LICENSE

setup.py

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
# -*- coding: utf-8 -*-
2+
3+
from os import path
4+
5+
from setuptools import setup
6+
7+
# Version
8+
with open(path.join(path.dirname(__file__), 'narrative', 'VERSION')) as version_file:
9+
VERSION = version_file.read().strip()
10+
# Long Description
11+
with open(path.join(path.dirname(__file__), 'README.rst')) as readme_file:
12+
LONG_DESCRIPTION = readme_file.read()
13+
14+
15+
setup(
16+
name="narrative",
17+
version=VERSION,
18+
url="https://github.com/prosegrinder/python-narrative",
19+
20+
author="David L. Day",
21+
author_email="[email protected]",
22+
23+
description="A Python small package for splitting text into dialogue and narrative.",
24+
long_description=LONG_DESCRIPTION,
25+
26+
packages=[
27+
'narrative'
28+
],
29+
package_dir={'narrative': 'narrative'},
30+
package_data={
31+
'': ['LICENSE', '*.rst', 'MANIFEST.in'],
32+
},
33+
include_package_data=True,
34+
35+
classifiers=[
36+
'Development Status :: 4 - Beta',
37+
'Intended Audience :: Developers',
38+
'License :: OSI Approved :: GNU General Public License v3 (GPLv3)',
39+
'Natural Language :: English',
40+
'Programming Language :: Python',
41+
'Programming Language :: Python :: 2',
42+
'Programming Language :: Python :: 2.7',
43+
'Programming Language :: Python :: 3',
44+
'Programming Language :: Python :: 3.4',
45+
'Programming Language :: Python :: 3.5',
46+
'Programming Language :: Python :: 3.6',
47+
],
48+
)

0 commit comments

Comments
 (0)