#! /usr/bin/gawk -f # Last edited on 2004-02-26 18:31:20 by stolfi # Sampling functions for engn/wnm # English - plant names from Culpeper's Herbal, # without hyphens, mapped to lowercase. # Note that hyphens are encoded as "~". # To be included in wds-to-tlw function smp_define_patterns(smp,sec) { # No patterns needed if (sec != "tot.1") { data_error(("invalid section \"" sec "\"")); } } function smp_reclassify_word(smp,sec,cursec,curlin,type,wd) { # Keep only alpha words (possibly hyphenated) if (type != "a") { return "n"; } # Take only table of plants by planets and chapter titles in herbal proper. if (cursec ~ /^{tbs}{pp}{ls[1-9][0-9]*}$/) { return type; } else if (cursec ~ /^{hb}{h[1-9][0-9]*}{tt}$/) { return type; } else { return "n"; } } function smp_fix_word(smp,sec,type,wd) { # The {wmap} table should delete connectives, # "also", "known as", etc. if (wd in wmap) { wd = wmap[wd]; } # Map upper case to lower case: wd = tolower(wd); # Break at hyphens: gsub(/[~]/, " ", wd); return wd; } function smp_is_good_word(smp,sec,type,wd) { # Accept only lowercase alpha plus apostrophe. # Apostrophes can't be doubled. # Note that 'tis OK to begin an' end with apostrophe! return (wd ~ /^([\']?[a-z])+[\']?$/); }