Skip to content

Commit b07d043

Browse files
authored
Merge pull request #1 from prosegrinder/init
Initial package release.
2 parents cf18495 + eadb618 commit b07d043

File tree

13 files changed

+286
-2
lines changed

13 files changed

+286
-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: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# Config file for automatic testing at travis-ci.org
2+
3+
language: python
4+
5+
python:
6+
- "pypy3"
7+
- "pypy"
8+
- "3.6"
9+
- "3.5"
10+
- "3.4"
11+
- "2.7"
12+
13+
# Use container-based infrastructure
14+
sudo: false
15+
16+
# command to install dependencies, e.g. pip install -r requirements.txt --use-mirrors
17+
install:
18+
- pip install -U pip
19+
- pip install -U pytest
20+
21+
# command to run tests, e.g. python setup.py test
22+
script:
23+
- python ./setup.py develop
24+
- pytest tests/*
25+
26+
after_script:
27+
- pip install pycodestyle pyflakes
28+
- pyflakes . | tee >(wc -l) # static analysis
29+
- pycodestyle --statistics --count . # static analysis

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 pointofview
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: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
pointofview
2+
===========
3+
4+
.. image:: https://img.shields.io/pypi/v/pointofview.svg
5+
:target: https://pypi.python.org/pypi/pointofview
6+
:alt: Latest PyPI version
7+
8+
.. image:: https://travis-ci.org/prosegrinder/python-pointofview.svg?branch=master
9+
:target: https://travis-ci.org/prosegrinder/python-pointofview
10+
:alt: Latest Travis CI build status
11+
12+
.. image:: https://api.codacy.com/project/badge/Grade/df0afcc70ffc4a86a8777588567820c0
13+
:target: https://www.codacy.com/app/ProseGrinder/python-pointofview?utm_source=github.com&utm_medium=referral&utm_content=prosegrinder/python-pointofview&utm_campaign=Badge_Grade
14+
:alt: Latest Codacy Coverage Report
15+
16+
A Python package for determining a piece of text's point of view (first, second, third, or unknown).
17+
18+
Installation
19+
------------
20+
21+
``pointofview`` is available on PyPI. Simply install it with ``pip``::
22+
23+
$ pip install pointofview
24+
25+
You can also install it from source::
26+
27+
$ git clone https://github.com/prosegrinder/python-pointofview.git
28+
Cloning into 'python-pointofview'...
29+
...
30+
31+
$ cd python-pointofview
32+
$ python setup.py install
33+
...
34+
35+
Usage
36+
-----
37+
38+
``pointofview`` guesses a text's point of view by counting point of view pronouns. The main function ``get_pov()`` will return 'first', 'second', 'third', or null (Python's ``None`` object)::
39+
40+
>>> import pointofview
41+
>>> text = "I'm a piece of text written in first person! What are you?"
42+
>>> pointofview.get_pov(text)
43+
'first'
44+
45+
There are two other helper functions as well.
46+
47+
``get_word_pov()`` returns the point of view of a single word::
48+
49+
>>> pointofview.get_word_pov("I")
50+
'first'
51+
>>> pointofview.get_word_pov("nope")
52+
None
53+
54+
``parse_pov_words`` returns a dict containing all first, second, and third person pov words::
55+
56+
>>> text = """
57+
... When I try to analyze my own cravings, motives, actions and so forth, I surrender to a sort of retrospective imagination which feeds the analytic faculty with boundless alternatives and which causes each visualized route to fork and re-fork without end in the maddeningly complex prospect of my past.
58+
... """
59+
>>> pointofview.parse_pov_words(text)
60+
{'first': ['i', 'i'], 'second': [], 'third': []}
61+
62+
Authors
63+
-------
64+
65+
`pointofview` was written by `David L. Day <[email protected]>`_.

pointofview/VERSION

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

pointofview/__init__.py

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
# -*- coding: utf-8 -*-
2+
3+
"""pointofview - A Python package for determining a piece of text's point of view (first, second, third, or unknown)."""
4+
5+
import re
6+
7+
import pkg_resources
8+
9+
__version__ = pkg_resources.resource_string(
10+
'pointofview', 'VERSION').decode('utf-8').strip()
11+
12+
POV_WORDS = {
13+
'first':
14+
["i", "i'm", "i'll", "i'd", "i've", "me", "mine", "myself", "we",
15+
"we're", "we'll", "we'd", "we've", "us", "ours", "ourselves"],
16+
'second':
17+
["you", "you're", "you'll", "you'd", "you've",
18+
"your", "yours", "yourself", "yourselves"],
19+
'third':
20+
["he", "he's", "he'll", "he'd", "him", "his", "himself", "she", "she's",
21+
"she'll", "she'd", "her", "hers", "herself", "it", "it's", "it'll",
22+
"it'd", "itself", "they", "they're", "they'll", "they'd", "they've",
23+
"them", "their", "theirs", "themselves"]
24+
}
25+
26+
RE_WORDS = re.compile(r"[^\w’']+")
27+
28+
29+
def _normalize_word(word):
30+
return word.strip().lower().replace("’", "'")
31+
32+
33+
def get_word_pov(word):
34+
for pov in POV_WORDS:
35+
if _normalize_word(word) in POV_WORDS[pov]:
36+
return pov
37+
return None
38+
39+
40+
def parse_pov_words(text):
41+
pov_words = {
42+
'first': [],
43+
'second': [],
44+
'third': [],
45+
}
46+
words = re.split(RE_WORDS, text.strip().lower())
47+
for word in words:
48+
pov = get_word_pov(word)
49+
if pov != None:
50+
pov_words[pov].append(word)
51+
return pov_words
52+
53+
54+
def get_pov(text):
55+
pov_words = parse_pov_words(text)
56+
if len(pov_words['first']) > 0:
57+
return 'first'
58+
elif len(pov_words['second']) > 0:
59+
return 'second'
60+
elif len(pov_words['third']) > 0:
61+
return 'third'
62+
else:
63+
return None

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__), 'pointofview', '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="pointofview",
17+
version=VERSION,
18+
url="https://github.com/prosegrinder/python-pointofview",
19+
20+
author="David L. Day",
21+
author_email="[email protected]",
22+
23+
description="A Python package for determining a piece of text's point of view (first, second, third, or unknown).",
24+
long_description=LONG_DESCRIPTION,
25+
26+
packages=[
27+
'pointofview'
28+
],
29+
package_dir={'pointofview': 'pointofview'},
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)