Code Monkey home page Code Monkey logo

gender-flip's Introduction

GenderFlip

Accepts any text and returns it gender flipped. For example:

It is a truth universally acknowledged, that a single man in possession of a good fortune, must be in want of a wife.

flips to:

It is a truth universally acknowledged, that a single woman in possession of a good fortune, must be in want of a husband.

Using GenderFlip is easy. Just copy this repository to your web server and navigate to index.php. This will display a simple form that allows you to gender flip any web page. We also include several example texts from Project Gutenberg.

Custom implementation is not required, but is also easy:

require_once 'GenderFlip.php';
$text = file_get_contents('/path/to/text.txt');
$genderFlip = new GenderFlip($text);
echo $genderFlip->flip();

You can even add your own flips:

require_once 'GenderFlip.php';
$text = file_get_contents('/path/to/text.txt');
$genderFlip = new GenderFlip($text);
// Flips match an exact word. This one replaces "handsome" and "Handsome" with
// "pretty" and "Pretty" respectively.
$genderFlip->addFlip('handsome', 'pretty');
// Pattern flips use regular expressions to match a word. This is helpful to
// match proper nouns, such as person names, and words that contain non-word
// characters, such as "Ph.D.".
$genderFlip->addPatternFlip('/\bLizzy\b/', 'John');
$genderFlip->addPatternFlip('/\bJane\b/', 'Paul');
$genderFlip->addPatternFlip('/\bLydia\b/', 'Ringo');
echo $genderFlip->flip();

"I desire you will do no such thing. John is not a bit better than the others; and I am sure he is not half so pretty as Paul, nor half so good-humoured as Ringo. But you are always giving his the preference."

Gender flipping is not an exact science. There are semantic inconsistencies (her/his, hers/his), as well as ambiguous cases (Lady/Sir, lady/gentleman). This tool does not attempt to flip gendered adjectives (pretty/handsome, womanly/manly) or gendered names (Jill/Jack, Marsha/John). Use the addFlip() or addPatternFlip() method to customize what words are flipped.

gender-flip's People

Contributors

fcheslack avatar jimsafley avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar

Forkers

fcheslack

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.