Skip to content

Commit 71139a1

Browse files
RyanMcCarlNytelife26
authored andcommitted
Added simple passive voice checker.
1 parent c17ad87 commit 71139a1

File tree

5 files changed

+87
-0
lines changed

5 files changed

+87
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,7 @@ Additionally for compatible reason, the legacy configuration `~/.proselintrc` wi
206206
| `needless_variants.misc` | Using the preferred form |
207207
| `nonwords.misc` | Avoid using nonwords |
208208
| `oxymorons.misc` | Avoiding oxymorons |
209+
| `passive_voice.misc` | Reduce unnecessary use of passive voice |
209210
| `psychology.misc` | Avoiding misused psychological terms |
210211
| `redundancy.misc` | Avoiding redundancy and saying things twice |
211212
| `redundancy.ras_syndrome` | Avoiding RAS syndrome |

proselint/.proselintrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@
5757
"needless_variants.misc" : true,
5858
"nonwords.misc" : true,
5959
"oxymorons.misc" : true,
60+
"passive_voice.misc" : true,
6061
"psychology.misc" : true,
6162
"redundancy.misc" : true,
6263
"redundancy.ras_syndrome" : true,
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
"""Basic checks for passive voice."""
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# -*- coding: utf-8 -*-
2+
"""Check for constructs that may signal passive voice.
3+
4+
Resources:
5+
https://writingcenter.unc.edu/tips-and-tools/passive-voice/
6+
https://owl.english.purdue.edu/owl/owlprint/539/
7+
8+
---
9+
layout: post
10+
source: Purdue OWL
11+
source_url: https://owl.english.purdue.edu/owl/owlprint/539/
12+
title: Passive voice
13+
date: 2018-06-12 21:35:00
14+
categories: writing
15+
---
16+
17+
"""
18+
19+
from proselint.tools import existence_check, memoize
20+
21+
22+
@memoize
23+
def check(text):
24+
"""Check for constructs that may signal passive voice."""
25+
err = "passive_voice.misc"
26+
msg = u"This seems to be in passive voice. Consider using active voice."
27+
regex = (r"(\b(?:be|am|is|are|was|were|have|has|had|get)"
28+
r"\b[\w\s]{,15}?(?:d|(?<!whe)n|ne|left|being|made)"
29+
r"\b(?: by\b)?)")
30+
31+
return existence_check(text, [regex], err, msg,
32+
require_padding=False, offset=0)

tests/test_passive_voice.py

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
"""Tests for passive_voice.passive_voice check."""
2+
from __future__ import absolute_import
3+
from proselint.checks.passive_voice import misc as chk
4+
from .check import Check
5+
6+
7+
class TestCheck(Check):
8+
"""The test class for passive_voice.passive_voice."""
9+
10+
__test__ = True
11+
12+
@property
13+
def this_check(self):
14+
"""Boilerplate."""
15+
return chk
16+
17+
@property
18+
def test_smoke(self):
19+
"""Basic smoke test for passive_voice.passive_voice."""
20+
assert self.passes("This sentence is in the active voice.")
21+
assert self.passes("Harry ate six shrimp at dinner.")
22+
assert not self.passes("At dinner, six shrimp were eaten by Harry.")
23+
assert self.passes("Beautiful giraffes roam the savannah.")
24+
assert not self.passes("The savannah is roamed by beautiful giraffes.")
25+
assert self.passes("Sue changed the flat tire.")
26+
assert not self.passes("The flat tire was changed by sue.")
27+
assert self.passes("I ran the course in record time.")
28+
assert not self.passes("The course was run by me in record time.")
29+
assert self.passes("The choir really enjoys that piece.")
30+
assert not self.passes("That piece is really enjoyed by the choir.")
31+
assert self.passes("The two kings are signing the treaty.")
32+
assert not self.passes("The treaty is being signed by two kings.")
33+
34+
def test_special_cases(self):
35+
"""
36+
Test for special cases in passive voice.
37+
https://multimedia-english.com/grammar/passive-voice-special-cases-52
38+
"""
39+
assert self.passes(["I got fired yesterday.",
40+
"I was fired yesterday.",
41+
"If you get mugged, report it."
42+
"The balloon got filled with gas."
43+
"There was a fight, but nobody got hurt.",
44+
"Mary was given some flowers",
45+
"Some flowers were given to Mary",
46+
"I am thought to be a spy",
47+
"I was considered to be a tourist.",
48+
"I was made to do it.",
49+
"We were allowed to go."])
50+
# Passive imperative, gramatically correct nonesense.
51+
assert not self.passes(["Let the television be turned off.",
52+
"Let your money be given to me."])

0 commit comments

Comments
 (0)