From b8f960e70926de7e09848f833581b4cd685e5549 Mon Sep 17 00:00:00 2001 From: Josh Grant Date: Mon, 27 Jun 2016 10:28:06 -0400 Subject: [PATCH] updates based on pr 486 --- proselint/checks/glaad/__init__.py | 1 + proselint/checks/glaad/offensive_terms.py | 41 +++++++++++++++++++++++ proselint/checks/glaad/terms.py | 39 +++++++++++++++++++++ tests/test_glaad_offensive_terms.py | 23 +++++++++++++ tests/test_glaad_terms.py | 31 +++++++++++++++++ 5 files changed, 135 insertions(+) create mode 100644 proselint/checks/glaad/__init__.py create mode 100644 proselint/checks/glaad/offensive_terms.py create mode 100644 proselint/checks/glaad/terms.py create mode 100644 tests/test_glaad_offensive_terms.py create mode 100644 tests/test_glaad_terms.py diff --git a/proselint/checks/glaad/__init__.py b/proselint/checks/glaad/__init__.py new file mode 100644 index 000000000..a0d060318 --- /dev/null +++ b/proselint/checks/glaad/__init__.py @@ -0,0 +1 @@ +"""GLAAD.""" diff --git a/proselint/checks/glaad/offensive_terms.py b/proselint/checks/glaad/offensive_terms.py new file mode 100644 index 000000000..daf96946a --- /dev/null +++ b/proselint/checks/glaad/offensive_terms.py @@ -0,0 +1,41 @@ +# -*- coding: utf-8 -*- +"""GLAAD. + +--- +layout: post +source: GLAAD Media Reference Guide - 9th Edition +source_url: http://www.glaad.org/reference +title: GLAAD Guidelines +date: 2016-07-06 +categories: writing +--- + +This check looks for offensive terms related to LGBTQ issues and +raises an error marking them as offensive. The New York Times and +Associated Press have also adopted this style guide. + +""" +from proselint.tools import memoize, existence_check + + +@memoize +def check(text): + """Flag offensive words based on the GLAAD reference guide.""" + err = "glaad.offensive_terms" + msg = "Offensive term. Remove it or consider the context." + + list = [ + "fag", + "faggot", + "dyke", + "sodomite", + "homosexual agenda", + "gay agenda", + "transvestite", + "homosexual lifestyle", + "gay lifestyle" + # homo - may create false positives without additional context + # FIXME use topic detetor to decide whether "homo" is offensive + ] + + return existence_check(text, list, err, msg, join=True, ignore_case=False) diff --git a/proselint/checks/glaad/terms.py b/proselint/checks/glaad/terms.py new file mode 100644 index 000000000..6eebb64ba --- /dev/null +++ b/proselint/checks/glaad/terms.py @@ -0,0 +1,39 @@ +# -*- coding: utf-8 -*- +"""GLAAD. + +--- +layout: post +source: GLAAD Media Reference Guide - 9th Edition +source_url: http://www.glaad.org/reference +title: GLAAD Guidelines +date: 2016-07-06 +categories: writing +--- + +This check looks for possibly offensive terms related to LGBTQ issues and +makes more acceptable recommendations. TheNew York Times and +Associated Press have also adopted this style guide. + +""" +from proselint.tools import memoize, preferred_forms_check + + +@memoize +def check(text): + """Suggest preferred forms given the reference document.""" + err = "glaad.terms" + msg = "Possibly offensive term. Consider using '{}' instead of '{}'." + + list = [ + ["gay man", ["homosexual man"]], + ["gay men", ["homosexual men"]], + ["lesbian", ["homosexual woman"]], + ["lesbians", ["homosexual women"]], + ["gay people", ["homosexual people"]], + ["gay couple", ["homosexual couple"]], + ["sexual orientation", ["sexual preference"]], + ["openly gay", ["admitted homosexual", "avowed homosexual"]], + ["equal rights", ["special rights"]] + ] + + return preferred_forms_check(text, list, err, msg, ignore_case=False) diff --git a/tests/test_glaad_offensive_terms.py b/tests/test_glaad_offensive_terms.py new file mode 100644 index 000000000..c63bd8922 --- /dev/null +++ b/tests/test_glaad_offensive_terms.py @@ -0,0 +1,23 @@ +"""Test GLAAD Guidelines.""" +from __future__ import absolute_import + +from .check import Check + +from proselint.checks.glaad import offensive_terms as chk + + +class TestCheck(Check): + """The test class for glaad.offensive_terms.""" + + __test__ = True + + @property + def this_check(self): + """Bolierplate.""" + return chk + + def test_smoke(self): + """Basic smoke test for glaad.offensive_terms.""" + assert self.passes("""Smoke phrase with nothing flagged.""") + assert self.passes("""I once met a gay man.""") + assert not self.passes("""I once met a fag.""") diff --git a/tests/test_glaad_terms.py b/tests/test_glaad_terms.py new file mode 100644 index 000000000..eb06bbbc7 --- /dev/null +++ b/tests/test_glaad_terms.py @@ -0,0 +1,31 @@ +"""Test GLAAD Guidelines.""" +from __future__ import absolute_import + +from .check import Check + +from proselint.checks.glaad import terms as chk + + +class TestCheck(Check): + """The test class for glaad.terms.""" + + __test__ = True + + @property + def this_check(self): + """Bolierplate.""" + return chk + + def test_smoke(self): + """Basic smoke test for glaad.terms.""" + assert self.passes("""Smoke phrase with nothing flagged.""") + assert self.passes("""They were a gay couple.""") + assert not self.passes("""He was a homosexual man.""") + + def test_homosexual_term(self): + """Check that the term homosexual does not get caught.""" + assert self.passes("""Homosexual.""") + + def test_sexual_prefence(self): + """Check that sexual preference is flagged.""" + assert not self.passes("""My sexual preference is for women.""")