PoshCode Archive  Artifact [a0cb39eac0]

Artifact a0cb39eac004b20ebd815a2a3cc4106f037e0bc9aa715dd80d340c05f562dc9e:

  • File Get-Gender.ps1 — part of check-in [e9eb1c0788] at 2018-06-10 14:11:00 on branch trunk — Guesses the gender of a first name. Uses BabyNameAddicts.com, and works with most common names (not just anglo) ... (user: Joel Bennett size: 1215)

# encoding: ascii
# api: powershell
# title: Get-Gender
# description: Guesses the gender of a first name.  Uses BabyNameAddicts.com, and works with most common names (not just anglo) ... 
# version: 0.1
# type: function
# author: Joel Bennett
# license: CC0
# function: get-gender
# x-poshcode-id: 623
# x-archived: 2012-12-23T23:40:34
# x-published: 2008-10-02T20:19:00
#
# NOTE: this is just for fun.  It reports even tiny statistical blips like a few hundred boys named Susan in the 1950’s and girls named Mark in the 1960’s and so on, so you’ll frequently get an inconclusive answer for names you would expect to be solidly one or the other :)
#
function get-gender {
   param([string]$name)
   
   if($name.Length -lt 2) { throw "You need at least two letters in the name" }
   $name = "$($name[0])".ToUpper()  + $name.SubString(1).ToLower()

   $page = get-web "http://www.babynameaddicts.com/cgi-bin/search.pl?gender=ALL;searchfield=Names;origins=ALL;searchtype=matching;searchtext=$name"
   switch( $page.SelectNodes( "//table//font[ b/descendant::font[contains(text(),'$name')]]" ) | select -expand color ) {
      "fucshia" { "Female" }
      "#088dd0" { "Male" }
   }
}