Skip to content

Commit

Permalink
Merge pull request #2 from prosegrinder/defaults
Browse files Browse the repository at this point in the history
v0.2.0
  • Loading branch information
davidlday authored Apr 7, 2018
2 parents b07d043 + 32f6f86 commit d70241b
Show file tree
Hide file tree
Showing 6 changed files with 62 additions and 75 deletions.
42 changes: 18 additions & 24 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,29 +1,23 @@
# Config file for automatic testing at travis-ci.org

language: python

python:
- "pypy3"
- "pypy"
- "3.6"
- "3.5"
- "3.4"
- "2.7"

# Use container-based infrastructure
- pypy3
- pypy
- '3.6'
- '3.5'
- '3.4'
- '2.7'
sudo: false

# command to install dependencies, e.g. pip install -r requirements.txt --use-mirrors
install:
- pip install -U pip
- pip install -U pytest

# command to run tests, e.g. python setup.py test
- pip install -U pip
- pip install -U pytest
script:
- python ./setup.py develop
- pytest tests/*

after_script:
- pip install pycodestyle pyflakes
- pyflakes . | tee >(wc -l) # static analysis
- pycodestyle --statistics --count . # static analysis
- python ./setup.py develop
- pytest tests/*
deploy:
provider: pypi
user: davidlday
password:
secure: Sqbs5JjSDlgfhfDjqBUQibtFkonfOr7WOIXRcGywclcb/BoblK2i6y5TMZE4Le0aMwtmWZ72CruIJu31H010HzVi2LuH+l6MiDdkDJW5J54ctnCXi9jysvp2iHt7EXsFMG5tMwbc0fQtnPGskaBq7WFt/NMkPyFfodIJa/OAWaMDPCLXaultDzcLCGCVD9EAJCz49cEJeYCGPBY5bCwwsq95OmM/71snJNoWwIhsl8x9wydsTEqESNokrSXzk52+YJ1eWmIP8dFn7mcHroveAEaV7raHprNDTskBLvkfDYiaqvjOb+VHYk/HxHvJOAqDdBvJSzhA18PjmFkfdxveV/BehbvGzBCrQU4hNNP9HdPFyx0wU2xkPeEC6BlSqzYpx/esvAcFJYFEeGZlX8ciDIaCYynRe40EbeQQgI4QSiisMsZ0PyBzOCJ271yoxzrqYlTrlsEkTfp9o1x9HX6hQwRPjMoIVnBHB8jKginkPjXLuxythOQ14/1+D11He6HHrFiYVQ2TSJwA/bOuuJVolrXWwwM52LB7JjoF9jr79V+/804ZzfWehVBChmaDl+hZLxqcJ7LExHhvCKB08p8yRZeWdtttBsxQMCa+7NAVwiZSOTSg4jnqlMKLR9be3eblGkeQkWFNOpbA1LP89amIixhi91zBY7bEP6HOXlMR2gg=
distributions: sdist bdist_wheel
on:
tags: true
4 changes: 2 additions & 2 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,11 @@ You can also install it from source::
Usage
-----

``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)::
``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)::

>>> import pointofview
>>> text = "I'm a piece of text written in first person! What are you?"
>>> pointofview.get_pov(text)
>>> pointofview.get_text_pov(text)
'first'

There are two other helper functions as well.
Expand Down
2 changes: 1 addition & 1 deletion pointofview/VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.1.0
0.2.0
73 changes: 36 additions & 37 deletions pointofview/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,61 +3,60 @@
"""pointofview - A Python package for determining a piece of text's point of view (first, second, third, or unknown)."""

import re
from collections import OrderedDict

import pkg_resources

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

POV_WORDS = {
'first':
# NOTE:
# Words are expected to be in lower case.
#
# Point of view is in order of precedence.
# First person PoV can also contain second and third person words.
# Second person PoV can also contain third person words.
# Third person PoV can only contain third person words.
POV_WORDS = OrderedDict([
('first',
["i", "i'm", "i'll", "i'd", "i've", "me", "mine", "myself", "we",
"we're", "we'll", "we'd", "we've", "us", "ours", "ourselves"],
'second':
"we're", "we'll", "we'd", "we've", "us", "ours", "ourselves"]),
('second',
["you", "you're", "you'll", "you'd", "you've",
"your", "yours", "yourself", "yourselves"],
'third':
"your", "yours", "yourself", "yourselves"]),
('third',
["he", "he's", "he'll", "he'd", "him", "his", "himself", "she", "she's",
"she'll", "she'd", "her", "hers", "herself", "it", "it's", "it'll",
"it'd", "itself", "they", "they're", "they'll", "they'd", "they've",
"them", "their", "theirs", "themselves"]
}
"them", "their", "theirs", "themselves"])
])

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


def _normalize_word(word):
return word.strip().lower().replace("’", "'")


def get_word_pov(word):
for pov in POV_WORDS:
if _normalize_word(word) in POV_WORDS[pov]:
def get_word_pov(word, pov_words=POV_WORDS):
for pov in pov_words:
if word.lower().replace("’", "'") in (
pov_word.lower() for pov_word in pov_words[pov]):
return pov
return None


def parse_pov_words(text):
pov_words = {
'first': [],
'second': [],
'third': [],
}
def parse_pov_words(text, pov_words=POV_WORDS):
text_pov_words = {}
words = re.split(RE_WORDS, text.strip().lower())
for pov in pov_words:
text_pov_words[pov] = []
for word in words:
pov = get_word_pov(word)
if pov != None:
pov_words[pov].append(word)
return pov_words


def get_pov(text):
pov_words = parse_pov_words(text)
if len(pov_words['first']) > 0:
return 'first'
elif len(pov_words['second']) > 0:
return 'second'
elif len(pov_words['third']) > 0:
return 'third'
else:
return None
word_pov = get_word_pov(word, pov_words)
if word_pov != None:
text_pov_words[word_pov].append(word)
return text_pov_words


def get_text_pov(text, pov_words=POV_WORDS):
text_pov_words = parse_pov_words(text, pov_words)
for pov in POV_WORDS:
if len(text_pov_words[pov]) > 0:
return pov
return None
10 changes: 5 additions & 5 deletions tests/test_pointofview.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,14 @@
# https://docs.pytest.org/en/latest/index.html

def test_first():
assert(pointofview.get_pov(POV_FIRST_SINGULAR) == 'first') # nosec
assert(pointofview.get_pov(POV_FIRST_PLURAL) == 'first') # nosec
assert(pointofview.get_text_pov(POV_FIRST_SINGULAR) == 'first') # nosec
assert(pointofview.get_text_pov(POV_FIRST_PLURAL) == 'first') # nosec

def test_second():
assert(pointofview.get_pov(POV_SECOND) == 'second') # nosec
assert(pointofview.get_text_pov(POV_SECOND) == 'second') # nosec

def test_third():
assert(pointofview.get_pov(POV_THIRD) == 'third') # nosec
assert(pointofview.get_text_pov(POV_THIRD) == 'third') # nosec

def test_none():
assert(pointofview.get_pov(POV_NONE) == None) # nosec
assert(pointofview.get_text_pov(POV_NONE) == None) # nosec
6 changes: 0 additions & 6 deletions tox.ini

This file was deleted.

0 comments on commit d70241b

Please sign in to comment.