4
\$\begingroup\$

Yesterday at work, the Google Doodle convinced me to share my rather long gender swap script here, but the code-golf criteria of the question i asked were not clear. As my question still got downvoted after giving examples, i changed the tag to popularity-contest, as suggested before i clarified it.

Here's a more golfy version:

The UN theme for International Women's Day 2014 is "Equality for Women is Progress for All".

In the interest of gender equality, write a program that correctly changes that Wikipedia page from a female to a male perspective. Names and anatomical details may be left unchanged. It should not change who is being referred to.

Example:

Before:

He said she took her girlish books on Feminism with her.

After:

She said he took his boyish books on Masculism with him.

All gendered pronouns and nouns, as well as all adjectival forms of such words, must be changed in the visible English text.

The shortest code that fully transforms the linked version of the IWD Wikipedia page according to the stated rules, wins.

\$\endgroup\$
  • 1
    \$\begingroup\$ Could still do with some scoping if you want it to be a code-golf. Must proper names be changed? Must words in URLs be changed? Should herstory become history, and vice versa? Historian/herstorian? I can guess at your intent, but to make it objective it is best to spell out the tasks that must be done. "Adjectives e.g. boyish and girlish - MUST CONVERT, Proper names - DO NOT CONVERT, etc." In essence, we need to know how you will determine the page is "correctly" changed. \$\endgroup\$ – Jonathan Van Matre Mar 8 '14 at 15:11
  • \$\begingroup\$ @JonathanVanMatre Please read carefully: "Names and anatomical details may be left unchanged." \$\endgroup\$ – Cees Timmerman Mar 8 '14 at 15:14
  • 1
    \$\begingroup\$ Apologies for overlooking that sentence, but setting that example aside the point is the same: it is best to spell out what must be done. A single sentence that says something to the effect of "All gendered pronouns and nouns, as well as all adjectival forms of such words, must be changed." would suffice. \$\endgroup\$ – Jonathan Van Matre Mar 8 '14 at 15:28
  • 2
    \$\begingroup\$ 5 hours in the sandbox on a weekend is a long way short of granting a reasonable expectation that more than a couple of people have seen it. There's no point putting something in the sandbox unless you're going to leave it there for two days or more. And recently people seem too eager to upvote in the sandbox: in the past couple of weeks I've seen people upvote things which then needed to go through three or four edits before becoming truly ready to post. This could still be improved by making explicit that it's a particular version of the page which needs changing, so it's a static target. \$\endgroup\$ – Peter Taylor Mar 8 '14 at 17:41
  • 2
    \$\begingroup\$ (Although even then it's not going to be a very good question: it's basically "work out what the altered text should be (the hardest part), and then find a minimum set of substitutions and a language which has a compact syntax for mass substitutions"). \$\endgroup\$ – Peter Taylor Mar 8 '14 at 17:43
2
\$\begingroup\$

JavaScript, 707 bytes (680 in web console)

javascript:(function(){l=function(s){return s.toLowerCase()};b=document.body;t=b.innerHTML;s="Actress;Actor;Daughters;Sons;Feminine;Masculine;Feminism;Masculism;Feminist;Masculist;Femininity;Masculinity;Mother;Father;Mothers;Fathers;Motherland;Fatherland;Motherhood;Fatherhood;Woman;Man;Female;Male;Females;Males;Girl;Boy;Girls;Boys;Girlfriends;Boyfriends;Grandmothers;Grandfathers;Her;His;She;He;Sister;Brother;Wives;Husbands;WomenWatch;MenWatch;Women;Men;Womensday;Mensday;Internationalwomensday;Internationalmensday;IWD;IMD";a=s.split(';');c=t.split(/\b/);d={};for(i=0;i<a.length;i+=2){x=a[i];y=a[i+1];d[x]=y;d[y]=x;d[l(x)]=l(y);d[l(y)]=l(x)}t='';for(i=0;i<c.length;++i)t+=d[c[i]]||c[i];b.innerHTML=t})()

This is a bookmarklet/favelet; set as URL of a bookmark/favorite and click to transform the loaded webpage.

\$\endgroup\$
  • \$\begingroup\$ I guess it simply can't get much shorter than that. \$\endgroup\$ – Cees Timmerman Mar 17 '14 at 21:16
  • \$\begingroup\$ Hi, I tried it out and it is super awesome, but not all pronouns are swapped. I tried it on a random Wikipedia page and the pronoun him was not swapped, for example. it was this Wiki page But it's nice to have a gender-swap bookmark anyway. :) \$\endgroup\$ – linse Mar 21 '14 at 16:10
  • \$\begingroup\$ @linse, thanks, but this code-golf challenge is about transforming this specific page. Here was a more generic popularity-contest answer, but that question was deleted for unclear reasons. \$\endgroup\$ – Cees Timmerman Mar 21 '14 at 21:42
1
\$\begingroup\$

Not a completely worked out answer, but Cees' substitution solution reminded me of the str_replace syntax in PHP:

$body = file_get_contents($url);
$body = str_replace(
  array("Actress", "Daughters", "Feminine", "Feminism", "Feminist", "Femininity", "Mother", "Mothers", "Motherland", "Motherhood", "Woman", "Female", "Females", "Girl", "Girls", "Girlfriends", "Grandmothers", "Her", "She", "Sister", "Wives", "WomenWatch", "Women", "Womensday", "Internationalwomensday", "IWD"),
  array("Actor", "Sons", "Masculine", "Masculism", "Masculist", "Masculinity", "Father", "Fathers", "Fatherland", "Fatherhood", "Man", "Male", "Males", "Boy", "Boys", "Boyfriends", "Grandfathers", "His", "He", "Brother", "Husbands", "MenWatch", "Men", "Mensday", "Internationalmensday", "IMD"),
  $body);

You can shorten this by putting everything into one string, e.g.

str_replace( 
  split(';', "Actor;Sons;Masculine;Masculism;Masculist;Masculinity;Father;Fathers;Fatherland;Fatherhood;Man;Male;Males;Boy;Boys;Boyfriends;Grandfathers;His;He;Brother;Husbands;MenWatch;Men;Mensday;Internationalmensday;IMD"), 
   ....

but that only makes it marginally better. I'll leave it up to someone to come up with the creative solution.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.