gender utilities #41

Parent #79Owner #36Flags readSource QuestCore.db

Aliases: gender utilities, Gender_Utilities

8 verbs · 20 properties · 0 children

Verbs

VerbSpecFlagsDefinerLines
setthis none thisrxd#4123
addthis none thisrxd#4124
get_pronounthis none thisrxd#4127
get_conj*ugationthis none thisrxd#4122
_verb_pluralthis none thisrxd#4131
_verb_singularthis none thisrxd#4118
_dothis none thisrxd#4142
pronoun_subthis none thisrxd#4153

Properties

PropertyDefinerFlagsOwnerValue
is_plural#41rc#36
list of 11{0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1}
have#41rc#36
list of 11{"has", "has", "has", "has", "has", "has", "have", "have", "have", "have", "have"}
be#41rc#36
list of 11{"is", "is", "is", "is", "is", "is", "are", "am", "are", "are", "are"}
pronouns#41rc#36
list of 10{"ps", "po", "pp", "pq", "pr", "psc", "poc", "ppc", "pqc", "prc"}
genders#41rc#36
list of 10{"neuter", "male", "female", "either", "Spivak", "splat", "plural", "egotistical", "royal", "2nd"}
ps#41rc#36
list of 10{"it", "he", "she", "s/he", "e", "*e", "they", "I", "we", "you"}
po#41rc#36
list of 10{"it", "him", "her", "him/her", "em", "h*", "them", "me", "us", "you"}
pp#41rc#36
list of 10{"its", "his", "her", "his/her", "eir", "h*", "their", "my", "our", "your"}
pq#41rc#36
list of 10{"its", "his", "hers", "his/hers", "eirs", "h*s", "theirs", "mine", "ours", "yours"}
pr#41rc#36
list of 10{"itself", "himself", "herself", "(him/her)self", "emself", "h*self", "themselves", "myself", "ourselves", "yourself"}
psc#41rc#36
list of 10{"It", "He", "She", "S/He", "E", "*E", "They", "I", "We", "You"}
poc#41rc#36
list of 10{"It", "Him", "Her", "Him/Her", "Em", "H*", "Them", "Me", "Us", "You"}
ppc#41rc#36
list of 10{"Its", "His", "Her", "His/Her", "Eir", "H*", "Their", "My", "Our", "Your"}
pqc#41rc#36
list of 10{"Its", "His", "Hers", "His/Hers", "Eirs", "H*s", "Theirs", "Mine", "Ours", "Yours"}
prc#41rc#36
list of 10{"Itself", "Himself", "Herself", "(Him/Her)self", "Emself", "H*self", "Themselves", "Myself", "Ourselves", "Yourself"}
help_msg#79rc#36
list of 18{"Defines the list of standard genders, the default pronouns for each, and routines for adding or setting pronoun properties on any gendered object.", "", "Properties:", " .genders -- list of standard genders", " .pronouns -- list of pronoun properties", " .ps .po .pp .pq .pr .psc .poc .ppc .pqc .prc ", " -- lists of pronouns for each of the standard genders", "", " If foo is of gender this.gender[n], ", " then the default pronoun foo.p is this.p[n] ", " (where p is one of ps/po/pp/pq...)", "", "Verbs:", " :set(object,newgender) -- changes pronoun properties to match new gender.", " :add(object[,perms[,owner]]) -- adds pronoun properties to object.", "", " :get_pronoun (which,object) -- return pronoun for a given object", " :get_conj*ugation(verbspec,object) -- return appropriately conjugated verb"}
key#1c#36<clear>
aliases#1rc#36{"gender utilities", "Gender_Utilities"}
description#1rc#36{"This is the gender utilities utility package. See `help $gender_utils' for more details."}
object_size#1r#36{16564, -1090650497}

Ancestry

Ancestors (nearest first): #79 Generic Utilities Package#1 Root Class

Children: none

Call graph

calls n41_0 #41:set n20_22 #20:find_prefix n41_0->n20_22 n41_1 #41:add n41_1->n41_0 n52_0 #52:has_property n41_1->n52_0 n6_18 #6:tell n41_1->n6_18 n41_3 #41:get_conj*ugation n41_4 #41:_verb_plural n41_3->n41_4 n41_5 #41:_verb_singular n41_3->n41_5 n20_15 #20:capitalize n41_3->n20_15 n41_4->n41_4 n41_5->n41_5 n41_6 #41:_do n41_6->n41_6 n41_2 #41:get_pronoun n41_6->n41_2 n41_7 #41:pronoun_sub n41_7->n41_6 n41_7->n41_7 n20_33 #20:_cap_property n41_7->n20_33

Source

set

Spec this none thisFlags rxdOwner #2Definer #41

Referenced by

Source

1"$gender_utils:set(object,gender) --- sets the pronoun properties of object.";
2"gender is a string: one of the strings in $gender_utils.genders, the list of rcognized genders.  If the gender change is successful, the (full) name of the gender (e.g., \"male\") is returned.  E_NONE is returned if gender does not match any recognized gender.  Any other error encountered (e.g., E_PERM, E_PROPNF) is likewise returned and the object's pronoun properties are left unaltered.";
3set_task_perms(caller_perms());
4{object, gender} = args;
5if (this == object)
6return E_DIV;
7elseif (gnum = $string_utils:find_prefix(gender, this.genders))
8gender = this.genders[gnum];
9else
10return E_NONE;
11endif
12save = {};
13prons = this.pronouns;
14for p in (prons)
15save = {@save, e = `object.(p) ! ANY'};
16if ((typeof(e) != STR) || (typeof(e = `object.(p) = this.(p)[gnum] ! ANY') == ERR))
17for i in [1..length(save) - 1]
18object.(prons[i]) = save[i];
19endfor
20return e;
21endif
22endfor
23return gender;

add

Spec this none thisFlags rxdOwner #2Definer #41

Referenced by

none

Source

1"$gender_utils:add(object[,perms[,owner]])";
2"--- adds pronoun properties to object if they're not already there.";
3"    perms default to \"rc\", owner defaults to the object owner.";
4set_task_perms(caller_perms());
5{object, ?perms = "rc", ?owner = object.owner} = args;
6prons = this.pronouns;
7e = 1;
8for p in (prons)
9if (!$object_utils:has_property(object, p))
10e = `add_property(object, p, "", {owner, perms}) ! ANY';
11if (typeof(e) == ERR)
12player:tell("Couldn't add ", object, ".", p, ":  ", e);
13return;
14endif
15elseif ((typeof(object.(p)) != STR) && (typeof(e = `object.(p) = "" ! ANY') == ERR))
16player:tell("Couldn't reset ", object, ".", p, ":  ", e);
17return;
18elseif (!object.(p))
19e = 0;
20endif
21endfor
22if ((!e) && (ERR == typeof(e = this:set(object, "neuter"))))
23player:tell("Couldn't initialize pronouns:  ", e);
24endif

get_pronoun

Spec this none thisFlags rxdOwner #36Definer #41

Referenced by

Source

1"get_pronoun(key,object) => pronoun corresponding to object.";
2"key can be one of s,o,p,q,r,S,O,P,Q,R to refer to the pronoun properties relatively directly or it can be something of the form \"he/she\" or \"He/She\".";
3"Next the object is checked for the desired pronoun property.  If that doesn't exist, we look at object.gender and infer the pronoun from the corresponding $gender_utils property.  If .gender doesn't exist or the object itself is invalid, we use the corresponding property on $player.";
4{key, ?object = player} = args;
5if (key[1] == ":")
6key = key[2..$];
7endif
8if ((length(key) == 1) && (i = index("sopqrSOPQR", key, 1)))
9prop = this.pronouns[i];
10else
11search = "$1:he$s:she$1:he/she$2:him$2:him/her$3:his/her$4:hers$4:his/hers$5:himself$5:herself$5:himself/herself";
12i = index(search, (":" + key) + "$");
13if (!i)
14return "";
15endif
16cap = strcmp("a", key) > 0;
17prop = this.pronouns[toint(search[i - 1]) + (5 * cap)];
18endif
19if (!valid(object))
20return $player.(prop);
21elseif (STR == typeof(p = `object.(prop) ! ANY'))
22return p;
23elseif ((STR == typeof(g = `object.gender ! ANY')) && (i = g in this.genders))
24return this.(prop)[i];
25else
26return $player.(prop);
27endif

get_conj*ugation

Spec this none thisFlags rxdOwner #36Definer #41

Referenced by

none

Source

1"get_conj(verbspec,object) => verb conjugated according to object.";
2"verbspec can be one of \"singular/plural\", \"singular\", \"singular/\", or \"/plural\", e.g., \"is/are\", \"is\", \"is/\", or \"/are\".";
3"The object is checked to see whether it is singular or plural.  This is inferred from its .gender property.  If .gender doesn't exist or the object itself is invalid, we assume singular.";
4{spec, ?object = player} = args;
5i = index(spec + "/", "/");
6sing = spec[1..i - 1];
7if (i < length(spec))
8plur = spec[i + 1..$];
9else
10plur = "";
11endif
12cap = strcmp("a", (i == 1) ? spec[2] | spec) > 0;
13if (((valid(object) && (STR == typeof(g = `object.gender ! ANY'))) && (i = g in this.genders)) && this.is_plural[i])
14vb = plur || this:_verb_plural(sing, i);
15else
16vb = sing || this:_verb_singular(plur, i);
17endif
18if (cap)
19return $string_utils:capitalize(vb);
20else
21return vb;
22endif

_verb_plural

Spec this none thisFlags rxdOwner #36Definer #41

Referenced by

Source

1{st, idx} = args;
2if (typeof(st) != STR)
3return E_INVARG;
4endif
5len = length(st);
6if ((len >= 3) && (rindex(st, "n't") == (len - 2)))
7return this:_verb_plural(st[1..len - 3], idx) + "n't";
8elseif (i = st in {"has", "is"})
9return this.({"have", "be"}[i])[idx];
10elseif (st == "was")
11return (idx > 6) ? "were" | st;
12elseif ((len <= 3) || (st[len] != "s"))
13return st;
14elseif (st[len - 1] != "e")
15return st[1..len - 1];
16"elseif ((r = (rindex(st, \"sses\") || rindex(st, \"zzes\"))) && (r == (len - 3)))";
17elseif ((r = rindex(st, "zzes")) && (r == (len - 3)))
18return st[1..len - 3];
19elseif ((((st[len - 2] == "h") && index("cs", st[len - 3])) || index("ox", st[len - 2])) || (st[len - 3..len - 2] == "ss"))
20return st[1..len - 2];
21"washes => wash, belches => belch, boxes => box";
22"used to have || ((st[len - 2] == \"s\") && (!index(\"aeiouy\", st[len - 3])))";
23"so that <consonant>ses => <consonant>s";
24"known examples: none";
25"counterexample: browses => browse";
26"update of sorts--put in code to handle passes => pass";
27elseif (st[len - 2] == "i")
28return st[1..len - 3] + "y";
29else
30return st[1..len - 1];
31endif

_verb_singular

Spec this none thisFlags rxdOwner #36Definer #41

Referenced by

Source

1{st, idx} = args;
2if (typeof(st) != STR)
3return E_INVARG;
4endif
5len = length(st);
6if ((len >= 3) && (rindex(st, "n't") == (len - 2)))
7return this:_verb_singular(st[1..len - 3], idx) + "n't";
8elseif (i = st in {"have", "are"})
9return this.({"have", "be"}[i])[idx];
10elseif ((st[len] == "y") && (!index("aeiou", st[len - 1])))
11return st[1..len - 1] + "ies";
12elseif (index("sz", st[len]) && index("aeiou", st[len - 1]))
13return (st + st[len]) + "es";
14elseif (index("osx", st[len]) || ((len > 1) && (index("chsh", st[len - 1..len]) % 2)))
15return st + "es";
16else
17return st + "s";
18endif

_do

Spec this none thisFlags rxdOwner #36Definer #41

Referenced by

Source

1"_do(cap,object,modifiers...)";
2{cap, object, modifiers} = args;
3if (!modifiers)
4if (typeof(object) != OBJ)
5return tostr(object);
6elseif (!valid(object))
7return (cap ? "N" | "n") + "othing";
8else
9return cap ? object:titlec() | object:title();
10endif
11elseif (modifiers[1] == ".")
12if (i = index(modifiers[2..$], "."))
13i = i + 1;
14elseif (!(i = (index(modifiers, ":") || index(modifiers, "#")) || index(modifiers, "!")))
15i = length(modifiers) + 1;
16endif
17if (typeof(o = `object.(modifiers[2..i - 1]) ! ANY') == ERR)
18return tostr("%(", o, ")");
19else
20return this:_do(cap || (strcmp("a", modifiers[2]) > 0), o, modifiers[i..$]);
21endif
22elseif (modifiers[1] == ":")
23if (typeof(object) != OBJ)
24return tostr("%(", E_TYPE, ")");
25elseif (p = this:get_pronoun(modifiers, object))
26return p;
27else
28return tostr("%(", modifiers, "??)");
29endif
30elseif (modifiers[1] == "#")
31return tostr(object);
32elseif (modifiers[1] == "!")
33return this:get_conj(modifiers[2..$], object);
34else
35i = (((index(modifiers, ".") || index(modifiers, ":")) || index(modifiers, "#")) || index(modifiers, "!")) || (length(modifiers) + 1);
36s = modifiers[1..i - 1];
37if (j = s in {"dobj", "iobj", "this"})
38return this:_do(cap, {dobj, iobj, callers()[2][1]}[j], modifiers[i..$]);
39else
40return tostr("%(", s, "??)");
41endif
42endif

pronoun_sub

Spec this none thisFlags rxdOwner #2Definer #41

Referenced by

Source

1"Experimental pronoun substitution. The official version is on $string_utils.";
2"syntax:  :pronoun_sub(text[,who])";
3"experimental version that accomodates Aladdin's style...";
4set_task_perms($no_one);
5{old, ?who = player} = args;
6if (typeof(old) == LIST)
7plines = {};
8for line in (old)
9plines = {@plines, this:pronoun_sub(line, who)};
10endfor
11return plines;
12endif
13new = "";
14here = valid(who) ? who.location | $nothing;
15objspec = "nditl";
16objects = {who, dobj, iobj, caller, here};
17prnspec = "sopqrSOPQR";
18prprops = {"ps", "po", "pp", "pq", "pr", "Ps", "Po", "Pp", "Pq", "Pr"};
19oldlen = length(old);
20while ((prcnt = index(old, "%")) && (prcnt < oldlen))
21cp_args = {};
22s = old[k = prcnt + 1];
23if (brace = index("([{", s))
24if (!(w = index(old[k + 1..oldlen], ")]}"[brace])))
25return new + old;
26elseif (brace == 3)
27s = this:_do(0, who, old[prcnt + 2..(k = k + w) - 1]);
28else
29p = old[prcnt + 2..(k = k + w) - 1];
30if (brace == 1)
31cp_args = {who, p};
32elseif (p[1] == "#")
33s = (o = index(objspec, p[2])) ? tostr(objects[o]) | (("[" + p) + "]");
34elseif (!(o = index(objspec, p[1])))
35s = ("[" + p) + "]";
36else
37cp_args = {objects[o], p[2..w - 1], strcmp(p[1], "a") < 0};
38endif
39endif
40elseif (o = index(objspec, s))
41cp_args = {objects[o], "", strcmp(s, "a") < 0};
42elseif (w = index(prnspec, s, 1))
43cp_args = {who, prprops[w]};
44elseif (s == "#")
45s = tostr(who);
46elseif (s != "%")
47s = "%" + s;
48endif
49new = (new + old[1..prcnt - 1]) + ((!cp_args) ? s | ((typeof(sub = $string_utils:_cap_property(@cp_args)) != ERR) ? sub | (("%(" + tostr(sub)) + ")")));
50old = old[k + 1..oldlen];
51oldlen = oldlen - k;
52endwhile
53return new + old;