Pierce Conversion Project - Script Sourcecode

From WRG
Jump to: navigation, search

# To Do


# Correct dates for generations 1-5
# Correct lineage if needed


#Propose to do later, with Robot
# Date conversion not working when dates span lines
# Bold wives name(s)
# Add wife's name to Children of line (if only 1 wife)
# Convert place categories to include counties


#Completed
# Children names can be links to errors page - Fix manually
# Add Childrens' surnames - Done, manually fix two cases of name changes
# Indent children of female children
# Hyphenation not always working - caused by links, fix manually
# b. -> born replacement is too aggressive - fix manually
# Sometimes periods after abbreviations can indicate the end of sentence too - much better now
# Add superscripts
# Robert is adding to the list of state abbrevs

  %Abbrevs = ('Co\.' => 'County', 
              'Ala\.' => 'Alabama', 
              'Ark\.' => 'Arkansas', 
              'Cal\.' => 'California', 
              'Col\.' => 'Colorado', 
              'Colo\.' => 'Colorado', 
              'Conn\.' => 'Connecticut', 
              'CT' => 'Connecticut', 
              'Del\.' => 'Delaware', 
              'Fla\.' => 'Florida', 
              'Ga\.' => 'Georgia', 
              'Ill\.' => 'Illinois', 
              'Ind\.' => 'Indiana', 
              'Ia\.' => 'Iowa', 
              'Kan\.' => 'Kansas', 
              'Ky\.' => 'Kentucky', 
              'La\.' => 'Louisiana', 
              'Me\.' => 'Maine', 
              'Md\.' => 'Maryland', 
              'Mass\.' => 'Massachusetts', 
              'Mich\.' => 'Michigan', 
              'Minn\.' => 'Minnesota', 
              'Miss\.' => 'Mississippi', 
              'Mo\.' => 'Missouri', 
              'Mont\.' => 'Montana', 
              'Neb\.' => 'Nebraska', 
              'Nev\.' => 'Nevada', 
              'N\. H\.' => 'New Hampshire', 
              'N\.H\.' => 'New Hampshire', 
              'N\. J\.' => 'New Jersey', 
              'N\.J\.' => 'New Jersey', 
              'N\. M\.' => 'New Mexico', 
              'N\.M\.' => 'New Mexico', 
              'N\. Y\.' => 'New York', 
              'N\.Y\.' => 'New York', 
              'NY' => 'New York', 
              'N\. C\.' => 'North Carolina', 
              'N\.C\.' => 'North Carolina', 
              'N\. D\.' => 'North Dakota', 
              'N\.D\.' => 'North Dakota', 
              ', O\.' => ', Ohio', 
              'Ore\.' => 'Oregon', 
              'Pa\.' => 'Pennsylvania', 
              'R\. I\.' => 'Rhode Island', 
              'R\.I\.' => 'Rhode Island', 
              'S\. C\.' => 'South Carolina', 
              'S\.C\.' => 'South Carolina', 
              'Tenn\.' => 'Tennessee', 
              'Tex\.' => 'Texas', 
              'Vt\.' => 'Vermont', 
              'Va\.' => 'Virginia', 
              'Wash\.' => 'Washington', 
              'Wis\.' => 'Wisconsin', 
              'Wyo\.' => 'Wyoming', 
              'D\. C\.' => 'District of Columbia',
              'D\.C\.' => 'District of Columbia',
              'Penn\.' => 'Pennsylvania',
              'L\. I\.' => 'Long Island',
              'L\.I\.' => 'Long Island',
              'Can\.' => 'Canada',
              'Ca\.' => 'Canada',
              'N\. S\.' => 'Nova Scotia',
              'N\.S\.' => 'Nova Scotia',
              'Que\.' => 'Quebec',
              'Mex\.' => 'Mexico',
              'S\. A\.' => 'South America',  
              'W\. I\.' => 'West Indies',  
              'CT' => 'Connecticut',
              'IA' => 'Iowa',
              'IL' => 'Illinois',
              'IN' => 'Indiana',
              'MA' => 'Massachusetts',
              'ME' => 'Maine',
              'MI' => 'Michigan',
              'MO' => 'Missouri',
              'NC' => 'North Carolina',
              'NJ' => 'New Jersey',
              'NY' => 'New York',
              'OH' => 'Ohio',
              'PA' => 'Pennsylvania',
              'RI' => 'Rhode Island',
              'VT' => 'Vermont',
              'WA' => 'Washington',
              'WI' => 'Wisconsin',
              'Engl\.' => 'England', 
              'Eng\.' => 'England', 
              'Ont\.' => 'Ontario', 
              'N\.B\.' => 'New Brunswick');


%PageTitleOverrides = (
'C1' => 'Family:Whitney, John (1592-1673)',
'C3' => 'Family:Whitney, John (1621-1692)',
'C4' => 'Family:Whitney, Richard (1624-a1691)',
'C6' => 'Family:Whitney, Thomas (1627-1719)',
'C7' => 'Family:Whitney, Jonathan (c1634-1703)',
'C8' => 'Family:Whitney, Joshua (1635-1719)',
'C10' => 'Family:Whitney, Benjamin (1643-1723)',
'C11' => 'Family:Whitney, John (1643-1727)',
'C13' => 'Family:Whitney, Nathaniel (1647-1733)',
'C14' => 'Family:Whitney, Samuel (1648-c1730)',
'C16' => 'Family:Whitney, Joseph (1652-1702)',
'C20' => 'Family:Whitney, Benjamin (1660-?)',
'C22' => 'Family:Whitney, Moses (1655-a1729)',
'C26' => 'Family:Whitney, Richard (1661-1723)',
'C28' => 'Family:Whitney, Ebenezer (1672-1727)',
'C29' => 'Family:Whitney, Thomas (1656-1742)',
'C32' => 'Family:Whitney, Eleazer (1662-1738)',
'C38' => 'Family:Whitney, Isaiah (1671-1712)',
'C41' => 'Family:Whitney, Jonathan (1659-1735)',
'C43' => 'Family:Whitney, John (1662-b1731)',
'C44' => 'Family:Whitney, Josiah (1663-1717)',
'C48' => 'Family:Whitney, Joseph (1673-1754)',
'C51' => 'Family:Whitney, Joshua (1665-1753)',
'C54' => 'Family:Whitney, William (1678-1754)',
'C55' => 'Family:Whitney, Cornelius (c1680-?)',
'C56' => 'Family:Whitney, David (1682-1768)',
'C65' => 'Family:Whitney, John (c1678-a1739)',
'C66' => 'Family:Whitney, Nathaniel (1680-c1768)',
'C67' => 'Family:Whitney, Jonathan (1681-1754)',
'C68' => 'Family:Whitney, Benjamin (c1670-?)',
'C69' => 'Family:Whitney, Joshua (1687-1771)',
'C70' => 'Family:Whitney, Mark (c1700-1760)',
'C71' => 'Family:Whitney, Isaac (c1702-1749)',
'C72' => 'Family:Whitney, Daniel (1681-?)',
'C73' => 'Family:Whitney, Timothy (1678-a1736)',
'C78' => 'Family:Whitney, Nathaniel (1675-1730)',
'C80' => 'Family:Whitney, William (1683-1720)',
'C81' => 'Family:Whitney, Samuel (1687-1753)',
'C89' => 'Family:Whitney, John (1680-1760)',
'C92' => 'Family:Whitney, Benjamin (1685-1736)',
'C96' => 'Family:Whitney, Benjamin (1712-?)',
'C98' => 'Family:Whitney, John (1694-1776)',
'C99' => 'Family:Whitney, David (1697-1738)',
'C100' => 'Family:Whitney, Daniel (1700-b1775)',
'C102' => 'Family:Whitney, Moses (1689-1778)',
'C103' => 'Family:Whitney, Abraham (1692-1778)',
'C104' => 'Family:Whitney, Jonas (1699-1770)',
'C105' => 'Family:Whitney, Jason (1704-1785)',
'C106' => 'Family:Whitney, Lemuel (1706-1755)',
'C107' => 'Family:Whitney, John (1698-1765)',
'C109' => 'Family:Whitney, Richard (1692-1775)',
'C110' => 'Family:Whitney, Jonathan (1699-1773)',
'C111' => 'Family:Whitney, Joshua (c1707-1787)',
'C117' => 'Family:Whitney, Zachariah (s1701-?)',
'C118' => 'Family:Whitney, Ezekiel (s1703-1751)',
'C120' => 'Family:Whitney, Thomas (1681-?)',
'C122' => 'Family:Whitney, John (1684-1747)',
'C124' => 'Family:Whitney, Benjamin (1687-1737)',
'C125' => 'Family:Whitney, Nathan (c1689-b1761)',
'C131' => 'Family:Whitney, Thomas (c1694-1748)',
'C135' => 'Family:Whitney, Eleazer (1702-1758)',
'C136' => 'Family:Whitney, Elnathan (1705-1759)',
'C137' => 'Family:Whitney, James (1697-?)',
'C138' => 'Family:Whitney, Jonas (1708-1792)',
'C140' => 'Family:Whitney, Isaiah (1700-1737)',
'C143' => 'Family:Whitney, Elijah (1707-1755)',
'C145' => 'Family:Whitney, Jonas (1699-1770)',
'C146' => 'Family:Whitney, Abraham (1710-1784)',
'C151' => 'Family:Whitney, Shadrach (1698-1764)',
'C154' => 'Family:Whitney, Zaccheus (1707-1740)',
'C157' => 'Family:Whitney, Timothy (1709-b1740)',
'C158' => 'Family:Whitney, Daniel (1710-1779)',
'C160' => 'Family:Whitney, James (1692-1770)',
'C165' => 'Family:Whitney, Josiah (1714-1766)',
'C166' => 'Family:Whitney, Jonathan (1703-1768)',
'C169' => 'Family:Whitney, Joseph (1710-1786)',
'C171' => 'Family:Whitney, James (1714-1755)',
'C174' => 'Family:Whitney, William (1701-a1753)',
'C176' => 'Family:Whitney, Joshua (1714-1744)',
'C177' => 'Family:Whitney, John (1718-1793)',
'C179' => 'Family:Whitney, Caleb (1721-a1760)',
'C182' => 'Family:Whitney, Matthias (1720-a1770)',
'C184' => 'Family:Whitney, Joshua (1724-1814)',
'C188' => 'Family:Whitney, David (1716-a1764)',
'C189' => 'Family:Whitney, Joshua (1718-1761)',
'C194' => 'Family:Whitney, Josiah (1731-1824)',
'C195' => 'Family:Whitney, Solomon (c1734-1772)',
'C197' => 'Family:Whitney, Samuel (1707-1789)',
'C198' => 'Family:Whitney, Benjamin (1725-1797)',
'C206' => 'Family:Whitney, Nathan (1707-1804)',
'C207' => 'Family:Whitney, Nathaniel (1709-1804)',
'C208' => 'Family:Whitney, Abel (1712-1762)',
'C210' => 'Family:Whitney, Isaac (1721-1800)',
'C211' => 'Family:Whitney, Amos (1724-?)',
'C214' => 'Family:Whitney, Jonathan (1704-1755)',
'C219' => 'Family:Whitney, Elias (1716-1810)',
'C220' => 'Family:Whitney, George (1721-1752)',
'C224' => 'Family:Whitney, Benjamin (1709-1797)',
'C225' => 'Family:Whitney, Ezekiel (1716-1753)',
'C231' => 'Family:Whitney, Benjamin (1743-?)',
'C237' => 'Family:Whitney, Jason (1729-1807)',
'C241' => 'Family:Whitney, Thomas (1736-?)',
'C243' => 'Family:Whitney, Gideon (1729-1752)',
'C254' => 'Family:Whitney, Elijah (1716-1792)',
'C259' => 'Family:Whitney, Caleb (1711-1764)',
'C260' => 'Family:Whitney, Moses (1714-1804)',
'C261' => 'Family:Whitney, Joseph (1717-?)',
'C264' => 'Family:Whitney, Nathaniel (1696-1776)',
'C270' => 'Family:Whitney, Israel (b1709-1751)',
'C272' => 'Family:Whitney, Solomon (1709-?)',
'C273' => 'Family:Whitney, Samuel (c1710-1788)',
'C275' => 'Family:Whitney, Ebenezer (c1712-?)',
'C276' => 'Family:Whitney, David (1716-1754)',
'C277' => 'Family:Whitney, William (1707-a1789)',
'C281' => 'Family:Whitney, Samuel (1719-1782)',
'C284' => 'Family:Whitney, Samuel (1727-?)',
'C286' => 'Family:Whitney, Isaac (1710-?)',
'C287' => 'Family:Whitney, Zechariah (1711-?)',
'C289' => 'Family:Whitney, Abraham (1716-a1781)',
'C291' => 'Family:Whitney, Joseph (1719-1790)',
'C292' => 'Family:Whitney, Benjamin (1712-?)',
'C293' => 'Family:Whitney, Samuel (1715-b1807)',
'C304' => 'Family:Whitney, John (1731-?)',
'C307' => 'Family:Whitney, Abraham (1735-b1813)',
'C309' => 'Family:Whitney, Ezekiel (1741-1806)',
'C310' => 'Family:Whitney, Stephen (1743-1833)',
'C314' => 'Family:Whitney, David (1723-a1764)',
'C316' => 'Family:Whitney, Nathan (1727-1803)',
'C318' => 'Family:Whitney, Josiah (1730-1800)',
'C319' => 'Family:Whitney, Jonas (1733-1778)',
'C321' => 'Family:Whitney, Benjamin (1723-1790)',
'C322' => 'Family:Whitney, Simon (1727-1797)',
'C326' => 'Family:Whitney, Daniel (1735-c1801)',
'C327' => 'Family:Whitney, Joshua (1737-1809)',
'C328' => 'Family:Whitney, Henry (1746-b1788)',
'C329' => 'Family:Whitney, Israel (1741-1774)',
'C332' => 'Family:Whitney, Elisha (1747-1807)',
'C334' => 'Family:Whitney, Salmon (1712-1759)',
'C335' => 'Family:Whitney, Aaron (1714-1779)',
'C338' => 'Family:Whitney, Ephraim (1724-1796)',
'C345' => 'Family:Whitney, Abraham (1724-1818)',
'C350' => 'Family:Whitney, Jonas (1727-1791)',
'C351' => 'Family:Whitney, Ephraim (1728-1801)',
'C355' => 'Family:Whitney, Timothy (1730-1803)',
'C353' => 'Family:Whitney, Moses (1733-1810)',
'C355' => 'Family:Whitney, Aaron (1740-1817)',
'C368' => 'Family:Whitney, Isaac (1747-1815)',
'C370' => 'Family:Whitney, Elias (c1733-?)',
'C371' => 'Family:Whitney, Lemuel (a1738-1803)',
'C372' => 'Family:Whitney, John (1725-?)',
'C374' => 'Family:Whitney, Ezra (1731-a1800)',
'C376' => 'Family:Whitney, Abner (1734-1802)',
'C379' => 'Family:Whitney, Daniel (1720-1782)',
'C381' => 'Family:Whitney, Richard (1725-1798)',
'C383' => 'Family:Whitney, Josiah (1731-1806)',
'C385' => 'Family:Whitney, Oliver (1731-?)',
'C386' => 'Family:Whitney, Caleb (1729-1822)',
'C387' => 'Family:Whitney, Hezekiah (1735-1805)',
'C388' => 'Family:Whitney, Simon (1720-1778)',
'C389' => 'Family:Whitney, Jonathan (c1724-1770)',
'C398' => 'Family:Whitney, Joshua (1747-1771)',
'C400' => 'Family:Whitney, Zachariah (1732-1808)',
'C402' => 'Family:Whitney, Aaron (1737-?)',
'C404' => 'Family:Whitney, Joseph (1743-?)',
'C408' => 'Family:Whitney, Ezekial (1729-1814)',
'C409' => 'Family:Whitney, Ebenezer (1720-?)',
'C416' => 'Family:Whitney, Samuel (1714-1748)',
'C417' => 'Family:Whitney, David (1722-1802)',
'C418' => 'Family:Whitney, Joseph (1715-1796)',
'C423' => 'Family:Whitney, David (1717-1749)',
'C425' => 'Family:Whitney, Solomon (1721-1758)',
'C433' => 'Family:Whitney, Samuel (1734-1808)',
'C435' => 'Family:Whitney, Nathan (1724-1801)',
'C437' => 'Family:Whitney, Jeremiah (1729-1760)',
'C441' => 'Family:Whitney, Thomas (1722-1806)',
'C447' => 'Family:Whitney, Samuel (1746-?)',
'C449' => 'Family:Whitney, Alexander (1751-?)',
'C450' => 'Family:Whitney, Joshua (1754-?)',
'C454' => 'Family:Whitney, Aaron (1734-?)',
'C457' => 'Family:Whitney, Elnathan (1742-?)',
'C469' => 'Family:Whitney, Jacob (1737-1803)',
'C472' => 'Family:Whitney, Abner (1744-1826)',
'C475' => 'Family:Whitney, Isaiah (1735-1818)',
'C481' => 'Family:Whitney, Israel (1751-1826)',
'C487' => 'Family:Whitney, John (1746-1802)',
'C488' => 'Family:Whitney, Abraham (1748-1833)',
'C489' => 'Family:Whitney, Isaiah (c1756-1841)',
'C490' => 'Family:Whitney, Elijah (1754-1834)',
'C493' => 'Family:Whitney, Jonathan (1737-1802)',
'C495' => 'Family:Whitney, Levi (1739-1809)',
'C496' => 'Family:Whitney, Timothy (1743-?)',
'C497' => 'Family:Whitney, Daniel (1746-1817)',
'C500' => 'Family:Whitney, James (1718-1754)',
'C504' => 'Family:Whitney, Micah (1725-1791)',
'C505' => 'Family:Whitney, Benjamin (1727-1793)',
'C506' => 'Family:Whitney, Ezra (1730-1804)',
'C507' => 'Family:Whitney, Daniel (1733-1810)',
'C510' => 'Family:Whitney, Peter (1738-1826)',
'C520' => 'Family:Whitney, Josiah (1764-1792)',
'C523' => 'Family:Whitney, Benjamin (1741-1821)',
'C529' => 'Family:Whitney, Joseph (1755-?)',
'C530' => 'Family:Whitney, James (1757-1799)',
'C532' => 'Family:Whitney, James (1742-?)',
'C533' => 'Family:Whitney, John (1745-1829)',
'C534' => 'Family:Whitney, Jonathan (1745-1834)',
'C537' => 'Family:Whitney, William (1725-a1766)',
'C538' => 'Family:Whitney, Thomas (1728-1766)',
'C540' => 'Family:Whitney, Joshua (1750-1821)',
'C541' => 'Family:Whitney, Benjamin (1755-1801)',
'C543' => 'Family:Whitney, Elijah (1750-1821)',
'C544' => 'Family:Whitney, John (1754-1807)',
'C547' => 'Family:Whitney, Lebbeus (1745-1785)',
'C552' => 'Family:Whitney, John Mirick (1758-b1819)',
'C553' => 'Family:Whitney, James Rix (1760-1822)',
'C557' => 'Family:Whitney, Cornelius (1749-1833)',
'C558' => 'Family:Whitney, Joshua (1751-1796)',
'C560' => 'Family:Whitney, David (1764-1830)',
'C561' => 'Family:Whitney, Samuel (1757-1850)',
'C564' => 'Family:Whitney, Cornelius (1761-1831)',
'C565' => 'Family:Whitney, Joseph (1753-1832)',
'C566' => 'Family:Whitney, Matthias (1757-1851)',
'C568' => 'Family:Whitney, Rufus (s1751-1801)',
'C569' => 'Family:Whitney, Joshua (1769-1817)',
'C583' => 'Family:Whitney, Joshua (1745-1808)',
'C584' => 'Family:Whitney, Asa (1743-1803)',
'C585' => 'Family:Whitney, Josiah (1752-?)',
'C586' => 'Family:Whitney, David (1757-1850)',
'C601' => 'Family:Whitney, Samuel (1759-1814)',
'C602' => 'Family:Whitney, Tarball (1763-1850)',
'C603' => 'Family:Whitney, Solomon (1766-1854)',
'C604' => 'Family:Whitney, Samuel (1732-?)',
'C605' => 'Family:Whitney, Jonathan (1734-a1766)',
'C604a' => 'Family:Whitney, Abraham (1753-1831)',
'C606a' => 'Family:Whitney, Jacob (1763-1846)',
'C607a' => 'Family:Whitney, Nathan (1768-1849)',
'C610' => 'Family:Whitney, Samuel Lumber (1774-1846)',
'C616' => 'Family:Whitney, Moses (1739-1820)',
'C618' => 'Family:Whitney, Josiah (1752-1837)',
'C620' => 'Family:Whitney, Asa (1754-1806)',
'C621' => 'Family:Whitney, Abel (?-?)',
'C626' => 'Family:Whitney, Joel (1743-1791)',
'C629' => 'Family:Whitney, Zebulon (1747-1833)',
'C632' => 'Family:Whitney, Micah (1752-1832)',
'C633' => 'Family:Whitney, Daniel (1754-1834)',
'C637' => 'Family:Whitney, Isaac (1748-1837)',
'C639' => 'Family:Whitney, Stephan (1755-1848)',
'C642' => 'Family:Whitney, Barnabas (1766-1823)',
'C645' => 'Family:Whitney, Henry (1767-1849)',
'C654' => 'Family:Whitney, Jesse (1730-1815)',
'C656' => 'Family:Whitney, Jonathan (1737-1792)',
'C658' => 'Family:Whitney, David (1746-?)',
'C661' => 'Family:Whitney, Elias (1750-1828)',
'C668' => 'Family:Whitney, Jonathan (1734-1800)',
'C680' => 'Family:Whitney, Isaac (1770-1817)',
'C683' => 'Family:Whitney, Fisher (1775-1805)',
'C685' => 'Family:Whitney, George (1778-1849)',
'C686' => 'Family:Whitney, Jason (1780-1844)',
'C688' => 'Family:Whitney, Ebenezer (1784-1855)');

%FatherOverrides = (
'C96' => 'C92',
'C107' => 'C38',
'C270' => 'C28',
'C304' => 'C136',
'C328' => 'C321',
'C540' => 'C189',
'C541' => 'C184',
'C583' => 'C176',
'C584' => 'C176');

&MainSub("1"); # First Pass to get Links
&MainSub("2"); # Second Pass to do it

sub MainSub {
  $Pass = $_[0];

  $INFILE = "combined.txt";
  open( INFILE, "$INFILE" ) || die "Error opening $INFILE.";

  $OUTFILE = "dict.txt";
  open( OUTFILE, "> $OUTFILE" ) || die "Error opening $OUTFILE.";

  $NAMES = "names.txt";
  open( NAMES, "> $NAMES" ) || die "Error opening $NAMES.";

  $Text = '';
  $InChildren = 0;
  $FirstLineFound = 0;
  %PeopleLinks= ();
  $FatherKey = '';
  $PageNo = '';
  $CurPageNo = '';
  $InFootNote = 0;
  while ( <INFILE> ) {
  #print "LINE=$_";
    if (/<span id="P/) {
      if ( $Text ne '' ) {
        &BuildPageTitle; 
        #print "REG DUMP TXT=$Text<\n"; 
        &DumpPage; 
      }
    }

    #Just Zap the Footnotes - add them manually later
    if ( /^<i><\/i>-{20,}$/ ) { $InFootNote = 1; }
    if ( /^<\/p>/ ) { $InFootNote = 0; }
    if ( $InFootNote == 1 ) { $_ = ''; }

    if ((/<span id="C/) && ( $InChildren == 0 )) { &StartChildrenTable($_); }

    &GrabPageNo($_);
    &ZapMisc($_);    # Note: Spans are needed above, must be gone below, so do this here

    if ( $InChildren == 1 ) { &DoChildren($_); }

    &ConvertAbbrevs($_);
    &ConvertDates($_);            # Can't move, bombs out - move below as this won't work if dates span lines
    &ConvertStateNames($_);
    if ( $InChildren == 0 ) { &ConvertIndentations($_); }
    &ZapLeadingWhitespace($_);
    &ConvertLineBreaks($_);

    # Merge hyphenated words
    s/- $//;

    if ( s/\[\[Archive:The Descendants of John Whitney, page \d+#([^|]+)\|([^\]]+)\]\]. ([^(]+) \((.*)// ) {
      $PersonKey = $1;

      &DoSubjectNames($3);
     
      $_ = "$SubjectName ($4";
      #print "$_\n";
      #print "$PersonKey $SubjectName\n";

      $FatherKey = $PersonKey;
    }

    $Text .= $_;
  }

  if ($Text ne "" ) { 
    #print "LAST DUMP TXT=$Text<\n"; 
    &BuildPageTitle; 
    &DumpPage; 
  }

  close(OUTFILE); 
  close(INFILE); 
  close(NAMES); 
}

sub BuildPageTitle {
  $BirthYear = &GetBirthYear($Text);
  $DeathYear = &GetDeathYear($Text);

  $PageTitle = "Family:$SubjectLastName, $SubjectFirstNames ($BirthYear-$DeathYear)";

  #PageTitle Overrides for pages already existing on the wiki
  if ( $PageTitleOverrides{$PersonKey} ne '' ) {
    #print "OR $PageTitle -> $PageTitleOverrides{$PersonKey}\n";
    $PageTitle = $PageTitleOverrides{$PersonKey};
  }

  #print NAMES "$PageNo $PageTitle\n";
  print NAMES ":$PersonKey [[$PageTitle]]\n";
  #print "\n\nBUILT $PageTitle\n";
  #print "$PersonKey $PageTitle\n";

  $LinkKeys{$PersonKey} = $PageTitle; 

  $FatherKey = $FatherOf{$PersonKey};

  if ( $PersonKey eq 'C1' ) {
    $PeopleGens{$PersonKey} = 1;
    $SupStr = "<sup>$PeopleGens{$PersonKey}</sup>";
    $PeopleLinks{$PersonKey} = "[[$PageTitle|$SubjectFirstNames$SupStr]]";
  } else {
    $PeopleGens{$PersonKey} = $PeopleGens{$FatherKey} + 1;
    $SupStr = "<sup>$PeopleGens{$PersonKey}</sup>";
    $PeopleLinks{$PersonKey} = "[[$PageTitle|$SubjectFirstNames$SupStr]], " .$PeopleLinks{$FatherKey};
  }

  #if ( $Pass eq '2' ) {
  #  print "\n\nBUILT $PageTitle\n";
  #  print "$PersonKey $PageTitle\n";
  #  print "FK $FatherKey PK $PersonKey PT $PageTitle\n";
  #  print "AA K= $PersonKey V= $PeopleLinks{$PersonKey}\n";
  #}

}

sub DumpPage {
#print "SAVING $PageTitle\n";
    if ( $InChildren == 1 ) {
      $Text .= "==N====ET====N==";
    }

    # Get Categories (for Locations)
    # Do this before we add references as there's a location in the title
    $Categories = &GetCategories($Text);

    if ( $PageNo == $CurPageNo ) {
      $PageRange = "p. $PageNo";
    } else {
      $PageRange = "pp. $PageNo-$CurPageNo";
    }

    $Text .= "==N====References====N==";
    $Text .= "1. All data imported from [[Archive:The Descendants of John Whitney, page $PageNo|Frederick Clifton Pierce, ''The Descendants of John Whitney, Who Came from London, England, to Watertown, Massachusetts, in 1635'', (Chicago: 1895), $PageRange]].==N==";
    $Text .= "----==N==";
    $Text .= "Copyright © 2006, The Whitney Research Group==N==";

    # Fix improperly formatted tables
    $Text =~ s/:\{\|==N====N==\|-==N==/:{|==N==/;

    # Zap their newlines
    $Text =~ s/\n//g;

    # Convert dates - moved from above
    #$Text = &ConvertDates($Text);  #This apparently causes an error here

    # Make the Wives names bold
#    $Text =~ s/^[^\{]*married[^;=\n\.]* ([A-Z][a-z]*.?( [A-Z][a-z]*.?)? [A-Z\-]{3,})/$Text/g;
#TBD print "\n\n\n$PageNo $PersonKey WIFE $1\n";
#TBD print "$Text\n";



    # Convert my newlines
    $Text =~ s/==N==/\n/g;
    $Text =~ s/==ST==/{|/g;
    $Text =~ s/==ET==/|}/g;
    $Text =~ s/==NR==/|-/g;

    # Make the subject name bold
    $Text =~ s/([^(]+) \(/'''$1''' (/;

    # Namecase uppercase strings of 3+ characters
    $Text =~ s/([A-Z]{3,})/&NameCase($1)/eg;

    if ( $Categories ne '' ) { $Text .= "\n$Categories"; }

    # Convert the ancestry to links!
    $Text =~ s/^([^(]+)\([^)]+\)/$1($PeopleLinks{$FatherOf{$PersonKey}})/g;
    #if ( $Pass eq '2' ) {
    #  print "PT $PageTitle\n";
    #  print "PK $PersonKey\n";
    #  print "FO $FatherOf{$PersonKey}\n";
    #  print "PL $PeopleLinks{$FatherOf{$PersonKey}}\n";
    #}


    print OUTFILE "{{-start-}}\n";
    print OUTFILE "<!-- '''$PageTitle''' -->\n";
    print OUTFILE "$Text";
    print OUTFILE "\n{{-stop-}}\n\n";
    $Text = '';
    $InChildren = 0;
    $FirstLineFound = 0;
    $PageNo = $CurPageNo;
  }

sub GrabPageNo {
  local $thing;
  
  $thing = $_[0];

  if ( $thing =~ /\{\{PierceHeader\|[^|]+\|([^|]+)\|/ ) {
    $CurPageNo = $1;
  }

}

sub ZapMisc {
  $_ = $_[0];

  s/$\s{25,}.*//; # Zap lines indicating photos, etc.
  s/\{\{PierceHeader.*$//;
  s/\{\{PierceHeading.*$//;
  s/<p id="Pierce.*$//;
  s/^<\/p>$//;
  s/\{\{PierceFooter.*$//;
  s/<span id="[^"]*"><\/span>//;
  $_;
}

sub ConvertAbbrevs {
  $_ = $_[0];

  s/\bb\.(\s|\n)/born /g;
  s/\bd\.(\s|\n)/died /g;
  s/\bm\.(\s|\n)/married /g;
  s/\bres\.(\s|\n)/resided /g;
  s/\bRes\.(\s|\n)/Resided /g;
  s/\b2d\.(\s|\n)/second /g;
  s/\chn\.(\s|\n)/children /g;
  s/\rem\.(\s|\n)/removed /g;
  s/\s\. of(\s|\n)/son of /g;
  s/\dau\. of(\s|\n)/daughter of /g;
  s/\unm\.(\s|\n)/unmarried /g;
  s/\n\.\s?f\.\s?k\.(\s|\n)/nothing further known. /ig;

  $_;
}

sub ConvertDates {
  $_ = $_[0];

  s/Jan\. (\d{1,2}), /$1 Jan /g;
  s/Feb\. (\d{1,2}), /$1 Feb /g;
  s/Mar\. (\d{1,2}), /$1 Mar /g;
  s/Mch\. (\d{1,2}), /$1 Mar /g;
  s/Apr\. (\d{1,2}), /$1 Apr /g;
  s/May (\d{1,2}), /$1 May /g;
  s/June (\d{1,2}), /$1 Jun /g;
  s/July (\d{1,2}), /$1 Jul /g;
  s/Aug\. (\d{1,2}), /$1 Aug /g;
  s/Sept\. (\d{1,2}), /$1 Sep /g;
  s/Oct\. (\d{1,2}), /$1 Oct /g;
  s/Nov\. (\d{1,2}), /$1 Nov /g;
  s/Dec\. (\d{1,2}), /$1 Dec /g;
  $_;
}

sub ConvertStateNames {
  $_ = $_[0];

  #if ( $Pass eq '2' ) {
    #print "ZZZ$_\n";
    foreach $Abbr (keys(%Abbrevs)) {
      $FullName = $Abbrevs{$Abbr};
      s/\b$Abbr\n/$Abbrevs{$Abbr}.\n/g;
      s/\b$Abbr(\s+[A-Z])/$Abbrevs{$Abbr}.$1/g;
      s/\b$Abbr([^A-Za-z])/$Abbrevs{$Abbr}$1/g;
    }
  #}

  $_;
}

sub ConvertIndentations {
  $_ = $_[0];

  if ( /^\s*$/ ) {
    # Skip blank lines
  } else {
    if ( $FirstLineFound == 0 ) {
      s/^\s{2,}(.*)$/$1/;
      $FirstLineFound = 1;
    } else {
      s/^\s{2,}(.*)$/==N====N==$1/;
    }
  }

  $_;
}

sub ConvertLineBreaks {
  $_ = $_[0];

  s/\n$/ /;
  $_;
}

sub ZapLeadingWhitespace {
  $_ = $_[0];

  s/^\s+//;
  $_;
}

sub StartChildrenTable {
  $_ = $_[0];
 
  $Text .= "==N====N==Children of $SubjectNameWithGen:==N====N==";
  $Text .= ":==ST====N==";
  $InChildren = 1;
  $FirstChildDone = 0;
  $_;
}

sub DoChildren {
  $_ = $_[0];

  $LinkToChildsPage = '';

  if ( s/\[\[Archive:The Descendants of John Whitney, page \d+#([^|]+)\|(\d+)\]\]/$2/ ) {

    $LinkTo = $1;
    $LinkTo =~ s/^P/C/;

    if ( $Pass eq '1' ) {
      if ( $FatherOverrides{$LinkTo} ne '' ) {
        $FatherOf{$LinkTo} = $FatherOverrides{$LinkTo};
      } else { 
        $FatherOf{$LinkTo} = $FatherKey;
      }

      #print "Setting FO for $LinkTo to $FatherKey\n";
    }

    if ( $Pass eq '2' ) {
      $LinkToChildsPage = $LinkKeys{$LinkTo};
      #print "SV LK $PageName $LinkTo $LinkToChildsPage\n";

      $FatherKey = $FatherOf{$PersonKey};
      #print "SV PK $PersonKey FK $FatherKey PL $PeopleLinks{$FatherKey}\n";

    }
    if ( $LinkToChildsPage eq '' ) { $LinkToChildsPage = 'MISSINGLINK'; }
  }

  # Are we starting a new child?
  if ( /^\s{4,7}\d{1,4}\.\s+(\w+)\.\s+(.*)/ ) {
    $String = $2;

    if ( $FirstChildDone == 0 ) {
      $SupStr = $PeopleGens{$PersonKey}+1;
      $Gen = "<sup>$SupStr</sup>";
      $FirstChildDone = 1;
    } else {
      $Gen = '';
    }

    if ( $LinkToChildsPage ne '' ) {
      $String =~ s/^([^,]+),(.*)$/[[$LinkToChildsPage|'''$1$Gen Whitney''']],$2/; 
    } else {
      $String =~ s/^([^,]+),(.*)$/'''$1$Gen Whitney''',$2/; 
    }

    $_ = "==N====NR====N==| align=right valign=top | $1.==N==| $String\n"; #Yes, the final /n is important! Do not change!
  }

  s/Ch.:/==N==:Ch.:/;   # Indent children of daughters

  $_;
}

sub NameCase {
  local $thing;
  
  $thing = $_[0];

  $thing =~ s/(\w+)/\u\L$1/g;
  return $thing;
}

sub GetCategories {
#  $_ = $_[0];  This is VERY SLOW
  local $Cats = '';
  %Cats = ();

  @States = ('Alabama','Alaska','Arizona','Arkansas','California','Colorado','Connecticut', 
             'Delaware','Florida','Georgia','Hawaii','Idaho','Illinois', 'Indiana',
             'Iowa','Kansas','Kentucky','Louisiana','Maine','Maryland', 'Massachusetts',
             'Michigan','Minnesota','Mississippi','Missouri','Montana','Nebraska',
             'Nevada','New Hampshire','New Jersey','New Mexico','New York','North Carolina',
             'North Dakota','Ohio','Oklahoma','Oregon','Pennsylvania','Rhode Island',
             'South Carolina','South Dakota','Tennessee','Texas','Utah','Vermont', 
             'Virginia','Washington','West Virginia', 'Wisconsin','Wyoming');

  foreach $State (@States) {
    while ( $_[0] =~ /([^\s|\]]+)(])*, ($State)/g ) {
      $Cats{$State} = 1;
      $Cats{"$State|$1"} = 1; #Enable alpha sort by State, then locality
    }
  }

  # Check for a few other common places that might not have the state listed
  if ( $_[0] =~ /\b(Boston)/g ) {
    $State = 'Massachusetts';
    $Cats{$State} = 1;
    $Cats{"$State|$1"} = 1; #Enable alpha sort by State, then locality
  }
  if ( $_[0] =~ /\b(Watertown)/g ) {
    $State = 'Massachusetts';
    $Cats{$State} = 1;
    $Cats{"$State|$1"} = 1; #Enable alpha sort by State, then locality
  }

  foreach $Location (sort(keys %Cats)) {
    if ( $Location =~ /(.*)\|(.*)/ ) { $Location = "$2, $1"; }

    $Cats .= "[[Category: $Location]]\n";
  }

  return $Cats;
}

sub GetBirthYear {
  $Temp = $_[0];
    #print "1 $Temp\n";
  ($birthstring) = $Temp =~ /born (.*)/;
    #print "2 $birthstring\n";
  $birthstring =~ s/^([^;]*);.*$/$1/;
    #print "3 $birthstring\n";
  $birthstring =~ s/^([^=]*)=.*$/$1/;
    #print "4 $birthstring\n";
  $birthstring =~ s/==N==.*$//;   #Get rid of everything after a new paragraph
    #print "5 $birthstring\n";
  $birthstring =~ /(\d{4,4}).*/;
    #print "6 $birthstring\n";
  $potentialbirthyear = $1;
    #print "7 $potentialbirthyear\n";
  $bd = '?';
  if ( $potentialbirthyear =~ /^\d{4,4}$/ ) { $bd = $potentialbirthyear; }
  return $bd;
}

sub GetDeathYear {
  $Temp = $_[0];
    #print "1 $Temp\n";
  ($deathstring) = $Temp =~ /He died (.*)/;
    #print "2 $deathstring\n";
  $deathstring =~ s/^([^;]*);.*$/$1/;
    #print "3 $deathstring\n";
  $deathstring =~ s/^([^=]*)=.*$/$1/;
    #print "4 $deathstring\n";
  $deathstring =~ s/==N==.*$//;   #Get rid of everything after a new paragraph
    #print "5 $deathstring\n";
  $deathstring =~ /(\d{4,4}).*/;
    #print "6 $deathstring\n";
  $potentialdeathyear = $1;
    #print "7 $potentialdeathyear\n";
  $dd = '?';
  if ( $potentialdeathyear =~ /^\d{4,4}$/ ) { $dd = $potentialdeathyear; }
    #print "8 $dd\n";
  return $dd;
}

sub Trim($_) {
  my $string = $_[0];
  $string =~ s/^\s+//;
  $string =~ s/\s+$//;
  return $string;
}

sub DoSubjectNames {
  # $SubjectName - Name as found, but namecased (Still includes links)
  # $SubjectFirstNames - given names of the subject (excluding titles, suffix, etc.)
  # $SubjectLastName - Surname of the subject
  # $SubjectNameWithGen - Full name of subject (excluding titles, etc.) with generation superscript

  $SubjectName = &NameCase($_[0]);

  $Temp = $SubjectName;
  $Temp =~ s/\[\[[^|]+\|([^\]]+)\]\]/$1/;
  $Temp =~ s/\s{2,}/ /g;
  $Temp =~ s/Ll\. D\.//ig;
  $Temp =~ s/Ph\. D\.//ig;
  $Temp =~ s/Wm\./William/g;
  $Temp =~ s/WM\./William/g;
  $Temp =~ s/Whtney/Whitney/g;
  $Temp =~ s/Witney/Whitney/g;
  $Temp =~ s/ or \S+//ig;
  $Temp =~ s/Fred'k/Frederick/ig;
  $Temp =~ s/\S{2,}\.//g;
  $Temp =~ s/Ensign//g;
  $Temp =~ s/Elder//g;
  $Temp =~ s/Squire//g;
  $Temp =~ s/Judge//g;
  $Temp =~ s/Bishop//g;
  $Temp =~ s/Major//g;
  $Temp =~ s/A\.B\.//g;
  $Temp =~ s/M\.D\.//g;
  $Temp =~ s/,//g;
  $Temp =~ s/\n//g;
  $Temp = &Trim($Temp);

  $SubjectFirstNames = "ZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZ";
  $SubjectLastNames = "ZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZ";
  if ( $Temp =~ /(.*) ([^\s]+)$/ ) {
    $SubjectFirstNames = &Trim($1);
    $SubjectFirstNames =~ s/\s{2,}/ /;
    $SubjectLastName = &Trim($2);
  }

  $SupStr = "<sup>$PeopleGens{$PersonKey}</sup>";
  $SubjectNameWithGen = "$SubjectFirstNames$SupStr $SubjectLastName";

  $SubjectName =~ s/$SubjectFirstNames/$SubjectFirstNames$SupStr/;

  #if ( $Pass eq '2' ) {
  #  print "$SubjectName\n";
  #  print "$SubjectFirstNames\n";
  #  print "$SubjectLastName\n";
  #  print "$SubjectNameWithGen\n\n";
  #}

}

Personal tools