Skip to content

Commit d70241b

Browse files
authored
Merge pull request #2 from prosegrinder/defaults
v0.2.0
2 parents b07d043 + 32f6f86 commit d70241b

File tree

6 files changed

+62
-75
lines changed

6 files changed

+62
-75
lines changed

.travis.yml

Lines changed: 18 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,23 @@
1-
# Config file for automatic testing at travis-ci.org
2-
31
language: python
4-
52
python:
6-
- "pypy3"
7-
- "pypy"
8-
- "3.6"
9-
- "3.5"
10-
- "3.4"
11-
- "2.7"
12-
13-
# Use container-based infrastructure
3+
- pypy3
4+
- pypy
5+
- '3.6'
6+
- '3.5'
7+
- '3.4'
8+
- '2.7'
149
sudo: false
15-
16-
# command to install dependencies, e.g. pip install -r requirements.txt --use-mirrors
1710
install:
18-
- pip install -U pip
19-
- pip install -U pytest
20-
21-
# command to run tests, e.g. python setup.py test
11+
- pip install -U pip
12+
- pip install -U pytest
2213
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
14+
- python ./setup.py develop
15+
- pytest tests/*
16+
deploy:
17+
provider: pypi
18+
user: davidlday
19+
password:
20+
secure: Sqbs5JjSDlgfhfDjqBUQibtFkonfOr7WOIXRcGywclcb/BoblK2i6y5TMZE4Le0aMwtmWZ72CruIJu31H010HzVi2LuH+l6MiDdkDJW5J54ctnCXi9jysvp2iHt7EXsFMG5tMwbc0fQtnPGskaBq7WFt/NMkPyFfodIJa/OAWaMDPCLXaultDzcLCGCVD9EAJCz49cEJeYCGPBY5bCwwsq95OmM/71snJNoWwIhsl8x9wydsTEqESNokrSXzk52+YJ1eWmIP8dFn7mcHroveAEaV7raHprNDTskBLvkfDYiaqvjOb+VHYk/HxHvJOAqDdBvJSzhA18PjmFkfdxveV/BehbvGzBCrQU4hNNP9HdPFyx0wU2xkPeEC6BlSqzYpx/esvAcFJYFEeGZlX8ciDIaCYynRe40EbeQQgI4QSiisMsZ0PyBzOCJ271yoxzrqYlTrlsEkTfp9o1x9HX6hQwRPjMoIVnBHB8jKginkPjXLuxythOQ14/1+D11He6HHrFiYVQ2TSJwA/bOuuJVolrXWwwM52LB7JjoF9jr79V+/804ZzfWehVBChmaDl+hZLxqcJ7LExHhvCKB08p8yRZeWdtttBsxQMCa+7NAVwiZSOTSg4jnqlMKLR9be3eblGkeQkWFNOpbA1LP89amIixhi91zBY7bEP6HOXlMR2gg=
21+
distributions: sdist bdist_wheel
22+
on:
23+
tags: true

README.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,11 @@ You can also install it from source::
3535
Usage
3636
-----
3737

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)::
38+
``pointofview`` guesses a text's point of view by counting point of view pronouns. The main function ``get_text_pov()`` will return 'first', 'second', 'third', or null (Python's ``None`` object)::
3939

4040
>>> import pointofview
4141
>>> text = "I'm a piece of text written in first person! What are you?"
42-
>>> pointofview.get_pov(text)
42+
>>> pointofview.get_text_pov(text)
4343
'first'
4444

4545
There are two other helper functions as well.

pointofview/VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
0.1.0
1+
0.2.0

pointofview/__init__.py

Lines changed: 36 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -3,61 +3,60 @@
33
"""pointofview - A Python package for determining a piece of text's point of view (first, second, third, or unknown)."""
44

55
import re
6+
from collections import OrderedDict
67

78
import pkg_resources
89

910
__version__ = pkg_resources.resource_string(
1011
'pointofview', 'VERSION').decode('utf-8').strip()
1112

12-
POV_WORDS = {
13-
'first':
13+
# NOTE:
14+
# Words are expected to be in lower case.
15+
#
16+
# Point of view is in order of precedence.
17+
# First person PoV can also contain second and third person words.
18+
# Second person PoV can also contain third person words.
19+
# Third person PoV can only contain third person words.
20+
POV_WORDS = OrderedDict([
21+
('first',
1422
["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':
23+
"we're", "we'll", "we'd", "we've", "us", "ours", "ourselves"]),
24+
('second',
1725
["you", "you're", "you'll", "you'd", "you've",
18-
"your", "yours", "yourself", "yourselves"],
19-
'third':
26+
"your", "yours", "yourself", "yourselves"]),
27+
('third',
2028
["he", "he's", "he'll", "he'd", "him", "his", "himself", "she", "she's",
2129
"she'll", "she'd", "her", "hers", "herself", "it", "it's", "it'll",
2230
"it'd", "itself", "they", "they're", "they'll", "they'd", "they've",
23-
"them", "their", "theirs", "themselves"]
24-
}
31+
"them", "their", "theirs", "themselves"])
32+
])
2533

2634
RE_WORDS = re.compile(r"[^\w’']+")
2735

2836

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]:
37+
def get_word_pov(word, pov_words=POV_WORDS):
38+
for pov in pov_words:
39+
if word.lower().replace("’", "'") in (
40+
pov_word.lower() for pov_word in pov_words[pov]):
3641
return pov
3742
return None
3843

3944

40-
def parse_pov_words(text):
41-
pov_words = {
42-
'first': [],
43-
'second': [],
44-
'third': [],
45-
}
45+
def parse_pov_words(text, pov_words=POV_WORDS):
46+
text_pov_words = {}
4647
words = re.split(RE_WORDS, text.strip().lower())
48+
for pov in pov_words:
49+
text_pov_words[pov] = []
4750
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
51+
word_pov = get_word_pov(word, pov_words)
52+
if word_pov != None:
53+
text_pov_words[word_pov].append(word)
54+
return text_pov_words
55+
56+
57+
def get_text_pov(text, pov_words=POV_WORDS):
58+
text_pov_words = parse_pov_words(text, pov_words)
59+
for pov in POV_WORDS:
60+
if len(text_pov_words[pov]) > 0:
61+
return pov
62+
return None

tests/test_pointofview.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,14 +32,14 @@
3232
# https://docs.pytest.org/en/latest/index.html
3333

3434
def test_first():
35-
assert(pointofview.get_pov(POV_FIRST_SINGULAR) == 'first') # nosec
36-
assert(pointofview.get_pov(POV_FIRST_PLURAL) == 'first') # nosec
35+
assert(pointofview.get_text_pov(POV_FIRST_SINGULAR) == 'first') # nosec
36+
assert(pointofview.get_text_pov(POV_FIRST_PLURAL) == 'first') # nosec
3737

3838
def test_second():
39-
assert(pointofview.get_pov(POV_SECOND) == 'second') # nosec
39+
assert(pointofview.get_text_pov(POV_SECOND) == 'second') # nosec
4040

4141
def test_third():
42-
assert(pointofview.get_pov(POV_THIRD) == 'third') # nosec
42+
assert(pointofview.get_text_pov(POV_THIRD) == 'third') # nosec
4343

4444
def test_none():
45-
assert(pointofview.get_pov(POV_NONE) == None) # nosec
45+
assert(pointofview.get_text_pov(POV_NONE) == None) # nosec

tox.ini

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

0 commit comments

Comments
 (0)