| 1 |
#charset "us-ascii" |
| 2 |
|
| 3 |
/* |
| 4 |
* Copyright 2000, 2006 Michael J. Roberts. All Rights Reserved. |
| 5 |
*. Past-tense extensions written by Michel Nizette, and incorporated by |
| 6 |
* permission. |
| 7 |
* |
| 8 |
* TADS 3 Library - English (United States variant) implementation |
| 9 |
* |
| 10 |
* This defines the parts of the TADS 3 library that are specific to the |
| 11 |
* English language as spoken (and written) in the United States. |
| 12 |
* |
| 13 |
* We have attempted to isolate here the parts of the library that are |
| 14 |
* language-specific, so that translations to other languages or dialects |
| 15 |
* can be created by replacing this module, without changing the rest of |
| 16 |
* the library. |
| 17 |
* |
| 18 |
* In addition to this module, a separate set of US English messages are |
| 19 |
* defined in the various msg_xxx.t modules. Those modules define |
| 20 |
* messages in English for different stylistic variations. For a given |
| 21 |
* game, the author must select one of the message modules - but only |
| 22 |
* one, since they all define variations of the same messages. To |
| 23 |
* translate the library, a translator must create at least one module |
| 24 |
* defining those messages as well; only one message module is required |
| 25 |
* per language. |
| 26 |
* |
| 27 |
* The past-tense system was contributed by Michel Nizette. |
| 28 |
* |
| 29 |
*. ----- |
| 30 |
* |
| 31 |
* "Watch an immigrant struggling with a second language or a stroke |
| 32 |
* patient with a first one, or deconstruct a snatch of baby talk, or try |
| 33 |
* to program a computer to understand English, and ordinary speech |
| 34 |
* begins to look different." |
| 35 |
* |
| 36 |
*. Stephen Pinker, "The Language Instinct" |
| 37 |
*/ |
| 38 |
|
| 39 |
#include "tads.h" |
| 40 |
#include "tok.h" |
| 41 |
#include "adv3.h" |
| 42 |
#include "en_us.h" |
| 43 |
#include <vector.h> |
| 44 |
#include <dict.h> |
| 45 |
#include <gramprod.h> |
| 46 |
#include <strcomp.h> |
| 47 |
|
| 48 |
|
| 49 |
/* ------------------------------------------------------------------------ */ |
| 50 |
/* |
| 51 |
* Fill in the default language for the GameInfo metadata class. |
| 52 |
*/ |
| 53 |
modify GameInfoModuleID |
| 54 |
languageCode = 'en-US' |
| 55 |
; |
| 56 |
|
| 57 |
/* ------------------------------------------------------------------------ */ |
| 58 |
/* |
| 59 |
* Simple yes/no confirmation. The caller must display a prompt; we'll |
| 60 |
* read a command line response, then return true if it's an affirmative |
| 61 |
* response, nil if not. |
| 62 |
*/ |
| 63 |
yesOrNo() |
| 64 |
{ |
| 65 |
/* switch to no-command mode for the interactive input */ |
| 66 |
"<.commandnone>"; |
| 67 |
|
| 68 |
/* |
| 69 |
* Read a line of input. Do not allow real-time event processing; |
| 70 |
* this type of prompt is used in the middle of a command, so we |
| 71 |
* don't want any interruptions. Note that the caller must display |
| 72 |
* any desired prompt, and since we don't allow interruptions, we |
| 73 |
* won't need to redisplay the prompt, so we pass nil for the prompt |
| 74 |
* callback. |
| 75 |
*/ |
| 76 |
local str = inputManager.getInputLine(nil, nil); |
| 77 |
|
| 78 |
/* switch back to mid-command mode */ |
| 79 |
"<.commandmid>"; |
| 80 |
|
| 81 |
/* |
| 82 |
* If they answered with something starting with 'Y', it's |
| 83 |
* affirmative, otherwise it's negative. In reading the response, |
| 84 |
* ignore any leading whitespace. |
| 85 |
*/ |
| 86 |
return rexMatch('<space>*[yY]', str) != nil; |
| 87 |
} |
| 88 |
|
| 89 |
/* ------------------------------------------------------------------------ */ |
| 90 |
/* |
| 91 |
* During start-up, install a case-insensitive truncating comparator in |
| 92 |
* the main dictionary. |
| 93 |
*/ |
| 94 |
PreinitObject |
| 95 |
execute() |
| 96 |
{ |
| 97 |
/* set up the main dictionary's comparator */ |
| 98 |
languageGlobals.setStringComparator( |
| 99 |
new StringComparator(gameMain.parserTruncLength, nil, [])); |
| 100 |
} |
| 101 |
|
| 102 |
/* |
| 103 |
* Make sure we run BEFORE the main library preinitializer, so that |
| 104 |
* we install the comparator in the dictionary before we add the |
| 105 |
* vocabulary words to the dictionary. This doesn't make any |
| 106 |
* difference in terms of the correctness of the dictionary, since |
| 107 |
* the dictionary will automatically rebuild itself whenever we |
| 108 |
* install a new comparator, but it makes the preinitialization run |
| 109 |
* a tiny bit faster by avoiding that rebuild step. |
| 110 |
*/ |
| 111 |
execAfterMe = [adv3LibPreinit] |
| 112 |
; |
| 113 |
|
| 114 |
/* ------------------------------------------------------------------------ */ |
| 115 |
/* |
| 116 |
* Language-specific globals |
| 117 |
*/ |
| 118 |
languageGlobals: object |
| 119 |
/* |
| 120 |
* Set the StringComparator object for the parser. This sets the |
| 121 |
* comparator that's used in the main command parser dictionary. |
| 122 |
*/ |
| 123 |
setStringComparator(sc) |
| 124 |
{ |
| 125 |
/* remember it globally, and set it in the main dictionary */ |
| 126 |
dictComparator = sc; |
| 127 |
cmdDict.setComparator(sc); |
| 128 |
} |
| 129 |
|
| 130 |
/* |
| 131 |
* The character to use to separate groups of digits in large |
| 132 |
* numbers. US English uses commas; most Europeans use periods. |
| 133 |
* |
| 134 |
* Note that this setting does not affect system-level BigNumber |
| 135 |
* formatting, but this information can be passed when calling |
| 136 |
* BigNumber formatting routines. |
| 137 |
*/ |
| 138 |
digitGroupSeparator = ',' |
| 139 |
|
| 140 |
/* |
| 141 |
* The decimal point to display in floating-point numbers. US |
| 142 |
* English uses a period; most Europeans use a comma. |
| 143 |
* |
| 144 |
* Note that this setting doesn't affect system-level BigNumber |
| 145 |
* formatting, but this information can be passed when calling |
| 146 |
* BigNumber formatting routines. |
| 147 |
*/ |
| 148 |
decimalPointCharacter = '.' |
| 149 |
|
| 150 |
/* the main dictionary's string comparator */ |
| 151 |
dictComparator = nil |
| 152 |
; |
| 153 |
|
| 154 |
|
| 155 |
/* ------------------------------------------------------------------------ */ |
| 156 |
/* |
| 157 |
* Language-specific extension of the default gameMain object |
| 158 |
* implementation. |
| 159 |
*/ |
| 160 |
modify GameMainDef |
| 161 |
/* |
| 162 |
* Option setting: the parser's truncation length for player input. |
| 163 |
* As a convenience to the player, we can allow the player to |
| 164 |
* truncate long words, entering only the first, say, 6 characters. |
| 165 |
* For example, rather than typing "x flashlight", we could allow the |
| 166 |
* player to simply type "x flashl" - truncating "flashlight" to six |
| 167 |
* letters. |
| 168 |
* |
| 169 |
* We use a default truncation length of 6, but games can change this |
| 170 |
* by overriding this property in gameMain. We use a default of 6 |
| 171 |
* mostly because that's what the old Infocom games did - many |
| 172 |
* long-time IF players are accustomed to six-letter truncation from |
| 173 |
* those games. Shorter lengths are superficially more convenient |
| 174 |
* for the player, obviously, but there's a trade-off, which is that |
| 175 |
* shorter truncation lengths create more potential for ambiguity. |
| 176 |
* For some games, a longer length might actually be better for the |
| 177 |
* player, because it would reduce spurious ambiguity due to the |
| 178 |
* parser matching short input against long vocabulary words. |
| 179 |
* |
| 180 |
* If you don't want to allow the player to truncate long words at |
| 181 |
* all, set this to nil. This will require the player to type every |
| 182 |
* word in its entirety. |
| 183 |
* |
| 184 |
* Note that changing this property dynamicaly will have no effect. |
| 185 |
* The library only looks at it once, during library initialization |
| 186 |
* at the very start of the game. If you want to change the |
| 187 |
* truncation length dynamically, you must instead create a new |
| 188 |
* StringComparator object with the new truncation setting, and call |
| 189 |
* languageGlobals.setStringComparator() to select the new object. |
| 190 |
*/ |
| 191 |
parserTruncLength = 6 |
| 192 |
|
| 193 |
/* |
| 194 |
* Option: are we currently using a past tense narrative? By |
| 195 |
* default, we aren't. |
| 196 |
* |
| 197 |
* This property can be reset at any time during the game in order to |
| 198 |
* switch between the past and present tenses. The macro |
| 199 |
* setPastTense can be used for this purpose: it just provides a |
| 200 |
* shorthand for setting gameMain.usePastTense directly. |
| 201 |
* |
| 202 |
* Authors who want their game to start in the past tense can achieve |
| 203 |
* this by overriding this property on their gameMain object and |
| 204 |
* giving it a value of true. |
| 205 |
*/ |
| 206 |
usePastTense = nil |
| 207 |
; |
| 208 |
|
| 209 |
|
| 210 |
/* ------------------------------------------------------------------------ */ |
| 211 |
/* |
| 212 |
* Language-specific modifications for ThingState. |
| 213 |
*/ |
| 214 |
modify ThingState |
| 215 |
/* |
| 216 |
* Our state-specific tokens. This is a list of vocabulary words |
| 217 |
* that are state-specific: that is, if a word is in this list, the |
| 218 |
* word can ONLY refer to this object if the object is in a state |
| 219 |
* with that word in its list. |
| 220 |
* |
| 221 |
* The idea is that you set up the object's "static" vocabulary with |
| 222 |
* the *complete* list of words for all of its possible states. For |
| 223 |
* example: |
| 224 |
* |
| 225 |
*. + Matchstick 'lit unlit match'; |
| 226 |
* |
| 227 |
* Then, you define the states: in the "lit" state, the word 'lit' is |
| 228 |
* in the stateTokens list; in the "unlit" state, the word 'unlit' is |
| 229 |
* in the list. By putting the words in the state lists, you |
| 230 |
* "reserve" the words to their respective states. When the player |
| 231 |
* enters a command, the parser will limit object matches so that the |
| 232 |
* reserved state-specific words can only refer to objects in the |
| 233 |
* corresponding states. Hence, if the player refers to a "lit |
| 234 |
* match", the word 'lit' will only match an object in the "lit" |
| 235 |
* state, because 'lit' is a reserved state-specific word associated |
| 236 |
* with the "lit" state. |
| 237 |
* |
| 238 |
* You can re-use a word in multiple states. For example, you could |
| 239 |
* have a "red painted" state and a "blue painted" state, along with |
| 240 |
* an "unpainted" state. |
| 241 |
*/ |
| 242 |
stateTokens = [] |
| 243 |
|
| 244 |
/* |
| 245 |
* Match the name of an object in this state. We'll check the token |
| 246 |
* list for any words that apply only to *other* states the object |
| 247 |
* can assume; if we find any, we'll reject the match, since the |
| 248 |
* phrase must be referring to an object in a different state. |
| 249 |
*/ |
| 250 |
matchName(obj, origTokens, adjustedTokens, states) |
| 251 |
{ |
| 252 |
/* scan each word in our adjusted token list */ |
| 253 |
for (local i = 1, local len = adjustedTokens.length() ; |
| 254 |
i <= len ; i += 2) |
| 255 |
{ |
| 256 |
/* get the current token */ |
| 257 |
local cur = adjustedTokens[i]; |
| 258 |
|
| 259 |
/* |
| 260 |
* If this token is in our own state-specific token list, |
| 261 |
* it's acceptable as a match to this object. (It doesn't |
| 262 |
* matter whether or not it's in any other state's token list |
| 263 |
* if it's in our own, because its presence in our own makes |
| 264 |
* it an acceptable matching word when we're in this state.) |
| 265 |
*/ |
| 266 |
if (stateTokens.indexWhich({t: t == cur}) != nil) |
| 267 |
continue; |
| 268 |
|
| 269 |
/* |
| 270 |
* It's not in our own state-specific token list. Check to |
| 271 |
* see if the word appears in ANOTHER state's token list: if |
| 272 |
* it does, then this word CAN'T match an object in this |
| 273 |
* state, because the token is special to that other state |
| 274 |
* and thus can't refer to an object in a state without the |
| 275 |
* token. |
| 276 |
*/ |
| 277 |
if (states.indexWhich( |
| 278 |
{s: s.stateTokens.indexOf(cur) != nil}) != nil) |
| 279 |
return nil; |
| 280 |
} |
| 281 |
|
| 282 |
/* we didn't find any objection, so we can match this phrase */ |
| 283 |
return obj; |
| 284 |
} |
| 285 |
|
| 286 |
/* |
| 287 |
* Check a token list for any tokens matching any of our |
| 288 |
* state-specific words. Returns true if we find any such words, |
| 289 |
* nil if not. |
| 290 |
* |
| 291 |
* 'toks' is the *adjusted* token list used in matchName(). |
| 292 |
*/ |
| 293 |
findStateToken(toks) |
| 294 |
{ |
| 295 |
/* |
| 296 |
* Scan the token list for a match to any of our state-specific |
| 297 |
* words. Since we're using the adjusted token list, every |
| 298 |
* other entry is a part of speech, so work through the list in |
| 299 |
* pairs. |
| 300 |
*/ |
| 301 |
for (local i = 1, local len = toks.length() ; i <= len ; i += 2) |
| 302 |
{ |
| 303 |
/* |
| 304 |
* if this token matches any of our state tokens, indicate |
| 305 |
* that we found a match |
| 306 |
*/ |
| 307 |
if (stateTokens.indexWhich({x: x == toks[i]}) != nil) |
| 308 |
return true; |
| 309 |
} |
| 310 |
|
| 311 |
/* we didn't find a match */ |
| 312 |
return nil; |
| 313 |
} |
| 314 |
|
| 315 |
/* get our name */ |
| 316 |
listName(lst) { return listName_; } |
| 317 |
|
| 318 |
/* |
| 319 |
* our list name setting - we define this so that we can be easily |
| 320 |
* initialized with a template (we can't initialize listName() |
| 321 |
* directly in this manner because it's a method, but we define the |
| 322 |
* listName() method to simply return this property value, which we |
| 323 |
* can initialize with a template) |
| 324 |
*/ |
| 325 |
listName_ = nil |
| 326 |
; |
| 327 |
|
| 328 |
/* ------------------------------------------------------------------------ */ |
| 329 |
/* |
| 330 |
* Language-specific modifications for VocabObject. |
| 331 |
*/ |
| 332 |
modify VocabObject |
| 333 |
/* |
| 334 |
* The vocabulary initializer string for the object - this string |
| 335 |
* can be initialized (most conveniently via a template) to a string |
| 336 |
* of this format: |
| 337 |
* |
| 338 |
* 'adj adj adj noun/noun/noun*plural plural plural' |
| 339 |
* |
| 340 |
* The noun part of the string can be a hyphen, '-', in which case |
| 341 |
* it means that the string doesn't specify a noun or plural at all. |
| 342 |
* This can be useful when nouns and plurals are all inherited from |
| 343 |
* base classes, and only adjectives are to be specified. (In fact, |
| 344 |
* any word that consists of a single hyphen will be ignored, but |
| 345 |
* this is generally only useful for the adjective-only case.) |
| 346 |
* |
| 347 |
* During preinitialization, we'll parse this string and generate |
| 348 |
* dictionary entries and individual vocabulary properties for the |
| 349 |
* parts of speech we find. |
| 350 |
* |
| 351 |
* Note that the format described above is specific to the English |
| 352 |
* version of the library. Non-English versions will probably want |
| 353 |
* to use different formats to conveniently encode appropriate |
| 354 |
* language-specific information in the initializer string. See the |
| 355 |
* comments for initializeVocabWith() for more details. |
| 356 |
* |
| 357 |
* You can use the special wildcard # to match any numeric |
| 358 |
* adjective. This only works as a wildcard when it stands alone, |
| 359 |
* so a string like "7#" is matched as that literal string, not as a |
| 360 |
* wildcard. If you want to use a pound sign as a literal |
| 361 |
* adjective, just put it in double quotes. |
| 362 |
* |
| 363 |
* You can use the special wildcard "\u0001" (include the double |
| 364 |
* quotes within the string) to match any literal adjective. This |
| 365 |
* is the literal adjective equivalent of the pound sign. We use |
| 366 |
* this funny character value because it is unlikely ever to be |
| 367 |
* interesting in user input. |
| 368 |
* |
| 369 |
* If you want to match any string for a noun and/or adjective, you |
| 370 |
* can't do it with this property. Instead, just add the property |
| 371 |
* value noun='*' to the object. |
| 372 |
*/ |
| 373 |
vocabWords = '' |
| 374 |
|
| 375 |
/* |
| 376 |
* On dynamic construction, initialize our vocabulary words and add |
| 377 |
* them to the dictionary. |
| 378 |
*/ |
| 379 |
construct() |
| 380 |
{ |
| 381 |
/* initialize our vocabulary words from vocabWords */ |
| 382 |
initializeVocab(); |
| 383 |
|
| 384 |
/* add our vocabulary words to the dictionary */ |
| 385 |
addToDictionary(&noun); |
| 386 |
addToDictionary(&adjective); |
| 387 |
addToDictionary(&plural); |
| 388 |
addToDictionary(&adjApostS); |
| 389 |
addToDictionary(&literalAdjective); |
| 390 |
} |
| 391 |
|
| 392 |
/* add the words from a dictionary property to the global dictionary */ |
| 393 |
addToDictionary(prop) |
| 394 |
{ |
| 395 |
/* if we have any words defined, add them to the dictionary */ |
| 396 |
if (self.(prop) != nil) |
| 397 |
cmdDict.addWord(self, self.(prop), prop); |
| 398 |
} |
| 399 |
|
| 400 |
/* initialize the vocabulary from vocabWords */ |
| 401 |
initializeVocab() |
| 402 |
{ |
| 403 |
/* inherit vocabulary from this class and its superclasses */ |
| 404 |
inheritVocab(self, new Vector(10)); |
| 405 |
} |
| 406 |
|
| 407 |
/* |
| 408 |
* Inherit vocabulary from this class and its superclasses, adding |
| 409 |
* the words to the given target object. 'target' is the object to |
| 410 |
* which we add our vocabulary words, and 'done' is a vector of |
| 411 |
* classes that have been visited so far. |
| 412 |
* |
| 413 |
* Since a class can be inherited more than once in an inheritance |
| 414 |
* tree (for example, a class can have multiple superclasses, each |
| 415 |
* of which have a common base class), we keep a vector of all of |
| 416 |
* the classes we've visited. If we're already in the vector, we'll |
| 417 |
* skip adding vocabulary for this class or its superclasses, since |
| 418 |
* we must have already traversed this branch of the tree from |
| 419 |
* another subclass. |
| 420 |
*/ |
| 421 |
inheritVocab(target, done) |
| 422 |
{ |
| 423 |
/* |
| 424 |
* if we're in the list of classes handled already, don't bother |
| 425 |
* visiting me again |
| 426 |
*/ |
| 427 |
if (done.indexOf(self) != nil) |
| 428 |
return; |
| 429 |
|
| 430 |
/* add myself to the list of classes handled already */ |
| 431 |
done.append(self); |
| 432 |
|
| 433 |
/* |
| 434 |
* add words from our own vocabWords to the target object (but |
| 435 |
* only if it's our own - not if it's only inherited, as we'll |
| 436 |
* pick up the inherited ones explicitly in a bit) |
| 437 |
*/ |
| 438 |
if (propDefined(&vocabWords, PropDefDirectly)) |
| 439 |
target.initializeVocabWith(vocabWords); |
| 440 |
|
| 441 |
/* add vocabulary from each of our superclasses */ |
| 442 |
foreach (local sc in getSuperclassList()) |
| 443 |
sc.inheritVocab(target, done); |
| 444 |
} |
| 445 |
|
| 446 |
/* |
| 447 |
* Initialize our vocabulary from the given string. This parses the |
| 448 |
* given vocabulary initializer string and adds the words defined in |
| 449 |
* the string to the dictionary. |
| 450 |
* |
| 451 |
* Note that this parsing is intentionally located in the |
| 452 |
* English-specific part of the library, because it is expected that |
| 453 |
* other languages will want to define their own vocabulary |
| 454 |
* initialization string formats. For example, a language with |
| 455 |
* gendered nouns might want to use gendered articles in the |
| 456 |
* initializer string as an author-friendly way of defining noun |
| 457 |
* gender; languages with inflected (declined) nouns and/or |
| 458 |
* adjectives might want to encode inflected forms in the |
| 459 |
* initializer. Non-English language implementations are free to |
| 460 |
* completely redefine the format - there's no need to follow the |
| 461 |
* conventions of the English format in other languages where |
| 462 |
* different formats would be more convenient. |
| 463 |
*/ |
| 464 |
initializeVocabWith(str) |
| 465 |
{ |
| 466 |
local sectPart; |
| 467 |
local modList = []; |
| 468 |
|
| 469 |
/* start off in the adjective section */ |
| 470 |
sectPart = &adjective; |
| 471 |
|
| 472 |
/* scan the string until we run out of text */ |
| 473 |
while (str != '') |
| 474 |
{ |
| 475 |
local len; |
| 476 |
local cur; |
| 477 |
|
| 478 |
/* |
| 479 |
* if it starts with a quote, find the close quote; |
| 480 |
* otherwise, find the end of the current token by seeking |
| 481 |
* the next delimiter |
| 482 |
*/ |
| 483 |
if (str.startsWith('"')) |
| 484 |
{ |
| 485 |
/* find the close quote */ |
| 486 |
len = str.find('"', 2); |
| 487 |
} |
| 488 |
else |
| 489 |
{ |
| 490 |
/* no quotes - find the next delimiter */ |
| 491 |
len = rexMatch('<^space|star|/>*', str); |
| 492 |
} |
| 493 |
|
| 494 |
/* if there's no match, use the whole rest of the string */ |
| 495 |
if (len == nil) |
| 496 |
len = str.length(); |
| 497 |
|
| 498 |
/* if there's anything before the delimiter, extract it */ |
| 499 |
if (len != 0) |
| 500 |
{ |
| 501 |
/* extract the part up to but not including the delimiter */ |
| 502 |
cur = str.substr(1, len); |
| 503 |
|
| 504 |
/* |
| 505 |
* if we're in the adjectives, and either this is the |
| 506 |
* last token or the next delimiter is not a space, this |
| 507 |
* is implicitly a noun |
| 508 |
*/ |
| 509 |
if (sectPart == &adjective |
| 510 |
&& (len == str.length() |
| 511 |
|| str.substr(len + 1, 1) != ' ')) |
| 512 |
{ |
| 513 |
/* move to the noun section */ |
| 514 |
sectPart = &noun; |
| 515 |
} |
| 516 |
|
| 517 |
/* |
| 518 |
* if the word isn't a single hyphen (in which case it's |
| 519 |
* a null word placeholder, not an actual vocabulary |
| 520 |
* word), add it to our own appropriate part-of-speech |
| 521 |
* property and to the dictionary |
| 522 |
*/ |
| 523 |
if (cur != '-') |
| 524 |
{ |
| 525 |
/* |
| 526 |
* by default, use the part of speech of the current |
| 527 |
* string section as the part of speech for this |
| 528 |
* word |
| 529 |
*/ |
| 530 |
local wordPart = sectPart; |
| 531 |
|
| 532 |
/* |
| 533 |
* Check for parentheses, which indicate that the |
| 534 |
* token is "weak." This doesn't affect anything |
| 535 |
* about the token or its part of speech except that |
| 536 |
* we must include the token in our list of weak |
| 537 |
* tokens. |
| 538 |
*/ |
| 539 |
if (cur.startsWith('(') && cur.endsWith(')')) |
| 540 |
{ |
| 541 |
/* it's a weak token - remove the parens */ |
| 542 |
cur = cur.substr(2, cur.length() - 2); |
| 543 |
|
| 544 |
/* |
| 545 |
* if we don't have a weak token list yet, |
| 546 |
* create the list |
| 547 |
*/ |
| 548 |
if (weakTokens == nil) |
| 549 |
weakTokens = []; |
| 550 |
|
| 551 |
/* add the token to the weak list */ |
| 552 |
weakTokens += cur; |
| 553 |
} |
| 554 |
|
| 555 |
/* |
| 556 |
* Check for special formats: quoted strings, |
| 557 |
* apostrophe-S words. These formats are mutually |
| 558 |
* exclusive. |
| 559 |
*/ |
| 560 |
if (cur.startsWith('"')) |
| 561 |
{ |
| 562 |
/* |
| 563 |
* It's a quoted string, so it's a literal |
| 564 |
* adjective. |
| 565 |
*/ |
| 566 |
|
| 567 |
/* remove the quote(s) */ |
| 568 |
if (cur.endsWith('"')) |
| 569 |
cur = cur.substr(2, cur.length() - 2); |
| 570 |
else |
| 571 |
cur = cur.substr(2); |
| 572 |
|
| 573 |
/* change the part of speech to 'literal adjective' */ |
| 574 |
wordPart = &literalAdjective; |
| 575 |
} |
| 576 |
else if (cur.endsWith('\'s')) |
| 577 |
{ |
| 578 |
/* |
| 579 |
* It's an apostrophe-s word. Remove the "'s" |
| 580 |
* suffix and add the root word using adjApostS |
| 581 |
* as the part of speech. The grammar rules are |
| 582 |
* defined to allow this part of speech to be |
| 583 |
* used exclusively with "'s" suffixes in input. |
| 584 |
* Since the tokenizer always pulls the "'s" |
| 585 |
* suffix off of a word in the input, we have to |
| 586 |
* store any vocabulary words with "'s" suffixes |
| 587 |
* the same way, with the "'s" suffixes removed. |
| 588 |
*/ |
| 589 |
|
| 590 |
/* change the part of speech to adjApostS */ |
| 591 |
wordPart = &adjApostS; |
| 592 |
|
| 593 |
/* remove the "'s" suffix from the string */ |
| 594 |
cur = cur.substr(1, cur.length() - 2); |
| 595 |
} |
| 596 |
|
| 597 |
/* add the word to our own list for this part of speech */ |
| 598 |
if (self.(wordPart) == nil) |
| 599 |
self.(wordPart) = [cur]; |
| 600 |
else |
| 601 |
self.(wordPart) += cur; |
| 602 |
|
| 603 |
/* add it to the dictionary */ |
| 604 |
cmdDict.addWord(self, cur, wordPart); |
| 605 |
|
| 606 |
if (cur.endsWith('.')) |
| 607 |
{ |
| 608 |
local abbr; |
| 609 |
|
| 610 |
/* |
| 611 |
* It ends with a period, so this is an |
| 612 |
* abbreviated word. Enter the abbreviation |
| 613 |
* both with and without the period. The normal |
| 614 |
* handling will enter it with the period, so we |
| 615 |
* only need to enter it specifically without. |
| 616 |
*/ |
| 617 |
abbr = cur.substr(1, cur.length() - 1); |
| 618 |
self.(wordPart) += abbr; |
| 619 |
cmdDict.addWord(self, abbr, wordPart); |
| 620 |
} |
| 621 |
|
| 622 |
/* note that we added to this list */ |
| 623 |
if (modList.indexOf(wordPart) == nil) |
| 624 |
modList += wordPart; |
| 625 |
} |
| 626 |
} |
| 627 |
|
| 628 |
/* if we have a delimiter, see what we have */ |
| 629 |
if (len + 1 < str.length()) |
| 630 |
{ |
| 631 |
/* check the delimiter */ |
| 632 |
switch(str.substr(len + 1, 1)) |
| 633 |
{ |
| 634 |
case ' ': |
| 635 |
/* stick with the current part */ |
| 636 |
break; |
| 637 |
|
| 638 |
case '*': |
| 639 |
/* start plurals */ |
| 640 |
sectPart = &plural; |
| 641 |
break; |
| 642 |
|
| 643 |
case '/': |
| 644 |
/* start alternative nouns */ |
| 645 |
sectPart = &noun; |
| 646 |
break; |
| 647 |
} |
| 648 |
|
| 649 |
/* remove the part up to and including the delimiter */ |
| 650 |
str = str.substr(len + 2); |
| 651 |
|
| 652 |
/* skip any additional spaces following the delimiter */ |
| 653 |
if ((len = rexMatch('<space>+', str)) != nil) |
| 654 |
str = str.substr(len + 1); |
| 655 |
} |
| 656 |
else |
| 657 |
{ |
| 658 |
/* we've exhausted the string - we're done */ |
| 659 |
break; |
| 660 |
} |
| 661 |
} |
| 662 |
|
| 663 |
/* uniquify each word list we updated */ |
| 664 |
foreach (local p in modList) |
| 665 |
self.(p) = self.(p).getUnique(); |
| 666 |
} |
| 667 |
; |
| 668 |
|
| 669 |
/* ------------------------------------------------------------------------ */ |
| 670 |
/* |
| 671 |
* Language-specific modifications for Thing. This class contains the |
| 672 |
* methods and properties of Thing that need to be replaced when the |
| 673 |
* library is translated to another language. |
| 674 |
* |
| 675 |
* The properties and methods defined here should generally never be used |
| 676 |
* by language-independent library code, because everything defined here |
| 677 |
* is specific to English. Translators are thus free to change the |
| 678 |
* entire scheme defined here. For example, the notions of number and |
| 679 |
* gender are confined to the English part of the library; other language |
| 680 |
* implementations can completely replace these attributes, so they're |
| 681 |
* not constrained to emulate their own number and gender systems with |
| 682 |
* the English system. |
| 683 |
*/ |
| 684 |
modify Thing |
| 685 |
/* |
| 686 |
* Flag that this object's name is rendered as a plural (this |
| 687 |
* applies to both a singular noun with plural usage, such as |
| 688 |
* "pants" or "scissors," and an object used in the world model to |
| 689 |
* represent a collection of real-world objects, such as "shrubs"). |
| 690 |
*/ |
| 691 |
isPlural = nil |
| 692 |
|
| 693 |
/* |
| 694 |
* Flag that this is object's name is a "mass noun" - that is, a |
| 695 |
* noun denoting a continuous (effectively infinitely divisible) |
| 696 |
* substance or material, such as water, wood, or popcorn; and |
| 697 |
* certain abstract concepts, such as knowledge or beauty. Mass |
| 698 |
* nouns are never rendered in the plural, and use different |
| 699 |
* determiners than ordinary ("count") nouns: "some popcorn" vs "a |
| 700 |
* kernel", for example. |
| 701 |
*/ |
| 702 |
isMassNoun = nil |
| 703 |
|
| 704 |
/* |
| 705 |
* Flags indicating that the object should be referred to with |
| 706 |
* gendered pronouns (such as 'he' or 'she' rather than 'it'). |
| 707 |
* |
| 708 |
* Note that these flags aren't mutually exclusive, so it's legal |
| 709 |
* for the object to have both masculine and feminine usage. This |
| 710 |
* can be useful when creating collective objects that represent |
| 711 |
* more than one individual, for example. |
| 712 |
*/ |
| 713 |
isHim = nil |
| 714 |
isHer = nil |
| 715 |
|
| 716 |
/* |
| 717 |
* Flag indicating that the object can be referred to with a neuter |
| 718 |
* pronoun ('it'). By default, this is true if the object has |
| 719 |
* neither masculine nor feminine gender, but it can be overridden |
| 720 |
* so that an object has both gendered and ungendered usage. This |
| 721 |
* can be useful for collective objects, as well as for cases where |
| 722 |
* gendered usage varies by speaker or situation, such as animals. |
| 723 |
*/ |
| 724 |
isIt |
| 725 |
{ |
| 726 |
/* by default, we're an 'it' if we're not a 'him' or a 'her' */ |
| 727 |
return !(isHim || isHer); |
| 728 |
} |
| 729 |
|
| 730 |
/* |
| 731 |
* Test to see if we can match the pronouns 'him', 'her', 'it', and |
| 732 |
* 'them'. By default, these simply test the corresponding isXxx |
| 733 |
* flags (except 'canMatchThem', which tests 'isPlural' to see if the |
| 734 |
* name has plural usage). |
| 735 |
*/ |
| 736 |
canMatchHim = (isHim) |
| 737 |
canMatchHer = (isHer) |
| 738 |
canMatchIt = (isIt) |
| 739 |
canMatchThem = (isPlural) |
| 740 |
|
| 741 |
/* can we match the given PronounXxx pronoun type specifier? */ |
| 742 |
canMatchPronounType(typ) |
| 743 |
{ |
| 744 |
/* check the type, and return the appropriate indicator property */ |
| 745 |
switch (typ) |
| 746 |
{ |
| 747 |
case PronounHim: |
| 748 |
return canMatchHim; |
| 749 |
|
| 750 |
case PronounHer: |
| 751 |
return canMatchHer; |
| 752 |
|
| 753 |
case PronounIt: |
| 754 |
return canMatchIt; |
| 755 |
|
| 756 |
case PronounThem: |
| 757 |
return canMatchThem; |
| 758 |
|
| 759 |
default: |
| 760 |
return nil; |
| 761 |
} |
| 762 |
} |
| 763 |
|
| 764 |
/* |
| 765 |
* The grammatical cardinality of this item when it appears in a |
| 766 |
* list. This is used to ensure verb agreement when mentioning the |
| 767 |
* item in a list of items. ("Cardinality" is a fancy word for "how |
| 768 |
* many items does this look like"). |
| 769 |
* |
| 770 |
* English only distinguishes two degrees of cardinality in its |
| 771 |
* grammar: one, or many. That is, when constructing a sentence, the |
| 772 |
* only thing the grammar cares about is whether an object is |
| 773 |
* singular or plural: IT IS on the table, THEY ARE on the table. |
| 774 |
* Since English only distinguishes these two degrees, two is the |
| 775 |
* same as a hundred is the same as a million for grammatical |
| 776 |
* purposes, so we'll consider our cardinality to be 2 if we're |
| 777 |
* plural, 1 otherwise. |
| 778 |
* |
| 779 |
* Some languages don't express cardinality at all in their grammar, |
| 780 |
* and others distinguish cardinality in greater detail than just |
| 781 |
* singular-vs-plural, which is why this method has to be in the |
| 782 |
* language-specific part of the library. |
| 783 |
*/ |
| 784 |
listCardinality(lister) { return isPlural ? 2 : 1; } |
| 785 |
|
| 786 |
/* |
| 787 |
* Proper name flag. This indicates that the 'name' property is the |
| 788 |
* name of a person or place. We consider proper names to be fully |
| 789 |
* qualified, so we don't add articles for variations on the name |
| 790 |
* such as 'theName'. |
| 791 |
*/ |
| 792 |
isProperName = nil |
| 793 |
|
| 794 |
/* |
| 795 |
* Qualified name flag. This indicates that the object name, as |
| 796 |
* given by the 'name' property, is already fully qualified, so |
| 797 |
* doesn't need qualification by an article like "the" or "a" when |
| 798 |
* it appears in a sentence. By default, a name is considered |
| 799 |
* qualified if it's a proper name, but this can be overridden to |
| 800 |
* mark a non-proper name as qualified when needed. |
| 801 |
*/ |
| 802 |
isQualifiedName = (isProperName) |
| 803 |
|
| 804 |
/* |
| 805 |
* The name of the object - this is a string giving the object's |
| 806 |
* short description, for constructing sentences that refer to the |
| 807 |
* object by name. Each instance should override this to define the |
| 808 |
* name of the object. This string should not contain any articles; |
| 809 |
* we use this string as the root to generate various forms of the |
| 810 |
* object's name for use in different places in sentences. |
| 811 |
*/ |
| 812 |
name = '' |
| 813 |
|
| 814 |
/* |
| 815 |
* The name of the object, for the purposes of disambiguation |
| 816 |
* prompts. This should almost always be the object's ordinary |
| 817 |
* name, so we return self.name by default. |
| 818 |
* |
| 819 |
* In rare cases, it might be desirable to override this. In |
| 820 |
* particular, if a game has two objects that are NOT defined as |
| 821 |
* basic equivalents of one another (which means that the parser |
| 822 |
* will always ask for disambiguation when the two are ambiguous |
| 823 |
* with one another), but the two nonetheless have identical 'name' |
| 824 |
* properties, this property should be overridden for one or both |
| 825 |
* objects to give them different names. This will ensure that we |
| 826 |
* avoid asking questions of the form "which do you mean, the coin, |
| 827 |
* or the coin?". In most cases, non-equivalent objects will have |
| 828 |
* distinct 'name' properties to begin with, so this is not usually |
| 829 |
* an issue. |
| 830 |
* |
| 831 |
* When overriding this method, take care to override |
| 832 |
* theDisambigName, aDisambigName, countDisambigName, and/or |
| 833 |
* pluralDisambigName as needed. Those routines must be overridden |
| 834 |
* only when the default algorithms for determining articles and |
| 835 |
* plurals fail to work properly for the disambigName (for example, |
| 836 |
* the indefinite article algorithm fails with silent-h words like |
| 837 |
* "hour", so if disambigName is "hour", aDisambigName must be |
| 838 |
* overridden). In most cases, the automatic algorithms will |
| 839 |
* produce acceptable results, so the default implementations of |
| 840 |
* these other routines can be used without customization. |
| 841 |
*/ |
| 842 |
disambigName = (name) |
| 843 |
|
| 844 |
/* |
| 845 |
* The "equivalence key" is the value we use to group equivalent |
| 846 |
* objects. Note that we can only treat objects as equivalent when |
| 847 |
* they're explicitly marked with isEquivalent=true, so the |
| 848 |
* equivalence key is irrelevant for objects not so marked. |
| 849 |
* |
| 850 |
* Since the main point of equivalence is to allow creation of groups |
| 851 |
* of like-named objects that are interchangeable in listings and in |
| 852 |
* command input, we use the basic disambiguation name as the |
| 853 |
* equivalence key. |
| 854 |
*/ |
| 855 |
equivalenceKey = (disambigName) |
| 856 |
|
| 857 |
/* |
| 858 |
* The definite-article name for disambiguation prompts. |
| 859 |
* |
| 860 |
* By default, if the disambiguation name is identical to the |
| 861 |
* regular name (i.e, the string returned by self.disambigName is |
| 862 |
* the same as the string returned by self.name), then we simply |
| 863 |
* return self.theName. Since the base name is the same in either |
| 864 |
* case, presumably the definite article names should be the same as |
| 865 |
* well. This way, if the object overrides theName to do something |
| 866 |
* special, then we'll use the same definite-article name for |
| 867 |
* disambiguation prompts. |
| 868 |
* |
| 869 |
* If the disambigName isn't the same as the regular name, then |
| 870 |
* we'll apply the same algorithm to the base disambigName that we |
| 871 |
* normally do to the regular name to produce the theName. This |
| 872 |
* way, if the disambigName is overridden, we'll use the overridden |
| 873 |
* disambigName to produce the definite-article version, using the |
| 874 |
* standard definite-article algorithm. |
| 875 |
* |
| 876 |
* Note that there's an aspect of this conditional approach that |
| 877 |
* might not be obvious. It might look as though the test is |
| 878 |
* redundant: if name == disambigName, after all, and the default |
| 879 |
* theName returns theNameFrom(name), then this ought to be |
| 880 |
* identical to returning theNameFrom(disambigName). The subtlety |
| 881 |
* is that theName could be overridden to produce a custom result, |
| 882 |
* in which case returning theNameFrom(disambigName) would return |
| 883 |
* something different, which probably wouldn't be correct: the |
| 884 |
* whole reason theName would be overridden is that the algorithmic |
| 885 |
* determination (theNameFrom) gets it wrong. So, by calling |
| 886 |
* theName directly when disambigName is the same as name, we are |
| 887 |
* assured that we pick up any override in theName. |
| 888 |
* |
| 889 |
* Note that in rare cases, neither of these default approaches will |
| 890 |
* produce the right result; this will happen if the object uses a |
| 891 |
* custom disambigName, but that name doesn't fit the normal |
| 892 |
* algorithmic pattern for applying a definite article. In these |
| 893 |
* cases, the object should simply override this method to specify |
| 894 |
* the custom name. |
| 895 |
*/ |
| 896 |
theDisambigName = (name == disambigName |
| 897 |
? theName : theNameFrom(disambigName)) |
| 898 |
|
| 899 |
/* |
| 900 |
* The indefinite-article name for disambiguation prompts. We use |
| 901 |
* the same logic here as in theDisambigName. |
| 902 |
*/ |
| 903 |
aDisambigName = (name == disambigName ? aName : aNameFrom(disambigName)) |
| 904 |
|
| 905 |
/* |
| 906 |
* The counted name for disambiguation prompts. We use the same |
| 907 |
* logic here as in theDisambigName. |
| 908 |
*/ |
| 909 |
countDisambigName(cnt) |
| 910 |
{ |
| 911 |
return (name == disambigName && pluralName == pluralDisambigName |
| 912 |
? countName(cnt) |
| 913 |
: countNameFrom(cnt, disambigName, pluralDisambigName)); |
| 914 |
} |
| 915 |
|
| 916 |
/* |
| 917 |
* The plural name for disambiguation prompts. We use the same |
| 918 |
* logic here as in theDisambigName. |
| 919 |
*/ |
| 920 |
pluralDisambigName = (name == disambigName |
| 921 |
? pluralName : pluralNameFrom(disambigName)) |
| 922 |
|
| 923 |
/* |
| 924 |
* The name of the object, for the purposes of disambiguation prompts |
| 925 |
* to disambiguation among this object and basic equivalents of this |
| 926 |
* object (i.e., objects of the same class marked with |
| 927 |
* isEquivalent=true). |
| 928 |
* |
| 929 |
* This is used in disambiguation prompts in place of the actual text |
| 930 |
* typed by the user. For example, suppose the user types ">take |
| 931 |
* coin", then we ask for help disambiguating, and the player types |
| 932 |
* ">gold". This narrows things down to, say, three gold coins, but |
| 933 |
* they're in different locations so we need to ask for further |
| 934 |
* disambiguation. Normally, we ask "which gold do you mean", |
| 935 |
* because the player typed "gold" in the input. Once we're down to |
| 936 |
* equivalents, we don't have to rely on the input text any more, |
| 937 |
* which is good because the input text could be fragmentary (as in |
| 938 |
* our present example). Since we have only equivalents, we can use |
| 939 |
* the actual name of the objects (they're all the same, after all). |
| 940 |
* This property gives the name we use. |
| 941 |
* |
| 942 |
* For English, this is simply the object's ordinary disambiguation |
| 943 |
* name. This property is separate from 'name' and 'disambigName' |
| 944 |
* for the sake of languages that need to use an inflected form in |
| 945 |
* this context. |
| 946 |
*/ |
| 947 |
disambigEquivName = (disambigName) |
| 948 |
|
| 949 |
/* |
| 950 |
* Single-item listing description. This is used to display the |
| 951 |
* item when it appears as a single (non-grouped) item in a list. |
| 952 |
* By default, we just show the indefinite article description. |
| 953 |
*/ |
| 954 |
listName = (aName) |
| 955 |
|
| 956 |
/* |
| 957 |
* Return a string giving the "counted name" of the object - that is, |
| 958 |
* a phrase describing the given number of the object. For example, |
| 959 |
* for a red book, and a count of 5, we might return "five red |
| 960 |
* books". By default, we use countNameFrom() to construct a phrase |
| 961 |
* from the count and either our regular (singular) 'name' property |
| 962 |
* or our 'pluralName' property, according to whether count is 1 or |
| 963 |
* more than 1. |
| 964 |
*/ |
| 965 |
countName(count) { return countNameFrom(count, name, pluralName); } |
| 966 |
|
| 967 |
/* |
| 968 |
* Returns a string giving a count applied to the name string. The |
| 969 |
* name must be given in both singular and plural forms. |
| 970 |
*/ |
| 971 |
countNameFrom(count, singularStr, pluralStr) |
| 972 |
{ |
| 973 |
/* if the count is one, use 'one' plus the singular name */ |
| 974 |
if (count == 1) |
| 975 |
return 'one ' + singularStr; |
| 976 |
|
| 977 |
/* |
| 978 |
* Get the number followed by a space - spell out numbers below |
| 979 |
* 100, but use numerals to denote larger numbers. Append the |
| 980 |
* plural name to the number and return the result. |
| 981 |
*/ |
| 982 |
return spellIntBelowExt(count, 100, 0, DigitFormatGroupSep) |
| 983 |
+ ' ' + pluralStr; |
| 984 |
} |
| 985 |
|
| 986 |
/* |
| 987 |
* Get the 'pronoun selector' for the various pronoun methods. This |
| 988 |
* returns: |
| 989 |
* |
| 990 |
*. - singular neuter = 1 |
| 991 |
*. - singular masculine = 2 |
| 992 |
*. - singular feminine = 3 |
| 993 |
*. - plural = 4 |
| 994 |
*/ |
| 995 |
pronounSelector = (isPlural ? 4 : isHer ? 3 : isHim ? 2 : 1) |
| 996 |
|
| 997 |
/* |
| 998 |
* get a string with the appropriate pronoun for the object for the |
| 999 |
* nominative case, objective case, possessive adjective, possessive |
| 1000 |
* noun |
| 1001 |
*/ |
| 1002 |
itNom { return ['it', 'he', 'she', 'they'][pronounSelector]; } |
| 1003 |
itObj { return ['it', 'him', 'her', 'them'][pronounSelector]; } |
| 1004 |
itPossAdj { return ['its', 'his', 'her', 'their'][pronounSelector]; } |
| 1005 |
itPossNoun { return ['its', 'his', 'hers', 'theirs'][pronounSelector]; } |
| 1006 |
|
| 1007 |
/* get the object reflexive pronoun (itself, etc) */ |
| 1008 |
itReflexive |
| 1009 |
{ |
| 1010 |
return ['itself', 'himself', 'herself', 'themselves'] |
| 1011 |
[pronounSelector]; |
| 1012 |
} |
| 1013 |
|
| 1014 |
/* demonstrative pronouns ('that' or 'those') */ |
| 1015 |
thatNom { return ['that', 'he', 'she', 'those'][pronounSelector]; } |
| 1016 |
thatIsContraction |
| 1017 |
{ |
| 1018 |
return thatNom + tSel(isPlural ? ' are' : '’s', ' ' + verbToBe); |
| 1019 |
} |
| 1020 |
thatObj { return ['that', 'him', 'her', 'those'][pronounSelector]; } |
| 1021 |
|
| 1022 |
/* |
| 1023 |
* get a string with the appropriate pronoun for the object plus the |
| 1024 |
* correct conjugation of 'to be' |
| 1025 |
*/ |
| 1026 |
itIs { return itNom + ' ' + verbToBe; } |
| 1027 |
|
| 1028 |
/* get a pronoun plus a 'to be' contraction */ |
| 1029 |
itIsContraction |
| 1030 |
{ |
| 1031 |
return itNom |
| 1032 |
+ tSel(isPlural ? '’re' : '’s', ' ' + verbToBe); |
| 1033 |
} |
| 1034 |
|
| 1035 |
/* |
| 1036 |
* get a string with the appropriate pronoun for the object plus the |
| 1037 |
* correct conjugation of the given regular verb for the appropriate |
| 1038 |
* person |
| 1039 |
*/ |
| 1040 |
itVerb(verb) |
| 1041 |
{ |
| 1042 |
return itNom + ' ' + conjugateRegularVerb(verb); |
| 1043 |
} |
| 1044 |
|
| 1045 |
/* |
| 1046 |
* Conjugate a regular verb in the present or past tense for our |
| 1047 |
* person and number. |
| 1048 |
* |
| 1049 |
* In the present tense, this is pretty easy: we add an 's' for the |
| 1050 |
* third person singular, and leave the verb unchanged for plural (it |
| 1051 |
* asks, they ask). The only complication is that we must check some |
| 1052 |
* special cases to add the -s suffix: -y -> -ies (it carries), -o -> |
| 1053 |
* -oes (it goes). |
| 1054 |
* |
| 1055 |
* In the past tense, we can equally easily figure out when to use |
| 1056 |
* -d, -ed, or -ied. However, we have a more serious problem: for |
| 1057 |
* some verbs, the last consonant of the verb stem should be repeated |
| 1058 |
* (as in deter -> deterred), and for others it shouldn't (as in |
| 1059 |
* gather -> gathered). To figure out which rule applies, we would |
| 1060 |
* sometimes need to know whether the last syllable is stressed, and |
| 1061 |
* unfortunately there is no easy way to determine that |
| 1062 |
* programmatically. |
| 1063 |
* |
| 1064 |
* Therefore, we do *not* handle the case where the last consonant is |
| 1065 |
* repeated in the past tense. You shouldn't use this method for |
| 1066 |
* this case; instead, treat it as you would handle an irregular |
| 1067 |
* verb, by explicitly specifying the correct past tense form via the |
| 1068 |
* tSel macro. For example, to generate the properly conjugated form |
| 1069 |
* of the verb "deter" for an object named "thing", you could use an |
| 1070 |
* expression such as: |
| 1071 |
* |
| 1072 |
* 'deter' + tSel(thing.verbEndingS, 'red') |
| 1073 |
* |
| 1074 |
* This would correctly generate "deter", "deters", or "deterred" |
| 1075 |
* depending on the number of the object named "thing" and on the |
| 1076 |
* current narrative tense. |
| 1077 |
*/ |
| 1078 |
conjugateRegularVerb(verb) |
| 1079 |
{ |
| 1080 |
/* |
| 1081 |
* Which tense are we currently using? |
| 1082 |
*/ |
| 1083 |
if (gameMain.usePastTense) |
| 1084 |
{ |
| 1085 |
/* |
| 1086 |
* We want the past tense form. |
| 1087 |
* |
| 1088 |
* If the last letter is 'e', simply add 'd'. |
| 1089 |
*/ |
| 1090 |
if (verb.endsWith('e')) return verb + 'd'; |
| 1091 |
|
| 1092 |
/* |
| 1093 |
* Otherwise, if the verb ending would become 'ies' in the |
| 1094 |
* third-person singular present, then it becomes 'ied' in |
| 1095 |
* the past. |
| 1096 |
*/ |
| 1097 |
else if (rexMatch(iesEndingPat, verb)) |
| 1098 |
return verb.substr(1, verb.length() - 1) + 'ied'; |
| 1099 |
|
| 1100 |
/* |
| 1101 |
* Otherwise, use 'ed' as the ending. Don't try to determine |
| 1102 |
* if the last consonant should be repeated: that's too |
| 1103 |
* complicated. We'll just ignore the possibility. |
| 1104 |
*/ |
| 1105 |
else return verb + 'ed'; |
| 1106 |
} |
| 1107 |
else |
| 1108 |
{ |
| 1109 |
/* |
| 1110 |
* We want the present tense form. |
| 1111 |
* |
| 1112 |
* Check our number and person. |
| 1113 |
*/ |
| 1114 |
if (isPlural) |
| 1115 |
{ |
| 1116 |
/* |
| 1117 |
* We're plural, so simply use the base verb form ("they |
| 1118 |
* ask"). |
| 1119 |
*/ |
| 1120 |
return verb; |
| 1121 |
} |
| 1122 |
else |
| 1123 |
{ |
| 1124 |
/* |
| 1125 |
* Third-person singular, so we must add the -s suffix. |
| 1126 |
* Check for special spelling cases: |
| 1127 |
* |
| 1128 |
* '-y' changes to '-ies', unless the 'y' is preceded by |
| 1129 |
* a vowel |
| 1130 |
* |
| 1131 |
* '-sh', '-ch', and '-o' endings add suffix '-es' |
| 1132 |
*/ |
| 1133 |
if (rexMatch(iesEndingPat, verb)) |
| 1134 |
return verb.substr(1, verb.length() - 1) + 'ies'; |
| 1135 |
else if (rexMatch(esEndingPat, verb)) |
| 1136 |
return verb + 'es'; |
| 1137 |
else |
| 1138 |
return verb + 's'; |
| 1139 |
} |
| 1140 |
} |
| 1141 |
} |
| 1142 |
|
| 1143 |
/* verb-ending patterns for figuring out which '-s' ending to add */ |
| 1144 |
iesEndingPat = static new RexPattern('.*[^aeiou]y$') |
| 1145 |
esEndingPat = static new RexPattern('.*(o|ch|sh)$') |
| 1146 |
|
| 1147 |
/* |
| 1148 |
* Get the name with a definite article ("the box"). By default, we |
| 1149 |
* use our standard definite article algorithm to apply an article |
| 1150 |
* to self.name. |
| 1151 |
* |
| 1152 |
* The name returned must be in the nominative case (which makes no |
| 1153 |
* difference unless the name is a pronoun, since in English |
| 1154 |
* ordinary nouns don't vary according to how they're used in a |
| 1155 |
* sentence). |
| 1156 |
*/ |
| 1157 |
theName = (theNameFrom(name)) |
| 1158 |
|
| 1159 |
/* |
| 1160 |
* theName in objective case. In most cases, this is identical to |
| 1161 |
* the normal theName, so we use that by default. This must be |
| 1162 |
* overridden if theName is a pronoun (which is usually only the |
| 1163 |
* case for player character actors; see our language-specific Actor |
| 1164 |
* modifications for information on that case). |
| 1165 |
*/ |
| 1166 |
theNameObj { return theName; } |
| 1167 |
|
| 1168 |
/* |
| 1169 |
* Generate the definite-article name from the given name string. |
| 1170 |
* If my name is already qualified, don't add an article; otherwise, |
| 1171 |
* add a 'the' as the prefixed definite article. |
| 1172 |
*/ |
| 1173 |
theNameFrom(str) { return (isQualifiedName ? '' : 'the ') + str; } |
| 1174 |
|
| 1175 |
/* |
| 1176 |
* theName as a possessive adjective (Bob's book, your book). If the |
| 1177 |
* name's usage is singular (i.e., isPlural is nil), we'll simply add |
| 1178 |
* an apostrophe-S. If the name is plural, and it ends in an "s", |
| 1179 |
* we'll just add an apostrophe (no S). If it's plural and doesn't |
| 1180 |
* end in "s", we'll add an apostrophe-S. |
| 1181 |
* |
| 1182 |
* Note that some people disagree about the proper usage for |
| 1183 |
* singular-usage words (especially proper names) that end in 's'. |
| 1184 |
* Some people like to use a bare apostrophe for any name that ends |
| 1185 |
* in 's' (so Chris -> Chris'); other people use apostrophe-s for |
| 1186 |
* singular words that end in an "s" sound and a bare apostrophe for |
| 1187 |
* words that end in an "s" that sounds like a "z" (so Charles |
| 1188 |
* Dickens -> Charles Dickens'). However, most usage experts agree |
| 1189 |
* that proper names take an apostrophe-S in almost all cases, even |
| 1190 |
* when ending with an "s": "Chris's", "Charles Dickens's". That's |
| 1191 |
* what we do here. |
| 1192 |
* |
| 1193 |
* Note that this algorithm doesn't catch all of the special |
| 1194 |
* exceptions in conventional English usage. For example, Greek |
| 1195 |
* names ending with "-es" are usually written with the bare |
| 1196 |
* apostrophe, but we don't have a property that tells us whether the |
| 1197 |
* name is Greek or not, so we can't catch this case. Likewise, some |
| 1198 |
* authors like to possessive-ize words that end with an "s" sound |
| 1199 |
* with a bare apostrophe, as in "for appearance' sake", and we don't |
| 1200 |
* attempt to catch these either. For any of these exceptions, you |
| 1201 |
* must override this method for the individual object. |
| 1202 |
*/ |
| 1203 |
theNamePossAdj |
| 1204 |
{ |
| 1205 |
/* add apostrophe-S, unless it's a plural ending with 's' */ |
| 1206 |
return theName |
| 1207 |
+ (isPlural && theName.endsWith('s') ? '’' : '’s'); |
| 1208 |
} |
| 1209 |
|
| 1210 |
/* |
| 1211 |
* TheName as a possessive noun (that is Bob's, that is yours). We |
| 1212 |
* simply return the possessive adjective name, since the two forms |
| 1213 |
* are usually identical in English (except for pronouns, where they |
| 1214 |
* sometimes differ: "her" for the adjective vs "hers" for the noun). |
| 1215 |
*/ |
| 1216 |
theNamePossNoun = (theNamePossAdj) |
| 1217 |
|
| 1218 |
/* |
| 1219 |
* theName with my nominal owner explicitly stated, if we have a |
| 1220 |
* nominal owner: "your backpack," "Bob's flashlight." If we have |
| 1221 |
* no nominal owner, this is simply my theName. |
| 1222 |
*/ |
| 1223 |
theNameWithOwner() |
| 1224 |
{ |
| 1225 |
local owner; |
| 1226 |
|
| 1227 |
/* |
| 1228 |
* if we have a nominal owner, show with our owner name; |
| 1229 |
* otherwise, just show our regular theName |
| 1230 |
*/ |
| 1231 |
if ((owner = getNominalOwner()) != nil) |
| 1232 |
return owner.theNamePossAdj + ' ' + name; |
| 1233 |
else |
| 1234 |
return theName; |
| 1235 |
} |
| 1236 |
|
| 1237 |
/* |
| 1238 |
* Default preposition to use when an object is in/on this object. |
| 1239 |
* By default, we use 'in' as the preposition; subclasses can |
| 1240 |
* override to use others (such as 'on' for a surface). |
| 1241 |
*/ |
| 1242 |
objInPrep = 'in' |
| 1243 |
|
| 1244 |
/* |
| 1245 |
* Default preposition to use when an actor is in/on this object (as |
| 1246 |
* a nested location), and full prepositional phrase, with no article |
| 1247 |
* and with an indefinite article. By default, we use the objInPrep |
| 1248 |
* for actors as well. |
| 1249 |
*/ |
| 1250 |
actorInPrep = (objInPrep) |
| 1251 |
|
| 1252 |
/* preposition to use when an actor is being removed from this location */ |
| 1253 |
actorOutOfPrep = 'out of' |
| 1254 |
|
| 1255 |
/* preposition to use when an actor is being moved into this location */ |
| 1256 |
actorIntoPrep |
| 1257 |
{ |
| 1258 |
if (actorInPrep is in ('in', 'on')) |
| 1259 |
return actorInPrep + 'to'; |
| 1260 |
else |
| 1261 |
return actorInPrep; |
| 1262 |
} |
| 1263 |
|
| 1264 |
/* |
| 1265 |
* describe an actor as being in/being removed from/being moved into |
| 1266 |
* this location |
| 1267 |
*/ |
| 1268 |
actorInName = (actorInPrep + ' ' + theNameObj) |
| 1269 |
actorInAName = (actorInPrep + ' ' + aNameObj) |
| 1270 |
actorOutOfName = (actorOutOfPrep + ' ' + theNameObj) |
| 1271 |
actorIntoName = (actorIntoPrep + ' ' + theNameObj) |
| 1272 |
|
| 1273 |
/* |
| 1274 |
* A prepositional phrase that can be used to describe things that |
| 1275 |
* are in this room as seen from a remote point of view. This |
| 1276 |
* should be something along the lines of "in the airlock", "at the |
| 1277 |
* end of the alley", or "on the lawn". |
| 1278 |
* |
| 1279 |
* 'pov' is the point of view from which we're seeing this room; |
| 1280 |
* this might be |
| 1281 |
* |
| 1282 |
* We use this phrase in cases where we need to describe things in |
| 1283 |
* this room when viewed from a point of view outside of the room |
| 1284 |
* (i.e., in a different top-level room). By default, we'll use our |
| 1285 |
* actorInName. |
| 1286 |
*/ |
| 1287 |
inRoomName(pov) { return actorInName; } |
| 1288 |
|
| 1289 |
/* |
| 1290 |
* Provide the prepositional phrase for an object being put into me. |
| 1291 |
* For a container, for example, this would say "into the box"; for |
| 1292 |
* a surface, it would say "onto the table." By default, we return |
| 1293 |
* our library message given by our putDestMessage property; this |
| 1294 |
* default is suitable for most cases, but individual objects can |
| 1295 |
* customize as needed. When customizing this, be sure to make the |
| 1296 |
* phrase suitable for use in sentences like "You put the book |
| 1297 |
* <<putInName>>" and "The book falls <<putInName>>" - the phrase |
| 1298 |
* should be suitable for a verb indicating active motion by the |
| 1299 |
* object being received. |
| 1300 |
*/ |
| 1301 |
putInName() { return gLibMessages.(putDestMessage)(self); } |
| 1302 |
|
| 1303 |
/* |
| 1304 |
* Get a description of an object within this object, describing the |
| 1305 |
* object's location as this object. By default, we'll append "in |
| 1306 |
* <theName>" to the given object name. |
| 1307 |
*/ |
| 1308 |
childInName(childName) |
| 1309 |
{ return childInNameGen(childName, theName); } |
| 1310 |
|
| 1311 |
/* |
| 1312 |
* Get a description of an object within this object, showing the |
| 1313 |
* owner of this object. This is similar to childInName, but |
| 1314 |
* explicitly shows the owner of the containing object, if any: "the |
| 1315 |
* flashlight in bob's backpack". |
| 1316 |
*/ |
| 1317 |
childInNameWithOwner(childName) |
| 1318 |
{ return childInNameGen(childName, theNameWithOwner); } |
| 1319 |
|
| 1320 |
/* |
| 1321 |
* get a description of an object within this object, as seen from a |
| 1322 |
* remote location |
| 1323 |
*/ |
| 1324 |
childInRemoteName(childName, pov) |
| 1325 |
{ return childInNameGen(childName, inRoomName(pov)); } |
| 1326 |
|
| 1327 |
/* |
| 1328 |
* Base routine for generating childInName and related names. Takes |
| 1329 |
* the name to use for the child and the name to use for me, and |
| 1330 |
* combines them appropriately. |
| 1331 |
* |
| 1332 |
* In most cases, this is the only one of the various childInName |
| 1333 |
* methods that needs to be overridden per subclass, since the others |
| 1334 |
* are defined in terms of this one. Note also that if the only |
| 1335 |
* thing you need to do is change the preposition from 'in' to |
| 1336 |
* something else, you can just override objInPrep instead. |
| 1337 |
*/ |
| 1338 |
childInNameGen(childName, myName) |
| 1339 |
{ return childName + ' ' + objInPrep + ' ' + myName; } |
| 1340 |
|
| 1341 |
/* |
| 1342 |
* Get my name (in various forms) distinguished by my owner or |
| 1343 |
* location. |
| 1344 |
* |
| 1345 |
* If the object has an owner, and either we're giving priority to |
| 1346 |
* the owner or our immediate location is the same as the owner, |
| 1347 |
* we'll show using a possessive form with the owner ("bob's |
| 1348 |
* flashlight"). Otherwise, we'll show the name distinguished by |
| 1349 |
* our immediate container ("the flashlight in the backpack"). |
| 1350 |
* |
| 1351 |
* These are used by the ownership and location distinguishers to |
| 1352 |
* list objects according to owners in disambiguation lists. The |
| 1353 |
* ownership distinguisher gives priority to naming by ownership, |
| 1354 |
* regardless of the containment relationship between owner and |
| 1355 |
* self; the location distinguisher gives priority to naming by |
| 1356 |
* location, showing the owner only if the owner is the same as the |
| 1357 |
* location. |
| 1358 |
* |
| 1359 |
* We will presume that objects with proper names are never |
| 1360 |
* indistinguishable from other objects with proper names, so we |
| 1361 |
* won't worry about cases like "Bob's Bill". This leaves us free |
| 1362 |
* to use appropriate articles in all cases. |
| 1363 |
*/ |
| 1364 |
aNameOwnerLoc(ownerPriority) |
| 1365 |
{ |
| 1366 |
local owner; |
| 1367 |
|
| 1368 |
/* show in owner or location format, as appropriate */ |
| 1369 |
if ((owner = getNominalOwner()) != nil |
| 1370 |
&& (ownerPriority || isDirectlyIn(owner))) |
| 1371 |
{ |
| 1372 |
local ret; |
| 1373 |
|
| 1374 |
/* |
| 1375 |
* we have an owner - show as "one of Bob's items" (or just |
| 1376 |
* "Bob's items" if this is a mass noun or a proper name) |
| 1377 |
*/ |
| 1378 |
ret = owner.theNamePossAdj + ' ' + pluralName; |
| 1379 |
if (!isMassNoun && !isPlural) |
| 1380 |
ret = 'one of ' + ret; |
| 1381 |
|
| 1382 |
/* return the result */ |
| 1383 |
return ret; |
| 1384 |
} |
| 1385 |
else |
| 1386 |
{ |
| 1387 |
/* we have no owner - show as "an item in the location" */ |
| 1388 |
return location.childInNameWithOwner(aName); |
| 1389 |
} |
| 1390 |
} |
| 1391 |
theNameOwnerLoc(ownerPriority) |
| 1392 |
{ |
| 1393 |
local owner; |
| 1394 |
|
| 1395 |
/* show in owner or location format, as appropriate */ |
| 1396 |
if ((owner = getNominalOwner()) != nil |
| 1397 |
&& (ownerPriority || isDirectlyIn(owner))) |
| 1398 |
{ |
| 1399 |
/* we have an owner - show as "Bob's item" */ |
| 1400 |
return owner.theNamePossAdj + ' ' + name; |
| 1401 |
} |
| 1402 |
else |
| 1403 |
{ |
| 1404 |
/* we have no owner - show as "the item in the location" */ |
| 1405 |
return location.childInNameWithOwner(theName); |
| 1406 |
} |
| 1407 |
} |
| 1408 |
countNameOwnerLoc(cnt, ownerPriority) |
| 1409 |
{ |
| 1410 |
local owner; |
| 1411 |
|
| 1412 |
/* show in owner or location format, as appropriate */ |
| 1413 |
if ((owner = getNominalOwner()) != nil |
| 1414 |
&& (ownerPriority || isDirectlyIn(owner))) |
| 1415 |
{ |
| 1416 |
/* we have an owner - show as "Bob's five items" */ |
| 1417 |
return owner.theNamePossAdj + ' ' + countName(cnt); |
| 1418 |
} |
| 1419 |
else |
| 1420 |
{ |
| 1421 |
/* we have no owner - show as "the five items in the location" */ |
| 1422 |
return location.childInNameWithOwner('the ' + countName(cnt)); |
| 1423 |
} |
| 1424 |
} |
| 1425 |
|
| 1426 |
/* |
| 1427 |
* Note that I'm being used in a disambiguation prompt by |
| 1428 |
* owner/location. If we're showing the owner, we'll set the |
| 1429 |
* antecedent for the owner's pronoun, if the owner is a 'him' or |
| 1430 |
* 'her'; this allows the player to refer back to our prompt text |
| 1431 |
* with appropriate pronouns. |
| 1432 |
*/ |
| 1433 |
notePromptByOwnerLoc(ownerPriority) |
| 1434 |
{ |
| 1435 |
local owner; |
| 1436 |
|
| 1437 |
/* show in owner or location format, as appropriate */ |
| 1438 |
if ((owner = getNominalOwner()) != nil |
| 1439 |
&& (ownerPriority || isDirectlyIn(owner))) |
| 1440 |
{ |
| 1441 |
/* we are showing by owner - let the owner know about it */ |
| 1442 |
owner.notePromptByPossAdj(); |
| 1443 |
} |
| 1444 |
} |
| 1445 |
|
| 1446 |
/* |
| 1447 |
* Note that we're being used in a prompt question with our |
| 1448 |
* possessive adjective. If we're a 'him' or a 'her', set our |
| 1449 |
* pronoun antecedent so that the player's response to the prompt |
| 1450 |
* question can refer back to the prompt text by pronoun. |
| 1451 |
*/ |
| 1452 |
notePromptByPossAdj() |
| 1453 |
{ |
| 1454 |
if (isHim) |
| 1455 |
gPlayerChar.setHim(self); |
| 1456 |
if (isHer) |
| 1457 |
gPlayerChar.setHer(self); |
| 1458 |
} |
| 1459 |
|
| 1460 |
/* |
| 1461 |
* My name with an indefinite article. By default, we figure out |
| 1462 |
* which article to use (a, an, some) automatically. |
| 1463 |
* |
| 1464 |
* In rare cases, the automatic determination might get it wrong, |
| 1465 |
* since some English spellings defy all of the standard |
| 1466 |
* orthographic rules and must simply be handled as special cases; |
| 1467 |
* for example, the algorithmic determination doesn't know about |
| 1468 |
* silent-h words like "hour". When the automatic determination |
| 1469 |
* gets it wrong, simply override this routine to specify the |
| 1470 |
* correct article explicitly. |
| 1471 |
*/ |
| 1472 |
aName = (aNameFrom(name)) |
| 1473 |
|
| 1474 |
/* the indefinite-article name in the objective case */ |
| 1475 |
aNameObj { return aName; } |
| 1476 |
|
| 1477 |
/* |
| 1478 |
* Apply an indefinite article ("a box", "an orange", "some lint") |
| 1479 |
* to the given name. We'll try to figure out which indefinite |
| 1480 |
* article to use based on what kind of noun phrase we use for our |
| 1481 |
* name (singular, plural, or a "mass noun" like "lint"), and our |
| 1482 |
* spelling. |
| 1483 |
* |
| 1484 |
* By default, we'll use the article "a" if the name starts with a |
| 1485 |
* consonant, or "an" if it starts with a vowel. |
| 1486 |
* |
| 1487 |
* If the name starts with a "y", we'll look at the second letter; |
| 1488 |
* if it's a consonant, we'll use "an", otherwise "a" (hence "an |
| 1489 |
* yttrium block" but "a yellow brick"). |
| 1490 |
* |
| 1491 |
* If the object is marked as having plural usage, we will use |
| 1492 |
* "some" as the article ("some pants" or "some shrubs"). |
| 1493 |
* |
| 1494 |
* Some objects will want to override the default behavior, because |
| 1495 |
* the lexical rules about when to use "a" and "an" are not without |
| 1496 |
* exception. For example, silent-"h" words ("honor") are written |
| 1497 |
* with "an", and "h" words with a pronounced but weakly stressed |
| 1498 |
* initial "h" are sometimes used with "an" ("an historian"). Also, |
| 1499 |
* some 'y' words might not follow the generic 'y' rule. |
| 1500 |
* |
| 1501 |
* 'U' words are especially likely not to follow any lexical rule - |
| 1502 |
* any 'u' word that sounds like it starts with 'y' should use 'a' |
| 1503 |
* rather than 'an', but there's no good way to figure that out just |
| 1504 |
* looking at the spelling (consider "a universal symbol" and "an |
| 1505 |
* unimportant word", or "a unanimous decision" and "an unassuming |
| 1506 |
* man"). We simply always use 'an' for a word starting with 'u', |
| 1507 |
* but this will have to be overridden when the 'u' sounds like 'y'. |
| 1508 |
*/ |
| 1509 |
aNameFrom(str) |
| 1510 |
{ |
| 1511 |
/* remember the original source string */ |
| 1512 |
local inStr = str; |
| 1513 |
|
| 1514 |
/* |
| 1515 |
* The complete list of unaccented, accented, and ligaturized |
| 1516 |
* Latin vowels from the Unicode character set. (The Unicode |
| 1517 |
* database doesn't classify characters as vowels or the like, |
| 1518 |
* so it seems the only way we can come up with this list is |
| 1519 |
* simply to enumerate the vowels.) |
| 1520 |
* |
| 1521 |
* These are all lower-case letters; all of these are either |
| 1522 |
* exclusively lower-case or have upper-case equivalents that |
| 1523 |
* map to these lower-case letters. |
| 1524 |
* |
| 1525 |
* (Note an implementation detail: the compiler will append all |
| 1526 |
* of these strings together at compile time, so we don't have |
| 1527 |
* to perform all of this concatenation work each time we |
| 1528 |
* execute this method.) |
| 1529 |
* |
| 1530 |
* Note that we consider any word starting with an '8' to start |
| 1531 |
* with a vowel, since 'eight' and 'eighty' both take 'an'. |
| 1532 |
*/ |
| 1533 |
local vowels = '8aeiou\u00E0\u00E1\u00E2\u00E3\u00E4\u00E5\u00E6' |
| 1534 |
+ '\u00E8\u00E9\u00EA\u00EB\u00EC\u00ED\u00EE\u00EF' |
| 1535 |
+ '\u00F2\u00F3\u00F4\u00F5\u00F6\u00F8\u00F9\u00FA' |
| 1536 |
+ '\u00FB\u00FC\u0101\u0103\u0105\u0113\u0115\u0117' |
| 1537 |
+ '\u0119\u011B\u0129\u012B\u012D\u012F\u014D\u014F' |
| 1538 |
+ '\u0151\u0169\u016B\u016D\u016F\u0171\u0173\u01A1' |
| 1539 |
+ '\u01A3\u01B0\u01CE\u01D0\u01D2\u01D4\u01D6\u01D8' |
| 1540 |
+ '\u01DA\u01DC\u01DF\u01E1\u01E3\u01EB\u01ED\u01FB' |
| 1541 |
+ '\u01FD\u01FF\u0201\u0203\u0205\u0207\u0209\u020B' |
| 1542 |
+ '\u020D\u020F\u0215\u0217\u0254\u025B\u0268\u0289' |
| 1543 |
+ '\u1E01\u1E15\u1E17\u1E19\u1E1B\u1E1D\u1E2D\u1E2F' |
| 1544 |
+ '\u1E4D\u1E4F\u1E51\u1E53\u1E73\u1E75\u1E77\u1E79' |
| 1545 |
+ '\u1E7B\u1E9A\u1EA1\u1EA3\u1EA5\u1EA7\u1EA9\u1EAB' |
| 1546 |
+ '\u1EAD\u1EAF\u1EB1\u1EB3\u1EB5\u1EB7\u1EB9\u1EBB' |
| 1547 |
+ '\u1EBD\u1EBF\u1EC1\u1EC3\u1EC5\u1EC7\u1EC9\u1ECB' |
| 1548 |
+ '\u1ECD\u1ECF\u1ED1\u1ED3\u1ED5\u1ED7\u1ED9\u1EDB' |
| 1549 |
+ '\u1EDD\u1EDF\u1EE1\u1EE3\u1EE5\u1EE7\u1EE9\u1EEB' |
| 1550 |
+ '\u1EED\u1EEF\u1EF1\uFF41\uFF4F\uFF55'; |
| 1551 |
|
| 1552 |
/* |
| 1553 |
* A few upper-case vowels in unicode don't have lower-case |
| 1554 |
* mappings - consider them separately. |
| 1555 |
*/ |
| 1556 |
local vowelsUpperOnly = '\u0130\u019f'; |
| 1557 |
|
| 1558 |
/* |
| 1559 |
* the various accented forms of the letter 'y' - these are all |
| 1560 |
* lower-case versions; the upper-case versions all map to these |
| 1561 |
*/ |
| 1562 |
local ys = 'y\u00FD\u00FF\u0177\u01B4\u1E8F\u1E99\u1EF3' |
| 1563 |
+ '\u1EF5\u1EF7\u1EF9\u24B4\uFF59'; |
| 1564 |
|
| 1565 |
/* if the name is already qualified, don't add an article at all */ |
| 1566 |
if (isQualifiedName) |
| 1567 |
return str; |
| 1568 |
|
| 1569 |
/* if it's plural or a mass noun, use "some" as the article */ |
| 1570 |
if (isPlural || isMassNoun) |
| 1571 |
{ |
| 1572 |
/* use "some" as the article */ |
| 1573 |
return 'some ' + str; |
| 1574 |
} |
| 1575 |
else |
| 1576 |
{ |
| 1577 |
local firstChar; |
| 1578 |
local firstCharLower; |
| 1579 |
|
| 1580 |
/* if it's empty, just use "a" */ |
| 1581 |
if (inStr == '') |
| 1582 |
return 'a'; |
| 1583 |
|
| 1584 |
/* get the first character of the name */ |
| 1585 |
firstChar = inStr.substr(1, 1); |
| 1586 |
|
| 1587 |
/* skip any leading HTML tags */ |
| 1588 |
if (rexMatch(patTagOrQuoteChar, firstChar) != nil) |
| 1589 |
{ |
| 1590 |
/* |
| 1591 |
* Scan for tags. Note that this pattern isn't quite |
| 1592 |
* perfect, as it won't properly ignore close-brackets |
| 1593 |
* that are inside quoted material, but it should be good |
| 1594 |
* enough for nearly all cases in practice. In cases too |
| 1595 |
* complex for this pattern, the object will simply have |
| 1596 |
* to override aDesc. |
| 1597 |
*/ |
| 1598 |
local len = rexMatch(patLeadingTagOrQuote, inStr); |
| 1599 |
|
| 1600 |
/* if we got a match, strip out the leading tags */ |
| 1601 |
if (len != nil) |
| 1602 |
{ |
| 1603 |
/* strip off the leading tags */ |
| 1604 |
inStr = inStr.substr(len + 1); |
| 1605 |
|
| 1606 |
/* re-fetch the first character */ |
| 1607 |
firstChar = inStr.substr(1, 1); |
| 1608 |
} |
| 1609 |
} |
| 1610 |
|
| 1611 |
/* get the lower-case version of the first character */ |
| 1612 |
firstCharLower = firstChar.toLower(); |
| 1613 |
|
| 1614 |
/* |
| 1615 |
* if the first word of the name is only one letter long, |
| 1616 |
* treat it specially |
| 1617 |
*/ |
| 1618 |
if (rexMatch(patOneLetterWord, inStr) != nil) |
| 1619 |
{ |
| 1620 |
/* |
| 1621 |
* We have a one-letter first word, such as "I-beam" or |
| 1622 |
* "M-ray sensor", or just "A". Choose the article based |
| 1623 |
* on the pronunciation of the letter as a letter. |
| 1624 |
*/ |
| 1625 |
return (rexMatch(patOneLetterAnWord, inStr) != nil |
| 1626 |
? 'an ' : 'a ') + str; |
| 1627 |
} |
| 1628 |
|
| 1629 |
/* |
| 1630 |
* look for the first character in the lower-case and |
| 1631 |
* upper-case-only vowel lists - if we find it, it takes |
| 1632 |
* 'an' |
| 1633 |
*/ |
| 1634 |
if (vowels.find(firstCharLower) != nil |
| 1635 |
|| vowelsUpperOnly.find(firstChar) != nil) |
| 1636 |
{ |
| 1637 |
/* it starts with a vowel */ |
| 1638 |
return 'an ' + str; |
| 1639 |
} |
| 1640 |
else if (ys.find(firstCharLower) != nil) |
| 1641 |
{ |
| 1642 |
local secondChar; |
| 1643 |
|
| 1644 |
/* get the second character, if there is one */ |
| 1645 |
secondChar = inStr.substr(2, 1); |
| 1646 |
|
| 1647 |
/* |
| 1648 |
* It starts with 'y' - if the second letter is a |
| 1649 |
* consonant, assume the 'y' is a vowel sound, hence we |
| 1650 |
* should use 'an'; otherwise assume the 'y' is a |
| 1651 |
* diphthong 'ei' sound, which means we should use 'a'. |
| 1652 |
* If there's no second character at all, or the second |
| 1653 |
* character isn't alphabetic, use 'a' - "a Y" or "a |
| 1654 |
* Y-connector". |
| 1655 |
*/ |
| 1656 |
if (secondChar == '' |
| 1657 |
|| rexMatch(patIsAlpha, secondChar) == nil |
| 1658 |
|| vowels.find(secondChar.toLower()) != nil |
| 1659 |
|| vowelsUpperOnly.find(secondChar) != nil) |
| 1660 |
{ |
| 1661 |
/* |
| 1662 |
* it's just one character, or the second character |
| 1663 |
* is non-alphabetic, or the second character is a |
| 1664 |
* vowel - in any of these cases, use 'a' |
| 1665 |
*/ |
| 1666 |
return 'a ' + str; |
| 1667 |
} |
| 1668 |
else |
| 1669 |
{ |
| 1670 |
/* the second character is a consonant - use 'an' */ |
| 1671 |
return 'an ' + str; |
| 1672 |
} |
| 1673 |
} |
| 1674 |
else if (rexMatch(patElevenEighteen, inStr) != nil) |
| 1675 |
{ |
| 1676 |
/* |
| 1677 |
* it starts with '11' or '18', so it takes 'an' ('an |
| 1678 |
* 11th-hour appeal', 'an 18-hole golf course') |
| 1679 |
*/ |
| 1680 |
return 'an ' + str; |
| 1681 |
} |
| 1682 |
else |
| 1683 |
{ |
| 1684 |
/* it starts with a consonant */ |
| 1685 |
return 'a ' + str; |
| 1686 |
} |
| 1687 |
} |
| 1688 |
} |
| 1689 |
|
| 1690 |
/* pre-compile some regular expressions for aName */ |
| 1691 |
patTagOrQuoteChar = static new RexPattern('[<"\']') |
| 1692 |
patLeadingTagOrQuote = static new RexPattern( |
| 1693 |
'(<langle><^rangle>+<rangle>|"|\')+') |
| 1694 |
patOneLetterWord = static new RexPattern('<alpha>(<^alpha>|$)') |
| 1695 |
patOneLetterAnWord = static new RexPattern('<nocase>[aefhilmnorsx]') |
| 1696 |
patIsAlpha = static new RexPattern('<alpha>') |
| 1697 |
patElevenEighteen = static new RexPattern('1[18](<^digit>|$)') |
| 1698 |
|
| 1699 |
/* |
| 1700 |
* Get the default plural name. By default, we'll use the |
| 1701 |
* algorithmic plural determination, which is based on the spelling |
| 1702 |
* of the name. |
| 1703 |
* |
| 1704 |
* The algorithm won't always get it right, since some English |
| 1705 |
* plurals are irregular ("men", "children", "Attorneys General"). |
| 1706 |
* When the name doesn't fit the regular spelling patterns for |
| 1707 |
* plurals, the object should simply override this routine to return |
| 1708 |
* the correct plural name string. |
| 1709 |
*/ |
| 1710 |
pluralName = (pluralNameFrom(name)) |
| 1711 |
|
| 1712 |
/* |
| 1713 |
* Get the plural form of the given name string. If the name ends in |
| 1714 |
* anything other than 'y', we'll add an 's'; otherwise we'll replace |
| 1715 |
* the 'y' with 'ies'. We also handle abbreviations and individual |
| 1716 |
* letters specially. |
| 1717 |
* |
| 1718 |
* This can only deal with simple adjective-noun forms. For more |
| 1719 |
* complicated forms, particularly for compound words, it must be |
| 1720 |
* overridden (e.g., "Attorney General" -> "Attorneys General", |
| 1721 |
* "man-of-war" -> "men-of-war"). Likewise, names with irregular |
| 1722 |
* plurals ('child' -> 'children', 'man' -> 'men') must be handled |
| 1723 |
* with overrides. |
| 1724 |
*/ |
| 1725 |
pluralNameFrom(str) |
| 1726 |
{ |
| 1727 |
local len; |
| 1728 |
local lastChar; |
| 1729 |
local lastPair; |
| 1730 |
|
| 1731 |
/* |
| 1732 |
* if it's marked as having plural usage, just use the ordinary |
| 1733 |
* name, since it's already plural |
| 1734 |
*/ |
| 1735 |
if (isPlural) |
| 1736 |
return str; |
| 1737 |
|
| 1738 |
/* check for a 'phrase of phrase' format */ |
| 1739 |
if (rexMatch(patOfPhrase, str) != nil) |
| 1740 |
{ |
| 1741 |
local ofSuffix; |
| 1742 |
|
| 1743 |
/* |
| 1744 |
* Pull out the two parts - the part up to the 'of' is the |
| 1745 |
* part we'll actually pluralize, and the rest is a suffix |
| 1746 |
* we'll stick on the end of the pluralized part. |
| 1747 |
*/ |
| 1748 |
str = rexGroup(1)[3]; |
| 1749 |
ofSuffix = rexGroup(2)[3]; |
| 1750 |
|
| 1751 |
/* |
| 1752 |
* now pluralize the part up to the 'of' using the normal |
| 1753 |
* rules, then add the rest back in at the end |
| 1754 |
*/ |
| 1755 |
return pluralNameFrom(str) + ofSuffix; |
| 1756 |
} |
| 1757 |
|
| 1758 |
/* if there's no short description, return an empty string */ |
| 1759 |
len = str.length(); |
| 1760 |
if (len == 0) |
| 1761 |
return ''; |
| 1762 |
|
| 1763 |
/* |
| 1764 |
* If it's only one character long, handle it specially. If it's |
| 1765 |
* a lower-case letter, add an apostrophe-S. If it's a capital |
| 1766 |
* A, E, I, M, U, or V, we'll add apostrophe-S (because these |
| 1767 |
* could be confused with words or common abbreviations if we |
| 1768 |
* just added "s": As, Es, Is, Ms, Us, Vs). If it's anything |
| 1769 |
* else (any other capital letter, or any non-letter character), |
| 1770 |
* we'll just add an "s". |
| 1771 |
*/ |
| 1772 |
if (len == 1) |
| 1773 |
{ |
| 1774 |
if (rexMatch(patSingleApostropheS, str) != nil) |
| 1775 |
return str + '’s'; |
| 1776 |
else |
| 1777 |
return str + 's'; |
| 1778 |
} |
| 1779 |
|
| 1780 |
/* get the last character of the name, and the last pair of chars */ |
| 1781 |
lastChar = str.substr(len, 1); |
| 1782 |
lastPair = (len == 1 ? lastChar : str.substr(len - 1, 2)); |
| 1783 |
|
| 1784 |
/* |
| 1785 |
* If the last letter is a capital letter, assume it's an |
| 1786 |
* abbreviation without embedded periods (CPA, PC), in which case |
| 1787 |
* we just add an "s" (CPAs, PCs). Likewise, if it's a number, |
| 1788 |
* just add "s": "the 1940s", "the low 20s". |
| 1789 |
*/ |
| 1790 |
if (rexMatch(patUpperOrDigit, lastChar) != nil) |
| 1791 |
return str + 's'; |
| 1792 |
|
| 1793 |
/* |
| 1794 |
* If the last character is a period, it must be an abbreviation |
| 1795 |
* with embedded periods (B.A., B.S., Ph.D.). In these cases, |
| 1796 |
* add an apostrophe-S. |
| 1797 |
*/ |
| 1798 |
if (lastChar == '.') |
| 1799 |
return str + '’s'; |
| 1800 |
|
| 1801 |
/* |
| 1802 |
* If it ends in a non-vowel followed by 'y', change -y to -ies. |
| 1803 |
* (This doesn't apply if a vowel precedes a terminal 'y'; in |
| 1804 |
* such cases, we'll use the normal '-s' ending instead: "survey" |
| 1805 |
* -> "surveys", "essay" -> "essays", "day" -> "days".) |
| 1806 |
*/ |
| 1807 |
if (rexMatch(patVowelY, lastPair) != nil) |
| 1808 |
return str.substr(1, len - 1) + 'ies'; |
| 1809 |
|
| 1810 |
/* if it ends in s, x, z, or h, add -es */ |
| 1811 |
if ('sxzh'.find(lastChar) != nil) |
| 1812 |
return str + 'es'; |
| 1813 |
|
| 1814 |
/* for anything else, just add -s */ |
| 1815 |
return str + 's'; |
| 1816 |
} |
| 1817 |
|
| 1818 |
/* some pre-compiled patterns for pluralName */ |
| 1819 |
patSingleApostropheS = static new RexPattern('<case><lower|A|E|I|M|U|V>') |
| 1820 |
patUpperOrDigit = static new RexPattern('<upper|digit>') |
| 1821 |
patVowelY = static new RexPattern('[^aeoiu]y') |
| 1822 |
patOfPhrase = static new RexPattern( |
| 1823 |
'<nocase>(.+?)(<space>+of<space>+.+)') |
| 1824 |
|
| 1825 |
/* get my name plus a being verb ("the box is") */ |
| 1826 |
nameIs { return theName + ' ' + verbToBe; } |
| 1827 |
|
| 1828 |
/* get my name plus a negative being verb ("the box isn't") */ |
| 1829 |
nameIsnt { return nameIs + 'n’t'; } |
| 1830 |
|
| 1831 |
/* |
| 1832 |
* My name with the given regular verb in agreement: in the present |
| 1833 |
* tense, if my name has singular usage, we'll add 's' to the verb, |
| 1834 |
* otherwise we won't. In the past tense, we'll add 'd' (or 'ed'). |
| 1835 |
* This can't be used with irregular verbs, or with regular verbs |
| 1836 |
* that have the last consonant repeated before the past -ed ending, |
| 1837 |
* such as "deter". |
| 1838 |
*/ |
| 1839 |
nameVerb(verb) { return theName + ' ' + conjugateRegularVerb(verb); } |
| 1840 |
|
| 1841 |
/* being verb agreeing with this object as subject */ |
| 1842 |
verbToBe |
| 1843 |
{ |
| 1844 |
return tSel(isPlural ? 'are' : 'is', isPlural ? 'were' : 'was'); |
| 1845 |
} |
| 1846 |
|
| 1847 |
/* past tense being verb agreeing with object as subject */ |
| 1848 |
verbWas { return tSel(isPlural ? 'were' : 'was', 'had been'); } |
| 1849 |
|
| 1850 |
/* 'have' verb agreeing with this object as subject */ |
| 1851 |
verbToHave { return tSel(isPlural ? 'have' : 'has', 'had'); } |
| 1852 |
|
| 1853 |
/* |
| 1854 |
* A few common irregular verbs and name-plus-verb constructs, |
| 1855 |
* defined for convenience. |
| 1856 |
*/ |
| 1857 |
verbToDo = (tSel('do' + verbEndingEs, 'did')) |
| 1858 |
nameDoes = (theName + ' ' + verbToDo) |
| 1859 |
verbToGo = (tSel('go' + verbEndingEs, 'went')) |
| 1860 |
verbToCome = (tSel('come' + verbEndingS, 'came')) |
| 1861 |
verbToLeave = (tSel('leave' + verbEndingS, 'left')) |
| 1862 |
verbToSee = (tSel('see' + verbEndingS, 'saw')) |
| 1863 |
nameSees = (theName + ' ' + verbToSee) |
| 1864 |
verbToSay = (tSel('say' + verbEndingS, 'said')) |
| 1865 |
nameSays = (theName + ' ' + verbToSay) |
| 1866 |
verbMust = (tSel('must', 'had to')) |
| 1867 |
verbCan = (tSel('can', 'could')) |
| 1868 |
verbCannot = (tSel('cannot', 'could not')) |
| 1869 |
verbCant = (tSel('can’t', 'couldn’t')) |
| 1870 |
verbWill = (tSel('will', 'would')) |
| 1871 |
verbWont = (tSel('won’t', 'wouldn’t')) |
| 1872 |
|
| 1873 |
/* |
| 1874 |
* Verb endings for regular '-s' verbs, agreeing with this object as |
| 1875 |
* the subject. We define several methods each of which handles the |
| 1876 |
* past tense differently. |
| 1877 |
* |
| 1878 |
* verbEndingS doesn't try to handle the past tense at all - use it |
| 1879 |
* only in places where you know for certain that you'll never need |
| 1880 |
* the past tense form, or in expressions constructed with the tSel |
| 1881 |
* macro: use verbEndingS as the macro's first argument, and specify |
| 1882 |
* the past tense ending explicitly as the second argument. For |
| 1883 |
* example, you could generate the correctly conjugated form of the |
| 1884 |
* verb "to fit" for an object named "key" with an expression such |
| 1885 |
* as: |
| 1886 |
* |
| 1887 |
* 'fit' + tSel(key.verbEndingS, 'ted') |
| 1888 |
* |
| 1889 |
* This would generate 'fit', 'fits', or 'fitted' according to number |
| 1890 |
* and tense. |
| 1891 |
* |
| 1892 |
* verbEndingSD and verbEndingSEd return 'd' and 'ed' respectively in |
| 1893 |
* the past tense. |
| 1894 |
* |
| 1895 |
* verbEndingSMessageBuilder_ is for internal use only: it assumes |
| 1896 |
* that the correct ending to be displayed in the past tense is |
| 1897 |
* stored in langMessageBuilder.pastEnding_. It is used as part of |
| 1898 |
* the string parameter substitution mechanism. |
| 1899 |
*/ |
| 1900 |
verbEndingS { return isPlural ? '' : 's'; } |
| 1901 |
verbEndingSD = (tSel(verbEndingS, 'd')) |
| 1902 |
verbEndingSEd = (tSel(verbEndingS, 'ed')) |
| 1903 |
verbEndingSMessageBuilder_ = |
| 1904 |
(tSel(verbEndingS, langMessageBuilder.pastEnding_)) |
| 1905 |
|
| 1906 |
/* |
| 1907 |
* Verb endings (present or past) for regular '-es/-ed' and |
| 1908 |
* '-y/-ies/-ied' verbs, agreeing with this object as the subject. |
| 1909 |
*/ |
| 1910 |
verbEndingEs { return tSel(isPlural ? '' : 'es', 'ed'); } |
| 1911 |
verbEndingIes { return tSel(isPlural ? 'y' : 'ies', 'ied'); } |
| 1912 |
|
| 1913 |
/* |
| 1914 |
* Dummy name - this simply displays nothing; it's used for cases |
| 1915 |
* where messageBuilder substitutions want to refer to an object (for |
| 1916 |
* internal bookkeeping) without actually showing the name of the |
| 1917 |
* object in the output text. This should always simply return an |
| 1918 |
* empty string. |
| 1919 |
*/ |
| 1920 |
dummyName = '' |
| 1921 |
|
| 1922 |
/* |
| 1923 |
* Invoke a property (with an optional argument list) on this object |
| 1924 |
* while temporarily switching to the present tense, and return the |
| 1925 |
* result. |
| 1926 |
*/ |
| 1927 |
propWithPresent(prop, [args]) |
| 1928 |
{ |
| 1929 |
return withPresent({: self.(prop)(args...)}); |
| 1930 |
} |
| 1931 |
|
| 1932 |
/* |
| 1933 |
* Method for internal use only: invoke on this object the property |
| 1934 |
* stored in langMessageBuilder.fixedTenseProp_ while temporarily |
| 1935 |
* switching to the present tense, and return the result. This is |
| 1936 |
* used as part of the string parameter substitution mechanism. |
| 1937 |
*/ |
| 1938 |
propWithPresentMessageBuilder_ |
| 1939 |
{ |
| 1940 |
return propWithPresent(langMessageBuilder.fixedTenseProp_); |
| 1941 |
} |
| 1942 |
|
| 1943 |
/* |
| 1944 |
* For the most part, "strike" has the same meaning as "hit", so |
| 1945 |
* define this as a synonym for "attack" most objects. There are a |
| 1946 |
* few English idioms where "strike" means something different, as |
| 1947 |
* in "strike match" or "strike tent." |
| 1948 |
*/ |
| 1949 |
dobjFor(Strike) asDobjFor(Attack) |
| 1950 |
; |
| 1951 |
|
| 1952 |
/* ------------------------------------------------------------------------ */ |
| 1953 |
/* |
| 1954 |
* An object that uses the same name as another object. This maps all of |
| 1955 |
* the properties involved in supplying the object's name, number, and |
| 1956 |
* other usage information from this object to a given target object, so |
| 1957 |
* that all messages involving this object use the same name as the |
| 1958 |
* target object. This is a mix-in class that can be used with any other |
| 1959 |
* class. |
| 1960 |
* |
| 1961 |
* Note that we map only the *reported* name for the object. We do NOT |
| 1962 |
* give this object any vocabulary from the other object; in other words, |
| 1963 |
* we don't enter this object into the dictionary with the other object's |
| 1964 |
* vocabulary words. |
| 1965 |
*/ |
| 1966 |
class NameAsOther: object |
| 1967 |
/* the target object - we'll use the same name as this object */ |
| 1968 |
targetObj = nil |
| 1969 |
|
| 1970 |
/* map our naming and usage properties to the target object */ |
| 1971 |
isPlural = (targetObj.isPlural) |
| 1972 |
isMassNoun = (targetObj.isMassNoun) |
| 1973 |
isHim = (targetObj.isHim) |
| 1974 |
isHer = (targetObj.isHer) |
| 1975 |
isIt = (targetObj.isIt) |
| 1976 |
isProperName = (targetObj.isProperName) |
| 1977 |
isQualifiedName = (targetObj.isQualifiedName) |
| 1978 |
name = (targetObj.name) |
| 1979 |
|
| 1980 |
/* map the derived name properties as well, in case any are overridden */ |
| 1981 |
disambigName = (targetObj.disambigName) |
| 1982 |
theDisambigName = (targetObj.theDisambigName) |
| 1983 |
aDisambigName = (targetObj.aDisambigName) |
| 1984 |
countDisambigName(cnt) { return targetObj.countDisambigName(cnt); } |
| 1985 |
disambigEquivName = (targetObj.disambigEquivName) |
| 1986 |
listName = (targetObj.listName) |
| 1987 |
countName(cnt) { return targetObj.countName(cnt); } |
| 1988 |
|
| 1989 |
/* map the pronoun properites, in case any are overridden */ |
| 1990 |
itNom = (targetObj.itNom) |
| 1991 |
itObj = (targetObj.itObj) |
| 1992 |
itPossAdj = (targetObj.itPossAdj) |
| 1993 |
itPossNoun = (targetObj.itPossNoun) |
| 1994 |
itReflexive = (targetObj.itReflexive) |
| 1995 |
thatNom = (targetObj.thatNom) |
| 1996 |
thatObj = (targetObj.thatObj) |
| 1997 |
thatIsContraction = (targetObj.thatIsContraction) |
| 1998 |
itIs = (targetObj.itIs) |
| 1999 |
itIsContraction = (targetObj.itIsContraction) |
| 2000 |
itVerb(verb) { return targetObj.itVerb(verb); } |
| 2001 |
conjugateRegularVerb(verb) |
| 2002 |
{ return targetObj.conjugateRegularVerb(verb); } |
| 2003 |
theName = (targetObj.theName) |
| 2004 |
theNameObj = (targetObj.theNameObj) |
| 2005 |
theNamePossAdj = (targetObj.theNamePossAdj) |
| 2006 |
theNamePossNoun = (targetObj.theNamePossNoun) |
| 2007 |
theNameWithOwner = (targetObj.theNameWithOwner) |
| 2008 |
aNameOwnerLoc(ownerPri) |
| 2009 |
{ return targetObj.aNameOwnerLoc(ownerPri); } |
| 2010 |
theNameOwnerLoc(ownerPri) |
| 2011 |
{ return targetObj.theNameOwnerLoc(ownerPri); } |
| 2012 |
countNameOwnerLoc(cnt, ownerPri) |
| 2013 |
{ return targetObj.countNameOwnerLoc(cnt, ownerPri); } |
| 2014 |
notePromptByOwnerLoc(ownerPri) |
| 2015 |
{ targetObj.notePromptByOwnerLoc(ownerPri); } |
| 2016 |
notePromptByPossAdj() |
| 2017 |
{ targetObj.notePromptByPossAdj(); } |
| 2018 |
aName = (targetObj.aName) |
| 2019 |
aNameObj = (targetObj.aNameObj) |
| 2020 |
pluralName = (targetObj.pluralName) |
| 2021 |
nameIs = (targetObj.nameIs) |
| 2022 |
nameIsnt = (targetObj.nameIsnt) |
| 2023 |
nameVerb(verb) { return targetObj.nameVerb(verb); } |
| 2024 |
verbToBe = (targetObj.verbToBe) |
| 2025 |
verbWas = (targetObj.verbWas) |
| 2026 |
verbToHave = (targetObj.verbToHave) |
| 2027 |
verbToDo = (targetObj.verbToDo) |
| 2028 |
nameDoes = (targetObj.nameDoes) |
| 2029 |
verbToGo = (targetObj.verbToGo) |
| 2030 |
verbToCome = (targetObj.verbToCome) |
| 2031 |
verbToLeave = (targetObj.verbToLeave) |
| 2032 |
verbToSee = (targetObj.verbToSee) |
| 2033 |
nameSees = (targetObj.nameSees) |
| 2034 |
verbToSay = (targetObj.verbToSay) |
| 2035 |
nameSays = (targetObj.nameSays) |
| 2036 |
verbMust = (targetObj.verbMust) |
| 2037 |
verbCan = (targetObj.verbCan) |
| 2038 |
verbCannot = (targetObj.verbCannot) |
| 2039 |
verbCant = (targetObj.verbCant) |
| 2040 |
verbWill = (targetObj.verbWill) |
| 2041 |
verbWont = (targetObj.verbWont) |
| 2042 |
|
| 2043 |
verbEndingS = (targetObj.verbEndingS) |
| 2044 |
verbEndingSD = (targetObj.verbEndingSD) |
| 2045 |
verbEndingSEd = (targetObj.verbEndingSEd) |
| 2046 |
verbEndingEs = (targetObj.verbEndingEs) |
| 2047 |
verbEndingIes = (targetObj.verbEndingIes) |
| 2048 |
; |
| 2049 |
|
| 2050 |
/* |
| 2051 |
* Name as Parent - this is a special case of NameAsOther that uses the |
| 2052 |
* lexical parent of a nested object as the target object. (The lexical |
| 2053 |
* parent is the enclosing object in a nested object definition; in other |
| 2054 |
* words, it's the object in which the nested object is embedded.) |
| 2055 |
*/ |
| 2056 |
class NameAsParent: NameAsOther |
| 2057 |
targetObj = (lexicalParent) |
| 2058 |
; |
| 2059 |
|
| 2060 |
/* |
| 2061 |
* ChildNameAsOther is a mix-in class that can be used with NameAsOther |
| 2062 |
* to add the various childInXxx naming to the mapped properties. The |
| 2063 |
* childInXxx names are the names generated when another object is |
| 2064 |
* described as located within this object; by mapping these properties |
| 2065 |
* to our target object, we ensure that we use exactly the same phrasing |
| 2066 |
* as we would if the contained object were actually contained by our |
| 2067 |
* target rather than by us. |
| 2068 |
* |
| 2069 |
* Note that this should always be used in combination with NameAsOther: |
| 2070 |
* |
| 2071 |
* myObj: NameAsOther, ChildNameAsOther, Thing ... |
| 2072 |
* |
| 2073 |
* You can also use it the same way in combination with a subclass of |
| 2074 |
* NameAsOther, such as NameAsParent. |
| 2075 |
*/ |
| 2076 |
class ChildNameAsOther: object |
| 2077 |
objInPrep = (targetObj.objInPrep) |
| 2078 |
actorInPrep = (targetObj.actorInPrep) |
| 2079 |
actorOutOfPrep = (targetObj.actorOutOfPrep) |
| 2080 |
actorIntoPrep = (targetObj.actorIntoPrep) |
| 2081 |
childInName(childName) { return targetObj.childInName(childName); } |
| 2082 |
childInNameWithOwner(childName) |
| 2083 |
{ return targetObj.childInNameWithOwner(childName); } |
| 2084 |
childInNameGen(childName, myName) |
| 2085 |
{ return targetObj.childInNameGen(childName, myName); } |
| 2086 |
actorInName = (targetObj.actorInName) |
| 2087 |
actorOutOfName = (targetObj.actorOutOfName) |
| 2088 |
actorIntoName = (targetObj.actorIntoName) |
| 2089 |
actorInAName = (targetObj.actorInAName) |
| 2090 |
; |
| 2091 |
|
| 2092 |
|
| 2093 |
/* ------------------------------------------------------------------------ */ |
| 2094 |
/* |
| 2095 |
* Language modifications for the specialized container types |
| 2096 |
*/ |
| 2097 |
modify Surface |
| 2098 |
/* |
| 2099 |
* objects contained in a Surface are described as being on the |
| 2100 |
* Surface |
| 2101 |
*/ |
| 2102 |
objInPrep = 'on' |
| 2103 |
actorInPrep = 'on' |
| 2104 |
actorOutOfPrep = 'off of' |
| 2105 |
; |
| 2106 |
|
| 2107 |
modify Underside |
| 2108 |
objInPrep = 'under' |
| 2109 |
actorInPrep = 'under' |
| 2110 |
actorOutOfPrep = 'from under' |
| 2111 |
; |
| 2112 |
|
| 2113 |
modify RearContainer |
| 2114 |
objInPrep = 'behind' |
| 2115 |
actorInPrep = 'behind' |
| 2116 |
actorOutOfPrep = 'from behind' |
| 2117 |
; |
| 2118 |
|
| 2119 |
/* ------------------------------------------------------------------------ */ |
| 2120 |
/* |
| 2121 |
* Language modifications for Actor. |
| 2122 |
* |
| 2123 |
* An Actor has a "referral person" setting, which determines how we |
| 2124 |
* refer to the actor; this is almost exclusively for the use of the |
| 2125 |
* player character. The typical convention is that we refer to the |
| 2126 |
* player character in the second person, but a game can override this on |
| 2127 |
* an actor-by-actor basis. |
| 2128 |
*/ |
| 2129 |
modify Actor |
| 2130 |
/* by default, use my pronoun for my name */ |
| 2131 |
name = (itNom) |
| 2132 |
|
| 2133 |
/* |
| 2134 |
* Pronoun selector. This returns an index for selecting pronouns |
| 2135 |
* or other words based on number and gender, taking into account |
| 2136 |
* person, number, and gender. The value returned is the sum of the |
| 2137 |
* following components: |
| 2138 |
* |
| 2139 |
* number/gender: |
| 2140 |
*. - singular neuter = 1 |
| 2141 |
*. - singular masculine = 2 |
| 2142 |
*. - singular feminine = 3 |
| 2143 |
*. - plural = 4 |
| 2144 |
* |
| 2145 |
* person: |
| 2146 |
*. - first person = 0 |
| 2147 |
*. - second person = 4 |
| 2148 |
*. - third person = 8 |
| 2149 |
* |
| 2150 |
* The result can be used as a list selector as follows (1=first |
| 2151 |
* person, etc; s=singular, p=plural; n=neuter, m=masculine, |
| 2152 |
* f=feminine): |
| 2153 |
* |
| 2154 |
* [1/s/n, 1/s/m, 1/s/f, 1/p, 2/s/n, 2/s/m, 2/s/f, 2/p, |
| 2155 |
*. 3/s/n, 3/s/m, 3/s/f, 3/p] |
| 2156 |
*/ |
| 2157 |
pronounSelector |
| 2158 |
{ |
| 2159 |
return ((referralPerson - FirstPerson)*4 |
| 2160 |
+ (isPlural ? 4 : isHim ? 2 : isHer ? 3 : 1)); |
| 2161 |
} |
| 2162 |
|
| 2163 |
/* |
| 2164 |
* get the verb form selector index for the person and number: |
| 2165 |
* |
| 2166 |
* [1/s, 2/s, 3/s, 1/p, 2/p, 3/p] |
| 2167 |
*/ |
| 2168 |
conjugationSelector |
| 2169 |
{ |
| 2170 |
return (referralPerson + (isPlural ? 3 : 0)); |
| 2171 |
} |
| 2172 |
|
| 2173 |
/* |
| 2174 |
* get an appropriate pronoun for the object in the appropriate |
| 2175 |
* person for the nominative case, objective case, possessive |
| 2176 |
* adjective, possessive noun, and objective reflexive |
| 2177 |
*/ |
| 2178 |
itNom |
| 2179 |
{ |
| 2180 |
return ['I', 'I', 'I', 'we', |
| 2181 |
'you', 'you', 'you', 'you', |
| 2182 |
'it', 'he', 'she', 'they'][pronounSelector]; |
| 2183 |
} |
| 2184 |
itObj |
| 2185 |
{ |
| 2186 |
return ['me', 'me', 'me', 'us', |
| 2187 |
'you', 'you', 'you', 'you', |
| 2188 |
'it', 'him', 'her', 'them'][pronounSelector]; |
| 2189 |
} |
| 2190 |
itPossAdj |
| 2191 |
{ |
| 2192 |
return ['my', 'my', 'my', 'our', |
| 2193 |
'your', 'your', 'your', 'your', |
| 2194 |
'its', 'his', 'her', 'their'][pronounSelector]; |
| 2195 |
} |
| 2196 |
itPossNoun |
| 2197 |
{ |
| 2198 |
return ['mine', 'mine', 'mine', 'ours', |
| 2199 |
'yours', 'yours', 'yours', 'yours', |
| 2200 |
'its', 'his', 'hers', 'theirs'][pronounSelector]; |
| 2201 |
} |
| 2202 |
itReflexive |
| 2203 |
{ |
| 2204 |
return ['myself', 'myself', 'myself', 'ourselves', |
| 2205 |
'yourself', 'yourself', 'yourself', 'yourselves', |
| 2206 |
'itself', 'himself', 'herself', 'themselves'][pronounSelector]; |
| 2207 |
} |
| 2208 |
|
| 2209 |
/* |
| 2210 |
* Demonstrative pronoun, nominative case. We'll use personal a |
| 2211 |
* personal pronoun if we have a gender or we're in the first or |
| 2212 |
* second person, otherwise we'll use 'that' or 'those' as we would |
| 2213 |
* for an inanimate object. |
| 2214 |
*/ |
| 2215 |
thatNom |
| 2216 |
{ |
| 2217 |
return ['I', 'I', 'I', 'we', |
| 2218 |
'you', 'you', 'you', 'you', |
| 2219 |
'that', 'he', 'she', 'those'][pronounSelector]; |
| 2220 |
} |
| 2221 |
|
| 2222 |
/* demonstrative pronoun, objective case */ |
| 2223 |
thatObj |
| 2224 |
{ |
| 2225 |
return ['me', 'me', 'me', 'us', |
| 2226 |
'you', 'you', 'you', 'you', |
| 2227 |
'that', 'him', 'her', 'those'][pronounSelector]; |
| 2228 |
} |
| 2229 |
|
| 2230 |
/* demonstrative pronoun, nominative case with 'is' contraction */ |
| 2231 |
thatIsContraction |
| 2232 |
{ |
| 2233 |
return thatNom |
| 2234 |
+ tSel(['’m', '’re', '’s', |
| 2235 |
'’re', '’re', ' are'][conjugationSelector], |
| 2236 |
' ' + verbToBe); |
| 2237 |
} |
| 2238 |
|
| 2239 |
/* |
| 2240 |
* We don't need to override itIs: the base class handling works for |
| 2241 |
* actors too. |
| 2242 |
*/ |
| 2243 |
|
| 2244 |
/* get my pronoun with a being verb contraction ("the box's") */ |
| 2245 |
itIsContraction |
| 2246 |
{ |
| 2247 |
return itNom + tSel( |
| 2248 |
'’' |
| 2249 |
+ ['m', 're', 's', 're', 're', 're'][conjugationSelector], |
| 2250 |
' ' + verbToBe); |
| 2251 |
} |
| 2252 |
|
| 2253 |
/* |
| 2254 |
* Conjugate a regular verb in the present or past tense for our |
| 2255 |
* person and number. |
| 2256 |
* |
| 2257 |
* In the present tense, this is pretty easy: we add an 's' for the |
| 2258 |
* third person singular, and leave the verb unchanged for every |
| 2259 |
* other case. The only complication is that we must check some |
| 2260 |
* special cases to add the -s suffix: -y -> -ies, -o -> -oes. |
| 2261 |
* |
| 2262 |
* In the past tense, we use the inherited handling since the past |
| 2263 |
* tense ending doesn't vary with person. |
| 2264 |
*/ |
| 2265 |
conjugateRegularVerb(verb) |
| 2266 |
{ |
| 2267 |
/* |
| 2268 |
* If we're in the third person or if we use the past tense, |
| 2269 |
* inherit the default handling; otherwise, use the base verb |
| 2270 |
* form regardless of number (regular verbs use the same |
| 2271 |
* conjugated forms for every case but third person singular: I |
| 2272 |
* ask, you ask, we ask, they ask). |
| 2273 |
*/ |
| 2274 |
if (referralPerson != ThirdPerson && !gameMain.usePastTense) |
| 2275 |
{ |
| 2276 |
/* |
| 2277 |
* we're not using the third-person or the past tense, so the |
| 2278 |
* conjugation is the same as the base verb form |
| 2279 |
*/ |
| 2280 |
return verb; |
| 2281 |
} |
| 2282 |
else |
| 2283 |
{ |
| 2284 |
/* |
| 2285 |
* we're using the third person or the past tense, so inherit |
| 2286 |
* the base class handling, which conjugates these forms |
| 2287 |
*/ |
| 2288 |
return inherited(verb); |
| 2289 |
} |
| 2290 |
} |
| 2291 |
|
| 2292 |
/* |
| 2293 |
* Get the name with a definite article ("the box"). If the |
| 2294 |
* narrator refers to us in the first or second person, use a |
| 2295 |
* pronoun rather than the short description. |
| 2296 |
*/ |
| 2297 |
theName |
| 2298 |
{ return (referralPerson == ThirdPerson ? inherited : itNom); } |
| 2299 |
|
| 2300 |
/* theName in objective case */ |
| 2301 |
theNameObj |
| 2302 |
{ return (referralPerson == ThirdPerson ? inherited : itObj); } |
| 2303 |
|
| 2304 |
/* theName as a possessive adjective */ |
| 2305 |
theNamePossAdj |
| 2306 |
{ return (referralPerson == ThirdPerson ? inherited : itPossAdj); } |
| 2307 |
|
| 2308 |
/* theName as a possessive noun */ |
| 2309 |
theNamePossNoun |
| 2310 |
{ return (referralPerson == ThirdPerson ? inherited : itPossNoun); } |
| 2311 |
|
| 2312 |
/* |
| 2313 |
* Get the name with an indefinite article. Use the same rules of |
| 2314 |
* referral person as for definite articles. |
| 2315 |
*/ |
| 2316 |
aName { return (referralPerson == ThirdPerson ? inherited : itNom); } |
| 2317 |
|
| 2318 |
/* aName in objective case */ |
| 2319 |
aNameObj { return (referralPerson == ThirdPerson ? inherited : itObj); } |
| 2320 |
|
| 2321 |
/* being verb agreeing with this object as subject */ |
| 2322 |
verbToBe |
| 2323 |
{ |
| 2324 |
return tSel(['am', 'are', 'is', 'are', 'are', 'are'], |
| 2325 |
['was', 'were', 'was', 'were', 'were', 'were']) |
| 2326 |
[conjugationSelector]; |
| 2327 |
} |
| 2328 |
|
| 2329 |
/* past tense being verb agreeing with this object as subject */ |
| 2330 |
verbWas |
| 2331 |
{ |
| 2332 |
return tSel(['was', 'were', 'was', 'were', 'were', 'were'] |
| 2333 |
[conjugationSelector], 'had been'); |
| 2334 |
} |
| 2335 |
|
| 2336 |
/* 'have' verb agreeing with this object as subject */ |
| 2337 |
verbToHave |
| 2338 |
{ |
| 2339 |
return tSel(['have', 'have', 'has', 'have', 'have', 'have'] |
| 2340 |
[conjugationSelector], 'had'); |
| 2341 |
} |
| 2342 |
|
| 2343 |
/* |
| 2344 |
* verb endings for regular '-s' and '-es' verbs, agreeing with this |
| 2345 |
* object as the subject |
| 2346 |
*/ |
| 2347 |
verbEndingS |
| 2348 |
{ |
| 2349 |
return ['', '', 's', '', '', ''][conjugationSelector]; |
| 2350 |
} |
| 2351 |
verbEndingEs |
| 2352 |
{ |
| 2353 |
return tSel(['', '', 'es', '', '', ''][conjugationSelector], 'ed'); |
| 2354 |
} |
| 2355 |
verbEndingIes |
| 2356 |
{ |
| 2357 |
return tSel(['y', 'y', 'ies', 'y', 'y', 'y'][conjugationSelector], |
| 2358 |
'ied'); |
| 2359 |
} |
| 2360 |
|
| 2361 |
/* "I'm not" doesn't fit the regular "+n't" rule */ |
| 2362 |
nameIsnt |
| 2363 |
{ |
| 2364 |
return conjugationSelector == 1 && !gameMain.usePastTense |
| 2365 |
? 'I’m not' : inherited; |
| 2366 |
} |
| 2367 |
|
| 2368 |
/* |
| 2369 |
* Show my name for an arrival/departure message. If we've been seen |
| 2370 |
* before by the player character, we'll show our definite name, |
| 2371 |
* otherwise our indefinite name. |
| 2372 |
*/ |
| 2373 |
travelerName(arriving) |
| 2374 |
{ say(gPlayerChar.hasSeen(self) ? theName : aName); } |
| 2375 |
|
| 2376 |
/* |
| 2377 |
* Test to see if we can match the third-person pronouns. We'll |
| 2378 |
* match these if our inherited test says we match them AND we can |
| 2379 |
* be referred to in the third person. |
| 2380 |
*/ |
| 2381 |
canMatchHim = (inherited && canMatch3rdPerson) |
| 2382 |
canMatchHer = (inherited && canMatch3rdPerson) |
| 2383 |
canMatchIt = (inherited && canMatch3rdPerson) |
| 2384 |
canMatchThem = (inherited && canMatch3rdPerson) |
| 2385 |
|
| 2386 |
/* |
| 2387 |
* Test to see if we can match a third-person pronoun ('it', 'him', |
| 2388 |
* 'her', 'them'). We can unless we're the player character and the |
| 2389 |
* player character is referred to in the first or second person. |
| 2390 |
*/ |
| 2391 |
canMatch3rdPerson = (!isPlayerChar || referralPerson == ThirdPerson) |
| 2392 |
|
| 2393 |
/* |
| 2394 |
* Set a pronoun antecedent to the given list of ResolveInfo objects. |
| 2395 |
* Pronoun handling is language-specific, so this implementation is |
| 2396 |
* part of the English library, not the generic library. |
| 2397 |
* |
| 2398 |
* If only one object is present, we'll set the object to be the |
| 2399 |
* antecedent of 'it', 'him', or 'her', according to the object's |
| 2400 |
* gender. We'll also set the object as the single antecedent for |
| 2401 |
* 'them'. |
| 2402 |
* |
| 2403 |
* If we have multiple objects present, we'll set the list to be the |
| 2404 |
* antecedent of 'them', and we'll forget about any antecedent for |
| 2405 |
* 'it'. |
| 2406 |
* |
| 2407 |
* Note that the input is a list of ResolveInfo objects, so we must |
| 2408 |
* pull out the underlying game objects when setting the antecedents. |
| 2409 |
*/ |
| 2410 |
setPronoun(lst) |
| 2411 |
{ |
| 2412 |
/* if the list is empty, ignore it */ |
| 2413 |
if (lst == []) |
| 2414 |
return; |
| 2415 |
|
| 2416 |
/* |
| 2417 |
* if we have multiple objects, the entire list is the antecedent |
| 2418 |
* for 'them'; otherwise, it's a singular antecedent which |
| 2419 |
* depends on its gender |
| 2420 |
*/ |
| 2421 |
if (lst.length() > 1) |
| 2422 |
{ |
| 2423 |
local objs = lst.mapAll({x: x.obj_}); |
| 2424 |
|
| 2425 |
/* it's 'them' */ |
| 2426 |
setThem(objs); |
| 2427 |
|
| 2428 |
/* forget any 'it' */ |
| 2429 |
setIt(nil); |
| 2430 |
} |
| 2431 |
else if (lst.length() == 1) |
| 2432 |
{ |
| 2433 |
/* |
| 2434 |
* We have only one object, so set it as an antecedent |
| 2435 |
* according to its gender. |
| 2436 |
*/ |
| 2437 |
setPronounObj(lst[1].obj_); |
| 2438 |
} |
| 2439 |
} |
| 2440 |
|
| 2441 |
/* |
| 2442 |
* Set a pronoun to refer to multiple potential antecedents. This is |
| 2443 |
* used when the verb has multiple noun slots - UNLOCK DOOR WITH KEY. |
| 2444 |
* For verbs like this, we have no way of knowing in advance whether |
| 2445 |
* a future pronoun will refer back to the direct object or the |
| 2446 |
* indirect object (etc) - we could just assume that 'it' will refer |
| 2447 |
* to the direct object, but this won't always be what the player |
| 2448 |
* intended. In natural English, pronoun antecedents must often be |
| 2449 |
* inferred from context at the time of use - so we use the same |
| 2450 |
* approach. |
| 2451 |
* |
| 2452 |
* Pass an argument list consisting of ResolveInfo lists - that is, |
| 2453 |
* pass one argument per noun slot in the verb, and make each |
| 2454 |
* argument a list of ResolveInfo objects. In other words, you call |
| 2455 |
* this just as you would setPronoun(), except you can pass more than |
| 2456 |
* one list argument. |
| 2457 |
* |
| 2458 |
* We'll store the multiple objects as antecedents. When we need to |
| 2459 |
* resolve a future singular pronoun, we'll figure out which of the |
| 2460 |
* multiple antecedents is the most logical choice in the context of |
| 2461 |
* the pronoun's usage. |
| 2462 |
*/ |
| 2463 |
setPronounMulti([args]) |
| 2464 |
{ |
| 2465 |
local lst, subLst; |
| 2466 |
local gotThem; |
| 2467 |
|
| 2468 |
/* |
| 2469 |
* If there's a plural list, it's 'them'. Arbitrarily use only |
| 2470 |
* the first plural list if there's more than one. |
| 2471 |
*/ |
| 2472 |
if ((lst = args.valWhich({x: x.length() > 1})) != nil) |
| 2473 |
{ |
| 2474 |
/* set 'them' to the plural list */ |
| 2475 |
setPronoun(lst); |
| 2476 |
|
| 2477 |
/* note that we had a clear 'them' */ |
| 2478 |
gotThem = true; |
| 2479 |
} |
| 2480 |
|
| 2481 |
/* from now on, consider only the sublists with exactly one item */ |
| 2482 |
args = args.subset({x: x.length() == 1}); |
| 2483 |
|
| 2484 |
/* get a list of the singular items from the lists */ |
| 2485 |
lst = args.mapAll({x: x[1].obj_}); |
| 2486 |
|
| 2487 |
/* |
| 2488 |
* Set 'it' to all of the items that can match 'it'; do likewise |
| 2489 |
* with 'him' and 'her'. If there are no objects that can match |
| 2490 |
* a given pronoun, leave that pronoun unchanged. |
| 2491 |
*/ |
| 2492 |
if ((subLst = lst.subset({x: x.canMatchIt})).length() > 0) |
| 2493 |
setIt(subLst); |
| 2494 |
if ((subLst = lst.subset({x: x.canMatchHim})).length() > 0) |
| 2495 |
setHim(subLst); |
| 2496 |
if ((subLst = lst.subset({x: x.canMatchHer})).length() > 0) |
| 2497 |
setHer(subLst); |
| 2498 |
|
| 2499 |
/* |
| 2500 |
* set 'them' to the potential 'them' matches, if we didn't |
| 2501 |
* already find a clear plural list |
| 2502 |
*/ |
| 2503 |
if (!gotThem |
| 2504 |
&& (subLst = lst.subset({x: x.canMatchThem})).length() > 0) |
| 2505 |
setThem(subLst); |
| 2506 |
} |
| 2507 |
|
| 2508 |
/* |
| 2509 |
* Set a pronoun antecedent to the given ResolveInfo list, for the |
| 2510 |
* specified type of pronoun. We don't have to worry about setting |
| 2511 |
* other types of pronouns to this antecedent - we specifically want |
| 2512 |
* to set the given pronoun type. This is language-dependent |
| 2513 |
* because we still have to figure out the number (i.e. singular or |
| 2514 |
* plural) of the pronoun type. |
| 2515 |
*/ |
| 2516 |
setPronounByType(typ, lst) |
| 2517 |
{ |
| 2518 |
/* check for singular or plural pronouns */ |
| 2519 |
if (typ == PronounThem) |
| 2520 |
{ |
| 2521 |
/* it's plural - set a list antecedent */ |
| 2522 |
setPronounAntecedent(typ, lst.mapAll({x: x.obj_})); |
| 2523 |
} |
| 2524 |
else |
| 2525 |
{ |
| 2526 |
/* it's singular - set an individual antecedent */ |
| 2527 |
setPronounAntecedent(typ, lst[1].obj_); |
| 2528 |
} |
| 2529 |
} |
| 2530 |
|
| 2531 |
/* |
| 2532 |
* Set a pronoun antecedent to the given simulation object (usually |
| 2533 |
* an object descended from Thing). |
| 2534 |
*/ |
| 2535 |
setPronounObj(obj) |
| 2536 |
{ |
| 2537 |
/* |
| 2538 |
* Actually use the object's "identity object" as the antecedent |
| 2539 |
* rather than the object itself. In some cases, we use multiple |
| 2540 |
* program objects to represent what appears to be a single |
| 2541 |
* object in the game; in these cases, the internal program |
| 2542 |
* objects all point to the "real" object as their identity |
| 2543 |
* object. Whenever we're manipulating one of these internal |
| 2544 |
* program objects, we want to make sure that its the |
| 2545 |
* player-visible object - the identity object - that appears as |
| 2546 |
* the antecedent for subsequent references. |
| 2547 |
*/ |
| 2548 |
obj = obj.getIdentityObject(); |
| 2549 |
|
| 2550 |
/* |
| 2551 |
* Set the appropriate pronoun antecedent, depending on the |
| 2552 |
* object's gender. |
| 2553 |
* |
| 2554 |
* Note that we'll set an object to be the antecedent for both |
| 2555 |
* 'him' and 'her' if the object has both masculine and feminine |
| 2556 |
* usage. |
| 2557 |
*/ |
| 2558 |
|
| 2559 |
/* check for masculine usage */ |
| 2560 |
if (obj.canMatchHim) |
| 2561 |
setHim(obj); |
| 2562 |
|
| 2563 |
/* check for feminine usage */ |
| 2564 |
if (obj.canMatchHer) |
| 2565 |
setHer(obj); |
| 2566 |
|
| 2567 |
/* check for neuter usage */ |
| 2568 |
if (obj.canMatchIt) |
| 2569 |
setIt(obj); |
| 2570 |
|
| 2571 |
/* check for third-person plural usage */ |
| 2572 |
if (obj.canMatchThem) |
| 2573 |
setThem([obj]); |
| 2574 |
} |
| 2575 |
|
| 2576 |
/* set a possessive anaphor */ |
| 2577 |
setPossAnaphorObj(obj) |
| 2578 |
{ |
| 2579 |
/* check for each type of usage */ |
| 2580 |
if (obj.canMatchHim) |
| 2581 |
possAnaphorTable[PronounHim] = obj; |
| 2582 |
if (obj.canMatchHer) |
| 2583 |
possAnaphorTable[PronounHer] = obj; |
| 2584 |
if (obj.canMatchIt) |
| 2585 |
possAnaphorTable[PronounIt] = obj; |
| 2586 |
if (obj.canMatchThem) |
| 2587 |
possAnaphorTable[PronounThem] = [obj]; |
| 2588 |
} |
| 2589 |
; |
| 2590 |
|
| 2591 |
/* ------------------------------------------------------------------------ */ |
| 2592 |
/* |
| 2593 |
* Give the postures some additional attributes |
| 2594 |
*/ |
| 2595 |
|
| 2596 |
modify Posture |
| 2597 |
|
| 2598 |
/* |
| 2599 |
* Intransitive and transitive forms of the verb, for use in library |
| 2600 |
* messages. Each of these methods simply calls one of the two |
| 2601 |
* corresponding fixed-tense properties, depending on the current |
| 2602 |
* tense. |
| 2603 |
*/ |
| 2604 |
msgVerbI = (tSel(msgVerbIPresent, msgVerbIPast)) |
| 2605 |
msgVerbT = (tSel(msgVerbTPresent, msgVerbTPast)) |
| 2606 |
|
| 2607 |
/* |
| 2608 |
* Fixed-tense versions of the above properties, to be defined |
| 2609 |
* individually by each instance of the Posture class. |
| 2610 |
*/ |
| 2611 |
|
| 2612 |
/* our present-tense intransitive form ("he stands up") */ |
| 2613 |
// msgVerbIPresent = 'stand{s} up' |
| 2614 |
|
| 2615 |
/* our past-tense intransitive form ("he stood up") */ |
| 2616 |
// msgVerbIPast = 'stood up' |
| 2617 |
|
| 2618 |
/* our present-tense transitive form ("he stands on the chair") */ |
| 2619 |
// msgVerbTPresent = 'stand{s}' |
| 2620 |
|
| 2621 |
/* our past-tense transitive form ("he stood on the chair") */ |
| 2622 |
// msgVerbTPast = 'stood' |
| 2623 |
|
| 2624 |
/* our participle form */ |
| 2625 |
// participle = 'standing' |
| 2626 |
; |
| 2627 |
|
| 2628 |
modify standing |
| 2629 |
msgVerbIPresent = 'stand{s} up' |
| 2630 |
msgVerbIPast = 'stood up' |
| 2631 |
msgVerbTPresent = 'stand{s}' |
| 2632 |
msgVerbTPast = 'stood' |
| 2633 |
participle = 'standing' |
| 2634 |
; |
| 2635 |
|
| 2636 |
modify sitting |
| 2637 |
msgVerbIPresent = 'sit{s} down' |
| 2638 |
msgVerbIPast = 'sat down' |
| 2639 |
msgVerbTPresent = 'sit{s}' |
| 2640 |
msgVerbTPast = 'sat' |
| 2641 |
participle = 'sitting' |
| 2642 |
; |
| 2643 |
|
| 2644 |
modify lying |
| 2645 |
msgVerbIPresent = 'lie{s} down' |
| 2646 |
msgVerbIPast = 'lay down' |
| 2647 |
msgVerbTPresent = 'lie{s}' |
| 2648 |
msgVerbTPast = 'lay' |
| 2649 |
participle = 'lying' |
| 2650 |
; |
| 2651 |
|
| 2652 |
/* ------------------------------------------------------------------------ */ |
| 2653 |
/* |
| 2654 |
* For our various topic suggestion types, we can infer the full name |
| 2655 |
* from the short name fairly easily. |
| 2656 |
*/ |
| 2657 |
modify SuggestedAskTopic |
| 2658 |
fullName = ('ask {it targetActor/him} about ' + name) |
| 2659 |
; |
| 2660 |
|
| 2661 |
modify SuggestedTellTopic |
| 2662 |
fullName = ('tell {it targetActor/him} about ' + name) |
| 2663 |
; |
| 2664 |
|
| 2665 |
modify SuggestedAskForTopic |
| 2666 |
fullName = ('ask {it targetActor/him} for ' + name) |
| 2667 |
; |
| 2668 |
|
| 2669 |
modify SuggestedGiveTopic |
| 2670 |
fullName = ('give {it targetActor/him} ' + name) |
| 2671 |
; |
| 2672 |
|
| 2673 |
modify SuggestedShowTopic |
| 2674 |
fullName = ('show {it targetActor/him} ' + name) |
| 2675 |
; |
| 2676 |
|
| 2677 |
modify SuggestedYesTopic |
| 2678 |
name = 'yes' |
| 2679 |
fullName = 'say yes' |
| 2680 |
; |
| 2681 |
|
| 2682 |
modify SuggestedNoTopic |
| 2683 |
name = 'no' |
| 2684 |
fullName = 'say no' |
| 2685 |
; |
| 2686 |
|
| 2687 |
/* ------------------------------------------------------------------------ */ |
| 2688 |
/* |
| 2689 |
* Provide custom processing of the player input for matching |
| 2690 |
* SpecialTopic patterns. When we're trying to match a player's command |
| 2691 |
* to a set of active special topics, we'll run the input through this |
| 2692 |
* processing to produce the string that we actually match against the |
| 2693 |
* special topics. |
| 2694 |
* |
| 2695 |
* First, we'll remove any punctuation marks. This ensures that we'll |
| 2696 |
* still match a special topic, for example, if the player puts a period |
| 2697 |
* or a question mark at the end of the command. |
| 2698 |
* |
| 2699 |
* Second, if the user's input starts with "A" or "T" (the super-short |
| 2700 |
* forms of the ASK ABOUT and TELL ABOUT commands), remove the "A" or "T" |
| 2701 |
* and keep the rest of the input. Some users might think that special |
| 2702 |
* topic suggestions are meant as ask/tell topics, so they might |
| 2703 |
* instinctively try these as A/T commands. |
| 2704 |
* |
| 2705 |
* Users *probably* won't be tempted to do the same thing with the full |
| 2706 |
* forms of the commands (e.g., ASK BOB ABOUT APOLOGIZE, TELL BOB ABOUT |
| 2707 |
* EXPLAIN). It's more a matter of habit of using A or T for interaction |
| 2708 |
* that would tempt a user to phrase a special topic this way; once |
| 2709 |
* you're typing out the full form of the command, it generally won't be |
| 2710 |
* grammatical, as special topics generally contain the sense of a verb |
| 2711 |
* in their phrasing. |
| 2712 |
*/ |
| 2713 |
modify specialTopicPreParser |
| 2714 |
processInputStr(str) |
| 2715 |
{ |
| 2716 |
/* |
| 2717 |
* remove most punctuation from the string - we generally want to |
| 2718 |
* ignore these, as we mostly just want to match keywords |
| 2719 |
*/ |
| 2720 |
str = rexReplace(punctPat, str, '', ReplaceAll); |
| 2721 |
|
| 2722 |
/* if it starts with "A" or "T", strip off the leading verb */ |
| 2723 |
if (rexMatch(aOrTPat, str) != nil) |
| 2724 |
str = rexGroup(1)[3]; |
| 2725 |
|
| 2726 |
/* return the processed result */ |
| 2727 |
return str; |
| 2728 |
} |
| 2729 |
|
| 2730 |
/* pattern for string starting with "A" or "T" verbs */ |
| 2731 |
aOrTPat = static new RexPattern( |
| 2732 |
'<nocase><space>*[at]<space>+(<^space>.*)$') |
| 2733 |
|
| 2734 |
/* pattern to eliminate punctuation marks from the string */ |
| 2735 |
punctPat = static new RexPattern('[.?!,;:]'); |
| 2736 |
; |
| 2737 |
|
| 2738 |
/* |
| 2739 |
* For SpecialTopic matches, treat some strings as "weak": if the user's |
| 2740 |
* input consists of just one of these weak strings and nothing else, |
| 2741 |
* don't match the topic. |
| 2742 |
*/ |
| 2743 |
modify SpecialTopic |
| 2744 |
matchPreParse(str, procStr) |
| 2745 |
{ |
| 2746 |
/* if it's one of our 'weak' strings, don't match */ |
| 2747 |
if (rexMatch(weakPat, str) != nil) |
| 2748 |
return nil; |
| 2749 |
|
| 2750 |
/* it's not a weak string, so match as usual */ |
| 2751 |
return inherited(str, procStr); |
| 2752 |
} |
| 2753 |
|
| 2754 |
/* |
| 2755 |
* Our "weak" strings - 'i', 'l', 'look': these are weak because a |
| 2756 |
* user typing one of these strings by itself is probably actually |
| 2757 |
* trying to enter the command of the same name, rather than entering |
| 2758 |
* a special topic. These come up in cases where the special topic |
| 2759 |
* is something like "say I don't know" or "tell him you'll look into |
| 2760 |
* it". |
| 2761 |
*/ |
| 2762 |
weakPat = static new RexPattern('<nocase><space>*(i|l|look)<space>*$') |
| 2763 |
; |
| 2764 |
|
| 2765 |
/* ------------------------------------------------------------------------ */ |
| 2766 |
/* |
| 2767 |
* English-specific Traveler changes |
| 2768 |
*/ |
| 2769 |
modify Traveler |
| 2770 |
/* |
| 2771 |
* Get my location's name, from the PC's perspective, for describing |
| 2772 |
* my arrival to or departure from my current location. We'll |
| 2773 |
* simply return our location's destName, or "the area" if it |
| 2774 |
* doesn't have one. |
| 2775 |
*/ |
| 2776 |
travelerLocName() |
| 2777 |
{ |
| 2778 |
/* get our location's name from the PC's perspective */ |
| 2779 |
local nm = location.getDestName(gPlayerChar, gPlayerChar.location); |
| 2780 |
|
| 2781 |
/* if there's a name, return it; otherwise, use "the area" */ |
| 2782 |
return (nm != nil ? nm : 'the area'); |
| 2783 |
} |
| 2784 |
|
| 2785 |
/* |
| 2786 |
* Get my "remote" location name, from the PC's perspective. This |
| 2787 |
* returns my location name, but only if my location is remote from |
| 2788 |
* the PC's perspective - that is, my location has to be outside of |
| 2789 |
* the PC's top-level room. If we're within the PC's top-level |
| 2790 |
* room, we'll simply return an empty string. |
| 2791 |
*/ |
| 2792 |
travelerRemoteLocName() |
| 2793 |
{ |
| 2794 |
/* |
| 2795 |
* if my location is outside of the PC's outermost room, we're |
| 2796 |
* remote, so return my location name; otherwise, we're local, |
| 2797 |
* so we don't need a remote name at all |
| 2798 |
*/ |
| 2799 |
if (isIn(gPlayerChar.getOutermostRoom())) |
| 2800 |
return ''; |
| 2801 |
else |
| 2802 |
return travelerLocName; |
| 2803 |
} |
| 2804 |
; |
| 2805 |
|
| 2806 |
/* ------------------------------------------------------------------------ */ |
| 2807 |
/* |
| 2808 |
* English-specific Vehicle changes |
| 2809 |
*/ |
| 2810 |
modify Vehicle |
| 2811 |
/* |
| 2812 |
* Display the name of the traveler, for use in an arrival or |
| 2813 |
* departure message. |
| 2814 |
*/ |
| 2815 |
travelerName(arriving) |
| 2816 |
{ |
| 2817 |
/* |
| 2818 |
* By default, start with the indefinite name if we're arriving, |
| 2819 |
* or the definite name if we're leaving. |
| 2820 |
* |
| 2821 |
* If we're leaving, presumably they've seen us before, since we |
| 2822 |
* were already in the room to start with. Since we've been |
| 2823 |
* seen before, the definite is appropriate. |
| 2824 |
* |
| 2825 |
* If we're arriving, even if we're not being seen for the first |
| 2826 |
* time, we haven't been seen yet in this place around this |
| 2827 |
* time, so the indefinite is appropriate. |
| 2828 |
*/ |
| 2829 |
say(arriving ? aName : theName); |
| 2830 |
|
| 2831 |
/* show the list of actors aboard */ |
| 2832 |
aboardVehicleListerObj.showList( |
| 2833 |
libGlobal.playerChar, nil, allContents(), 0, 0, |
| 2834 |
libGlobal.playerChar.visibleInfoTable(), nil); |
| 2835 |
} |
| 2836 |
; |
| 2837 |
|
| 2838 |
/* ------------------------------------------------------------------------ */ |
| 2839 |
/* |
| 2840 |
* English-specific PushTraveler changes |
| 2841 |
*/ |
| 2842 |
modify PushTraveler |
| 2843 |
/* |
| 2844 |
* When an actor is pushing an object from one room to another, show |
| 2845 |
* its name with an additional clause indicating the object being |
| 2846 |
* moved along with us. |
| 2847 |
*/ |
| 2848 |
travelerName(arriving) |
| 2849 |
{ |
| 2850 |
"<<gPlayerChar.hasSeen(self) ? theName : aName>>, |
| 2851 |
pushing <<obj_.theNameObj>>,"; |
| 2852 |
} |
| 2853 |
; |
| 2854 |
|
| 2855 |
|
| 2856 |
/* ------------------------------------------------------------------------ */ |
| 2857 |
/* |
| 2858 |
* English-specific travel connector changes |
| 2859 |
*/ |
| 2860 |
|
| 2861 |
modify PathPassage |
| 2862 |
/* treat "take path" the same as "enter path" or "go through path" */ |
| 2863 |
dobjFor(Take) maybeRemapTo( |
| 2864 |
gAction.getEnteredVerbPhrase() == 'take (dobj)', TravelVia, self) |
| 2865 |
|
| 2866 |
dobjFor(Enter) |
| 2867 |
{ |
| 2868 |
verify() { logicalRank(50, 'enter path'); } |
| 2869 |
} |
| 2870 |
dobjFor(GoThrough) |
| 2871 |
{ |
| 2872 |
verify() { logicalRank(50, 'enter path'); } |
| 2873 |
} |
| 2874 |
; |
| 2875 |
|
| 2876 |
modify AskConnector |
| 2877 |
/* |
| 2878 |
* This is the noun phrase we'll use when asking disambiguation |
| 2879 |
* questions for this travel connector: "Which *one* do you want to |
| 2880 |
* enter..." |
| 2881 |
*/ |
| 2882 |
travelObjsPhrase = 'one' |
| 2883 |
; |
| 2884 |
|
| 2885 |
/* ------------------------------------------------------------------------ */ |
| 2886 |
/* |
| 2887 |
* English-specific changes for various nested room types. |
| 2888 |
*/ |
| 2889 |
modify BasicChair |
| 2890 |
/* by default, one sits *on* a chair */ |
| 2891 |
objInPrep = 'on' |
| 2892 |
actorInPrep = 'on' |
| 2893 |
actorOutOfPrep = 'off of' |
| 2894 |
; |
| 2895 |
|
| 2896 |
modify BasicPlatform |
| 2897 |
/* by default, one stands *on* a platform */ |
| 2898 |
objInPrep = 'on' |
| 2899 |
actorInPrep = 'on' |
| 2900 |
actorOutOfPrep = 'off of' |
| 2901 |
; |
| 2902 |
|
| 2903 |
modify Booth |
| 2904 |
/* by default, one is *in* a booth */ |
| 2905 |
objInPrep = 'in' |
| 2906 |
actorInPrep = 'in' |
| 2907 |
actorOutOfPrep = 'out of' |
| 2908 |
; |
| 2909 |
|
| 2910 |
/* ------------------------------------------------------------------------ */ |
| 2911 |
/* |
| 2912 |
* Language modifications for Matchstick |
| 2913 |
*/ |
| 2914 |
modify Matchstick |
| 2915 |
/* "strike match" means "light match" */ |
| 2916 |
dobjFor(Strike) asDobjFor(Burn) |
| 2917 |
|
| 2918 |
/* "light match" means "burn match" */ |
| 2919 |
dobjFor(Light) asDobjFor(Burn) |
| 2920 |
; |
| 2921 |
|
| 2922 |
/* |
| 2923 |
* Match state objects. We show "lit" as the state for a lit match, |
| 2924 |
* nothing for an unlit match. |
| 2925 |
*/ |
| 2926 |
matchStateLit: ThingState 'lit' |
| 2927 |
stateTokens = ['lit'] |
| 2928 |
; |
| 2929 |
matchStateUnlit: ThingState |
| 2930 |
stateTokens = ['unlit'] |
| 2931 |
; |
| 2932 |
|
| 2933 |
|
| 2934 |
/* ------------------------------------------------------------------------ */ |
| 2935 |
/* |
| 2936 |
* English-specific modifications for Room. |
| 2937 |
*/ |
| 2938 |
modify Room |
| 2939 |
/* |
| 2940 |
* The ordinary 'name' property is used the same way it's used for |
| 2941 |
* any other object, to refer to the room when it shows up in |
| 2942 |
* library messages and the like: "You can't take the hallway." |
| 2943 |
* |
| 2944 |
* By default, we derive the name from the roomName by converting |
| 2945 |
* the roomName to lower case. Virtually every room will need a |
| 2946 |
* custom room name setting, since the room name is used mostly as a |
| 2947 |
* title for the room, and good titles are hard to generate |
| 2948 |
* mechanically. Many times, converting the roomName to lower case |
| 2949 |
* will produce a decent name to use in messages: "Ice Cave" gives |
| 2950 |
* us "You can't eat the ice cave." However, games will want to |
| 2951 |
* customize the ordinary name separately in many cases, because the |
| 2952 |
* elliptical, title-like format of the room name doesn't always |
| 2953 |
* translate well to an object name: "West of Statue" gives us the |
| 2954 |
* unworkable "You can't eat the west of statue"; better to make the |
| 2955 |
* ordinary name something like "plaza". Note also that some rooms |
| 2956 |
* have proper names that want to preserve their capitalization in |
| 2957 |
* the ordinary name: "You can't eat the Hall of the Ancient Kings." |
| 2958 |
* These cases need to be customized as well. |
| 2959 |
*/ |
| 2960 |
name = (roomName.toLower()) |
| 2961 |
|
| 2962 |
/* |
| 2963 |
* The "destination name" of the room. This is primarily intended |
| 2964 |
* for use in showing exit listings, to describe the destination of |
| 2965 |
* a travel connector leading away from our current location, if the |
| 2966 |
* destination is known to the player character. We also use this |
| 2967 |
* as the default source of the name in similar contexts, such as |
| 2968 |
* when we can see this room from another room connected by a sense |
| 2969 |
* connector. |
| 2970 |
* |
| 2971 |
* The destination name usually mirrors the room name, but we use |
| 2972 |
* the name in prepositional phrases involving the room ("east, to |
| 2973 |
* the alley"), so this name should include a leading article |
| 2974 |
* (usually definite - "the") unless the name is proper ("east, to |
| 2975 |
* Dinsley Plaza"). So, by default, we simply use the "theName" of |
| 2976 |
* the room. In many cases, it's better to specify a custom |
| 2977 |
* destName, because this name is used when the PC is outside of the |
| 2978 |
* room, and thus can benefit from a more detailed description than |
| 2979 |
* we'd normally use for the basic name. For example, the ordinary |
| 2980 |
* name might simply be something like "hallway", but since we want |
| 2981 |
* to be clear about exactly which hallway we're talking about when |
| 2982 |
* we're elsewhere, we might want to use a destName like "the |
| 2983 |
* basement hallway" or "the hallway outside the operating room". |
| 2984 |
*/ |
| 2985 |
destName = (theName) |
| 2986 |
|
| 2987 |
/* |
| 2988 |
* For top-level rooms, describe an object as being in the room by |
| 2989 |
* describing it as being in the room's nominal drop destination, |
| 2990 |
* since that's the nominal location for the objects directly in the |
| 2991 |
* room. (In most cases, the nominal drop destination for a room is |
| 2992 |
* its floor.) |
| 2993 |
* |
| 2994 |
* If the player character isn't in the same outermost room as this |
| 2995 |
* container, use our remote name instead of the nominal drop |
| 2996 |
* destination. The nominal drop destination is usually something |
| 2997 |
* like the floor or the ground, so it's only suitable when we're in |
| 2998 |
* the same location as what we're describing. |
| 2999 |
*/ |
| 3000 |
childInName(childName) |
| 3001 |
{ |
| 3002 |
/* if the PC isn't inside us, we're viewing this remotely */ |
| 3003 |
if (!gPlayerChar.isIn(self)) |
| 3004 |
return childInRemoteName(childName, gPlayerChar); |
| 3005 |
else |
| 3006 |
return getNominalDropDestination().childInName(childName); |
| 3007 |
} |
| 3008 |
childInNameWithOwner(chiName) |
| 3009 |
{ |
| 3010 |
/* if the PC isn't inside us, we're viewing this remotely */ |
| 3011 |
if (!gPlayerChar.isIn(self)) |
| 3012 |
return inherited(chiName); |
| 3013 |
else |
| 3014 |
return getNominalDropDestination().childInNameWithOwner(chiName); |
| 3015 |
} |
| 3016 |
; |
| 3017 |
|
| 3018 |
/* ------------------------------------------------------------------------ */ |
| 3019 |
/* |
| 3020 |
* English-specific modifications for the default room parts. |
| 3021 |
*/ |
| 3022 |
|
| 3023 |
modify Floor |
| 3024 |
childInNameGen(childName, myName) { return childName + ' on ' + myName; } |
| 3025 |
objInPrep = 'on' |
| 3026 |
actorInPrep = 'on' |
| 3027 |
actorOutOfPrep = 'off of' |
| 3028 |
; |
| 3029 |
|
| 3030 |
modify defaultFloor |
| 3031 |
noun = 'floor' 'ground' |
| 3032 |
name = 'floor' |
| 3033 |
; |
| 3034 |
|
| 3035 |
modify defaultGround |
| 3036 |
noun = 'ground' 'floor' |
| 3037 |
name = 'ground' |
| 3038 |
; |
| 3039 |
|
| 3040 |
modify DefaultWall noun='wall' plural='walls' name='wall'; |
| 3041 |
modify defaultCeiling noun='ceiling' 'roof' name='ceiling'; |
| 3042 |
modify defaultNorthWall adjective='n' 'north' name='north wall'; |
| 3043 |
modify defaultSouthWall adjective='s' 'south' name='south wall'; |
| 3044 |
modify defaultEastWall adjective='e' 'east' name='east wall'; |
| 3045 |
modify defaultWestWall adjective='w' 'west' name='west wall'; |
| 3046 |
modify defaultSky noun='sky' name='sky'; |
| 3047 |
|
| 3048 |
|
| 3049 |
/* ------------------------------------------------------------------------ */ |
| 3050 |
/* |
| 3051 |
* The English-specific modifications for directions. |
| 3052 |
*/ |
| 3053 |
modify Direction |
| 3054 |
/* describe a traveler arriving from this direction */ |
| 3055 |
sayArriving(traveler) |
| 3056 |
{ |
| 3057 |
/* show the generic arrival message */ |
| 3058 |
gLibMessages.sayArriving(traveler); |
| 3059 |
} |
| 3060 |
|
| 3061 |
/* describe a traveler departing in this direction */ |
| 3062 |
sayDeparting(traveler) |
| 3063 |
{ |
| 3064 |
/* show the generic departure message */ |
| 3065 |
gLibMessages.sayDeparting(traveler); |
| 3066 |
} |
| 3067 |
; |
| 3068 |
|
| 3069 |
/* |
| 3070 |
* The English-specific modifications for compass directions. |
| 3071 |
*/ |
| 3072 |
modify CompassDirection |
| 3073 |
/* describe a traveler arriving from this direction */ |
| 3074 |
sayArriving(traveler) |
| 3075 |
{ |
| 3076 |
/* show the generic compass direction description */ |
| 3077 |
gLibMessages.sayArrivingDir(traveler, name); |
| 3078 |
} |
| 3079 |
|
| 3080 |
/* describe a traveler departing in this direction */ |
| 3081 |
sayDeparting(traveler) |
| 3082 |
{ |
| 3083 |
/* show the generic compass direction description */ |
| 3084 |
gLibMessages.sayDepartingDir(traveler, name); |
| 3085 |
} |
| 3086 |
; |
| 3087 |
|
| 3088 |
/* |
| 3089 |
* The English-specific definitions for the compass direction objects. |
| 3090 |
* In addition to modifying the direction objects to define the name of |
| 3091 |
* the direction, we add a 'directionName' grammar rule. |
| 3092 |
*/ |
| 3093 |
#define DefineLangDir(root, dirNames, backPre) \ |
| 3094 |
grammar directionName(root): dirNames: DirectionProd \ |
| 3095 |
dir = root##Direction \ |
| 3096 |
; \ |
| 3097 |
\ |
| 3098 |
modify root##Direction \ |
| 3099 |
name = #@root \ |
| 3100 |
backToPrefix = backPre |
| 3101 |
|
| 3102 |
DefineLangDir(north, 'north' | 'n', 'back to the'); |
| 3103 |
DefineLangDir(south, 'south' | 's', 'back to the'); |
| 3104 |
DefineLangDir(east, 'east' | 'e', 'back to the'); |
| 3105 |
DefineLangDir(west, 'west' | 'w', 'back to the'); |
| 3106 |
DefineLangDir(northeast, 'northeast' | 'ne', 'back to the'); |
| 3107 |
DefineLangDir(northwest, 'northwest' | 'nw', 'back to the'); |
| 3108 |
DefineLangDir(southeast, 'southeast' | 'se', 'back to the'); |
| 3109 |
DefineLangDir(southwest, 'southwest' | 'sw', 'back to the'); |
| 3110 |
DefineLangDir(up, 'up' | 'u', 'back'); |
| 3111 |
DefineLangDir(down, 'down' | 'd', 'back'); |
| 3112 |
DefineLangDir(in, 'in', 'back'); |
| 3113 |
DefineLangDir(out, 'out', 'back'); |
| 3114 |
|
| 3115 |
/* |
| 3116 |
* The English-specific shipboard direction modifications. Certain of |
| 3117 |
* the ship directions have no natural descriptions for arrival and/or |
| 3118 |
* departure; for example, there's no good way to say "arriving from |
| 3119 |
* fore." Others don't fit any regular pattern: "he goes aft" rather |
| 3120 |
* than "he departs to aft." As a result, these are a bit irregular |
| 3121 |
* compared to the compass directions and so are individually defined |
| 3122 |
* below. |
| 3123 |
*/ |
| 3124 |
|
| 3125 |
DefineLangDir(port, 'port' | 'p', 'back to') |
| 3126 |
sayArriving(trav) |
| 3127 |
{ gLibMessages.sayArrivingShipDir(trav, 'the port direction'); } |
| 3128 |
sayDeparting(trav) |
| 3129 |
{ gLibMessages.sayDepartingShipDir(trav, 'port'); } |
| 3130 |
; |
| 3131 |
|
| 3132 |
DefineLangDir(starboard, 'starboard' | 'sb', 'back to') |
| 3133 |
sayArriving(trav) |
| 3134 |
{ gLibMessages.sayArrivingShipDir(trav, 'starboard'); } |
| 3135 |
sayDeparting(trav) |
| 3136 |
{ gLibMessages.sayDepartingShipDir(trav, 'starboard'); } |
| 3137 |
; |
| 3138 |
|
| 3139 |
DefineLangDir(aft, 'aft' | 'a', 'back to') |
| 3140 |
sayArriving(trav) { gLibMessages.sayArrivingShipDir(trav, 'aft'); } |
| 3141 |
sayDeparting(trav) { gLibMessages.sayDepartingAft(trav); } |
| 3142 |
; |
| 3143 |
|
| 3144 |
DefineLangDir(fore, 'fore' | 'forward' | 'f', 'back to') |
| 3145 |
sayArriving(trav) { gLibMessages.sayArrivingShipDir(trav, 'forward'); } |
| 3146 |
sayDeparting(trav) { gLibMessages.sayDepartingFore(trav); } |
| 3147 |
; |
| 3148 |
|
| 3149 |
/* ------------------------------------------------------------------------ */ |
| 3150 |
/* |
| 3151 |
* Some helper routines for the library messages. |
| 3152 |
*/ |
| 3153 |
class MessageHelper: object |
| 3154 |
/* |
| 3155 |
* Show a list of objects for a disambiguation query. If |
| 3156 |
* 'showIndefCounts' is true, we'll show the number of equivalent |
| 3157 |
* items for each equivalent item; otherwise, we'll just show an |
| 3158 |
* indefinite noun phrase for each equivalent item. |
| 3159 |
*/ |
| 3160 |
askDisambigList(matchList, fullMatchList, showIndefCounts, dist) |
| 3161 |
{ |
| 3162 |
/* show each item */ |
| 3163 |
for (local i = 1, local len = matchList.length() ; i <= len ; ++i) |
| 3164 |
{ |
| 3165 |
local equivCnt; |
| 3166 |
local obj; |
| 3167 |
|
| 3168 |
/* get the current object */ |
| 3169 |
obj = matchList[i].obj_; |
| 3170 |
|
| 3171 |
/* |
| 3172 |
* if this isn't the first, add a comma; if this is the |
| 3173 |
* last, add an "or" as well |
| 3174 |
*/ |
| 3175 |
if (i == len) |
| 3176 |
", or "; |
| 3177 |
else if (i != 1) |
| 3178 |
", "; |
| 3179 |
|
| 3180 |
/* |
| 3181 |
* Check to see if more than one equivalent of this item |
| 3182 |
* appears in the full list. |
| 3183 |
*/ |
| 3184 |
for (equivCnt = 0, local j = 1, |
| 3185 |
local fullLen = fullMatchList.length() ; j <= fullLen ; ++j) |
| 3186 |
{ |
| 3187 |
/* |
| 3188 |
* if this item is equivalent for the purposes of the |
| 3189 |
* current distinguisher, count it |
| 3190 |
*/ |
| 3191 |
if (!dist.canDistinguish(obj, fullMatchList[j].obj_)) |
| 3192 |
{ |
| 3193 |
/* it's equivalent - count it */ |
| 3194 |
++equivCnt; |
| 3195 |
} |
| 3196 |
} |
| 3197 |
|
| 3198 |
/* show this item with the appropriate article */ |
| 3199 |
if (equivCnt > 1) |
| 3200 |
{ |
| 3201 |
/* |
| 3202 |
* we have multiple equivalents - show either with an |
| 3203 |
* indefinite article or with a count, depending on the |
| 3204 |
* flags the caller provided |
| 3205 |
*/ |
| 3206 |
if (showIndefCounts) |
| 3207 |
{ |
| 3208 |
/* a count is desired for each equivalent group */ |
| 3209 |
say(dist.countName(obj, equivCnt)); |
| 3210 |
} |
| 3211 |
else |
| 3212 |
{ |
| 3213 |
/* no counts desired - show with an indefinite article */ |
| 3214 |
say(dist.aName(obj)); |
| 3215 |
} |
| 3216 |
} |
| 3217 |
else |
| 3218 |
{ |
| 3219 |
/* there's only one - show with a definite article */ |
| 3220 |
say(dist.theName(obj)); |
| 3221 |
} |
| 3222 |
} |
| 3223 |
} |
| 3224 |
|
| 3225 |
/* |
| 3226 |
* For a TAction result, select the short-form or long-form message, |
| 3227 |
* according to the disambiguation status of the action. This is for |
| 3228 |
* the ultra-terse default messages, such as "Taken" or "Dropped", |
| 3229 |
* that sometimes need more descriptive variations. |
| 3230 |
* |
| 3231 |
* If there was no disambiguation involved, we'll use the short |
| 3232 |
* version of the message. |
| 3233 |
* |
| 3234 |
* If there was unclear disambiguation involved (meaning that there |
| 3235 |
* was more than one logical object matching a noun phrase, but the |
| 3236 |
* parser was able to decide based on likelihood rankings), we'll |
| 3237 |
* still use the short version, because we assume that the parser |
| 3238 |
* will have generated a parenthetical announcement to point out its |
| 3239 |
* choice. |
| 3240 |
* |
| 3241 |
* If there was clear disambiguation involved (meaning that more than |
| 3242 |
* one in-scope object matched a noun phrase, but there was only one |
| 3243 |
* choice that passed the logicalness tests), AND the announcement |
| 3244 |
* mode (in gameMain.ambigAnnounceMode) is DescribeClear, we'll |
| 3245 |
* choose the long-form message. |
| 3246 |
*/ |
| 3247 |
shortTMsg(short, long) |
| 3248 |
{ |
| 3249 |
/* check the disambiguation flags and the announcement mode */ |
| 3250 |
if ((gAction.getDobjFlags() & (ClearDisambig | AlwaysAnnounce)) |
| 3251 |
== ClearDisambig |
| 3252 |
&& gAction.getDobjCount() == 1 |
| 3253 |
&& gameMain.ambigAnnounceMode == DescribeClear) |
| 3254 |
{ |
| 3255 |
/* clear disambig and DescribeClear mode - use the long message */ |
| 3256 |
return long; |
| 3257 |
} |
| 3258 |
else |
| 3259 |
{ |
| 3260 |
/* in other cases, use the short message */ |
| 3261 |
return short; |
| 3262 |
} |
| 3263 |
} |
| 3264 |
|
| 3265 |
/* |
| 3266 |
* For a TIAction result, select the short-form or long-form message. |
| 3267 |
* This works just like shortTIMsg(), but takes into account both the |
| 3268 |
* direct and indirect objects. |
| 3269 |
*/ |
| 3270 |
shortTIMsg(short, long) |
| 3271 |
{ |
| 3272 |
/* check the disambiguation flags and the announcement mode */ |
| 3273 |
if (((gAction.getDobjFlags() & (ClearDisambig | AlwaysAnnounce)) |
| 3274 |
== ClearDisambig |
| 3275 |
|| (gAction.getIobjFlags() & (ClearDisambig | AlwaysAnnounce)) |
| 3276 |
== ClearDisambig) |
| 3277 |
&& gAction.getDobjCount() == 1 |
| 3278 |
&& gAction.getIobjCount() == 1 |
| 3279 |
&& gameMain.ambigAnnounceMode == DescribeClear) |
| 3280 |
{ |
| 3281 |
/* clear disambig and DescribeClear mode - use the long message */ |
| 3282 |
return long; |
| 3283 |
} |
| 3284 |
else |
| 3285 |
{ |
| 3286 |
/* in other cases, use the short message */ |
| 3287 |
return short; |
| 3288 |
} |
| 3289 |
} |
| 3290 |
; |
| 3291 |
|
| 3292 |
/* ------------------------------------------------------------------------ */ |
| 3293 |
/* |
| 3294 |
* Custom base resolver |
| 3295 |
*/ |
| 3296 |
modify Resolver |
| 3297 |
/* |
| 3298 |
* Get the default in-scope object list for a given pronoun. We'll |
| 3299 |
* look for a unique object in scope that matches the desired |
| 3300 |
* pronoun, and return a ResolveInfo list if we find one. If there |
| 3301 |
* aren't any objects in scope that match the pronoun, or multiple |
| 3302 |
* objects are in scope, there's no default. |
| 3303 |
*/ |
| 3304 |
getPronounDefault(typ, np) |
| 3305 |
{ |
| 3306 |
local map = [PronounHim, &canMatchHim, |
| 3307 |
PronounHer, &canMatchHer, |
| 3308 |
PronounIt, &canMatchIt]; |
| 3309 |
local idx = map.indexOf(typ); |
| 3310 |
local filterProp = (idx != nil ? map[idx + 1] : nil); |
| 3311 |
local lst; |
| 3312 |
|
| 3313 |
/* if we couldn't find a filter for the pronoun, ignore it */ |
| 3314 |
if (filterProp == nil) |
| 3315 |
return []; |
| 3316 |
|
| 3317 |
/* |
| 3318 |
* filter the list of all possible defaults to those that match |
| 3319 |
* the given pronoun |
| 3320 |
*/ |
| 3321 |
lst = getAllDefaults.subset({x: x.obj_.(filterProp)}); |
| 3322 |
|
| 3323 |
/* |
| 3324 |
* if the list contains exactly one element, then there's a |
| 3325 |
* unique default; otherwise, there's either nothing here that |
| 3326 |
* matches the pronoun or the pronoun is ambiguous, so there's |
| 3327 |
* no default |
| 3328 |
*/ |
| 3329 |
if (lst.length() == 1) |
| 3330 |
{ |
| 3331 |
/* |
| 3332 |
* we have a unique object, so they must be referring to it; |
| 3333 |
* because this is just a guess, though, mark it as vague |
| 3334 |
*/ |
| 3335 |
lst[1].flags_ |= UnclearDisambig; |
| 3336 |
|
| 3337 |
/* return the list */ |
| 3338 |
return lst; |
| 3339 |
} |
| 3340 |
else |
| 3341 |
{ |
| 3342 |
/* |
| 3343 |
* the pronoun doesn't have a unique in-scope referent, so |
| 3344 |
* we can't guess what they mean |
| 3345 |
*/ |
| 3346 |
return []; |
| 3347 |
} |
| 3348 |
} |
| 3349 |
; |
| 3350 |
|
| 3351 |
/* ------------------------------------------------------------------------ */ |
| 3352 |
/* |
| 3353 |
* Custom interactive resolver. This is used for responses to |
| 3354 |
* disambiguation questions and prompts for missing noun phrases. |
| 3355 |
*/ |
| 3356 |
modify InteractiveResolver |
| 3357 |
/* |
| 3358 |
* Resolve a pronoun antecedent. We'll resolve a third-person |
| 3359 |
* singular pronoun to the target actor if the target actor matches |
| 3360 |
* in gender, and the target actor isn't the PC. This allows |
| 3361 |
* exchanges like this: |
| 3362 |
* |
| 3363 |
*. >bob, examine |
| 3364 |
*. What do you want Bob to look at? |
| 3365 |
*. |
| 3366 |
*. >his book |
| 3367 |
* |
| 3368 |
* In the above exchange, we'll treat "his" as referring to Bob, the |
| 3369 |
* target actor of the action, because we have referred to Bob in |
| 3370 |
* the partial command (the "BOB, EXAMINE") that triggered the |
| 3371 |
* interactive question. |
| 3372 |
*/ |
| 3373 |
resolvePronounAntecedent(typ, np, results, poss) |
| 3374 |
{ |
| 3375 |
local lst; |
| 3376 |
|
| 3377 |
/* try resolving with the target actor as the antecedent */ |
| 3378 |
if ((lst = resolvePronounAsTargetActor(typ)) != nil) |
| 3379 |
return lst; |
| 3380 |
|
| 3381 |
/* use the inherited result */ |
| 3382 |
return inherited(typ, np, results, poss); |
| 3383 |
} |
| 3384 |
|
| 3385 |
/* |
| 3386 |
* Get the reflexive third-person pronoun binding (himself, herself, |
| 3387 |
* itself, themselves). If the target actor isn't the PC, and the |
| 3388 |
* gender of the pronoun matches, we'll consider this as referring |
| 3389 |
* to the target actor. This allows exchanges of this form: |
| 3390 |
* |
| 3391 |
*. >bob, examine |
| 3392 |
*. What do you want Bob to examine? |
| 3393 |
*. |
| 3394 |
*. >himself |
| 3395 |
*/ |
| 3396 |
getReflexiveBinding(typ) |
| 3397 |
{ |
| 3398 |
local lst; |
| 3399 |
|
| 3400 |
/* try resolving with the target actor as the antecedent */ |
| 3401 |
if ((lst = resolvePronounAsTargetActor(typ)) != nil) |
| 3402 |
return lst; |
| 3403 |
|
| 3404 |
/* use the inherited result */ |
| 3405 |
return inherited(typ); |
| 3406 |
} |
| 3407 |
|
| 3408 |
/* |
| 3409 |
* Try matching the given pronoun type to the target actor. If it |
| 3410 |
* matches in gender, and the target actor isn't the PC, we'll |
| 3411 |
* return a resolve list consisting of the target actor. If we |
| 3412 |
* don't have a match, we'll return nil. |
| 3413 |
*/ |
| 3414 |
resolvePronounAsTargetActor(typ) |
| 3415 |
{ |
| 3416 |
/* |
| 3417 |
* if the target actor isn't the player character, and the |
| 3418 |
* target actor can match the given pronoun type, resolve the |
| 3419 |
* pronoun as the target actor |
| 3420 |
*/ |
| 3421 |
if (actor_.canMatchPronounType(typ) && !actor_.isPlayerChar()) |
| 3422 |
{ |
| 3423 |
/* the match is the target actor */ |
| 3424 |
return [new ResolveInfo(actor_, 0, nil)]; |
| 3425 |
} |
| 3426 |
|
| 3427 |
/* we didn't match it */ |
| 3428 |
return nil; |
| 3429 |
} |
| 3430 |
; |
| 3431 |
|
| 3432 |
/* |
| 3433 |
* Custom disambiguation resolver. |
| 3434 |
*/ |
| 3435 |
modify DisambigResolver |
| 3436 |
/* |
| 3437 |
* Perform special resolution on pronouns used in interactive |
| 3438 |
* responses. If the pronoun is HIM or HER, then look through the |
| 3439 |
* list of possible matches for a matching gendered object, and use |
| 3440 |
* it as the result if we find one. If we find more than one, then |
| 3441 |
* use the default handling instead, treating the pronoun as |
| 3442 |
* referring back to the simple antecedent previously set. |
| 3443 |
*/ |
| 3444 |
resolvePronounAntecedent(typ, np, results, poss) |
| 3445 |
{ |
| 3446 |
/* if it's a non-possessive HIM or HER, use our special handling */ |
| 3447 |
if (!poss && typ is in (PronounHim, PronounHer)) |
| 3448 |
{ |
| 3449 |
local prop; |
| 3450 |
local sub; |
| 3451 |
|
| 3452 |
/* get the gender indicator property for the pronoun */ |
| 3453 |
prop = (typ == PronounHim ? &canMatchHim : &canMatchHer); |
| 3454 |
|
| 3455 |
/* |
| 3456 |
* Scan through the match list to find the objects that |
| 3457 |
* match the gender of the pronoun. Note that if the player |
| 3458 |
* character isn't referred to in the third person, we'll |
| 3459 |
* ignore the player character for the purposes of matching |
| 3460 |
* this pronoun - if we're calling the PC 'you', then we |
| 3461 |
* wouldn't expect the player to refer to the PC as 'him' or |
| 3462 |
* 'her'. |
| 3463 |
*/ |
| 3464 |
sub = matchList.subset({x: x.obj_.(prop)}); |
| 3465 |
|
| 3466 |
/* if the list has a single entry, then use it as the match */ |
| 3467 |
if (sub.length() == 1) |
| 3468 |
return sub; |
| 3469 |
|
| 3470 |
/* |
| 3471 |
* if it has more than one entry, it's still ambiguous, but |
| 3472 |
* we might have narrowed it down, so throw a |
| 3473 |
* still-ambiguous exception and let the interactive |
| 3474 |
* disambiguation ask for further clarification |
| 3475 |
*/ |
| 3476 |
results.ambiguousNounPhrase(nil, ResolveAsker, 'one', |
| 3477 |
sub, matchList, matchList, |
| 3478 |
1, self); |
| 3479 |
return []; |
| 3480 |
} |
| 3481 |
|
| 3482 |
/* |
| 3483 |
* if we get this far, it means we didn't use our special |
| 3484 |
* handling, so use the inherited behavior |
| 3485 |
*/ |
| 3486 |
return inherited(typ, np, results, poss); |
| 3487 |
} |
| 3488 |
; |
| 3489 |
|
| 3490 |
/* ------------------------------------------------------------------------ */ |
| 3491 |
/* |
| 3492 |
* Distinguisher customizations for English. |
| 3493 |
* |
| 3494 |
* Each distinguisher must provide a method that gets the name of an item |
| 3495 |
* for a disamgiguation query. Since these are inherently |
| 3496 |
* language-specific, they're defined here. |
| 3497 |
*/ |
| 3498 |
|
| 3499 |
/* |
| 3500 |
* The null distinguisher tells objects apart based strictly on the name |
| 3501 |
* string. When we list objects, we simply show the basic name - since |
| 3502 |
* we can tell apart our objects based on the base name, there's no need |
| 3503 |
* to resort to other names. |
| 3504 |
*/ |
| 3505 |
modify nullDistinguisher |
| 3506 |
/* we can tell objects apart if they have different base names */ |
| 3507 |
canDistinguish(a, b) { return a.name != b.name; } |
| 3508 |
|
| 3509 |
name(obj) { return obj.name; } |
| 3510 |
aName(obj) { return obj.aName; } |
| 3511 |
theName(obj) { return obj.theName; } |
| 3512 |
countName(obj, cnt) { return obj.countName(cnt); } |
| 3513 |
; |
| 3514 |
|
| 3515 |
|
| 3516 |
/* |
| 3517 |
* The basic distinguisher can tell apart objects that are not "basic |
| 3518 |
* equivalents" of one another. Thus, we need make no distinctions when |
| 3519 |
* listing objects apart from showing their names. |
| 3520 |
*/ |
| 3521 |
modify basicDistinguisher |
| 3522 |
name(obj) { return obj.disambigName; } |
| 3523 |
aName(obj) { return obj.aDisambigName; } |
| 3524 |
theName(obj) { return obj.theDisambigName; } |
| 3525 |
countName(obj, cnt) { return obj.countDisambigName(cnt); } |
| 3526 |
; |
| 3527 |
|
| 3528 |
/* |
| 3529 |
* The ownership distinguisher tells objects apart based on who "owns" |
| 3530 |
* them, so it shows the owner or location name when listing the object. |
| 3531 |
*/ |
| 3532 |
modify ownershipDistinguisher |
| 3533 |
name(obj) { return obj.theNameOwnerLoc(true); } |
| 3534 |
aName(obj) { return obj.aNameOwnerLoc(true); } |
| 3535 |
theName(obj) { return obj.theNameOwnerLoc(true); } |
| 3536 |
countName(obj, cnt) { return obj.countNameOwnerLoc(cnt, true); } |
| 3537 |
|
| 3538 |
/* note that we're prompting based on this distinguisher */ |
| 3539 |
notePrompt(lst) |
| 3540 |
{ |
| 3541 |
/* |
| 3542 |
* notify each object that we're referring to it by |
| 3543 |
* owner/location in a disambiguation prompt |
| 3544 |
*/ |
| 3545 |
foreach (local cur in lst) |
| 3546 |
cur.obj_.notePromptByOwnerLoc(true); |
| 3547 |
} |
| 3548 |
; |
| 3549 |
|
| 3550 |
/* |
| 3551 |
* The location distinguisher tells objects apart based on their |
| 3552 |
* containers, so it shows the location name when listing the object. |
| 3553 |
*/ |
| 3554 |
modify locationDistinguisher |
| 3555 |
name(obj) { return obj.theNameOwnerLoc(nil); } |
| 3556 |
aName(obj) { return obj.aNameOwnerLoc(nil); } |
| 3557 |
theName(obj) { return obj.theNameOwnerLoc(nil); } |
| 3558 |
countName(obj, cnt) { return obj.countNameOwnerLoc(cnt, nil); } |
| 3559 |
|
| 3560 |
/* note that we're prompting based on this distinguisher */ |
| 3561 |
notePrompt(lst) |
| 3562 |
{ |
| 3563 |
/* notify the objects of their use in a disambiguation prompt */ |
| 3564 |
foreach (local cur in lst) |
| 3565 |
cur.obj_.notePromptByOwnerLoc(nil); |
| 3566 |
} |
| 3567 |
; |
| 3568 |
|
| 3569 |
/* |
| 3570 |
* The lit/unlit distinguisher tells apart objects based on whether |
| 3571 |
* they're lit or unlit, so we list objects as lit or unlit explicitly. |
| 3572 |
*/ |
| 3573 |
modify litUnlitDistinguisher |
| 3574 |
name(obj) { return obj.nameLit; } |
| 3575 |
aName(obj) { return obj.aNameLit; } |
| 3576 |
theName(obj) { return obj.theNameLit; } |
| 3577 |
countName(obj, cnt) { return obj.pluralNameLit; } |
| 3578 |
; |
| 3579 |
|
| 3580 |
/* ------------------------------------------------------------------------ */ |
| 3581 |
/* |
| 3582 |
* Enligh-specific light source modifications |
| 3583 |
*/ |
| 3584 |
modify LightSource |
| 3585 |
/* provide lit/unlit names for litUnlitDistinguisher */ |
| 3586 |
nameLit = ((isLit ? 'lit ' : 'unlit ') + name) |
| 3587 |
aNameLit() |
| 3588 |
{ |
| 3589 |
/* |
| 3590 |
* if this is a mass noun or a plural name, just use the name |
| 3591 |
* with lit/unlit; otherwise, add "a" |
| 3592 |
*/ |
| 3593 |
if (isPlural || isMassNoun) |
| 3594 |
return (isLit ? 'lit ' : 'unlit ') + name; |
| 3595 |
else |
| 3596 |
return (isLit ? 'a lit ' : 'an unlit ') + name; |
| 3597 |
} |
| 3598 |
theNameLit = ((isLit ? 'the lit ' : 'the unlit ') + name) |
| 3599 |
pluralNameLit = ((isLit ? 'lit ' : 'unlit ') + pluralName) |
| 3600 |
|
| 3601 |
/* |
| 3602 |
* Allow 'lit' and 'unlit' as adjectives - but even though we define |
| 3603 |
* these as our adjectives in the dictionary, we'll only accept the |
| 3604 |
* one appropriate for our current state, thanks to our state |
| 3605 |
* objects. |
| 3606 |
*/ |
| 3607 |
adjective = 'lit' 'unlit' |
| 3608 |
; |
| 3609 |
|
| 3610 |
/* |
| 3611 |
* Light source list states. An illuminated light source shows its |
| 3612 |
* status as "providing light"; an unlit light source shows no extra |
| 3613 |
* status. |
| 3614 |
*/ |
| 3615 |
lightSourceStateOn: ThingState 'providing light' |
| 3616 |
stateTokens = ['lit'] |
| 3617 |
; |
| 3618 |
lightSourceStateOff: ThingState |
| 3619 |
stateTokens = ['unlit'] |
| 3620 |
; |
| 3621 |
|
| 3622 |
/* ------------------------------------------------------------------------ */ |
| 3623 |
/* |
| 3624 |
* Wearable states - a wearable item can be either worn or not worn. |
| 3625 |
*/ |
| 3626 |
|
| 3627 |
/* "worn" */ |
| 3628 |
wornState: ThingState 'being worn' |
| 3629 |
/* |
| 3630 |
* In listings of worn items, don't bother mentioning our 'worn' |
| 3631 |
* status, as the entire list consists of items being worn - it |
| 3632 |
* would be redundant to point out that the items in a list of items |
| 3633 |
* being worn are being worn. |
| 3634 |
*/ |
| 3635 |
wornName(lst) { return nil; } |
| 3636 |
; |
| 3637 |
|
| 3638 |
/* |
| 3639 |
* "Unworn" state. Don't bother mentioning the status of an unworn item, |
| 3640 |
* since this is the default for everything. |
| 3641 |
*/ |
| 3642 |
unwornState: ThingState; |
| 3643 |
|
| 3644 |
|
| 3645 |
/* ------------------------------------------------------------------------ */ |
| 3646 |
/* |
| 3647 |
* Typographical effects output filter. This filter looks for certain |
| 3648 |
* sequences in the text and converts them to typographical equivalents. |
| 3649 |
* Authors could simply write the HTML for the typographical markups in |
| 3650 |
* the first place, but it's easier to write the typewriter-like |
| 3651 |
* sequences and let this filter convert to HTML. |
| 3652 |
* |
| 3653 |
* We perform the following conversions: |
| 3654 |
* |
| 3655 |
* '---' -> &zwnbsp;— |
| 3656 |
*. '--' -> &zwnbsp;– |
| 3657 |
*. sentence-ending punctuation -> same +   |
| 3658 |
* |
| 3659 |
* Since this routine is called so frequently, we hard-code the |
| 3660 |
* replacement strings, rather than using properties, for slightly faster |
| 3661 |
* performance. Since this routine is so simple, games that want to |
| 3662 |
* customize the replacement style should simply replace this entire |
| 3663 |
* routine with a new routine that applies the customizations. |
| 3664 |
* |
| 3665 |
* Note that we define this filter in the English-specific part of the |
| 3666 |
* library, because it seems almost certain that each language will want |
| 3667 |
* to customize it for local conventions. |
| 3668 |
*/ |
| 3669 |
typographicalOutputFilter: OutputFilter |
| 3670 |
filterText(ostr, val) |
| 3671 |
{ |
| 3672 |
/* |
| 3673 |
* Look for sentence-ending punctuation, and put an 'en' space |
| 3674 |
* after each occurrence. Recognize ends of sentences even if we |
| 3675 |
* have closing quotes, parentheses, or other grouping characters |
| 3676 |
* following the punctuation. Do this before the hyphen |
| 3677 |
* substitutions so that we can look for ordinary hyphens rather |
| 3678 |
* than all of the expanded versions. |
| 3679 |
*/ |
| 3680 |
val = rexReplace(eosPattern, val, '%1\u2002', ReplaceAll); |
| 3681 |
|
| 3682 |
/* undo any abbreviations we mistook for sentence endings */ |
| 3683 |
val = rexReplace(abbrevPat, val, '%1. ', ReplaceAll); |
| 3684 |
|
| 3685 |
/* |
| 3686 |
* Replace dashes with typographical hyphens. Three hyphens in a |
| 3687 |
* row become an em-dash, and two in a row become an en-dash. |
| 3688 |
* Note that we look for the three-hyphen sequence first, because |
| 3689 |
* if we did it the other way around, we'd incorrectly find the |
| 3690 |
* first two hyphens of each '---' sequence and replace them with |
| 3691 |
* an en-dash, causing us to miss the '---' sequences entirely. |
| 3692 |
* |
| 3693 |
* We put a no-break marker (\uFEFF) just before each hyphen, and |
| 3694 |
* an okay-to-break marker (\u200B) just after, to ensure that we |
| 3695 |
* won't have a line break between the preceding text and the |
| 3696 |
* hyphen, and to indicate that a line break is specifically |
| 3697 |
* allowed if needed to the right of the hyphen. |
| 3698 |
*/ |
| 3699 |
val = val.findReplace(['---', '--'], |
| 3700 |
['\uFEFF—\u200B', '\uFEFF–\u200B']); |
| 3701 |
|
| 3702 |
/* return the result */ |
| 3703 |
return val; |
| 3704 |
} |
| 3705 |
|
| 3706 |
/* |
| 3707 |
* The end-of-sentence pattern. This looks a bit complicated, but |
| 3708 |
* all we're looking for is a period, exclamation point, or question |
| 3709 |
* mark, optionally followed by any number of closing group marks |
| 3710 |
* (right parentheses or square brackets, closing HTML tags, or |
| 3711 |
* double or single quotes in either straight or curly styles), all |
| 3712 |
* followed by an ordinary space. |
| 3713 |
* |
| 3714 |
* If a lower-case letter follows the space, though, we won't |
| 3715 |
* consider it a sentence ending. This applies most commonly after |
| 3716 |
* quoted passages ending with what would normally be sentence-ending |
| 3717 |
* punctuation: "'Who are you?' he asked." In these cases, the |
| 3718 |
* enclosing sentence isn't ending, so we don't want the extra space. |
| 3719 |
* We can tell the enclosing sentence isn't ending because a |
| 3720 |
* non-capital letter follows. |
| 3721 |
* |
| 3722 |
* Note that we specifically look only for ordinary spaces. Any |
| 3723 |
* sentence-ending punctuation that's followed by a quoted space or |
| 3724 |
* any typographical space overrides this substitution. |
| 3725 |
*/ |
| 3726 |
eosPattern = static new RexPattern( |
| 3727 |
'<case>' |
| 3728 |
+ '(' |
| 3729 |
+ '[.!?]' |
| 3730 |
+ '(' |
| 3731 |
+ '<rparen|rsquare|dquote|squote|\u2019|\u201D>' |
| 3732 |
+ '|<langle><^rangle>*<rangle>' |
| 3733 |
+ ')*' |
| 3734 |
+ ')' |
| 3735 |
+ ' +(?![-a-z])' |
| 3736 |
) |
| 3737 |
|
| 3738 |
/* pattern for abbreviations that were mistaken for sentence endings */ |
| 3739 |
abbrevPat = static new RexPattern( |
| 3740 |
'<nocase>%<(' + abbreviations + ')<dot>\u2002') |
| 3741 |
|
| 3742 |
/* |
| 3743 |
* Common abbreviations. These are excluded from being treated as |
| 3744 |
* sentence endings when they appear with a trailing period. |
| 3745 |
* |
| 3746 |
* Note that abbrevPat must be rebuilt manually if you change this on |
| 3747 |
* the fly - abbrevPat is static, so it picks up the initial value of |
| 3748 |
* this property at start-up, and doesn't re-evaluate it while the |
| 3749 |
* game is running. |
| 3750 |
*/ |
| 3751 |
abbreviations = 'mr|mrs|ms|dr|prof' |
| 3752 |
; |
| 3753 |
|
| 3754 |
/* ------------------------------------------------------------------------ */ |
| 3755 |
/* |
| 3756 |
* The English-specific message builder. |
| 3757 |
*/ |
| 3758 |
langMessageBuilder: MessageBuilder |
| 3759 |
|
| 3760 |
/* |
| 3761 |
* The English message substitution parameter table. |
| 3762 |
* |
| 3763 |
* Note that we specify two additional elements for each table entry |
| 3764 |
* beyond the standard language-independent complement: |
| 3765 |
* |
| 3766 |
* info[4] = reflexive property - this is the property to invoke |
| 3767 |
* when the parameter is used reflexively (in other words, its |
| 3768 |
* target object is the same as the most recent target object used |
| 3769 |
* in the nominative case). If this is nil, the parameter has no |
| 3770 |
* reflexive form. |
| 3771 |
* |
| 3772 |
* info[5] = true if this is a nominative usage, nil if not. We use |
| 3773 |
* this to determine which target objects are used in the nominative |
| 3774 |
* case, so that we can remember those objects for subsequent |
| 3775 |
* reflexive usages. |
| 3776 |
*/ |
| 3777 |
paramList_ = |
| 3778 |
[ |
| 3779 |
/* parameters that imply the actor as the target object */ |
| 3780 |
['you/he', &theName, 'actor', nil, true], |
| 3781 |
['you/she', &theName, 'actor', nil, true], |
| 3782 |
['you\'re/he\'s', &itIsContraction, 'actor', nil, true], |
| 3783 |
['you\'re/she\'s', &itIsContraction, 'actor', nil, true], |
| 3784 |
['you\'re', &itIsContraction, 'actor', nil, true], |
| 3785 |
['you/him', &theNameObj, 'actor', &itReflexive, nil], |
| 3786 |
['you/her', &theNameObj, 'actor', &itReflexive, nil], |
| 3787 |
['your/her', &theNamePossAdj, 'actor', nil, nil], |
| 3788 |
['your/his', &theNamePossAdj, 'actor', nil, nil], |
| 3789 |
['your', &theNamePossAdj, 'actor', nil, nil], |
| 3790 |
['yours/hers', &theNamePossNoun, 'actor', nil, nil], |
| 3791 |
['yours/his', &theNamePossNoun, 'actor', nil, nil], |
| 3792 |
['yours', &theNamePossNoun, 'actor', nil, nil], |
| 3793 |
['yourself/himself', &itReflexive, 'actor', nil, nil], |
| 3794 |
['yourself/herself', &itReflexive, 'actor', nil, nil], |
| 3795 |
['yourself', &itReflexive, 'actor', nil, nil], |
| 3796 |
|
| 3797 |
/* parameters that don't imply any target object */ |
| 3798 |
['the/he', &theName, nil, nil, true], |
| 3799 |
['the/she', &theName, nil, nil, true], |
| 3800 |
['the/him', &theNameObj, nil, &itReflexive, nil], |
| 3801 |
['the/her', &theNameObj, nil, &itReflexive, nil], |
| 3802 |
['the\'s/her', &theNamePossAdj, nil, &itPossAdj, nil], |
| 3803 |
['the\'s/hers', &theNamePossNoun, nil, &itPossNoun, nil], |
| 3804 |
|
| 3805 |
/* |
| 3806 |
* Verb 's' endings. In most cases, you should use 's/d', 's/ed', |
| 3807 |
* or 's/?ed' rather than 's', except in places where you know you |
| 3808 |
* will never need the past tense form, because 's' doesn't handle |
| 3809 |
* the past tense. Don't use 's/?ed' with a literal question |
| 3810 |
* mark; put a consonant in place of the question mark instead. |
| 3811 |
*/ |
| 3812 |
['s', &verbEndingS, nil, nil, true], |
| 3813 |
['s/d', &verbEndingSD, nil, nil, true], |
| 3814 |
['s/ed', &verbEndingSEd, nil, nil, true], |
| 3815 |
['s/?ed', &verbEndingSMessageBuilder_, nil, nil, true], |
| 3816 |
|
| 3817 |
['es', &verbEndingEs, nil, nil, true], |
| 3818 |
['es/ed', &verbEndingEs, nil, nil, true], |
| 3819 |
['ies', &verbEndingIes, nil, nil, true], |
| 3820 |
['ies/ied', &verbEndingIes, nil, nil, true], |
| 3821 |
['is', &verbToBe, nil, nil, true], |
| 3822 |
['are', &verbToBe, nil, nil, true], |
| 3823 |
['was', &verbWas, nil, nil, true], |
| 3824 |
['were', &verbWas, nil, nil, true], |
| 3825 |
['has', &verbToHave, nil, nil, true], |
| 3826 |
['have', &verbToHave, nil, nil, true], |
| 3827 |
['does', &verbToDo, nil, nil, true], |
| 3828 |
['do', &verbToDo, nil, nil, true], |
| 3829 |
['goes', &verbToGo, nil, nil, true], |
| 3830 |
['go', &verbToGo, nil, nil, true], |
| 3831 |
['comes', &verbToCome, nil, nil, true], |
| 3832 |
['come', &verbToCome, nil, nil, true], |
| 3833 |
['leaves', &verbToLeave, nil, nil, true], |
| 3834 |
['leave', &verbToLeave, nil, nil, true], |
| 3835 |
['sees', &verbToSee, nil, nil, true], |
| 3836 |
['see', &verbToSee, nil, nil, true], |
| 3837 |
['says', &verbToSay, nil, nil, true], |
| 3838 |
['say', &verbToSay, nil, nil, true], |
| 3839 |
['must', &verbMust, nil, nil, true], |
| 3840 |
['can', &verbCan, nil, nil, true], |
| 3841 |
['cannot', &verbCannot, nil, nil, true], |
| 3842 |
['can\'t', &verbCant, nil, nil, true], |
| 3843 |
['will', &verbWill, nil, nil, true], |
| 3844 |
['won\'t', &verbWont, nil, nil, true], |
| 3845 |
['a/he', &aName, nil, nil, true], |
| 3846 |
['an/he', &aName, nil, nil, true], |
| 3847 |
['a/she', &aName, nil, nil, true], |
| 3848 |
['an/she', &aName, nil, nil, true], |
| 3849 |
['a/him', &aNameObj, nil, &itReflexive, nil], |
| 3850 |
['an/him', &aNameObj, nil, &itReflexive, nil], |
| 3851 |
['a/her', &aNameObj, nil, &itReflexive, nil], |
| 3852 |
['an/her', &aNameObj, nil, &itReflexive, nil], |
| 3853 |
['it/he', &itNom, nil, nil, true], |
| 3854 |
['it/she', &itNom, nil, nil, true], |
| 3855 |
['it/him', &itObj, nil, &itReflexive, nil], |
| 3856 |
['it/her', &itObj, nil, &itReflexive, nil], |
| 3857 |
|
| 3858 |
/* |
| 3859 |
* note that we don't have its/his, because that leaves |
| 3860 |
* ambiguous whether we want an adjective or noun form - so we |
| 3861 |
* only use the feminine pronouns with these, to make the |
| 3862 |
* meaning unambiguous |
| 3863 |
*/ |
| 3864 |
['its/her', &itPossAdj, nil, nil, nil], |
| 3865 |
['its/hers', &itPossNoun, nil, nil, nil], |
| 3866 |
|
| 3867 |
['it\'s/he\'s', &itIsContraction, nil, nil, true], |
| 3868 |
['it\'s/she\'s', &itIsContraction, nil, nil, true], |
| 3869 |
['it\'s', &itIsContraction, nil, nil, true], |
| 3870 |
['that/he', &thatNom, nil, nil, true], |
| 3871 |
['that/she', &thatNom, nil, nil, true], |
| 3872 |
['that/him', &thatObj, nil, &itReflexive, nil], |
| 3873 |
['that/her', &thatObj, nil, &itReflexive, nil], |
| 3874 |
['that\'s', &thatIsContraction, nil, nil, true], |
| 3875 |
['itself', &itReflexive, nil, nil, nil], |
| 3876 |
['itself/himself', &itReflexive, nil, nil, nil], |
| 3877 |
['itself/herself', &itReflexive, nil, nil, nil], |
| 3878 |
|
| 3879 |
/* default preposition for standing in/on something */ |
| 3880 |
['on', &actorInName, nil, nil, nil], |
| 3881 |
['in', &actorInName, nil, nil, nil], |
| 3882 |
['outof', &actorOutOfName, nil, nil, nil], |
| 3883 |
['offof', &actorOutOfName, nil, nil, nil], |
| 3884 |
['onto', &actorIntoName, nil, nil, nil], |
| 3885 |
['into', &actorIntoName, nil, nil, nil], |
| 3886 |
|
| 3887 |
/* |
| 3888 |
* The special invisible subject marker - this can be used to |
| 3889 |
* mark the subject in sentences that vary from the |
| 3890 |
* subject-verb-object structure that most English sentences |
| 3891 |
* take. The usual SVO structure allows the message builder to |
| 3892 |
* see the subject first in most sentences naturally, but in |
| 3893 |
* unusual sentence forms it is sometimes useful to be able to |
| 3894 |
* mark the subject explicitly. This doesn't actually result in |
| 3895 |
* any output; it's purely for marking the subject for our |
| 3896 |
* internal book-keeping. |
| 3897 |
* |
| 3898 |
* (The main reason the message builder wants to know the subject |
| 3899 |
* in the first place is so that it can use a reflexive pronoun |
| 3900 |
* if the same object ends up being used as a direct or indirect |
| 3901 |
* object: "you can't open yourself" rather than "you can't open |
| 3902 |
* you.") |
| 3903 |
*/ |
| 3904 |
['subj', &dummyName, nil, nil, true] |
| 3905 |
] |
| 3906 |
|
| 3907 |
/* |
| 3908 |
* Add a hook to the generateMessage method, which we use to |
| 3909 |
* pre-process the source string before expanding the substitution |
| 3910 |
* parameters. |
| 3911 |
*/ |
| 3912 |
generateMessage(orig) { return inherited(processOrig(orig)); } |
| 3913 |
|
| 3914 |
/* |
| 3915 |
* Pre-process a source string containing substitution parameters, |
| 3916 |
* before generating the expanded message from it. |
| 3917 |
* |
| 3918 |
* We use this hook to implement the special tense-switching syntax |
| 3919 |
* {<present>|<past>}. Although it superficially looks like an |
| 3920 |
* ordinary substitution parameter, we actually can't use the normal |
| 3921 |
* parameter substitution framework for that, because we want to |
| 3922 |
* allow the <present> and <past> substrings themselves to contain |
| 3923 |
* substitution parameters, and the normal framework doesn't allow |
| 3924 |
* for recursive substitution. |
| 3925 |
* |
| 3926 |
* We simply replace every sequence of the form {<present>|<past>} |
| 3927 |
* with either <present> or <past>, depending on the current |
| 3928 |
* narrative tense. We then substitute braces for square brackets in |
| 3929 |
* the resulting string. This allows treating every bracketed tag |
| 3930 |
* inside the tense-switching sequence as a regular substitution |
| 3931 |
* parameter. |
| 3932 |
* |
| 3933 |
* For example, the sequence "{take[s]|took}" appearing in the |
| 3934 |
* message string would be replaced with "take{s}" if the current |
| 3935 |
* narrative tense is present, and would be replaced with "took" if |
| 3936 |
* the current narrative tense is past. The string "take{s}", if |
| 3937 |
* selected, would in turn be expanded to either "take" or "takes", |
| 3938 |
* depending on the grammatical person of the subject, as per the |
| 3939 |
* regular substitution mechanism. |
| 3940 |
*/ |
| 3941 |
processOrig(str) |
| 3942 |
{ |
| 3943 |
local idx = 1; |
| 3944 |
local len; |
| 3945 |
local match; |
| 3946 |
local replStr; |
| 3947 |
|
| 3948 |
/* |
| 3949 |
* Keep searching the string until we run out of character |
| 3950 |
* sequences with a special meaning (specifically, we look for |
| 3951 |
* substrings enclosed in braces, and stuttered opening braces). |
| 3952 |
*/ |
| 3953 |
for (;;) |
| 3954 |
{ |
| 3955 |
/* |
| 3956 |
* Find the next special sequence. |
| 3957 |
*/ |
| 3958 |
match = rexSearch(patSpecial, str, idx); |
| 3959 |
|
| 3960 |
/* |
| 3961 |
* If there are no more special sequence, we're done |
| 3962 |
* pre-processing the string. |
| 3963 |
*/ |
| 3964 |
if (match == nil) break; |
| 3965 |
|
| 3966 |
/* |
| 3967 |
* Remember the starting index and length of the special |
| 3968 |
* sequence. |
| 3969 |
*/ |
| 3970 |
idx = match[1]; |
| 3971 |
len = match[2]; |
| 3972 |
|
| 3973 |
/* |
| 3974 |
* Check if this special sequence matches our tense-switching |
| 3975 |
* syntax. |
| 3976 |
*/ |
| 3977 |
if (rexMatch(patTenseSwitching, str, idx) == nil) |
| 3978 |
{ |
| 3979 |
/* |
| 3980 |
* It doesn't, so forget about it and continue searching |
| 3981 |
* from the end of this special sequence. |
| 3982 |
*/ |
| 3983 |
idx += len; |
| 3984 |
continue; |
| 3985 |
} |
| 3986 |
|
| 3987 |
/* |
| 3988 |
* Extract either the first or the second embedded string, |
| 3989 |
* depending on the current narrative tense. |
| 3990 |
*/ |
| 3991 |
match = rexGroup(tSel(1, 2)); |
| 3992 |
replStr = match[3]; |
| 3993 |
|
| 3994 |
/* |
| 3995 |
* Convert all square brackets to braces in the extracted |
| 3996 |
* string. |
| 3997 |
*/ |
| 3998 |
replStr = replStr.findReplace('[', '{', ReplaceAll); |
| 3999 |
replStr = replStr.findReplace(']', '}', ReplaceAll); |
| 4000 |
|
| 4001 |
/* |
| 4002 |
* In the original string, replace the tense-switching |
| 4003 |
* sequence with the extracted string. |
| 4004 |
*/ |
| 4005 |
str = str.substr(1, idx - 1) + replStr + str.substr(idx + len); |
| 4006 |
|
| 4007 |
/* |
| 4008 |
* Move the index at the end of the substituted string. |
| 4009 |
*/ |
| 4010 |
idx += match[2]; |
| 4011 |
} |
| 4012 |
|
| 4013 |
/* |
| 4014 |
* We're done - return the result. |
| 4015 |
*/ |
| 4016 |
return str; |
| 4017 |
} |
| 4018 |
|
| 4019 |
/* |
| 4020 |
* Pre-compiled regular expression pattern matching any sequence with |
| 4021 |
* a special meaning in a message string. |
| 4022 |
* |
| 4023 |
* We match either a stuttered opening brace, or a single opening |
| 4024 |
* brace followed by any sequence of characters that doesn't contain |
| 4025 |
* a closing brace followed by a closing brace. |
| 4026 |
*/ |
| 4027 |
patSpecial = static new RexPattern |
| 4028 |
('<lbrace><lbrace>|<lbrace>(?!<lbrace>)((?:<^rbrace>)*)<rbrace>') |
| 4029 |
|
| 4030 |
/* |
| 4031 |
* Pre-compiled regular expression pattern matching our special |
| 4032 |
* tense-switching syntax. |
| 4033 |
* |
| 4034 |
* We match a single opening brace, followed by any sequence of |
| 4035 |
* characters that doesn't contain a closing brace or a vertical bar, |
| 4036 |
* followed by a vertical bar, followed by any sequence of characters |
| 4037 |
* that doesn't contain a closing brace or a vertical bar, followed |
| 4038 |
* by a closing brace. |
| 4039 |
*/ |
| 4040 |
patTenseSwitching = static new RexPattern |
| 4041 |
( |
| 4042 |
'<lbrace>(?!<lbrace>)((?:<^rbrace|vbar>)*)<vbar>' |
| 4043 |
+ '((?:<^rbrace|vbar>)*)<rbrace>' |
| 4044 |
) |
| 4045 |
|
| 4046 |
/* |
| 4047 |
* The most recent target object used in the nominative case. We |
| 4048 |
* note this so that we can supply reflexive mappings when the same |
| 4049 |
* object is re-used in the objective case. This allows us to map |
| 4050 |
* things like "you can't take you" to the better-sounding "you |
| 4051 |
* can't take yourself". |
| 4052 |
*/ |
| 4053 |
lastSubject_ = nil |
| 4054 |
|
| 4055 |
/* the parameter name of the last subject ('dobj', 'actor', etc) */ |
| 4056 |
lastSubjectName_ = nil |
| 4057 |
|
| 4058 |
/* |
| 4059 |
* Get the target object property mapping. If the target object is |
| 4060 |
* the same as the most recent subject object (i.e., the last object |
| 4061 |
* used in the nominative case), and this parameter has a reflexive |
| 4062 |
* form property, we'll return the reflexive form property. |
| 4063 |
* Otherwise, we'll return the standard property mapping. |
| 4064 |
* |
| 4065 |
* Also, if there was an exclamation mark at the end of any word in |
| 4066 |
* the tag, we'll return a property returning a fixed-tense form of |
| 4067 |
* the property for the tag. |
| 4068 |
*/ |
| 4069 |
getTargetProp(targetObj, paramObj, info) |
| 4070 |
{ |
| 4071 |
local ret; |
| 4072 |
|
| 4073 |
/* |
| 4074 |
* If this target object matches the last subject, and we have a |
| 4075 |
* reflexive rendering, return the property for the reflexive |
| 4076 |
* rendering. |
| 4077 |
* |
| 4078 |
* Only use the reflexive rendering if the parameter name is |
| 4079 |
* different - if the parameter name is the same, then presumably |
| 4080 |
* the message will have been written with a reflexive pronoun or |
| 4081 |
* not, exactly as the author wants it. When the author knows |
| 4082 |
* going in that these two objects are structurally the same, |
| 4083 |
* they want the exact usage they wrote. |
| 4084 |
*/ |
| 4085 |
if (targetObj == lastSubject_ |
| 4086 |
&& paramObj != lastSubjectName_ |
| 4087 |
&& info[4] != nil) |
| 4088 |
{ |
| 4089 |
/* use the reflexive rendering */ |
| 4090 |
ret = info[4]; |
| 4091 |
} |
| 4092 |
else |
| 4093 |
{ |
| 4094 |
/* no special handling; inherit the default handling */ |
| 4095 |
ret = inherited(targetObj, paramObj, info); |
| 4096 |
} |
| 4097 |
|
| 4098 |
/* if this is a nominative usage, note it as the last subject */ |
| 4099 |
if (info[5]) |
| 4100 |
{ |
| 4101 |
lastSubject_ = targetObj; |
| 4102 |
lastSubjectName_ = paramObj; |
| 4103 |
} |
| 4104 |
|
| 4105 |
/* |
| 4106 |
* If there was an exclamation mark at the end of any word in the |
| 4107 |
* parameter string (which we remember via the fixedTenseProp_ |
| 4108 |
* property), store the original target property in |
| 4109 |
* fixedTenseProp_ and use &propWithPresentMessageBuilder_ as the |
| 4110 |
* target property instead. propWithPresentMessageBuilder_ acts |
| 4111 |
* as a wrapper for the original target property, which it |
| 4112 |
* invokes after temporarily switching to the present tense. |
| 4113 |
*/ |
| 4114 |
if (fixedTenseProp_) |
| 4115 |
{ |
| 4116 |
fixedTenseProp_ = ret; |
| 4117 |
ret = &propWithPresentMessageBuilder_; |
| 4118 |
} |
| 4119 |
|
| 4120 |
/* return the result */ |
| 4121 |
return ret; |
| 4122 |
} |
| 4123 |
|
| 4124 |
/* end-of-sentence match pattern */ |
| 4125 |
patEndOfSentence = static new RexPattern('[.;:!?]<^alphanum>') |
| 4126 |
|
| 4127 |
/* |
| 4128 |
* Process result text. |
| 4129 |
*/ |
| 4130 |
processResult(txt) |
| 4131 |
{ |
| 4132 |
/* |
| 4133 |
* If the text contains any sentence-ending punctuation, reset |
| 4134 |
* our internal memory of the subject of the sentence. We |
| 4135 |
* consider the sentence to end with a period, semicolon, colon, |
| 4136 |
* question mark, or exclamation point followed by anything |
| 4137 |
* other than an alpha-numeric. (We require the secondary |
| 4138 |
* character so that we don't confuse things like "3:00" or |
| 4139 |
* "7.5" to contain sentence-ending punctuation.) |
| 4140 |
*/ |
| 4141 |
if (rexSearch(patEndOfSentence, txt) != nil) |
| 4142 |
{ |
| 4143 |
/* |
| 4144 |
* we have a sentence ending in this run of text, so any |
| 4145 |
* saved subject object will no longer apply after this text |
| 4146 |
* - forget our subject object |
| 4147 |
*/ |
| 4148 |
lastSubject_ = nil; |
| 4149 |
lastSubjectName_ = nil; |
| 4150 |
} |
| 4151 |
|
| 4152 |
/* return the inherited processing */ |
| 4153 |
return inherited(txt); |
| 4154 |
} |
| 4155 |
|
| 4156 |
/* some pre-compiled search patterns we use a lot */ |
| 4157 |
patIdObjSlashIdApostS = static new RexPattern( |
| 4158 |
'(<^space>+)(<space>+<^space>+)\'s(/<^space>+)$') |
| 4159 |
patIdObjApostS = static new RexPattern( |
| 4160 |
'(?!<^space>+\'s<space>)(<^space>+)(<space>+<^space>+)\'s$') |
| 4161 |
patParamWithExclam = static new RexPattern('.*(!)(?:<space>.*|/.*|$)') |
| 4162 |
patSSlashLetterEd = static new RexPattern( |
| 4163 |
's/(<alpha>ed)$|(<alpha>ed)/s$') |
| 4164 |
|
| 4165 |
/* |
| 4166 |
* Rewrite a parameter string for a language-specific syntax |
| 4167 |
* extension. |
| 4168 |
* |
| 4169 |
* For English, we'll handle the possessive apostrophe-s suffix |
| 4170 |
* specially, by allowing the apostrophe-s to be appended to the |
| 4171 |
* target object name. If we find an apostrophe-s on the target |
| 4172 |
* object name, we'll move it to the preceding identifier name: |
| 4173 |
* |
| 4174 |
* the dobj's -> the's dobj |
| 4175 |
*. the dobj's/he -> the's dobj/he |
| 4176 |
*. he/the dobj's -> he/the's dobj |
| 4177 |
* |
| 4178 |
* We also use this method to check for the presence of an |
| 4179 |
* exclamation mark at the end of any word in the parameter string |
| 4180 |
* (triggering the fixed-tense handling), and to detect a parameter |
| 4181 |
* string matching the {s/?ed} syntax, where ? is any letter, and |
| 4182 |
* rewrite it literally as 's/?ed' literally. |
| 4183 |
*/ |
| 4184 |
langRewriteParam(paramStr) |
| 4185 |
{ |
| 4186 |
/* |
| 4187 |
* Check for an exclamation mark at the end of any word in the |
| 4188 |
* parameter string, and remember the result of the test. |
| 4189 |
*/ |
| 4190 |
local exclam = rexMatch(patParamWithExclam, paramStr); |
| 4191 |
fixedTenseProp_ = exclam; |
| 4192 |
|
| 4193 |
/* |
| 4194 |
* Remove the exclamation mark, if any. |
| 4195 |
*/ |
| 4196 |
if (exclam) |
| 4197 |
{ |
| 4198 |
local exclamInd = rexGroup(1)[1]; |
| 4199 |
paramStr = paramStr.substr(1, exclamInd - 1) |
| 4200 |
+ paramStr.substr(exclamInd + 1); |
| 4201 |
} |
| 4202 |
|
| 4203 |
/* look for "id obj's" and "id1 obj's/id2" */ |
| 4204 |
if (rexMatch(patIdObjSlashIdApostS, paramStr) != nil) |
| 4205 |
{ |
| 4206 |
/* rewrite with the "'s" moved to the preceding parameter name */ |
| 4207 |
paramStr = rexGroup(1)[3] + '\'s' |
| 4208 |
+ rexGroup(2)[3] + rexGroup(3)[3]; |
| 4209 |
} |
| 4210 |
else if (rexMatch(patIdObjApostS, paramStr) != nil) |
| 4211 |
{ |
| 4212 |
/* rewrite with the "'s" moved to the preceding parameter name */ |
| 4213 |
paramStr = rexGroup(1)[3] + '\'s' + rexGroup(2)[3]; |
| 4214 |
} |
| 4215 |
|
| 4216 |
/* |
| 4217 |
* Check if this parameter matches the {s/?ed} or {?ed/s} syntax. |
| 4218 |
*/ |
| 4219 |
if (rexMatch(patSSlashLetterEd, paramStr)) |
| 4220 |
{ |
| 4221 |
/* |
| 4222 |
* It does - remember the past verb ending, and rewrite the |
| 4223 |
* parameter literally as 's/?ed'. |
| 4224 |
*/ |
| 4225 |
pastEnding_ = rexGroup(1)[3]; |
| 4226 |
paramStr = 's/?ed'; |
| 4227 |
} |
| 4228 |
|
| 4229 |
/* return our (possibly modified) result */ |
| 4230 |
return paramStr; |
| 4231 |
} |
| 4232 |
|
| 4233 |
/* |
| 4234 |
* This property is used to temporarily store the past-tense ending |
| 4235 |
* of a verb to be displayed by Thing.verbEndingSMessageBuilder_. |
| 4236 |
* It's for internal use only; game authors shouldn't have any reason |
| 4237 |
* to access it directly. |
| 4238 |
*/ |
| 4239 |
pastEnding_ = nil |
| 4240 |
|
| 4241 |
/* |
| 4242 |
* This property is used to temporarily store either a boolean value |
| 4243 |
* indicating whether the last encountered parameter string had an |
| 4244 |
* exclamation mark at the end of any word, or a property to be |
| 4245 |
* invoked by Thing.propWithPresentMessageBuilder_. This field is |
| 4246 |
* for internal use only; authors shouldn't have any reason to access |
| 4247 |
* it directly. |
| 4248 |
*/ |
| 4249 |
fixedTenseProp_ = nil |
| 4250 |
; |
| 4251 |
|
| 4252 |
|
| 4253 |
/* ------------------------------------------------------------------------ */ |
| 4254 |
/* |
| 4255 |
* Temporarily override the current narrative tense and invoke a callback |
| 4256 |
* function. |
| 4257 |
*/ |
| 4258 |
withTense(usePastTense, callback) |
| 4259 |
{ |
| 4260 |
/* |
| 4261 |
* Remember the old value of the usePastTense flag. |
| 4262 |
*/ |
| 4263 |
local oldUsePastTense = gameMain.usePastTense; |
| 4264 |
/* |
| 4265 |
* Set the new value. |
| 4266 |
*/ |
| 4267 |
gameMain.usePastTense = usePastTense; |
| 4268 |
/* |
| 4269 |
* Invoke the callback (remembering the return value) and restore the |
| 4270 |
* usePastTense flag on our way out. |
| 4271 |
*/ |
| 4272 |
local ret; |
| 4273 |
try { ret = callback(); } |
| 4274 |
finally { gameMain.usePastTense = oldUsePastTense; } |
| 4275 |
/* |
| 4276 |
* Return the result. |
| 4277 |
*/ |
| 4278 |
return ret; |
| 4279 |
} |
| 4280 |
|
| 4281 |
|
| 4282 |
/* ------------------------------------------------------------------------ */ |
| 4283 |
/* |
| 4284 |
* Functions for spelling out numbers. These functions take a numeric |
| 4285 |
* value as input, and return a string with the number spelled out as |
| 4286 |
* words in English. For example, given the number 52, we'd return a |
| 4287 |
* string like 'fifty-two'. |
| 4288 |
* |
| 4289 |
* These functions obviously have language-specific implementations. |
| 4290 |
* Note also that even their interfaces might vary by language. Some |
| 4291 |
* languages might need additional information in the interface; for |
| 4292 |
* example, some languages might need to know the grammatical context |
| 4293 |
* (such as part of speech, case, or gender) of the result. |
| 4294 |
* |
| 4295 |
* Note that some of the spellIntXxx flags might not be meaningful in all |
| 4296 |
* languages, because most of the flags are by their very nature |
| 4297 |
* associated with language-specific idioms. Translations are free to |
| 4298 |
* ignore flags that indicate variations with no local equivalent, and to |
| 4299 |
* add their own language-specific flags as needed. |
| 4300 |
*/ |
| 4301 |
|
| 4302 |
/* |
| 4303 |
* Spell out an integer number in words. Returns a string with the |
| 4304 |
* spelled-out number. |
| 4305 |
* |
| 4306 |
* Note that this simple version of the function uses the default |
| 4307 |
* options. If you want to specify non-default options with the |
| 4308 |
* SpellIntXxx flags, you can call spellIntExt(). |
| 4309 |
*/ |
| 4310 |
spellInt(val) |
| 4311 |
{ |
| 4312 |
return spellIntExt(val, 0); |
| 4313 |
} |
| 4314 |
|
| 4315 |
/* |
| 4316 |
* Spell out an integer number in words, but only if it's below the given |
| 4317 |
* threshold. It's often awkward in prose to spell out large numbers, |
| 4318 |
* but exactly what constitutes a large number depends on context, so |
| 4319 |
* this routine lets the caller specify the threshold. |
| 4320 |
* |
| 4321 |
* If the absolute value of val is less than (not equal to) the threshold |
| 4322 |
* value, we'll return a string with the number spelled out. If the |
| 4323 |
* absolute value is greater than or equal to the threshold value, we'll |
| 4324 |
* return a string representing the number in decimal digits. |
| 4325 |
*/ |
| 4326 |
spellIntBelow(val, threshold) |
| 4327 |
{ |
| 4328 |
return spellIntBelowExt(val, threshold, 0, 0); |
| 4329 |
} |
| 4330 |
|
| 4331 |
/* |
| 4332 |
* Spell out an integer number in words if it's below a threshold, using |
| 4333 |
* the spellIntXxx flags given in spellFlags to control the spelled-out |
| 4334 |
* format, and using the DigitFormatXxx flags in digitFlags to control |
| 4335 |
* the digit format. |
| 4336 |
*/ |
| 4337 |
spellIntBelowExt(val, threshold, spellFlags, digitFlags) |
| 4338 |
{ |
| 4339 |
local absval; |
| 4340 |
|
| 4341 |
/* compute the absolute value */ |
| 4342 |
absval = (val < 0 ? -val : val); |
| 4343 |
|
| 4344 |
/* check the value to see whether to spell it or write it as digits */ |
| 4345 |
if (absval < threshold) |
| 4346 |
{ |
| 4347 |
/* it's below the threshold - spell it out in words */ |
| 4348 |
return spellIntExt(val, spellFlags); |
| 4349 |
} |
| 4350 |
else |
| 4351 |
{ |
| 4352 |
/* it's not below the threshold - write it as digits */ |
| 4353 |
return intToDecimal(val, digitFlags); |
| 4354 |
} |
| 4355 |
} |
| 4356 |
|
| 4357 |
/* |
| 4358 |
* Format a number as a string of decimal digits. The DigitFormatXxx |
| 4359 |
* flags specify how the number is to be formatted.` |
| 4360 |
*/ |
| 4361 |
intToDecimal(val, flags) |
| 4362 |
{ |
| 4363 |
local str; |
| 4364 |
local sep; |
| 4365 |
|
| 4366 |
/* perform the basic conversion */ |
| 4367 |
str = toString(val); |
| 4368 |
|
| 4369 |
/* add group separators as needed */ |
| 4370 |
if ((flags & DigitFormatGroupComma) != 0) |
| 4371 |
{ |
| 4372 |
/* explicitly use a comma as a separator */ |
| 4373 |
sep = ','; |
| 4374 |
} |
| 4375 |
else if ((flags & DigitFormatGroupPeriod) != 0) |
| 4376 |
{ |
| 4377 |
/* explicitly use a period as a separator */ |
| 4378 |
sep = '.'; |
| 4379 |
} |
| 4380 |
else if ((flags & DigitFormatGroupSep) != 0) |
| 4381 |
{ |
| 4382 |
/* use the current languageGlobals separator */ |
| 4383 |
sep = languageGlobals.digitGroupSeparator; |
| 4384 |
} |
| 4385 |
else |
| 4386 |
{ |
| 4387 |
/* no separator */ |
| 4388 |
sep = nil; |
| 4389 |
} |
| 4390 |
|
| 4391 |
/* if there's a separator, add it in */ |
| 4392 |
if (sep != nil) |
| 4393 |
{ |
| 4394 |
local i; |
| 4395 |
local len; |
| 4396 |
|
| 4397 |
/* |
| 4398 |
* Insert the separator before each group of three digits. |
| 4399 |
* Start at the right end of the string and work left: peel off |
| 4400 |
* the last three digits and insert a comma. Then, move back |
| 4401 |
* four characters through the string - another three-digit |
| 4402 |
* group, plus the comma we inserted - and repeat. Keep going |
| 4403 |
* until the amount we'd want to peel off the end is as long or |
| 4404 |
* longer than the entire remaining string. |
| 4405 |
*/ |
| 4406 |
for (i = 3, len = str.length() ; len > i ; i += 4) |
| 4407 |
{ |
| 4408 |
/* insert this comma */ |
| 4409 |
str = str.substr(1, len - i) + sep + str.substr(len - i + 1); |
| 4410 |
|
| 4411 |
/* note the new length */ |
| 4412 |
len = str.length(); |
| 4413 |
} |
| 4414 |
} |
| 4415 |
|
| 4416 |
/* return the result */ |
| 4417 |
return str; |
| 4418 |
} |
| 4419 |
|
| 4420 |
/* |
| 4421 |
* Spell out an integer number - "extended" interface with flags. The |
| 4422 |
* "flags" argument is a (bitwise-OR'd) combination of SpellIntXxx |
| 4423 |
* values, specifying the desired format of the result. |
| 4424 |
*/ |
| 4425 |
spellIntExt(val, flags) |
| 4426 |
{ |
| 4427 |
local str; |
| 4428 |
local trailingSpace; |
| 4429 |
local needAnd; |
| 4430 |
local powers = [1000000000, ' billion ', |
| 4431 |
1000000, ' million ', |
| 4432 |
1000, ' thousand ', |
| 4433 |
100, ' hundred ']; |
| 4434 |
|
| 4435 |
/* start with an empty string */ |
| 4436 |
str = ''; |
| 4437 |
trailingSpace = nil; |
| 4438 |
needAnd = nil; |
| 4439 |
|
| 4440 |
/* if it's zero, it's a special case */ |
| 4441 |
if (val == 0) |
| 4442 |
return 'zero'; |
| 4443 |
|
| 4444 |
/* |
| 4445 |
* if the number is negative, note it in the string, and use the |
| 4446 |
* absolute value |
| 4447 |
*/ |
| 4448 |
if (val < 0) |
| 4449 |
{ |
| 4450 |
str = 'negative '; |
| 4451 |
val = -val; |
| 4452 |
} |
| 4453 |
|
| 4454 |
/* do each named power of ten */ |
| 4455 |
for (local i = 1 ; val >= 100 && i <= powers.length() ; i += 2) |
| 4456 |
{ |
| 4457 |
/* |
| 4458 |
* if we're in teen-hundreds mode, do the teen-hundreds - this |
| 4459 |
* only works for values from 1,100 to 9,999, since a number like |
| 4460 |
* 12,000 doesn't work this way - 'one hundred twenty hundred' is |
| 4461 |
* no good |
| 4462 |
*/ |
| 4463 |
if ((flags & SpellIntTeenHundreds) != 0 |
| 4464 |
&& val >= 1100 && val < 10000) |
| 4465 |
{ |
| 4466 |
/* if desired, add a comma if there was a prior power group */ |
| 4467 |
if (needAnd && (flags & SpellIntCommas) != 0) |
| 4468 |
str = str.substr(1, str.length() - 1) + ', '; |
| 4469 |
|
| 4470 |
/* spell it out as a number of hundreds */ |
| 4471 |
str += spellIntExt(val / 100, flags) + ' hundred '; |
| 4472 |
|
| 4473 |
/* take off the hundreds */ |
| 4474 |
val %= 100; |
| 4475 |
|
| 4476 |
/* note the trailing space */ |
| 4477 |
trailingSpace = true; |
| 4478 |
|
| 4479 |
/* we have something to put an 'and' after, if desired */ |
| 4480 |
needAnd = true; |
| 4481 |
|
| 4482 |
/* |
| 4483 |
* whatever's left is below 100 now, so there's no need to |
| 4484 |
* keep scanning the big powers of ten |
| 4485 |
*/ |
| 4486 |
break; |
| 4487 |
} |
| 4488 |
|
| 4489 |
/* if we have something in this power range, apply it */ |
| 4490 |
if (val >= powers[i]) |
| 4491 |
{ |
| 4492 |
/* if desired, add a comma if there was a prior power group */ |
| 4493 |
if (needAnd && (flags & SpellIntCommas) != 0) |
| 4494 |
str = str.substr(1, str.length() - 1) + ', '; |
| 4495 |
|
| 4496 |
/* add the number of multiples of this power and the power name */ |
| 4497 |
str += spellIntExt(val / powers[i], flags) + powers[i+1]; |
| 4498 |
|
| 4499 |
/* take it out of the remaining value */ |
| 4500 |
val %= powers[i]; |
| 4501 |
|
| 4502 |
/* |
| 4503 |
* note that we have a trailing space in the string (all of |
| 4504 |
* the power-of-ten names have a trailing space, to make it |
| 4505 |
* easy to tack on the remainder of the value) |
| 4506 |
*/ |
| 4507 |
trailingSpace = true; |
| 4508 |
|
| 4509 |
/* we have something to put an 'and' after, if one is desired */ |
| 4510 |
needAnd = true; |
| 4511 |
} |
| 4512 |
} |
| 4513 |
|
| 4514 |
/* |
| 4515 |
* if we have anything left, and we have written something so far, |
| 4516 |
* and the caller wanted an 'and' before the tens part, add the |
| 4517 |
* 'and' |
| 4518 |
*/ |
| 4519 |
if ((flags & SpellIntAndTens) != 0 |
| 4520 |
&& needAnd |
| 4521 |
&& val != 0) |
| 4522 |
{ |
| 4523 |
/* add the 'and' */ |
| 4524 |
str += 'and '; |
| 4525 |
trailingSpace = true; |
| 4526 |
} |
| 4527 |
|
| 4528 |
/* do the tens */ |
| 4529 |
if (val >= 20) |
| 4530 |
{ |
| 4531 |
/* anything above the teens is nice and regular */ |
| 4532 |
str += ['twenty', 'thirty', 'forty', 'fifty', 'sixty', |
| 4533 |
'seventy', 'eighty', 'ninety'][val/10 - 1]; |
| 4534 |
val %= 10; |
| 4535 |
|
| 4536 |
/* if it's non-zero, we'll add the units, so add a hyphen */ |
| 4537 |
if (val != 0) |
| 4538 |
str += '-'; |
| 4539 |
|
| 4540 |
/* we no longer have a trailing space in the string */ |
| 4541 |
trailingSpace = nil; |
| 4542 |
} |
| 4543 |
else if (val >= 10) |
| 4544 |
{ |
| 4545 |
/* we have a teen */ |
| 4546 |
str += ['ten', 'eleven', 'twelve', 'thirteen', 'fourteen', |
| 4547 |
'fifteen', 'sixteen', 'seventeen', 'eighteen', |
| 4548 |
'nineteen'][val - 9]; |
| 4549 |
|
| 4550 |
/* we've finished with the number */ |
| 4551 |
val = 0; |
| 4552 |
|
| 4553 |
/* there's no trailing space */ |
| 4554 |
trailingSpace = nil; |
| 4555 |
} |
| 4556 |
|
| 4557 |
/* if we have a units value, add it */ |
| 4558 |
if (val != 0) |
| 4559 |
{ |
| 4560 |
/* add the units name */ |
| 4561 |
str += ['one', 'two', 'three', 'four', 'five', |
| 4562 |
'six', 'seven', 'eight', 'nine'][val]; |
| 4563 |
|
| 4564 |
/* we have no trailing space now */ |
| 4565 |
trailingSpace = nil; |
| 4566 |
} |
| 4567 |
|
| 4568 |
/* if there's a trailing space, remove it */ |
| 4569 |
if (trailingSpace) |
| 4570 |
str = str.substr(1, str.length() - 1); |
| 4571 |
|
| 4572 |
/* return the string */ |
| 4573 |
return str; |
| 4574 |
} |
| 4575 |
|
| 4576 |
/* |
| 4577 |
* Return a string giving the numeric ordinal representation of a number: |
| 4578 |
* 1st, 2nd, 3rd, 4th, etc. |
| 4579 |
*/ |
| 4580 |
intOrdinal(n) |
| 4581 |
{ |
| 4582 |
local s; |
| 4583 |
|
| 4584 |
/* start by getting the string form of the number */ |
| 4585 |
s = toString(n); |
| 4586 |
|
| 4587 |
/* now add the appropriate suffix */ |
| 4588 |
if (n >= 10 && n <= 19) |
| 4589 |
{ |
| 4590 |
/* the teens all end in 'th' */ |
| 4591 |
return s + 'th'; |
| 4592 |
} |
| 4593 |
else |
| 4594 |
{ |
| 4595 |
/* |
| 4596 |
* for anything but a teen, a number whose last digit is 1 |
| 4597 |
* always has the suffix 'st' (for 'xxx-first', as in '141st'), |
| 4598 |
* a number whose last digit is 2 always ends in 'nd' (for |
| 4599 |
* 'xxx-second', as in '532nd'), a number whose last digit is 3 |
| 4600 |
* ends in 'rd' (for 'xxx-third', as in '53rd'), and anything |
| 4601 |
* else ends in 'th' |
| 4602 |
*/ |
| 4603 |
switch(n % 10) |
| 4604 |
{ |
| 4605 |
case 1: |
| 4606 |
return s + 'st'; |
| 4607 |
|
| 4608 |
case 2: |
| 4609 |
return s + 'nd'; |
| 4610 |
|
| 4611 |
case 3: |
| 4612 |
return s + 'rd'; |
| 4613 |
|
| 4614 |
default: |
| 4615 |
return s + 'th'; |
| 4616 |
} |
| 4617 |
} |
| 4618 |
} |
| 4619 |
|
| 4620 |
|
| 4621 |
/* |
| 4622 |
* Return a string giving a fully spelled-out ordinal form of a number: |
| 4623 |
* first, second, third, etc. |
| 4624 |
*/ |
| 4625 |
spellIntOrdinal(n) |
| 4626 |
{ |
| 4627 |
return spellIntOrdinalExt(n, 0); |
| 4628 |
} |
| 4629 |
|
| 4630 |
/* |
| 4631 |
* Return a string giving a fully spelled-out ordinal form of a number: |
| 4632 |
* first, second, third, etc. This form takes the same flag values as |
| 4633 |
* spellIntExt(). |
| 4634 |
*/ |
| 4635 |
spellIntOrdinalExt(n, flags) |
| 4636 |
{ |
| 4637 |
local s; |
| 4638 |
|
| 4639 |
/* get the spelled-out form of the number itself */ |
| 4640 |
s = spellIntExt(n, flags); |
| 4641 |
|
| 4642 |
/* |
| 4643 |
* If the number ends in 'one', change the ending to 'first'; 'two' |
| 4644 |
* becomes 'second'; 'three' becomes 'third'; 'five' becomes |
| 4645 |
* 'fifth'; 'eight' becomes 'eighth'; 'nine' becomes 'ninth'. If |
| 4646 |
* the number ends in 'y', change the 'y' to 'ieth'. 'Zero' becomes |
| 4647 |
* 'zeroeth'. For everything else, just add 'th' to the spelled-out |
| 4648 |
* name |
| 4649 |
*/ |
| 4650 |
if (s == 'zero') |
| 4651 |
return 'zeroeth'; |
| 4652 |
if (s.endsWith('one')) |
| 4653 |
return s.substr(1, s.length() - 3) + 'first'; |
| 4654 |
else if (s.endsWith('two')) |
| 4655 |
return s.substr(1, s.length() - 3) + 'second'; |
| 4656 |
else if (s.endsWith('three')) |
| 4657 |
return s.substr(1, s.length() - 5) + 'third'; |
| 4658 |
else if (s.endsWith('five')) |
| 4659 |
return s.substr(1, s.length() - 4) + 'fifth'; |
| 4660 |
else if (s.endsWith('eight')) |
| 4661 |
return s.substr(1, s.length() - 5) + 'eighth'; |
| 4662 |
else if (s.endsWith('nine')) |
| 4663 |
return s.substr(1, s.length() - 4) + 'ninth'; |
| 4664 |
else if (s.endsWith('y')) |
| 4665 |
return s.substr(1, s.length() - 1) + 'ieth'; |
| 4666 |
else |
| 4667 |
return s + 'th'; |
| 4668 |
} |
| 4669 |
|
| 4670 |
/* ------------------------------------------------------------------------ */ |
| 4671 |
/* |
| 4672 |
* Parse a spelled-out number. This is essentially the reverse of |
| 4673 |
* spellInt() and related functions: we take a string that contains a |
| 4674 |
* spelled-out number and return the integer value. This uses the |
| 4675 |
* command parser's spelled-out number rules, so we can parse anything |
| 4676 |
* that would be recognized as a number in a command. |
| 4677 |
* |
| 4678 |
* If the string contains numerals, we'll treat it as a number in digit |
| 4679 |
* format: for example, if it contains '789', we'll return 789. |
| 4680 |
* |
| 4681 |
* If the string doesn't parse as a number, we return nil. |
| 4682 |
*/ |
| 4683 |
parseInt(str) |
| 4684 |
{ |
| 4685 |
try |
| 4686 |
{ |
| 4687 |
/* tokenize the string */ |
| 4688 |
local toks = cmdTokenizer.tokenize(str); |
| 4689 |
|
| 4690 |
/* parse it */ |
| 4691 |
return parseIntTokens(toks); |
| 4692 |
} |
| 4693 |
catch (Exception exc) |
| 4694 |
{ |
| 4695 |
/* |
| 4696 |
* on any exception, just return nil to indicate that we couldn't |
| 4697 |
* parse the string as a number |
| 4698 |
*/ |
| 4699 |
return nil; |
| 4700 |
} |
| 4701 |
} |
| 4702 |
|
| 4703 |
/* |
| 4704 |
* Parse a spelled-out number that's given as a token list (as returned |
| 4705 |
* from Tokenizer.tokenize). If we can successfully parse the token list |
| 4706 |
* as a number, we'll return the integer value. If not, we'll return |
| 4707 |
* nil. |
| 4708 |
*/ |
| 4709 |
parseIntTokens(toks) |
| 4710 |
{ |
| 4711 |
try |
| 4712 |
{ |
| 4713 |
/* |
| 4714 |
* if the first token contains digits, treat it as a numeric |
| 4715 |
* string value rather than a spelled-out number |
| 4716 |
*/ |
| 4717 |
if (toks.length() != 0 |
| 4718 |
&& rexMatch('<digit>+', getTokOrig(toks[1])) != nil) |
| 4719 |
return toInteger(getTokOrig(toks[1])); |
| 4720 |
|
| 4721 |
/* parse it using the spelledNumber production */ |
| 4722 |
local lst = spelledNumber.parseTokens(toks, cmdDict); |
| 4723 |
|
| 4724 |
/* |
| 4725 |
* if we got a match, return the integer value; if not, it's not |
| 4726 |
* parseable as a number, so return nil |
| 4727 |
*/ |
| 4728 |
return (lst.length() != 0 ? lst[1].getval() : nil); |
| 4729 |
} |
| 4730 |
catch (Exception exc) |
| 4731 |
{ |
| 4732 |
/* |
| 4733 |
* on any exception, just return nil to indicate that it's not |
| 4734 |
* parseable as a number |
| 4735 |
*/ |
| 4736 |
return nil; |
| 4737 |
} |
| 4738 |
} |
| 4739 |
|
| 4740 |
|
| 4741 |
/* ------------------------------------------------------------------------ */ |
| 4742 |
/* |
| 4743 |
* Additional token types for US English. |
| 4744 |
*/ |
| 4745 |
|
| 4746 |
/* special "apostrophe-s" token */ |
| 4747 |
enum token tokApostropheS; |
| 4748 |
|
| 4749 |
/* special apostrophe token for plural possessives ("the smiths' house") */ |
| 4750 |
enum token tokPluralApostrophe; |
| 4751 |
|
| 4752 |
/* special abbreviation-period token */ |
| 4753 |
enum token tokAbbrPeriod; |
| 4754 |
|
| 4755 |
/* special "#nnn" numeric token */ |
| 4756 |
enum token tokPoundInt; |
| 4757 |
|
| 4758 |
/* |
| 4759 |
* Command tokenizer for US English. Other language modules should |
| 4760 |
* provide their own tokenizers to allow for differences in punctuation |
| 4761 |
* and other lexical elements. |
| 4762 |
*/ |
| 4763 |
cmdTokenizer: Tokenizer |
| 4764 |
rules_ = static |
| 4765 |
[ |
| 4766 |
/* skip whitespace */ |
| 4767 |
['whitespace', new RexPattern('<Space>+'), nil, &tokCvtSkip, nil], |
| 4768 |
|
| 4769 |
/* certain punctuation marks */ |
| 4770 |
['punctuation', new RexPattern('[.,;:?!]'), tokPunct, nil, nil], |
| 4771 |
|
| 4772 |
/* |
| 4773 |
* We have a special rule for spelled-out numbers from 21 to 99: |
| 4774 |
* when we see a 'tens' word followed by a hyphen followed by a |
| 4775 |
* digits word, we'll pull out the tens word, the hyphen, and |
| 4776 |
* the digits word as separate tokens. |
| 4777 |
*/ |
| 4778 |
['spelled number', |
| 4779 |
new RexPattern('<NoCase>(twenty|thirty|forty|fifty|sixty|' |
| 4780 |
+ 'seventy|eighty|ninety)-' |
| 4781 |
+ '(one|two|three|four|five|six|seven|eight|nine)' |
| 4782 |
+ '(?!<AlphaNum>)'), |
| 4783 |
tokWord, &tokCvtSpelledNumber, nil], |
| 4784 |
|
| 4785 |
|
| 4786 |
/* |
| 4787 |
* Initials. We'll look for strings of three or two initials, |
| 4788 |
* set off by periods but without spaces. We'll look for |
| 4789 |
* three-letter initials first ("G.H.W. Billfold"), then |
| 4790 |
* two-letter initials ("X.Y. Zed"), so that we find the longest |
| 4791 |
* sequence that's actually in the dictionary. Note that we |
| 4792 |
* don't have a separate rule for individual initials, since |
| 4793 |
* we'll pick that up with the regular abbreviated word rule |
| 4794 |
* below. |
| 4795 |
* |
| 4796 |
* Some games could conceivably extend this to allow strings of |
| 4797 |
* initials of four letters or longer, but in practice people |
| 4798 |
* tend to elide the periods in longer sets of initials, so that |
| 4799 |
* the initials become an acronym, and thus would fit the |
| 4800 |
* ordinary word token rule. |
| 4801 |
*/ |
| 4802 |
['three initials', |
| 4803 |
new RexPattern('<alpha><period><alpha><period><alpha><period>'), |
| 4804 |
tokWord, &tokCvtAbbr, &acceptAbbrTok], |
| 4805 |
|
| 4806 |
['two initials', |
| 4807 |
new RexPattern('<alpha><period><alpha><period>'), |
| 4808 |
tokWord, &tokCvtAbbr, &acceptAbbrTok], |
| 4809 |
|
| 4810 |
/* |
| 4811 |
* Abbbreviated word - this is a word that ends in a period, |
| 4812 |
* such as "Mr.". This rule comes before the ordinary word rule |
| 4813 |
* because we will only consider the period to be part of the |
| 4814 |
* word (and not a separate token) if the entire string |
| 4815 |
* including the period is in the main vocabulary dictionary. |
| 4816 |
*/ |
| 4817 |
['abbreviation', |
| 4818 |
new RexPattern('<Alpha|-><AlphaNum|-|squote>*<period>'), |
| 4819 |
tokWord, &tokCvtAbbr, &acceptAbbrTok], |
| 4820 |
|
| 4821 |
/* |
| 4822 |
* A word ending in an apostrophe-s. We parse this as two |
| 4823 |
* separate tokens: one for the word and one for the |
| 4824 |
* apostrophe-s. |
| 4825 |
*/ |
| 4826 |
['apostrophe-s word', |
| 4827 |
new RexPattern('<Alpha|-|&><AlphaNum|-|&|squote>*<squote>[sS]'), |
| 4828 |
tokWord, &tokCvtApostropheS, nil], |
| 4829 |
|
| 4830 |
/* |
| 4831 |
* A plural word ending in an apostrophe. We parse this as two |
| 4832 |
* separate tokens: one for the word and one for the apostrophe. |
| 4833 |
*/ |
| 4834 |
['plural possessive word', |
| 4835 |
new RexPattern('<Alpha|-|&><AlphaNum|-|&|squote>*<squote>' |
| 4836 |
+ '(?!<AlphaNum>)'), |
| 4837 |
tokWord, &tokCvtPluralApostrophe, nil], |
| 4838 |
|
| 4839 |
/* |
| 4840 |
* Words - note that we convert everything to lower-case. A word |
| 4841 |
* must start with an alphabetic character, a hyphen, or an |
| 4842 |
* ampersand; after the initial character, a word can contain |
| 4843 |
* alphabetics, digits, hyphens, ampersands, and apostrophes. |
| 4844 |
*/ |
| 4845 |
['word', |
| 4846 |
new RexPattern('<Alpha|-|&><AlphaNum|-|&|squote>*'), |
| 4847 |
tokWord, nil, nil], |
| 4848 |
|
| 4849 |
/* an abbreviation word starting with a number */ |
| 4850 |
['abbreviation with initial digit', |
| 4851 |
new RexPattern('<Digit>(?=<AlphaNum|-|&|squote>*<Alpha|-|&|squote>)' |
| 4852 |
+ '<AlphaNum|-|&|squote>*<period>'), |
| 4853 |
tokWord, &tokCvtAbbr, &acceptAbbrTok], |
| 4854 |
|
| 4855 |
/* |
| 4856 |
* A word can start with a number, as long as there's something |
| 4857 |
* other than numbers in the string - if it's all numbers, we |
| 4858 |
* want to treat it as a numeric token. |
| 4859 |
*/ |
| 4860 |
['word with initial digit', |
| 4861 |
new RexPattern('<Digit>(?=<AlphaNum|-|&|squote>*<Alpha|-|&|squote>)' |
| 4862 |
+ '<AlphaNum|-|&|squote>*'), tokWord, nil, nil], |
| 4863 |
|
| 4864 |
/* strings with ASCII "straight" quotes */ |
| 4865 |
['string ascii-quote', |
| 4866 |
new RexPattern('<min>([`\'"])(.*)%1(?!<AlphaNum>)'), |
| 4867 |
tokString, nil, nil], |
| 4868 |
|
| 4869 |
/* some people like to use single quotes like `this' */ |
| 4870 |
['string back-quote', |
| 4871 |
new RexPattern('<min>`(.*)\'(?!<AlphaNum>)'), tokString, nil, nil], |
| 4872 |
|
| 4873 |
/* strings with Latin-1 curly quotes (single and double) */ |
| 4874 |
['string curly single-quote', |
| 4875 |
new RexPattern('<min>\u2018(.*)\u2019'), tokString, nil, nil], |
| 4876 |
['string curly double-quote', |
| 4877 |
new RexPattern('<min>\u201C(.*)\u201D'), tokString, nil, nil], |
| 4878 |
|
| 4879 |
/* |
| 4880 |
* unterminated string - if we didn't just match a terminated |
| 4881 |
* string, but we have what looks like the start of a string, |
| 4882 |
* match to the end of the line |
| 4883 |
*/ |
| 4884 |
['string unterminated', |
| 4885 |
new RexPattern('([`\'"\u2018\u201C](.*)'), tokString, nil, nil], |
| 4886 |
|
| 4887 |
/* integer numbers */ |
| 4888 |
['integer', new RexPattern('[0-9]+'), tokInt, nil, nil], |
| 4889 |
|
| 4890 |
/* numbers with a '#' preceding */ |
| 4891 |
['integer with #', |
| 4892 |
new RexPattern('#[0-9]+'), tokPoundInt, nil, nil] |
| 4893 |
] |
| 4894 |
|
| 4895 |
/* |
| 4896 |
* Handle an apostrophe-s word. We'll return this as two separate |
| 4897 |
* tokens: one for the word preceding the apostrophe-s, and one for |
| 4898 |
* the apostrophe-s itself. |
| 4899 |
*/ |
| 4900 |
tokCvtApostropheS(txt, typ, toks) |
| 4901 |
{ |
| 4902 |
local w; |
| 4903 |
local s; |
| 4904 |
|
| 4905 |
/* |
| 4906 |
* pull out the part up to but not including the apostrophe, and |
| 4907 |
* pull out the apostrophe-s part |
| 4908 |
*/ |
| 4909 |
w = txt.substr(1, txt.length() - 2); |
| 4910 |
s = txt.substr(-2); |
| 4911 |
|
| 4912 |
/* add the part before the apostrophe as the main token type */ |
| 4913 |
toks.append([w, typ, w]); |
| 4914 |
|
| 4915 |
/* add the apostrophe-s as a separate special token */ |
| 4916 |
toks.append([s, tokApostropheS, s]); |
| 4917 |
} |
| 4918 |
|
| 4919 |
/* |
| 4920 |
* Handle a plural apostrophe word ("the smiths' house"). We'll |
| 4921 |
* return this as two tokens: one for the plural word, and one for |
| 4922 |
* the apostrophe. |
| 4923 |
*/ |
| 4924 |
tokCvtPluralApostrophe(txt, typ, toks) |
| 4925 |
{ |
| 4926 |
local w; |
| 4927 |
local s; |
| 4928 |
|
| 4929 |
/* |
| 4930 |
* pull out the part up to but not including the apostrophe, and |
| 4931 |
* separately pull out the apostrophe |
| 4932 |
*/ |
| 4933 |
w = txt.substr(1, txt.length() - 1); |
| 4934 |
s = txt.substr(-1); |
| 4935 |
|
| 4936 |
/* add the part before the apostrophe as the main token type */ |
| 4937 |
toks.append([w, typ, w]); |
| 4938 |
|
| 4939 |
/* add the apostrophe-s as a separate special token */ |
| 4940 |
toks.append([s, tokPluralApostrophe, s]); |
| 4941 |
} |
| 4942 |
|
| 4943 |
/* |
| 4944 |
* Handle a spelled-out hyphenated number from 21 to 99. We'll |
| 4945 |
* return this as three separate tokens: a word for the tens name, a |
| 4946 |
* word for the hyphen, and a word for the units name. |
| 4947 |
*/ |
| 4948 |
tokCvtSpelledNumber(txt, typ, toks) |
| 4949 |
{ |
| 4950 |
/* parse the number into its three parts with a regular expression */ |
| 4951 |
rexMatch(patAlphaDashAlpha, txt); |
| 4952 |
|
| 4953 |
/* add the part before the hyphen */ |
| 4954 |
toks.append([rexGroup(1)[3], typ, rexGroup(1)[3]]); |
| 4955 |
|
| 4956 |
/* add the hyphen */ |
| 4957 |
toks.append(['-', typ, '-']); |
| 4958 |
|
| 4959 |
/* add the part after the hyphen */ |
| 4960 |
toks.append([rexGroup(2)[3], typ, rexGroup(2)[3]]); |
| 4961 |
} |
| 4962 |
patAlphaDashAlpha = static new RexPattern('(<alpha>+)-(<alpha>+)') |
| 4963 |
|
| 4964 |
/* |
| 4965 |
* Check to see if we want to accept an abbreviated token - this is |
| 4966 |
* a token that ends in a period, which we use for abbreviated words |
| 4967 |
* like "Mr." or "Ave." We'll accept the token only if it appears |
| 4968 |
* as given - including the period - in the dictionary. Note that |
| 4969 |
* we ignore truncated matches, since the only way we'll accept a |
| 4970 |
* period in a word token is as the last character; there is thus no |
| 4971 |
* way that a token ending in a period could be a truncation of any |
| 4972 |
* longer valid token. |
| 4973 |
*/ |
| 4974 |
acceptAbbrTok(txt) |
| 4975 |
{ |
| 4976 |
/* look up the word, filtering out truncated results */ |
| 4977 |
return cmdDict.isWordDefined( |
| 4978 |
txt, {result: (result & StrCompTrunc) == 0}); |
| 4979 |
} |
| 4980 |
|
| 4981 |
/* |
| 4982 |
* Process an abbreviated token. |
| 4983 |
* |
| 4984 |
* When we find an abbreviation, we'll enter it with the abbreviated |
| 4985 |
* word minus the trailing period, plus the period as a separate |
| 4986 |
* token. We'll mark the period as an "abbreviation period" so that |
| 4987 |
* grammar rules will be able to consider treating it as an |
| 4988 |
* abbreviation -- but since it's also a regular period, grammar |
| 4989 |
* rules that treat periods as regular punctuation will also be able |
| 4990 |
* to try to match the result. This will ensure that we try it both |
| 4991 |
* ways - as abbreviation and as a word with punctuation - and pick |
| 4992 |
* the one that gives us the best result. |
| 4993 |
*/ |
| 4994 |
tokCvtAbbr(txt, typ, toks) |
| 4995 |
{ |
| 4996 |
local w; |
| 4997 |
|
| 4998 |
/* add the part before the period as the ordinary token */ |
| 4999 |
w = txt.substr(1, txt.length() - 1); |
| 5000 |
toks.append([w, typ, w]); |
| 5001 |
|
| 5002 |
/* add the token for the "abbreviation period" */ |
| 5003 |
toks.append(['.', tokAbbrPeriod, '.']); |
| 5004 |
} |
| 5005 |
|
| 5006 |
/* |
| 5007 |
* Given a list of token strings, rebuild the original input string. |
| 5008 |
* We can't recover the exact input string, because the tokenization |
| 5009 |
* process throws away whitespace information, but we can at least |
| 5010 |
* come up with something that will display cleanly and produce the |
| 5011 |
* same results when run through the tokenizer. |
| 5012 |
*/ |
| 5013 |
buildOrigText(toks) |
| 5014 |
{ |
| 5015 |
local str; |
| 5016 |
|
| 5017 |
/* start with an empty string */ |
| 5018 |
str = ''; |
| 5019 |
|
| 5020 |
/* concatenate each token in the list */ |
| 5021 |
for (local i = 1, local len = toks.length() ; i <= len ; ++i) |
| 5022 |
{ |
| 5023 |
/* add the current token to the string */ |
| 5024 |
str += getTokOrig(toks[i]); |
| 5025 |
|
| 5026 |
/* |
| 5027 |
* if this looks like a hyphenated number that we picked |
| 5028 |
* apart into two tokens, put it back together without |
| 5029 |
* spaces |
| 5030 |
*/ |
| 5031 |
if (i + 2 <= len |
| 5032 |
&& rexMatch(patSpelledTens, getTokVal(toks[i])) != nil |
| 5033 |
&& getTokVal(toks[i+1]) == '-' |
| 5034 |
&& rexMatch(patSpelledUnits, getTokVal(toks[i+2])) != nil) |
| 5035 |
{ |
| 5036 |
/* |
| 5037 |
* it's a hyphenated number, all right - put the three |
| 5038 |
* tokens back together without any intervening spaces, |
| 5039 |
* so ['twenty', '-', 'one'] turns into 'twenty-one' |
| 5040 |
*/ |
| 5041 |
str += getTokOrig(toks[i+1]) + getTokOrig(toks[i+2]); |
| 5042 |
|
| 5043 |
/* skip ahead by the two extra tokens we're adding */ |
| 5044 |
i += 2; |
| 5045 |
} |
| 5046 |
else if (i + 1 <= len |
| 5047 |
&& getTokType(toks[i]) == tokWord |
| 5048 |
&& getTokType(toks[i+1]) is in |
| 5049 |
(tokApostropheS, tokPluralApostrophe)) |
| 5050 |
{ |
| 5051 |
/* |
| 5052 |
* it's a word followed by an apostrophe-s token - these |
| 5053 |
* are appended together without any intervening spaces |
| 5054 |
*/ |
| 5055 |
str += getTokOrig(toks[i+1]); |
| 5056 |
|
| 5057 |
/* skip the extra token we added */ |
| 5058 |
++i; |
| 5059 |
} |
| 5060 |
|
| 5061 |
/* |
| 5062 |
* If another token follows, and the next token isn't a |
| 5063 |
* punctuation mark, and the previous token wasn't an open |
| 5064 |
* paren, add a space before the next token. |
| 5065 |
*/ |
| 5066 |
if (i != len |
| 5067 |
&& rexMatch(patPunct, getTokVal(toks[i+1])) == nil |
| 5068 |
&& getTokVal(toks[i]) != '(') |
| 5069 |
str += ' '; |
| 5070 |
} |
| 5071 |
|
| 5072 |
/* return the result string */ |
| 5073 |
return str; |
| 5074 |
} |
| 5075 |
|
| 5076 |
/* some pre-compiled regular expressions */ |
| 5077 |
patSpelledTens = static new RexPattern( |
| 5078 |
'<nocase>twenty|thirty|forty|fifty|sixty|seventy|eighty|ninety') |
| 5079 |
patSpelledUnits = static new RexPattern( |
| 5080 |
'<nocase>one|two|three|four|five|six|seven|eight|nine') |
| 5081 |
patPunct = static new RexPattern('[.,;:?!)]') |
| 5082 |
; |
| 5083 |
|
| 5084 |
|
| 5085 |
/* ------------------------------------------------------------------------ */ |
| 5086 |
/* |
| 5087 |
* Grammar Rules |
| 5088 |
*/ |
| 5089 |
|
| 5090 |
/* |
| 5091 |
* Command with explicit target actor. When a command starts with an |
| 5092 |
* actor's name followed by a comma followed by a verb, we take it as |
| 5093 |
* being directed to the actor. |
| 5094 |
*/ |
| 5095 |
grammar firstCommandPhrase(withActor): |
| 5096 |
singleNounOnly->actor_ ',' commandPhrase->cmd_ |
| 5097 |
: FirstCommandProdWithActor |
| 5098 |
|
| 5099 |
/* "execute" the target actor phrase */ |
| 5100 |
execActorPhrase(issuingActor) |
| 5101 |
{ |
| 5102 |
/* flag that the actor's being addressed in the second person */ |
| 5103 |
resolvedActor_.commandReferralPerson = SecondPerson; |
| 5104 |
} |
| 5105 |
; |
| 5106 |
|
| 5107 |
grammar firstCommandPhrase(askTellActorTo): |
| 5108 |
('ask' | 'tell' | 'a' | 't') singleNounOnly->actor_ |
| 5109 |
'to' commandPhrase->cmd_ |
| 5110 |
: FirstCommandProdWithActor |
| 5111 |
|
| 5112 |
/* "execute" the target actor phrase */ |
| 5113 |
execActorPhrase(issuingActor) |
| 5114 |
{ |
| 5115 |
/* |
| 5116 |
* Since our phrasing is TELL <ACTOR> TO <DO SOMETHING>, the |
| 5117 |
* actor clearly becomes the antecedent for a subsequent |
| 5118 |
* pronoun. For example, in TELL BOB TO READ HIS BOOK, the word |
| 5119 |
* HIS pretty clearly refers back to BOB. |
| 5120 |
*/ |
| 5121 |
if (resolvedActor_ != nil) |
| 5122 |
{ |
| 5123 |
/* set the possessive anaphor object to the actor */ |
| 5124 |
resolvedActor_.setPossAnaphorObj(resolvedActor_); |
| 5125 |
|
| 5126 |
/* flag that the actor's being addressed in the third person */ |
| 5127 |
resolvedActor_.commandReferralPerson = ThirdPerson; |
| 5128 |
|
| 5129 |
/* |
| 5130 |
* in subsequent commands carried out by the issuer, the |
| 5131 |
* target actor is now the pronoun antecedent (for example: |
| 5132 |
* after TELL BOB TO GO NORTH, the command FOLLOW HIM means |
| 5133 |
* to follow Bob) |
| 5134 |
*/ |
| 5135 |
issuingActor.setPronounObj(resolvedActor_); |
| 5136 |
} |
| 5137 |
} |
| 5138 |
; |
| 5139 |
|
| 5140 |
/* |
| 5141 |
* An actor-targeted command with a bad command phrase. This is used as |
| 5142 |
* a fallback if we fail to match anything on the first attempt at |
| 5143 |
* parsing the first command on a line. The point is to at least detect |
| 5144 |
* the target actor phrase, if that much is valid, so that we better |
| 5145 |
* customize error messages for the rest of the command. |
| 5146 |
*/ |
| 5147 |
grammar actorBadCommandPhrase(main): |
| 5148 |
singleNounOnly->actor_ ',' miscWordList |
| 5149 |
| ('ask' | 'tell' | 'a' | 't') singleNounOnly->actor_ 'to' miscWordList |
| 5150 |
: FirstCommandProdWithActor |
| 5151 |
|
| 5152 |
/* to resolve nouns, we merely resolve the actor */ |
| 5153 |
resolveNouns(issuingActor, targetActor, results) |
| 5154 |
{ |
| 5155 |
/* resolve the underlying actor phrase */ |
| 5156 |
return actor_.resolveNouns(getResolver(issuingActor), results); |
| 5157 |
} |
| 5158 |
; |
| 5159 |
|
| 5160 |
|
| 5161 |
/* |
| 5162 |
* Command-only conjunctions. These words and groups of words can |
| 5163 |
* separate commands from one another, and can't be used to separate noun |
| 5164 |
* phrases in a noun list. |
| 5165 |
*/ |
| 5166 |
grammar commandOnlyConjunction(sentenceEnding): |
| 5167 |
'.' |
| 5168 |
| '!' |
| 5169 |
: BasicProd |
| 5170 |
|
| 5171 |
/* these conjunctions end the sentence */ |
| 5172 |
isEndOfSentence() { return true; } |
| 5173 |
; |
| 5174 |
|
| 5175 |
grammar commandOnlyConjunction(nonSentenceEnding): |
| 5176 |
'then' |
| 5177 |
| 'and' 'then' |
| 5178 |
| ',' 'then' |
| 5179 |
| ',' 'and' 'then' |
| 5180 |
| ';' |
| 5181 |
: BasicProd |
| 5182 |
|
| 5183 |
/* these conjunctions do not end a sentence */ |
| 5184 |
isEndOfSentence() { return nil; } |
| 5185 |
; |
| 5186 |
|
| 5187 |
|
| 5188 |
/* |
| 5189 |
* Command-or-noun conjunctions. These words and groups of words can be |
| 5190 |
* used to separate commands from one another, and can also be used to |
| 5191 |
* separate noun phrases in a noun list. |
| 5192 |
*/ |
| 5193 |
grammar commandOrNounConjunction(main): |
| 5194 |
',' |
| 5195 |
| 'and' |
| 5196 |
| ',' 'and' |
| 5197 |
: BasicProd |
| 5198 |
|
| 5199 |
/* these do not end a sentence */ |
| 5200 |
isEndOfSentence() { return nil; } |
| 5201 |
; |
| 5202 |
|
| 5203 |
/* |
| 5204 |
* Noun conjunctions. These words and groups of words can be used to |
| 5205 |
* separate noun phrases from one another. Note that these do not need |
| 5206 |
* to be exclusive to noun phrases - these can occur as command |
| 5207 |
* conjunctions as well; this list is separated from |
| 5208 |
* commandOrNounConjunction in case there are conjunctions that can never |
| 5209 |
* be used as command conjunctions, since such conjunctions, which can |
| 5210 |
* appear here, would not appear in commandOrNounConjunctions. |
| 5211 |
*/ |
| 5212 |
grammar nounConjunction(main): |
| 5213 |
',' |
| 5214 |
| 'and' |
| 5215 |
| ',' 'and' |
| 5216 |
: BasicProd |
| 5217 |
|
| 5218 |
/* these conjunctions do not end a sentence */ |
| 5219 |
isEndOfSentence() { return nil; } |
| 5220 |
; |
| 5221 |
|
| 5222 |
/* ------------------------------------------------------------------------ */ |
| 5223 |
/* |
| 5224 |
* Noun list: one or more noun phrases connected with conjunctions. This |
| 5225 |
* kind of noun list can end in a terminal noun phrase. |
| 5226 |
* |
| 5227 |
* Note that a single noun phrase is a valid noun list, since a list can |
| 5228 |
* simply be a list of one. The separate production nounMultiList can be |
| 5229 |
* used when multiple noun phrases are required. |
| 5230 |
*/ |
| 5231 |
|
| 5232 |
/* |
| 5233 |
* a noun list can consist of a single terminal noun phrase |
| 5234 |
*/ |
| 5235 |
grammar nounList(terminal): terminalNounPhrase->np_ : NounListProd |
| 5236 |
resolveNouns(resolver, results) |
| 5237 |
{ |
| 5238 |
/* resolve the underlying noun phrase */ |
| 5239 |
return np_.resolveNouns(resolver, results); |
| 5240 |
} |
| 5241 |
; |
| 5242 |
|
| 5243 |
/* |
| 5244 |
* a noun list can consist of a list of a single complete (non-terminal) |
| 5245 |
* noun phrase |
| 5246 |
*/ |
| 5247 |
grammar nounList(nonTerminal): completeNounPhrase->np_ : NounListProd |
| 5248 |
resolveNouns(resolver, results) |
| 5249 |
{ |
| 5250 |
/* resolve the underlying noun phrase */ |
| 5251 |
return np_.resolveNouns(resolver, results); |
| 5252 |
} |
| 5253 |
; |
| 5254 |
|
| 5255 |
/* |
| 5256 |
* a noun list can consist of a list with two or more entries |
| 5257 |
*/ |
| 5258 |
grammar nounList(list): nounMultiList->lst_ : NounListProd |
| 5259 |
resolveNouns(resolver, results) |
| 5260 |
{ |
| 5261 |
/* resolve the underlying list */ |
| 5262 |
return lst_.resolveNouns(resolver, results); |
| 5263 |
} |
| 5264 |
; |
| 5265 |
|
| 5266 |
/* |
| 5267 |
* An empty noun list is one with no words at all. This is matched when |
| 5268 |
* a command requires a noun list but the player doesn't include one; |
| 5269 |
* this construct has "badness" because we only want to match it when we |
| 5270 |
* have no choice. |
| 5271 |
*/ |
| 5272 |
grammar nounList(empty): [badness 500] : EmptyNounPhraseProd |
| 5273 |
responseProd = nounList |
| 5274 |
; |
| 5275 |
|
| 5276 |
/* ------------------------------------------------------------------------ */ |
| 5277 |
/* |
| 5278 |
* Noun Multi List: two or more noun phrases connected by conjunctions. |
| 5279 |
* This is almost the same as the basic nounList production, but this |
| 5280 |
* type of production requires at least two noun phrases, whereas the |
| 5281 |
* basic nounList production more generally defines its list as any |
| 5282 |
* number - including one - of noun phrases. |
| 5283 |
*/ |
| 5284 |
|
| 5285 |
/* |
| 5286 |
* a multi list can consist of a noun multi- list plus a terminal noun |
| 5287 |
* phrase, separated by a conjunction |
| 5288 |
*/ |
| 5289 |
grammar nounMultiList(multi): |
| 5290 |
nounMultiList->lst_ nounConjunction terminalNounPhrase->np_ |
| 5291 |
: NounListProd |
| 5292 |
resolveNouns(resolver, results) |
| 5293 |
{ |
| 5294 |
/* return a list of all of the objects from both underlying lists */ |
| 5295 |
return np_.resolveNouns(resolver, results) |
| 5296 |
+ lst_.resolveNouns(resolver, results); |
| 5297 |
} |
| 5298 |
; |
| 5299 |
|
| 5300 |
/* |
| 5301 |
* a multi list can consist of a non-terminal multi list |
| 5302 |
*/ |
| 5303 |
grammar nounMultiList(nonterminal): nonTerminalNounMultiList->lst_ |
| 5304 |
: NounListProd |
| 5305 |
resolveNouns(resolver, results) |
| 5306 |
{ |
| 5307 |
/* resolve the underlying list */ |
| 5308 |
return lst_.resolveNouns(resolver, results); |
| 5309 |
} |
| 5310 |
; |
| 5311 |
|
| 5312 |
/* ------------------------------------------------------------------------ */ |
| 5313 |
/* |
| 5314 |
* A non-terminal noun multi list is a noun list made up of at least two |
| 5315 |
* non-terminal noun phrases, connected by conjunctions. |
| 5316 |
* |
| 5317 |
* This is almost the same as the regular non-terminal noun list |
| 5318 |
* production, but this production requires two or more underlying noun |
| 5319 |
* phrases, whereas the basic non-terminal noun list matches any number |
| 5320 |
* of underlying phrases, including one. |
| 5321 |
*/ |
| 5322 |
|
| 5323 |
/* |
| 5324 |
* a non-terminal multi-list can consist of a pair of complete noun |
| 5325 |
* phrases separated by a conjunction |
| 5326 |
*/ |
| 5327 |
grammar nonTerminalNounMultiList(pair): |
| 5328 |
completeNounPhrase->np1_ nounConjunction completeNounPhrase->np2_ |
| 5329 |
: NounListProd |
| 5330 |
resolveNouns(resolver, results) |
| 5331 |
{ |
| 5332 |
/* return the combination of the two underlying noun phrases */ |
| 5333 |
return np1_.resolveNouns(resolver, results) |
| 5334 |
+ np2_.resolveNouns(resolver, results); |
| 5335 |
} |
| 5336 |
; |
| 5337 |
|
| 5338 |
/* |
| 5339 |
* a non-terminal multi-list can consist of another non-terminal |
| 5340 |
* multi-list plus a complete noun phrase, connected by a conjunction |
| 5341 |
*/ |
| 5342 |
grammar nonTerminalNounMultiList(multi): |
| 5343 |
nonTerminalNounMultiList->lst_ nounConjunction completeNounPhrase->np_ |
| 5344 |
: NounListProd |
| 5345 |
resolveNouns(resolver, results) |
| 5346 |
{ |
| 5347 |
/* return the combination of the sublist and the noun phrase */ |
| 5348 |
return lst_.resolveNouns(resolver, results) |
| 5349 |
+ np_.resolveNouns(resolver, results); |
| 5350 |
} |
| 5351 |
; |
| 5352 |
|
| 5353 |
|
| 5354 |
/* ------------------------------------------------------------------------ */ |
| 5355 |
/* |
| 5356 |
* "Except" list. This is a noun list that can contain anything that's |
| 5357 |
* in a regular noun list plus some things that only make sense as |
| 5358 |
* exceptions, such as possessive nouns (e.g., "mine"). |
| 5359 |
*/ |
| 5360 |
|
| 5361 |
grammar exceptList(single): exceptNounPhrase->np_ : ExceptListProd |
| 5362 |
resolveNouns(resolver, results) |
| 5363 |
{ |
| 5364 |
return np_.resolveNouns(resolver, results); |
| 5365 |
} |
| 5366 |
; |
| 5367 |
|
| 5368 |
grammar exceptList(list): |
| 5369 |
exceptNounPhrase->np_ nounConjunction exceptList->lst_ |
| 5370 |
: ExceptListProd |
| 5371 |
resolveNouns(resolver, results) |
| 5372 |
{ |
| 5373 |
/* return a list consisting of all of our objects */ |
| 5374 |
return np_.resolveNouns(resolver, results) |
| 5375 |
+ lst_.resolveNouns(resolver, results); |
| 5376 |
} |
| 5377 |
; |
| 5378 |
|
| 5379 |
/* |
| 5380 |
* An "except" noun phrase is a normal "complete" noun phrase or a |
| 5381 |
* possessive noun phrase that doesn't explicitly qualify another phrase |
| 5382 |
* (for example, "all the coins but bob's" - the "bob's" is just a |
| 5383 |
* possessive noun phrase without another noun phrase attached, since it |
| 5384 |
* implicitly qualifies "the coins"). |
| 5385 |
*/ |
| 5386 |
grammar exceptNounPhrase(singleComplete): completeNounPhraseWithoutAll->np_ |
| 5387 |
: ExceptListProd |
| 5388 |
resolveNouns(resolver, results) |
| 5389 |
{ |
| 5390 |
return np_.resolveNouns(resolver, results); |
| 5391 |
} |
| 5392 |
; |
| 5393 |
|
| 5394 |
grammar exceptNounPhrase(singlePossessive): possessiveNounPhrase->poss_ |
| 5395 |
: ButPossessiveProd |
| 5396 |
; |
| 5397 |
|
| 5398 |
|
| 5399 |
/* ------------------------------------------------------------------------ */ |
| 5400 |
/* |
| 5401 |
* A single noun is sometimes required where, structurally, a list is not |
| 5402 |
* allowed. Single nouns should not be used to prohibit lists where |
| 5403 |
* there is no structural reason for the prohibition - these should be |
| 5404 |
* used only where it doesn't make sense to use a list structurally. |
| 5405 |
*/ |
| 5406 |
grammar singleNoun(normal): singleNounOnly->np_ : LayeredNounPhraseProd |
| 5407 |
; |
| 5408 |
|
| 5409 |
/* |
| 5410 |
* An empty single noun is one with no words at all. This is matched |
| 5411 |
* when a command requires a noun list but the player doesn't include |
| 5412 |
* one; this construct has "badness" because we only want to match it |
| 5413 |
* when we have no choice. |
| 5414 |
*/ |
| 5415 |
grammar singleNoun(empty): [badness 500] : EmptyNounPhraseProd |
| 5416 |
/* use a nil responseProd, so that we get the phrasing from the action */ |
| 5417 |
responseProd = nil |
| 5418 |
|
| 5419 |
/* the fallback responseProd, if we can't get one from the action */ |
| 5420 |
fallbackResponseProd = singleNoun |
| 5421 |
; |
| 5422 |
|
| 5423 |
/* |
| 5424 |
* A user could attempt to use a noun list with more than one entry (a |
| 5425 |
* "multi list") where a single noun is required. This is not a |
| 5426 |
* grammatical error, so we accept it grammatically; however, for |
| 5427 |
* disambiguation purposes we score it lower than a singleNoun production |
| 5428 |
* with only one noun phrase, and if we try to resolve it, we'll fail |
| 5429 |
* with an error. |
| 5430 |
*/ |
| 5431 |
grammar singleNoun(multiple): nounMultiList->np_ : SingleNounWithListProd |
| 5432 |
; |
| 5433 |
|
| 5434 |
|
| 5435 |
/* |
| 5436 |
* A *structural* single noun phrase. This production is for use where a |
| 5437 |
* single noun phrase (not a list of nouns) is required grammatically. |
| 5438 |
*/ |
| 5439 |
grammar singleNounOnly(main): |
| 5440 |
terminalNounPhrase->np_ |
| 5441 |
| completeNounPhrase->np_ |
| 5442 |
: SingleNounProd |
| 5443 |
; |
| 5444 |
|
| 5445 |
/* ------------------------------------------------------------------------ */ |
| 5446 |
/* |
| 5447 |
* Prepositionally modified single noun phrases. These can be used in |
| 5448 |
* indirect object responses, so allow for interactions like this: |
| 5449 |
* |
| 5450 |
* >unlock door |
| 5451 |
*. What do you want to unlock it with? |
| 5452 |
* |
| 5453 |
* >with the key |
| 5454 |
* |
| 5455 |
* The entire notion of prepositionally qualified noun phrases in |
| 5456 |
* interactive indirect object responses is specific to English, so this |
| 5457 |
* is implemented in the English module only. However, the general |
| 5458 |
* notion of specialized responses to interactive indirect object queries |
| 5459 |
* is handled in the language-independent library in some cases, in such |
| 5460 |
* a way that the language-specific library can customize the behavior - |
| 5461 |
* see TIAction.askIobjResponseProd. |
| 5462 |
*/ |
| 5463 |
class PrepSingleNounProd: SingleNounProd |
| 5464 |
resolveNouns(resolver, results) |
| 5465 |
{ |
| 5466 |
return np_.resolveNouns(resolver, results); |
| 5467 |
} |
| 5468 |
|
| 5469 |
/* |
| 5470 |
* If the response starts with a preposition, it's pretty clearly a |
| 5471 |
* response to the special query rather than a new command. |
| 5472 |
*/ |
| 5473 |
isSpecialResponseMatch() |
| 5474 |
{ |
| 5475 |
return (np_ != nil && np_.firstTokenIndex > 1); |
| 5476 |
} |
| 5477 |
; |
| 5478 |
|
| 5479 |
/* |
| 5480 |
* Same thing for a Topic phrase |
| 5481 |
*/ |
| 5482 |
class PrepSingleTopicProd: TopicProd |
| 5483 |
resolveNouns(resolver, results) |
| 5484 |
{ |
| 5485 |
return np_.resolveNouns(resolver, results); |
| 5486 |
} |
| 5487 |
; |
| 5488 |
|
| 5489 |
grammar inSingleNoun(main): |
| 5490 |
singleNoun->np_ | ('in' | 'into' | 'in' 'to') singleNoun->np_ |
| 5491 |
: PrepSingleNounProd |
| 5492 |
; |
| 5493 |
|
| 5494 |
grammar forSingleNoun(main): |
| 5495 |
singleNoun->np_ | 'for' singleNoun->np_ : PrepSingleNounProd |
| 5496 |
; |
| 5497 |
|
| 5498 |
grammar toSingleNoun(main): |
| 5499 |
singleNoun->np_ | 'to' singleNoun->np_ : PrepSingleNounProd |
| 5500 |
; |
| 5501 |
|
| 5502 |
grammar throughSingleNoun(main): |
| 5503 |
singleNoun->np_ | ('through' | 'thru') singleNoun->np_ |
| 5504 |
: PrepSingleNounProd |
| 5505 |
; |
| 5506 |
|
| 5507 |
grammar fromSingleNoun(main): |
| 5508 |
singleNoun->np_ | 'from' singleNoun->np_ : PrepSingleNounProd |
| 5509 |
; |
| 5510 |
|
| 5511 |
grammar onSingleNoun(main): |
| 5512 |
singleNoun->np_ | ('on' | 'onto' | 'on' 'to') singleNoun->np_ |
| 5513 |
: PrepSingleNounProd |
| 5514 |
; |
| 5515 |
|
| 5516 |
grammar withSingleNoun(main): |
| 5517 |
singleNoun->np_ | 'with' singleNoun->np_ : PrepSingleNounProd |
| 5518 |
; |
| 5519 |
|
| 5520 |
grammar atSingleNoun(main): |
| 5521 |
singleNoun->np_ | 'at' singleNoun->np_ : PrepSingleNounProd |
| 5522 |
; |
| 5523 |
|
| 5524 |
grammar outOfSingleNoun(main): |
| 5525 |
singleNoun->np_ | 'out' 'of' singleNoun->np_ : PrepSingleNounProd |
| 5526 |
; |
| 5527 |
|
| 5528 |
grammar aboutTopicPhrase(main): |
| 5529 |
topicPhrase->np_ | 'about' topicPhrase->np_ |
| 5530 |
: PrepSingleTopicProd |
| 5531 |
; |
| 5532 |
|
| 5533 |
/* ------------------------------------------------------------------------ */ |
| 5534 |
/* |
| 5535 |
* Complete noun phrase - this is a fully-qualified noun phrase that |
| 5536 |
* cannot be modified with articles, quantifiers, or anything else. This |
| 5537 |
* is the highest-level individual noun phrase. |
| 5538 |
*/ |
| 5539 |
|
| 5540 |
grammar completeNounPhrase(main): |
| 5541 |
completeNounPhraseWithAll->np_ | completeNounPhraseWithoutAll->np_ |
| 5542 |
: LayeredNounPhraseProd |
| 5543 |
; |
| 5544 |
|
| 5545 |
/* |
| 5546 |
* Slightly better than a purely miscellaneous word list is a pair of |
| 5547 |
* otherwise valid noun phrases connected by a preposition that's |
| 5548 |
* commonly used in command phrases. This will match commands where the |
| 5549 |
* user has assumed a command with a prepositional structure that doesn't |
| 5550 |
* exist among the defined commands. Since we have badness, we'll be |
| 5551 |
* ignored any time there's a valid command syntax with the same |
| 5552 |
* prepositional structure. |
| 5553 |
*/ |
| 5554 |
grammar completeNounPhrase(miscPrep): |
| 5555 |
[badness 100] completeNounPhrase->np1_ |
| 5556 |
('with' | 'into' | 'in' 'to' | 'through' | 'thru' | 'for' | 'to' |
| 5557 |
| 'onto' | 'on' 'to' | 'at' | 'under' | 'behind') |
| 5558 |
completeNounPhrase->np2_ |
| 5559 |
: NounPhraseProd |
| 5560 |
resolveNouns(resolver, results) |
| 5561 |
{ |
| 5562 |
/* note that we have an invalid prepositional phrase structure */ |
| 5563 |
results.noteBadPrep(); |
| 5564 |
|
| 5565 |
/* resolve the underlying noun phrases, for scoring purposes */ |
| 5566 |
np1_.resolveNouns(resolver, results); |
| 5567 |
np2_.resolveNouns(resolver, results); |
| 5568 |
|
| 5569 |
/* return nothing */ |
| 5570 |
return []; |
| 5571 |
} |
| 5572 |
; |
| 5573 |
|
| 5574 |
|
| 5575 |
/* |
| 5576 |
* A qualified noun phrase can, all by itself, be a full noun phrase |
| 5577 |
*/ |
| 5578 |
grammar completeNounPhraseWithoutAll(qualified): qualifiedNounPhrase->np_ |
| 5579 |
: LayeredNounPhraseProd |
| 5580 |
; |
| 5581 |
|
| 5582 |
/* |
| 5583 |
* Pronoun rules. A pronoun is a complete noun phrase; it does not allow |
| 5584 |
* further qualification. |
| 5585 |
*/ |
| 5586 |
grammar completeNounPhraseWithoutAll(it): 'it' : ItProd; |
| 5587 |
grammar completeNounPhraseWithoutAll(them): 'them' : ThemProd; |
| 5588 |
grammar completeNounPhraseWithoutAll(him): 'him' : HimProd; |
| 5589 |
grammar completeNounPhraseWithoutAll(her): 'her' : HerProd; |
| 5590 |
|
| 5591 |
/* |
| 5592 |
* Reflexive second-person pronoun, for things like "bob, look at |
| 5593 |
* yourself" |
| 5594 |
*/ |
| 5595 |
grammar completeNounPhraseWithoutAll(yourself): |
| 5596 |
'yourself' | 'yourselves' | 'you' : YouProd |
| 5597 |
; |
| 5598 |
|
| 5599 |
/* |
| 5600 |
* Reflexive third-person pronouns. We accept these in places such as |
| 5601 |
* the indirect object of a two-object verb. |
| 5602 |
*/ |
| 5603 |
grammar completeNounPhraseWithoutAll(itself): 'itself' : ItselfProd |
| 5604 |
/* check agreement of our binding */ |
| 5605 |
checkAgreement(lst) |
| 5606 |
{ |
| 5607 |
/* the result is required to be singular and ungendered */ |
| 5608 |
return (lst.length() == 1 && lst[1].obj_.canMatchIt); |
| 5609 |
} |
| 5610 |
; |
| 5611 |
|
| 5612 |
grammar completeNounPhraseWithoutAll(themselves): |
| 5613 |
'themself' | 'themselves' : ThemselvesProd |
| 5614 |
|
| 5615 |
/* check agreement of our binding */ |
| 5616 |
checkAgreement(lst) |
| 5617 |
{ |
| 5618 |
/* |
| 5619 |
* For 'themselves', allow anything; we could balk at this |
| 5620 |
* matching a single object that isn't a mass noun, but that |
| 5621 |
* would be overly picky, and it would probably reject at least |
| 5622 |
* a few things that really ought to be acceptable. Besides, |
| 5623 |
* 'them' is the closest thing English has to a singular |
| 5624 |
* gender-neutral pronoun, and some people intentionally use it |
| 5625 |
* as such. |
| 5626 |
*/ |
| 5627 |
return true; |
| 5628 |
} |
| 5629 |
; |
| 5630 |
|
| 5631 |
grammar completeNounPhraseWithoutAll(himself): 'himself' : HimselfProd |
| 5632 |
/* check agreement of our binding */ |
| 5633 |
checkAgreement(lst) |
| 5634 |
{ |
| 5635 |
/* the result is required to be singular and masculine */ |
| 5636 |
return (lst.length() == 1 && lst[1].obj_.canMatchHim); |
| 5637 |
} |
| 5638 |
; |
| 5639 |
|
| 5640 |
grammar completeNounPhraseWithoutAll(herself): 'herself' : HerselfProd |
| 5641 |
/* check agreement of our binding */ |
| 5642 |
checkAgreement(lst) |
| 5643 |
{ |
| 5644 |
/* the result is required to be singular and feminine */ |
| 5645 |
return (lst.length() == 1 && lst[1].obj_.canMatchHer); |
| 5646 |
} |
| 5647 |
; |
| 5648 |
|
| 5649 |
/* |
| 5650 |
* First-person pronoun, for referring to the speaker: "bob, look at me" |
| 5651 |
*/ |
| 5652 |
grammar completeNounPhraseWithoutAll(me): 'me' | 'myself' : MeProd; |
| 5653 |
|
| 5654 |
/* |
| 5655 |
* "All" and "all but". |
| 5656 |
* |
| 5657 |
* "All" is a "complete" noun phrase, because there's nothing else needed |
| 5658 |
* to make it a noun phrase. We make this a special kind of complete |
| 5659 |
* noun phrase because 'all' is not acceptable as a complete noun phrase |
| 5660 |
* in some contexts where any of the other complete noun phrases are |
| 5661 |
* acceptable. |
| 5662 |
* |
| 5663 |
* "All but" is a "terminal" noun phrase - this is a special kind of |
| 5664 |
* complete noun phrase that cannot be followed by another noun phrase |
| 5665 |
* with "and". "All but" is terminal because we want any and's that |
| 5666 |
* follow it to be part of the exception list, so that we interpret "take |
| 5667 |
* all but a and b" as excluding a and b, not as excluding a but then |
| 5668 |
* including b as a separate list. |
| 5669 |
*/ |
| 5670 |
grammar completeNounPhraseWithAll(main): |
| 5671 |
'all' | 'everything' |
| 5672 |
: EverythingProd |
| 5673 |
; |
| 5674 |
|
| 5675 |
grammar terminalNounPhrase(allBut): |
| 5676 |
('all' | 'everything') ('but' | 'except' | 'except' 'for') |
| 5677 |
exceptList->except_ |
| 5678 |
: EverythingButProd |
| 5679 |
; |
| 5680 |
|
| 5681 |
/* |
| 5682 |
* Plural phrase with an exclusion list. This is a terminal noun phrase |
| 5683 |
* because it ends in an exclusion list. |
| 5684 |
*/ |
| 5685 |
grammar terminalNounPhrase(pluralExcept): |
| 5686 |
(qualifiedPluralNounPhrase->np_ | detPluralNounPhrase->np_) |
| 5687 |
('except' | 'except' 'for' | 'but' | 'but' 'not') exceptList->except_ |
| 5688 |
: ListButProd |
| 5689 |
; |
| 5690 |
|
| 5691 |
/* |
| 5692 |
* Qualified singular with an exception |
| 5693 |
*/ |
| 5694 |
grammar terminalNounPhrase(anyBut): |
| 5695 |
'any' nounPhrase->np_ |
| 5696 |
('but' | 'except' | 'except' 'for' | 'but' 'not') exceptList->except_ |
| 5697 |
: IndefiniteNounButProd |
| 5698 |
; |
| 5699 |
|
| 5700 |
/* ------------------------------------------------------------------------ */ |
| 5701 |
/* |
| 5702 |
* A qualified noun phrase is a noun phrase with an optional set of |
| 5703 |
* qualifiers: a definite or indefinite article, a quantifier, words such |
| 5704 |
* as 'any' and 'all', possessives, and locational specifiers ("the box |
| 5705 |
* on the table"). |
| 5706 |
* |
| 5707 |
* Without qualification, a definite article is implicit, so we read |
| 5708 |
* "take box" as equivalent to "take the box." |
| 5709 |
* |
| 5710 |
* Grammar rule instantiations in language-specific modules should set |
| 5711 |
* property np_ to the underlying noun phrase match tree. |
| 5712 |
*/ |
| 5713 |
|
| 5714 |
/* |
| 5715 |
* A qualified noun phrase can be either singular or plural. The number |
| 5716 |
* is a feature of the overall phrase; the phrase might consist of |
| 5717 |
* subphrases of different numbers (for example, "bob's coins" is plural |
| 5718 |
* even though it contains a singular subphrase, "bob"; and "one of the |
| 5719 |
* coins" is singular, even though its subphrase "coins" is plural). |
| 5720 |
*/ |
| 5721 |
grammar qualifiedNounPhrase(main): |
| 5722 |
qualifiedSingularNounPhrase->np_ |
| 5723 |
| qualifiedPluralNounPhrase->np_ |
| 5724 |
: LayeredNounPhraseProd |
| 5725 |
; |
| 5726 |
|
| 5727 |
/* ------------------------------------------------------------------------ */ |
| 5728 |
/* |
| 5729 |
* Singular qualified noun phrase. |
| 5730 |
*/ |
| 5731 |
|
| 5732 |
/* |
| 5733 |
* A singular qualified noun phrase with an implicit or explicit definite |
| 5734 |
* article. If there is no article, a definite article is implied (we |
| 5735 |
* interpret "take box" as though it were "take the box"). |
| 5736 |
*/ |
| 5737 |
grammar qualifiedSingularNounPhrase(definite): |
| 5738 |
('the' | 'the' 'one' | 'the' '1' | ) indetSingularNounPhrase->np_ |
| 5739 |
: DefiniteNounProd |
| 5740 |
; |
| 5741 |
|
| 5742 |
/* |
| 5743 |
* A singular qualified noun phrase with an explicit indefinite article. |
| 5744 |
*/ |
| 5745 |
grammar qualifiedSingularNounPhrase(indefinite): |
| 5746 |
('a' | 'an') indetSingularNounPhrase->np_ |
| 5747 |
: IndefiniteNounProd |
| 5748 |
; |
| 5749 |
|
| 5750 |
/* |
| 5751 |
* A singular qualified noun phrase with an explicit arbitrary |
| 5752 |
* determiner. |
| 5753 |
*/ |
| 5754 |
grammar qualifiedSingularNounPhrase(arbitrary): |
| 5755 |
('any' | 'one' | '1' | 'any' ('one' | '1')) indetSingularNounPhrase->np_ |
| 5756 |
: ArbitraryNounProd |
| 5757 |
; |
| 5758 |
|
| 5759 |
/* |
| 5760 |
* A singular qualified noun phrase with a possessive adjective. |
| 5761 |
*/ |
| 5762 |
grammar qualifiedSingularNounPhrase(possessive): |
| 5763 |
possessiveAdjPhrase->poss_ indetSingularNounPhrase->np_ |
| 5764 |
: PossessiveNounProd |
| 5765 |
; |
| 5766 |
|
| 5767 |
/* |
| 5768 |
* A singular qualified noun phrase that arbitrarily selects from a |
| 5769 |
* plural set. This is singular, even though the underlying noun phrase |
| 5770 |
* is plural, because we're explicitly selecting one item. |
| 5771 |
*/ |
| 5772 |
grammar qualifiedSingularNounPhrase(anyPlural): |
| 5773 |
'any' 'of' explicitDetPluralNounPhrase->np_ |
| 5774 |
: ArbitraryNounProd |
| 5775 |
; |
| 5776 |
|
| 5777 |
/* |
| 5778 |
* A singular object specified only by its containment, with a definite |
| 5779 |
* article. |
| 5780 |
*/ |
| 5781 |
grammar qualifiedSingularNounPhrase(theOneIn): |
| 5782 |
'the' 'one' ('that' ('is' | 'was') | 'that' tokApostropheS | ) |
| 5783 |
('in' | 'inside' | 'inside' 'of' | 'on' | 'from') |
| 5784 |
completeNounPhraseWithoutAll->cont_ |
| 5785 |
: VagueContainerDefiniteNounPhraseProd |
| 5786 |
|
| 5787 |
/* |
| 5788 |
* our main phrase is simply 'one' (so disambiguation prompts will |
| 5789 |
* read "which one do you mean...") |
| 5790 |
*/ |
| 5791 |
mainPhraseText = 'one' |
| 5792 |
; |
| 5793 |
|
| 5794 |
/* |
| 5795 |
* A singular object specified only by its containment, with an |
| 5796 |
* indefinite article. |
| 5797 |
*/ |
| 5798 |
grammar qualifiedSingularNounPhrase(anyOneIn): |
| 5799 |
('anything' | 'one') ('that' ('is' | 'was') | 'that' tokApostropheS | ) |
| 5800 |
('in' | 'inside' | 'inside' 'of' | 'on' | 'from') |
| 5801 |
completeNounPhraseWithoutAll->cont_ |
| 5802 |
: VagueContainerIndefiniteNounPhraseProd |
| 5803 |
; |
| 5804 |
|
| 5805 |
/* ------------------------------------------------------------------------ */ |
| 5806 |
/* |
| 5807 |
* An "indeterminate" singular noun phrase is a noun phrase without any |
| 5808 |
* determiner. A determiner is a phrase that specifies the phrase's |
| 5809 |
* number and indicates whether or not it refers to a specific object, |
| 5810 |
* and if so fixes which object it refers to; determiners include |
| 5811 |
* articles ("the", "a") and possessives. |
| 5812 |
* |
| 5813 |
* Note that an indeterminate phrase is NOT necessarily an indefinite |
| 5814 |
* phrase. In fact, in most cases, we assume a definite usage when the |
| 5815 |
* determiner is omitted: we take TAKE BOX as meaning TAKE THE BOX. This |
| 5816 |
* is more or less the natural way an English speaker would interpret |
| 5817 |
* this ill-formed phrasing, but even more than that, it's the |
| 5818 |
* Adventurese convention, taking into account that most players enter |
| 5819 |
* commands telegraphically and are accustomed to noun phrases being |
| 5820 |
* definite by default. |
| 5821 |
*/ |
| 5822 |
|
| 5823 |
/* an indetermine noun phrase can be a simple noun phrase */ |
| 5824 |
grammar indetSingularNounPhrase(basic): |
| 5825 |
nounPhrase->np_ |
| 5826 |
: LayeredNounPhraseProd |
| 5827 |
; |
| 5828 |
|
| 5829 |
/* |
| 5830 |
* An indetermine noun phrase can specify a location for the object(s). |
| 5831 |
* The location must be a singular noun phrase, but can itself be a fully |
| 5832 |
* qualified noun phrase (so it can have possessives, articles, and |
| 5833 |
* locational qualifiers of its own). |
| 5834 |
* |
| 5835 |
* Note that we take 'that are' even though the noun phrase is singular, |
| 5836 |
* because what we consider a singular noun phrase can have plural usage |
| 5837 |
* ("scissors", for example). |
| 5838 |
*/ |
| 5839 |
grammar indetSingularNounPhrase(locational): |
| 5840 |
nounPhrase->np_ |
| 5841 |
('that' ('is' | 'was') |
| 5842 |
| 'that' tokApostropheS |
| 5843 |
| 'that' ('are' | 'were') |
| 5844 |
| ) |
| 5845 |
('in' | 'inside' | 'inside' 'of' | 'on' | 'from') |
| 5846 |
completeNounPhraseWithoutAll->cont_ |
| 5847 |
: ContainerNounPhraseProd |
| 5848 |
; |
| 5849 |
|
| 5850 |
/* ------------------------------------------------------------------------ */ |
| 5851 |
/* |
| 5852 |
* Plural qualified noun phrase. |
| 5853 |
*/ |
| 5854 |
|
| 5855 |
/* |
| 5856 |
* A simple unqualified plural phrase with determiner. Since this form |
| 5857 |
* of plural phrase doesn't have any additional syntax that makes it an |
| 5858 |
* unambiguous plural, we can only accept an actual plural for the |
| 5859 |
* underlying phrase here - we can't accept an adjective phrase. |
| 5860 |
*/ |
| 5861 |
grammar qualifiedPluralNounPhrase(determiner): |
| 5862 |
('any' | ) detPluralOnlyNounPhrase->np_ |
| 5863 |
: LayeredNounPhraseProd |
| 5864 |
; |
| 5865 |
|
| 5866 |
/* plural phrase qualified with a number and optional "any" */ |
| 5867 |
grammar qualifiedPluralNounPhrase(anyNum): |
| 5868 |
('any' | ) numberPhrase->quant_ indetPluralNounPhrase->np_ |
| 5869 |
| ('any' | ) numberPhrase->quant_ 'of' explicitDetPluralNounPhrase->np_ |
| 5870 |
: QuantifiedPluralProd |
| 5871 |
; |
| 5872 |
|
| 5873 |
/* plural phrase qualified with a number and "all" */ |
| 5874 |
grammar qualifiedPluralNounPhrase(allNum): |
| 5875 |
'all' numberPhrase->quant_ indetPluralNounPhrase->np_ |
| 5876 |
| 'all' numberPhrase->quant_ 'of' explicitDetPluralNounPhrase->np_ |
| 5877 |
: ExactQuantifiedPluralProd |
| 5878 |
; |
| 5879 |
|
| 5880 |
/* plural phrase qualified with "both" */ |
| 5881 |
grammar qualifiedPluralNounPhrase(both): |
| 5882 |
'both' detPluralNounPhrase->np_ |
| 5883 |
| 'both' 'of' explicitDetPluralNounPhrase->np_ |
| 5884 |
: BothPluralProd |
| 5885 |
; |
| 5886 |
|
| 5887 |
/* plural phrase qualified with "all" */ |
| 5888 |
grammar qualifiedPluralNounPhrase(all): |
| 5889 |
'all' detPluralNounPhrase->np_ |
| 5890 |
| 'all' 'of' explicitDetPluralNounPhrase->np_ |
| 5891 |
: AllPluralProd |
| 5892 |
; |
| 5893 |
|
| 5894 |
/* vague plural phrase with location specified */ |
| 5895 |
grammar qualifiedPluralNounPhrase(theOnesIn): |
| 5896 |
('the' 'ones' ('that' ('are' | 'were') | ) |
| 5897 |
| ('everything' | 'all') |
| 5898 |
('that' ('is' | 'was') | 'that' tokApostropheS | )) |
| 5899 |
('in' | 'inside' | 'inside' 'of' | 'on' | 'from') |
| 5900 |
completeNounPhraseWithoutAll->cont_ |
| 5901 |
: AllInContainerNounPhraseProd |
| 5902 |
; |
| 5903 |
|
| 5904 |
/* ------------------------------------------------------------------------ */ |
| 5905 |
/* |
| 5906 |
* A plural noun phrase with a determiner. The determiner can be |
| 5907 |
* explicit (such as an article or possessive) or it can implied (the |
| 5908 |
* implied determiner is the definite article, so "take boxes" is |
| 5909 |
* understood as "take the boxes"). |
| 5910 |
*/ |
| 5911 |
grammar detPluralNounPhrase(main): |
| 5912 |
indetPluralNounPhrase->np_ | explicitDetPluralNounPhrase->np_ |
| 5913 |
: LayeredNounPhraseProd |
| 5914 |
; |
| 5915 |
|
| 5916 |
/* ------------------------------------------------------------------------ */ |
| 5917 |
/* |
| 5918 |
* A determiner plural phrase with an explicit underlying plural (i.e., |
| 5919 |
* excluding adjective phrases with no explicitly plural words). |
| 5920 |
*/ |
| 5921 |
grammar detPluralOnlyNounPhrase(main): |
| 5922 |
implicitDetPluralOnlyNounPhrase->np_ |
| 5923 |
| explicitDetPluralOnlyNounPhrase->np_ |
| 5924 |
: LayeredNounPhraseProd |
| 5925 |
; |
| 5926 |
|
| 5927 |
/* |
| 5928 |
* An implicit determiner plural phrase is an indeterminate plural phrase |
| 5929 |
* without any extra determiner - i.e., the determiner is implicit. |
| 5930 |
* We'll treat this the same way we do a plural explicitly determined |
| 5931 |
* with a definite article, since this is the most natural interpretation |
| 5932 |
* in English. |
| 5933 |
* |
| 5934 |
* (This might seem like a pointless extra layer in the grammar, but it's |
| 5935 |
* necessary for the resolution process to have a layer that explicitly |
| 5936 |
* declares the phrase to be determined, even though the determiner is |
| 5937 |
* implied in the structure. This extra layer is important because it |
| 5938 |
* explicitly calls results.noteMatches(), which is needed for rankings |
| 5939 |
* and the like.) |
| 5940 |
*/ |
| 5941 |
grammar implicitDetPluralOnlyNounPhrase(main): |
| 5942 |
indetPluralOnlyNounPhrase->np_ |
| 5943 |
: DefinitePluralProd |
| 5944 |
; |
| 5945 |
|
| 5946 |
/* ------------------------------------------------------------------------ */ |
| 5947 |
/* |
| 5948 |
* A plural noun phrase with an explicit determiner. |
| 5949 |
*/ |
| 5950 |
|
| 5951 |
/* a plural noun phrase with a definite article */ |
| 5952 |
grammar explicitDetPluralNounPhrase(definite): |
| 5953 |
'the' indetPluralNounPhrase->np_ |
| 5954 |
: DefinitePluralProd |
| 5955 |
; |
| 5956 |
|
| 5957 |
/* a plural noun phrase with a definite article and a number */ |
| 5958 |
grammar explicitDetPluralNounPhrase(definiteNumber): |
| 5959 |
'the' numberPhrase->quant_ indetPluralNounPhrase->np_ |
| 5960 |
: ExactQuantifiedPluralProd |
| 5961 |
; |
| 5962 |
|
| 5963 |
/* a plural noun phrase with a possessive */ |
| 5964 |
grammar explicitDetPluralNounPhrase(possessive): |
| 5965 |
possessiveAdjPhrase->poss_ indetPluralNounPhrase->np_ |
| 5966 |
: PossessivePluralProd |
| 5967 |
; |
| 5968 |
|
| 5969 |
/* a plural noun phrase with a possessive and a number */ |
| 5970 |
grammar explicitDetPluralNounPhrase(possessiveNumber): |
| 5971 |
possessiveAdjPhrase->poss_ numberPhrase->quant_ |
| 5972 |
indetPluralNounPhrase->np_ |
| 5973 |
: ExactQuantifiedPossessivePluralProd |
| 5974 |
; |
| 5975 |
|
| 5976 |
/* ------------------------------------------------------------------------ */ |
| 5977 |
/* |
| 5978 |
* A plural noun phrase with an explicit determiner and only an |
| 5979 |
* explicitly plural underlying phrase. |
| 5980 |
*/ |
| 5981 |
grammar explicitDetPluralOnlyNounPhrase(definite): |
| 5982 |
'the' indetPluralOnlyNounPhrase->np_ |
| 5983 |
: AllPluralProd |
| 5984 |
; |
| 5985 |
|
| 5986 |
grammar explicitDetPluralOnlyNounPhrase(definiteNumber): |
| 5987 |
'the' numberPhrase->quant_ indetPluralNounPhrase->np_ |
| 5988 |
: ExactQuantifiedPluralProd |
| 5989 |
; |
| 5990 |
|
| 5991 |
grammar explicitDetPluralOnlyNounPhrase(possessive): |
| 5992 |
possessiveAdjPhrase->poss_ indetPluralOnlyNounPhrase->np_ |
| 5993 |
: PossessivePluralProd |
| 5994 |
; |
| 5995 |
|
| 5996 |
grammar explicitDetPluralOnlyNounPhrase(possessiveNumber): |
| 5997 |
possessiveAdjPhrase->poss_ numberPhrase->quant_ |
| 5998 |
indetPluralNounPhrase->np_ |
| 5999 |
: ExactQuantifiedPossessivePluralProd |
| 6000 |
; |
| 6001 |
|
| 6002 |
|
| 6003 |
/* ------------------------------------------------------------------------ */ |
| 6004 |
/* |
| 6005 |
* An indeterminate plural noun phrase. |
| 6006 |
* |
| 6007 |
* For the basic indeterminate plural phrase, allow an adjective phrase |
| 6008 |
* anywhere a plural phrase is allowed; this makes possible the |
| 6009 |
* short-hand of omitting a plural word when the plural number is |
| 6010 |
* unambiguous from context. |
| 6011 |
*/ |
| 6012 |
|
| 6013 |
/* a simple plural noun phrase */ |
| 6014 |
grammar indetPluralNounPhrase(basic): |
| 6015 |
pluralPhrase->np_ | adjPhrase->np_ |
| 6016 |
: LayeredNounPhraseProd |
| 6017 |
; |
| 6018 |
|
| 6019 |
/* |
| 6020 |
* A plural noun phrase with a locational qualifier. Note that even |
| 6021 |
* though the overall phrase is plural (and so the main underlying noun |
| 6022 |
* phrase is plural), the location phrase itself must always be singular. |
| 6023 |
*/ |
| 6024 |
grammar indetPluralNounPhrase(locational): |
| 6025 |
(pluralPhrase->np_ | adjPhrase->np_) ('that' ('are' | 'were') | ) |
| 6026 |
('in' | 'inside' | 'inside' 'of' | 'on' | 'from') |
| 6027 |
completeNounPhraseWithoutAll->cont_ |
| 6028 |
: ContainerNounPhraseProd |
| 6029 |
; |
| 6030 |
|
| 6031 |
/* |
| 6032 |
* An indetermine plural noun phrase with only explicit plural phrases. |
| 6033 |
*/ |
| 6034 |
grammar indetPluralOnlyNounPhrase(basic): |
| 6035 |
pluralPhrase->np_ |
| 6036 |
: LayeredNounPhraseProd |
| 6037 |
; |
| 6038 |
|
| 6039 |
grammar indetPluralOnlyNounPhrase(locational): |
| 6040 |
pluralPhrase->np_ ('that' ('are' | 'were') | ) |
| 6041 |
('in' | 'inside' | 'inside' 'of' | 'on' | 'from') |
| 6042 |
completeNounPhraseWithoutAll->cont_ |
| 6043 |
: ContainerNounPhraseProd |
| 6044 |
; |
| 6045 |
|
| 6046 |
/* ------------------------------------------------------------------------ */ |
| 6047 |
/* |
| 6048 |
* Noun Phrase. This is the basic noun phrase, which serves as a |
| 6049 |
* building block for complete noun phrases. This type of noun phrase |
| 6050 |
* can be qualified with articles, quantifiers, and possessives, and can |
| 6051 |
* be used to construct possessives via the addition of "'s" at the end |
| 6052 |
* of the phrase. |
| 6053 |
* |
| 6054 |
* In most cases, custom noun phrase rules should be added to this |
| 6055 |
* production, as long as qualification (with numbers, articles, and |
| 6056 |
* possessives) is allowed. For a custom noun phrase rule that cannot be |
| 6057 |
* qualified, a completeNounPhrase rule should be added instead. |
| 6058 |
*/ |
| 6059 |
grammar nounPhrase(main): compoundNounPhrase->np_ |
| 6060 |
: LayeredNounPhraseProd |
| 6061 |
; |
| 6062 |
|
| 6063 |
/* |
| 6064 |
* Plural phrase. This is the basic plural phrase, and corresponds to |
| 6065 |
* the basic nounPhrase for plural forms. |
| 6066 |
*/ |
| 6067 |
grammar pluralPhrase(main): compoundPluralPhrase->np_ |
| 6068 |
: LayeredNounPhraseProd |
| 6069 |
; |
| 6070 |
|
| 6071 |
/* ------------------------------------------------------------------------ */ |
| 6072 |
/* |
| 6073 |
* Compound noun phrase. This is one or more noun phrases connected with |
| 6074 |
* 'of', as in "piece of paper". The part after the 'of' is another |
| 6075 |
* compound noun phrase. |
| 6076 |
* |
| 6077 |
* Note that this general rule does not allow the noun phrase after the |
| 6078 |
* 'of' to be qualified with an article or number, except that we make an |
| 6079 |
* exception to allow a definite article. Other cases ("a piece of four |
| 6080 |
* papers") do not generally make sense, so we won't attempt to support |
| 6081 |
* them; instead, games can add as special cases new nounPhrase rules for |
| 6082 |
* specific literal sequences where more complex grammar is necessary. |
| 6083 |
*/ |
| 6084 |
grammar compoundNounPhrase(simple): simpleNounPhrase->np_ |
| 6085 |
: NounPhraseWithVocab |
| 6086 |
getVocabMatchList(resolver, results, extraFlags) |
| 6087 |
{ |
| 6088 |
return np_.getVocabMatchList(resolver, results, extraFlags); |
| 6089 |
} |
| 6090 |
getAdjustedTokens() |
| 6091 |
{ |
| 6092 |
return np_.getAdjustedTokens(); |
| 6093 |
} |
| 6094 |
; |
| 6095 |
|
| 6096 |
grammar compoundNounPhrase(of): |
| 6097 |
simpleNounPhrase->np1_ 'of'->of_ compoundNounPhrase->np2_ |
| 6098 |
| simpleNounPhrase->np1_ 'of'->of_ 'the'->the_ compoundNounPhrase->np2_ |
| 6099 |
: NounPhraseWithVocab |
| 6100 |
getVocabMatchList(resolver, results, extraFlags) |
| 6101 |
{ |
| 6102 |
local lst1; |
| 6103 |
local lst2; |
| 6104 |
|
| 6105 |
/* resolve the two underlying lists */ |
| 6106 |
lst1 = np1_.getVocabMatchList(resolver, results, extraFlags); |
| 6107 |
lst2 = np2_.getVocabMatchList(resolver, results, extraFlags); |
| 6108 |
|
| 6109 |
/* |
| 6110 |
* the result is the intersection of the two lists, since we |
| 6111 |
* want the list of objects with all of the underlying |
| 6112 |
* vocabulary words |
| 6113 |
*/ |
| 6114 |
return intersectNounLists(lst1, lst2); |
| 6115 |
} |
| 6116 |
getAdjustedTokens() |
| 6117 |
{ |
| 6118 |
local ofLst; |
| 6119 |
|
| 6120 |
/* generate the 'of the' list from the original words */ |
| 6121 |
if (the_ == nil) |
| 6122 |
ofLst = [of_, &miscWord]; |
| 6123 |
else |
| 6124 |
ofLst = [of_, &miscWord, the_, &miscWord]; |
| 6125 |
|
| 6126 |
/* return the full list */ |
| 6127 |
return np1_.getAdjustedTokens() + ofLst + np2_.getAdjustedTokens(); |
| 6128 |
} |
| 6129 |
; |
| 6130 |
|
| 6131 |
|
| 6132 |
/* ------------------------------------------------------------------------ */ |
| 6133 |
/* |
| 6134 |
* Compound plural phrase - same as a compound noun phrase, but involving |
| 6135 |
* a plural part before the 'of'. |
| 6136 |
*/ |
| 6137 |
|
| 6138 |
/* |
| 6139 |
* just a single plural phrase |
| 6140 |
*/ |
| 6141 |
grammar compoundPluralPhrase(simple): simplePluralPhrase->np_ |
| 6142 |
: NounPhraseWithVocab |
| 6143 |
getVocabMatchList(resolver, results, extraFlags) |
| 6144 |
{ |
| 6145 |
return np_.getVocabMatchList(resolver, results, extraFlags); |
| 6146 |
} |
| 6147 |
getAdjustedTokens() |
| 6148 |
{ |
| 6149 |
return np_.getAdjustedTokens(); |
| 6150 |
} |
| 6151 |
; |
| 6152 |
|
| 6153 |
/* |
| 6154 |
* <plural-phrase> of <noun-phrase> |
| 6155 |
*/ |
| 6156 |
grammar compoundPluralPhrase(of): |
| 6157 |
simplePluralPhrase->np1_ 'of'->of_ compoundNounPhrase->np2_ |
| 6158 |
| simplePluralPhrase->np1_ 'of'->of_ 'the'->the_ compoundNounPhrase->np2_ |
| 6159 |
: NounPhraseWithVocab |
| 6160 |
getVocabMatchList(resolver, results, extraFlags) |
| 6161 |
{ |
| 6162 |
local lst1; |
| 6163 |
local lst2; |
| 6164 |
|
| 6165 |
/* resolve the two underlying lists */ |
| 6166 |
lst1 = np1_.getVocabMatchList(resolver, results, extraFlags); |
| 6167 |
lst2 = np2_.getVocabMatchList(resolver, results, extraFlags); |
| 6168 |
|
| 6169 |
/* |
| 6170 |
* the result is the intersection of the two lists, since we |
| 6171 |
* want the list of objects with all of the underlying |
| 6172 |
* vocabulary words |
| 6173 |
*/ |
| 6174 |
return intersectNounLists(lst1, lst2); |
| 6175 |
} |
| 6176 |
getAdjustedTokens() |
| 6177 |
{ |
| 6178 |
local ofLst; |
| 6179 |
|
| 6180 |
/* generate the 'of the' list from the original words */ |
| 6181 |
if (the_ == nil) |
| 6182 |
ofLst = [of_, &miscWord]; |
| 6183 |
else |
| 6184 |
ofLst = [of_, &miscWord, the_, &miscWord]; |
| 6185 |
|
| 6186 |
/* return the full list */ |
| 6187 |
return np1_.getAdjustedTokens() + ofLst + np2_.getAdjustedTokens(); |
| 6188 |
} |
| 6189 |
; |
| 6190 |
|
| 6191 |
/* ------------------------------------------------------------------------ */ |
| 6192 |
/* |
| 6193 |
* Simple noun phrase. This is the most basic noun phrase, which is |
| 6194 |
* simply a noun, optionally preceded by one or more adjectives. |
| 6195 |
*/ |
| 6196 |
|
| 6197 |
/* |
| 6198 |
* just a noun |
| 6199 |
*/ |
| 6200 |
grammar simpleNounPhrase(noun): nounWord->noun_ : NounPhraseWithVocab |
| 6201 |
/* generate a list of my resolved objects */ |
| 6202 |
getVocabMatchList(resolver, results, extraFlags) |
| 6203 |
{ |
| 6204 |
return noun_.getVocabMatchList(resolver, results, extraFlags); |
| 6205 |
} |
| 6206 |
getAdjustedTokens() |
| 6207 |
{ |
| 6208 |
return noun_.getAdjustedTokens(); |
| 6209 |
} |
| 6210 |
; |
| 6211 |
|
| 6212 |
/* |
| 6213 |
* <adjective> <simple-noun-phrase> (this allows any number of adjectives |
| 6214 |
* to be applied) |
| 6215 |
*/ |
| 6216 |
grammar simpleNounPhrase(adjNP): adjWord->adj_ simpleNounPhrase->np_ |
| 6217 |
: NounPhraseWithVocab |
| 6218 |
|
| 6219 |
/* generate a list of my resolved objects */ |
| 6220 |
getVocabMatchList(resolver, results, extraFlags) |
| 6221 |
{ |
| 6222 |
/* |
| 6223 |
* return the list of objects in scope matching our adjective |
| 6224 |
* plus the list from the underlying noun phrase |
| 6225 |
*/ |
| 6226 |
return intersectNounLists( |
| 6227 |
adj_.getVocabMatchList(resolver, results, extraFlags), |
| 6228 |
np_.getVocabMatchList(resolver, results, extraFlags)); |
| 6229 |
} |
| 6230 |
getAdjustedTokens() |
| 6231 |
{ |
| 6232 |
return adj_.getAdjustedTokens() + np_.getAdjustedTokens(); |
| 6233 |
} |
| 6234 |
; |
| 6235 |
|
| 6236 |
/* |
| 6237 |
* A simple noun phrase can also include a number or a quoted string |
| 6238 |
* before or after a noun. A number can be spelled out or written with |
| 6239 |
* numerals; we consider both forms equivalent in meaning. |
| 6240 |
* |
| 6241 |
* A number in this type of usage is grammatically equivalent to an |
| 6242 |
* adjective - it's not meant to quantify the rest of the noun phrase, |
| 6243 |
* but rather is simply an adjective-like modifier. For example, an |
| 6244 |
* elevator's control panel might have a set of numbered buttons which we |
| 6245 |
* want to refer to as "button 1," "button 2," and so on. It is |
| 6246 |
* frequently the case that numeric adjectives are equally at home before |
| 6247 |
* or after their noun: "push 3 button" or "push button 3". In addition, |
| 6248 |
* we accept a number by itself as a lone adjective, as in "push 3". |
| 6249 |
*/ |
| 6250 |
|
| 6251 |
/* |
| 6252 |
* just a numeric/string adjective (for things like "push 3", "push #3", |
| 6253 |
* 'push "G"') |
| 6254 |
*/ |
| 6255 |
grammar simpleNounPhrase(number): literalAdjPhrase->adj_ |
| 6256 |
: NounPhraseWithVocab |
| 6257 |
getVocabMatchList(resolver, results, extraFlags) |
| 6258 |
{ |
| 6259 |
/* |
| 6260 |
* note that this counts as an adjective-ending phrase, since we |
| 6261 |
* don't have a noun involved |
| 6262 |
*/ |
| 6263 |
results.noteAdjEnding(); |
| 6264 |
|
| 6265 |
/* pass through to the underlying literal adjective phrase */ |
| 6266 |
local lst = adj_.getVocabMatchList(resolver, results, |
| 6267 |
extraFlags | EndsWithAdj); |
| 6268 |
|
| 6269 |
/* if in global scope, also try a noun interpretation */ |
| 6270 |
if (resolver.isGlobalScope) |
| 6271 |
lst = adj_.addNounMatchList(lst, resolver, results, extraFlags); |
| 6272 |
|
| 6273 |
/* return the result */ |
| 6274 |
return lst; |
| 6275 |
} |
| 6276 |
getAdjustedTokens() |
| 6277 |
{ |
| 6278 |
/* pass through to the underlying literal adjective phrase */ |
| 6279 |
return adj_.getAdjustedTokens(); |
| 6280 |
} |
| 6281 |
; |
| 6282 |
|
| 6283 |
/* |
| 6284 |
* <literal-adjective> <noun> (for things like "board 44 bus" or 'push |
| 6285 |
* "G" button') |
| 6286 |
*/ |
| 6287 |
grammar simpleNounPhrase(numberAndNoun): |
| 6288 |
literalAdjPhrase->adj_ nounWord->noun_ |
| 6289 |
: NounPhraseWithVocab |
| 6290 |
getVocabMatchList(resolver, results, extraFlags) |
| 6291 |
{ |
| 6292 |
local nounList; |
| 6293 |
local adjList; |
| 6294 |
|
| 6295 |
/* get the list of objects matching the rest of the noun phrase */ |
| 6296 |
nounList = noun_.getVocabMatchList(resolver, results, extraFlags); |
| 6297 |
|
| 6298 |
/* get the list of objects matching the literal adjective */ |
| 6299 |
adjList = adj_.getVocabMatchList(resolver, results, extraFlags); |
| 6300 |
|
| 6301 |
/* intersect the two lists and return the results */ |
| 6302 |
return intersectNounLists(nounList, adjList); |
| 6303 |
} |
| 6304 |
getAdjustedTokens() |
| 6305 |
{ |
| 6306 |
return adj_.getAdjustedTokens() + noun_.getAdjustedTokens(); |
| 6307 |
} |
| 6308 |
; |
| 6309 |
|
| 6310 |
/* |
| 6311 |
* <noun> <literal-adjective> (for things like "press button 3" or 'put |
| 6312 |
* tab "A" in slot "B"') |
| 6313 |
*/ |
| 6314 |
grammar simpleNounPhrase(nounAndNumber): |
| 6315 |
nounWord->noun_ literalAdjPhrase->adj_ |
| 6316 |
: NounPhraseWithVocab |
| 6317 |
getVocabMatchList(resolver, results, extraFlags) |
| 6318 |
{ |
| 6319 |
local nounList; |
| 6320 |
local adjList; |
| 6321 |
|
| 6322 |
/* get the list of objects matching the rest of the noun phrase */ |
| 6323 |
nounList = noun_.getVocabMatchList(resolver, results, extraFlags); |
| 6324 |
|
| 6325 |
/* get the literal adjective matches */ |
| 6326 |
adjList = adj_.getVocabMatchList(resolver, results, extraFlags); |
| 6327 |
|
| 6328 |
/* intersect the two lists and return the results */ |
| 6329 |
return intersectNounLists(nounList, adjList); |
| 6330 |
} |
| 6331 |
getAdjustedTokens() |
| 6332 |
{ |
| 6333 |
return noun_.getAdjustedTokens() + adj_.getAdjustedTokens(); |
| 6334 |
} |
| 6335 |
; |
| 6336 |
|
| 6337 |
/* |
| 6338 |
* A simple noun phrase can also end in an adjective, which allows |
| 6339 |
* players to refer to objects using only their unique adjectives rather |
| 6340 |
* than their full names, which is sometimes more convenient: just "take |
| 6341 |
* gold" rather than "take gold key." |
| 6342 |
* |
| 6343 |
* When a particular phrase can be interpreted as either ending in an |
| 6344 |
* adjective or ending in a noun, we will always take the noun-ending |
| 6345 |
* interpretation - in such cases, the adjective-ending interpretation is |
| 6346 |
* probably a weak binding. For example, "take pizza" almost certainly |
| 6347 |
* refers to the pizza itself when "pizza" and "pizza box" are both |
| 6348 |
* present, but it can also refer just to the box when no pizza is |
| 6349 |
* present. |
| 6350 |
* |
| 6351 |
* Equivalent to a noun phrase ending in an adjective is a noun phrase |
| 6352 |
* ending with an adjective followed by "one," as in "the red one." |
| 6353 |
*/ |
| 6354 |
grammar simpleNounPhrase(adj): adjWord->adj_ : NounPhraseWithVocab |
| 6355 |
/* generate a list of my resolved objects */ |
| 6356 |
getVocabMatchList(resolver, results, extraFlags) |
| 6357 |
{ |
| 6358 |
/* note in the results that we end in an adjective */ |
| 6359 |
results.noteAdjEnding(); |
| 6360 |
|
| 6361 |
/* generate a list of objects matching the adjective */ |
| 6362 |
local lst = adj_.getVocabMatchList( |
| 6363 |
resolver, results, extraFlags | EndsWithAdj); |
| 6364 |
|
| 6365 |
/* if in global scope, also try a noun interpretation */ |
| 6366 |
if (resolver.isGlobalScope) |
| 6367 |
lst = adj_.addNounMatchList(lst, resolver, results, extraFlags); |
| 6368 |
|
| 6369 |
/* return the result */ |
| 6370 |
return lst; |
| 6371 |
} |
| 6372 |
getAdjustedTokens() |
| 6373 |
{ |
| 6374 |
/* return the adjusted token list for the adjective */ |
| 6375 |
return adj_.getAdjustedTokens(); |
| 6376 |
} |
| 6377 |
; |
| 6378 |
|
| 6379 |
grammar simpleNounPhrase(adjAndOne): adjective->adj_ 'one' |
| 6380 |
: NounPhraseWithVocab |
| 6381 |
/* generate a list of my resolved objects */ |
| 6382 |
getVocabMatchList(resolver, results, extraFlags) |
| 6383 |
{ |
| 6384 |
/* |
| 6385 |
* This isn't exactly an adjective ending, but consider it as |
| 6386 |
* such anyway, since we're not matching 'one' to a vocabulary |
| 6387 |
* word - we're just using it as a grammatical marker that we're |
| 6388 |
* not providing a real noun. If there's another match for |
| 6389 |
* which 'one' is a noun, that one is definitely preferred to |
| 6390 |
* this one; the adj-ending marking will ensure that we choose |
| 6391 |
* the other one. |
| 6392 |
*/ |
| 6393 |
results.noteAdjEnding(); |
| 6394 |
|
| 6395 |
/* generate a list of objects matching the adjective */ |
| 6396 |
return getWordMatches(adj_, &adjective, resolver, |
| 6397 |
extraFlags | EndsWithAdj, VocabTruncated); |
| 6398 |
} |
| 6399 |
getAdjustedTokens() |
| 6400 |
{ |
| 6401 |
return [adj_, &adjective]; |
| 6402 |
} |
| 6403 |
; |
| 6404 |
|
| 6405 |
/* |
| 6406 |
* In the worst case, a simple noun phrase can be constructed from |
| 6407 |
* arbitrary words that don't appear in our dictionary. |
| 6408 |
*/ |
| 6409 |
grammar simpleNounPhrase(misc): |
| 6410 |
[badness 200] miscWordList->lst_ : NounPhraseWithVocab |
| 6411 |
getVocabMatchList(resolver, results, extraFlags) |
| 6412 |
{ |
| 6413 |
/* get the match list from the underlying list */ |
| 6414 |
local lst = lst_.getVocabMatchList(resolver, results, extraFlags); |
| 6415 |
|
| 6416 |
/* |
| 6417 |
* If there are no matches, note in the results that we have an |
| 6418 |
* arbitrary word list. Note that we do this only if there are |
| 6419 |
* no matches, because we might match non-dictionary words to an |
| 6420 |
* object with a wildcard in its vocabulary words, in which case |
| 6421 |
* this is a valid, matching phrase after all. |
| 6422 |
*/ |
| 6423 |
if (lst == nil || lst.length() == 0) |
| 6424 |
results.noteMiscWordList(lst_.getOrigText()); |
| 6425 |
|
| 6426 |
/* return the match list */ |
| 6427 |
return lst; |
| 6428 |
} |
| 6429 |
getAdjustedTokens() |
| 6430 |
{ |
| 6431 |
return lst_.getAdjustedTokens(); |
| 6432 |
} |
| 6433 |
; |
| 6434 |
|
| 6435 |
/* |
| 6436 |
* If the command has qualifiers but omits everything else, we can have |
| 6437 |
* an empty simple noun phrase. |
| 6438 |
*/ |
| 6439 |
grammar simpleNounPhrase(empty): [badness 600] : NounPhraseWithVocab |
| 6440 |
getVocabMatchList(resolver, results, extraFlags) |
| 6441 |
{ |
| 6442 |
/* we have an empty noun phrase */ |
| 6443 |
return results.emptyNounPhrase(resolver); |
| 6444 |
} |
| 6445 |
getAdjustedTokens() |
| 6446 |
{ |
| 6447 |
return []; |
| 6448 |
} |
| 6449 |
; |
| 6450 |
|
| 6451 |
/* ------------------------------------------------------------------------ */ |
| 6452 |
/* |
| 6453 |
* An AdjPhraseWithVocab is an English-specific subclass of |
| 6454 |
* NounPhraseWithVocab, specifically for noun phrases that contain |
| 6455 |
* entirely adjectives. |
| 6456 |
*/ |
| 6457 |
class AdjPhraseWithVocab: NounPhraseWithVocab |
| 6458 |
/* the property for the adjective literal - this is usually adj_ */ |
| 6459 |
adjVocabProp = &adj_ |
| 6460 |
|
| 6461 |
/* |
| 6462 |
* Add the vocabulary matches that we'd get if we were treating our |
| 6463 |
* adjective as a noun. This combines the noun interpretation with a |
| 6464 |
* list of matches we got for the adjective version. |
| 6465 |
*/ |
| 6466 |
addNounMatchList(lst, resolver, results, extraFlags) |
| 6467 |
{ |
| 6468 |
/* get the word matches with a noun interpretation of our adjective */ |
| 6469 |
local nLst = getWordMatches( |
| 6470 |
self.(adjVocabProp), &noun, resolver, extraFlags, VocabTruncated); |
| 6471 |
|
| 6472 |
/* combine the lists and return the result */ |
| 6473 |
return combineWordMatches(lst, nLst); |
| 6474 |
} |
| 6475 |
; |
| 6476 |
|
| 6477 |
/* ------------------------------------------------------------------------ */ |
| 6478 |
/* |
| 6479 |
* A "literal adjective" phrase is a number or string used as an |
| 6480 |
* adjective. |
| 6481 |
*/ |
| 6482 |
grammar literalAdjPhrase(number): |
| 6483 |
numberPhrase->num_ | poundNumberPhrase->num_ |
| 6484 |
: AdjPhraseWithVocab |
| 6485 |
|
| 6486 |
adj_ = (num_.getStrVal()) |
| 6487 |
getVocabMatchList(resolver, results, extraFlags) |
| 6488 |
{ |
| 6489 |
local numList; |
| 6490 |
|
| 6491 |
/* |
| 6492 |
* get the list of objects matching the numeral form of the |
| 6493 |
* number as an adjective |
| 6494 |
*/ |
| 6495 |
numList = getWordMatches(num_.getStrVal(), &adjective, |
| 6496 |
resolver, extraFlags, VocabTruncated); |
| 6497 |
|
| 6498 |
/* add the list of objects matching the special '#' wildcard */ |
| 6499 |
numList += getWordMatches('#', &adjective, resolver, |
| 6500 |
extraFlags, VocabTruncated); |
| 6501 |
|
| 6502 |
/* return the combined lists */ |
| 6503 |
return numList; |
| 6504 |
} |
| 6505 |
getAdjustedTokens() |
| 6506 |
{ |
| 6507 |
return [num_.getStrVal(), &adjective]; |
| 6508 |
} |
| 6509 |
; |
| 6510 |
|
| 6511 |
grammar literalAdjPhrase(string): quotedStringPhrase->str_ |
| 6512 |
: AdjPhraseWithVocab |
| 6513 |
|
| 6514 |
adj_ = (str_.getStringText().toLower()) |
| 6515 |
getVocabMatchList(resolver, results, extraFlags) |
| 6516 |
{ |
| 6517 |
local strList; |
| 6518 |
local wLst; |
| 6519 |
|
| 6520 |
/* |
| 6521 |
* get the list of objects matching the string with the quotes |
| 6522 |
* removed |
| 6523 |
*/ |
| 6524 |
strList = getWordMatches(str_.getStringText().toLower(), |
| 6525 |
&literalAdjective, |
| 6526 |
resolver, extraFlags, VocabTruncated); |
| 6527 |
|
| 6528 |
/* add the list of objects matching the literal-adjective wildcard */ |
| 6529 |
wLst = getWordMatches('\u0001', &literalAdjective, resolver, |
| 6530 |
extraFlags, VocabTruncated); |
| 6531 |
strList = combineWordMatches(strList, wLst); |
| 6532 |
|
| 6533 |
/* return the combined lists */ |
| 6534 |
return strList; |
| 6535 |
} |
| 6536 |
getAdjustedTokens() |
| 6537 |
{ |
| 6538 |
return [str_.getStringText().toLower(), &adjective]; |
| 6539 |
} |
| 6540 |
; |
| 6541 |
|
| 6542 |
/* |
| 6543 |
* In many cases, we might want to write what is semantically a literal |
| 6544 |
* string qualifier without the quotes. For example, we might want to |
| 6545 |
* refer to an elevator button that's labeled "G" as simply "button G", |
| 6546 |
* without any quotes around the "G". To accommodate these cases, we |
| 6547 |
* provide the literalAdjective part-of-speech. We'll match these parts |
| 6548 |
* of speech the same way we'd match them if they were quoted. |
| 6549 |
*/ |
| 6550 |
grammar literalAdjPhrase(literalAdj): literalAdjective->adj_ |
| 6551 |
: AdjPhraseWithVocab |
| 6552 |
getVocabMatchList(resolver, results, extraFlags) |
| 6553 |
{ |
| 6554 |
local lst; |
| 6555 |
|
| 6556 |
/* get a list of objects in scope matching our literal adjective */ |
| 6557 |
lst = getWordMatches(adj_, &literalAdjective, resolver, |
| 6558 |
extraFlags, VocabTruncated); |
| 6559 |
|
| 6560 |
/* if the scope is global, also include ordinary adjective matches */ |
| 6561 |
if (resolver.isGlobalScope) |
| 6562 |
{ |
| 6563 |
/* get the ordinary adjective bindings */ |
| 6564 |
local aLst = getWordMatches(adj_, &adjective, resolver, |
| 6565 |
extraFlags, VocabTruncated); |
| 6566 |
|
| 6567 |
/* global scope - combine the lists */ |
| 6568 |
lst = combineWordMatches(lst, aLst); |
| 6569 |
} |
| 6570 |
|
| 6571 |
/* return the result */ |
| 6572 |
return lst; |
| 6573 |
} |
| 6574 |
getAdjustedTokens() |
| 6575 |
{ |
| 6576 |
return [adj_, &literalAdjective]; |
| 6577 |
} |
| 6578 |
; |
| 6579 |
|
| 6580 |
|
| 6581 |
/* ------------------------------------------------------------------------ */ |
| 6582 |
/* |
| 6583 |
* A noun word. This can be either a simple 'noun' vocabulary word, or |
| 6584 |
* it can be an abbreviated noun with a trailing abbreviation period. |
| 6585 |
*/ |
| 6586 |
class NounWordProd: NounPhraseWithVocab |
| 6587 |
getVocabMatchList(resolver, results, extraFlags) |
| 6588 |
{ |
| 6589 |
local w; |
| 6590 |
local nLst; |
| 6591 |
|
| 6592 |
/* get our word text */ |
| 6593 |
w = getNounText(); |
| 6594 |
|
| 6595 |
/* get the list of matches as nouns */ |
| 6596 |
nLst = getWordMatches(w, &noun, resolver, extraFlags, VocabTruncated); |
| 6597 |
|
| 6598 |
/* |
| 6599 |
* If the resolver indicates that we're in a "global" scope, |
| 6600 |
* *also* include any additional matches as adjectives. |
| 6601 |
* |
| 6602 |
* Normally, when we're operating in limited, local scopes, we |
| 6603 |
* use the structure of the phrasing to determine whether to |
| 6604 |
* match a noun or adjective; if we have a match for a given word |
| 6605 |
* as a noun, we'll treat it only as a noun. This allows us to |
| 6606 |
* take PIZZA to refer to the pizza (for which 'pizza' is defined |
| 6607 |
* as a noun) rather than to the PIZZA BOX (for which 'pizza' is |
| 6608 |
* a mere adjective) when both are in scope. It's obvious which |
| 6609 |
* the player means in such cases, so we can be smart about |
| 6610 |
* choosing the stronger match. |
| 6611 |
* |
| 6612 |
* In cases of global scope, though, it's much harder to guess |
| 6613 |
* about the player's intentions. When the player types PIZZA, |
| 6614 |
* they might be thinking of the box even though there's a pizza |
| 6615 |
* somewhere else in the game. Since the two objects might be in |
| 6616 |
* entirely different locations, both out of view, we can't |
| 6617 |
* assume that one or the other is more likely on the basis of |
| 6618 |
* which is closer to the player's senses. So, it's better to |
| 6619 |
* allow both to match for now, and decide later, based on the |
| 6620 |
* context of the command, which was actually meant. |
| 6621 |
*/ |
| 6622 |
if (resolver.isGlobalScope) |
| 6623 |
{ |
| 6624 |
/* get the list of matching adjectives */ |
| 6625 |
local aLst = getWordMatches(w, &adjective, resolver, |
| 6626 |
extraFlags, VocabTruncated); |
| 6627 |
|
| 6628 |
/* combine it with the noun list */ |
| 6629 |
nLst = combineWordMatches(nLst, aLst); |
| 6630 |
} |
| 6631 |
|
| 6632 |
/* return the match list */ |
| 6633 |
return nLst; |
| 6634 |
} |
| 6635 |
getAdjustedTokens() |
| 6636 |
{ |
| 6637 |
/* the noun includes the period as part of the literal text */ |
| 6638 |
return [getNounText(), &noun]; |
| 6639 |
} |
| 6640 |
|
| 6641 |
/* the actual text of the noun to match to the dictionary */ |
| 6642 |
getNounText() { return noun_; } |
| 6643 |
; |
| 6644 |
|
| 6645 |
grammar nounWord(noun): noun->noun_ : NounWordProd |
| 6646 |
; |
| 6647 |
|
| 6648 |
grammar nounWord(nounAbbr): noun->noun_ tokAbbrPeriod->period_ |
| 6649 |
: NounWordProd |
| 6650 |
|
| 6651 |
/* |
| 6652 |
* for dictionary matching purposes, include the text of our noun |
| 6653 |
* with the period attached - the period is part of the dictionary |
| 6654 |
* entry for an abbreviated word |
| 6655 |
*/ |
| 6656 |
getNounText() { return noun_ + period_; } |
| 6657 |
; |
| 6658 |
|
| 6659 |
/* ------------------------------------------------------------------------ */ |
| 6660 |
/* |
| 6661 |
* An adjective word. This can be either a simple 'adjective' vocabulary |
| 6662 |
* word, or it can be an 'adjApostS' vocabulary word plus a 's token. |
| 6663 |
*/ |
| 6664 |
grammar adjWord(adj): adjective->adj_ : AdjPhraseWithVocab |
| 6665 |
/* generate a list of resolved objects */ |
| 6666 |
getVocabMatchList(resolver, results, extraFlags) |
| 6667 |
{ |
| 6668 |
/* return a list of objects in scope matching our adjective */ |
| 6669 |
return getWordMatches(adj_, &adjective, resolver, |
| 6670 |
extraFlags, VocabTruncated); |
| 6671 |
} |
| 6672 |
getAdjustedTokens() |
| 6673 |
{ |
| 6674 |
return [adj_, &adjective]; |
| 6675 |
} |
| 6676 |
; |
| 6677 |
|
| 6678 |
grammar adjWord(adjApostS): adjApostS->adj_ tokApostropheS->apost_ |
| 6679 |
: AdjPhraseWithVocab |
| 6680 |
/* generate a list of resolved objects */ |
| 6681 |
getVocabMatchList(resolver, results, extraFlags) |
| 6682 |
{ |
| 6683 |
/* return a list of objects in scope matching our adjective */ |
| 6684 |
return getWordMatches(adj_, &adjApostS, resolver, |
| 6685 |
extraFlags, VocabTruncated); |
| 6686 |
} |
| 6687 |
getAdjustedTokens() |
| 6688 |
{ |
| 6689 |
return [adj_, &adjApostS]; |
| 6690 |
} |
| 6691 |
; |
| 6692 |
|
| 6693 |
grammar adjWord(adjAbbr): adjective->adj_ tokAbbrPeriod->period_ |
| 6694 |
: AdjPhraseWithVocab |
| 6695 |
getVocabMatchList(resolver, results, extraFlags) |
| 6696 |
{ |
| 6697 |
/* |
| 6698 |
* return the list matching our adjective *with* the period |
| 6699 |
* attached; the period is part of the dictionary entry for an |
| 6700 |
* abbreviated word |
| 6701 |
*/ |
| 6702 |
return getWordMatches(adj_ + period_, &adjective, resolver, |
| 6703 |
extraFlags, VocabTruncated); |
| 6704 |
} |
| 6705 |
getAdjustedTokens() |
| 6706 |
{ |
| 6707 |
/* the adjective includes the period as part of the literal text */ |
| 6708 |
return [adj_ + period_, &adjective]; |
| 6709 |
} |
| 6710 |
; |
| 6711 |
|
| 6712 |
/* ------------------------------------------------------------------------ */ |
| 6713 |
/* |
| 6714 |
* Possessive phrase. This is a noun phrase expressing ownership of |
| 6715 |
* another object. |
| 6716 |
* |
| 6717 |
* Note that all possessive phrases that can possibly be ambiguous must |
| 6718 |
* define getOrigMainText() to return the "main noun phrase" text. In |
| 6719 |
* English, this means that we must omit any "'s" suffix. This is needed |
| 6720 |
* only when the phrase can be ambiguous, so pronouns don't need it since |
| 6721 |
* they are inherently unambiguous. |
| 6722 |
*/ |
| 6723 |
grammar possessiveAdjPhrase(its): 'its' : ItsAdjProd |
| 6724 |
/* we only agree with a singular ungendered noun */ |
| 6725 |
checkAnaphorAgreement(lst) |
| 6726 |
{ return lst.length() == 1 && lst[1].obj_.canMatchIt; } |
| 6727 |
; |
| 6728 |
grammar possessiveAdjPhrase(his): 'his' : HisAdjProd |
| 6729 |
/* we only agree with a singular masculine noun */ |
| 6730 |
checkAnaphorAgreement(lst) |
| 6731 |
{ return lst.length() == 1 && lst[1].obj_.canMatchHim; } |
| 6732 |
; |
| 6733 |
grammar possessiveAdjPhrase(her): 'her' : HerAdjProd |
| 6734 |
/* we only agree with a singular feminine noun */ |
| 6735 |
checkAnaphorAgreement(lst) |
| 6736 |
{ return lst.length() == 1 && lst[1].obj_.canMatchHer; } |
| 6737 |
; |
| 6738 |
grammar possessiveAdjPhrase(their): 'their' : TheirAdjProd |
| 6739 |
/* we only agree with a single noun that has plural usage */ |
| 6740 |
checkAnaphorAgreement(lst) |
| 6741 |
{ return lst.length() == 1 && lst[1].obj_.isPlural; } |
| 6742 |
; |
| 6743 |
grammar possessiveAdjPhrase(your): 'your' : YourAdjProd |
| 6744 |
/* we are non-anaphoric */ |
| 6745 |
checkAnaphorAgreement(lst) { return nil; } |
| 6746 |
; |
| 6747 |
grammar possessiveAdjPhrase(my): 'my' : MyAdjProd |
| 6748 |
/* we are non-anaphoric */ |
| 6749 |
checkAnaphorAgreement(lst) { return nil; } |
| 6750 |
; |
| 6751 |
|
| 6752 |
grammar possessiveAdjPhrase(npApostropheS): |
| 6753 |
('the' | ) nounPhrase->np_ tokApostropheS->apost_ : LayeredNounPhraseProd |
| 6754 |
|
| 6755 |
/* get the original text without the "'s" suffix */ |
| 6756 |
getOrigMainText() |
| 6757 |
{ |
| 6758 |
/* return just the basic noun phrase part */ |
| 6759 |
return np_.getOrigText(); |
| 6760 |
} |
| 6761 |
; |
| 6762 |
|
| 6763 |
grammar possessiveAdjPhrase(ppApostropheS): |
| 6764 |
('the' | ) pluralPhrase->np_ |
| 6765 |
(tokApostropheS->apost_ | tokPluralApostrophe->apost_) |
| 6766 |
: LayeredNounPhraseProd |
| 6767 |
|
| 6768 |
/* get the original text without the "'s" suffix */ |
| 6769 |
getOrigMainText() |
| 6770 |
{ |
| 6771 |
/* return just the basic noun phrase part */ |
| 6772 |
return np_.getOrigText(); |
| 6773 |
} |
| 6774 |
|
| 6775 |
resolveNouns(resolver, results) |
| 6776 |
{ |
| 6777 |
/* note that we have a plural phrase, structurally speaking */ |
| 6778 |
results.notePlural(); |
| 6779 |
|
| 6780 |
/* inherit the default handling */ |
| 6781 |
return inherited(resolver, results); |
| 6782 |
} |
| 6783 |
|
| 6784 |
/* the possessive phrase is plural */ |
| 6785 |
isPluralPossessive = true |
| 6786 |
; |
| 6787 |
|
| 6788 |
/* |
| 6789 |
* Possessive noun phrases. These are similar to possessive phrases, but |
| 6790 |
* are stand-alone phrases that can act as nouns rather than as |
| 6791 |
* qualifiers for other noun phrases. For example, for a first-person |
| 6792 |
* player character, "mine" would be a possessive noun phrase referring |
| 6793 |
* to an object owned by the player character. |
| 6794 |
* |
| 6795 |
* Note that many of the words used for possessive nouns are the same as |
| 6796 |
* for possessive adjectives - for example "his" is the same in either |
| 6797 |
* case, as are "'s" words. However, we make the distinction internally |
| 6798 |
* because the two have different grammatical uses, and some of the words |
| 6799 |
* do differ ("her" vs "hers", for example). |
| 6800 |
*/ |
| 6801 |
grammar possessiveNounPhrase(its): 'its': ItsNounProd; |
| 6802 |
grammar possessiveNounPhrase(his): 'his': HisNounProd; |
| 6803 |
grammar possessiveNounPhrase(hers): 'hers': HersNounProd; |
| 6804 |
grammar possessiveNounPhrase(theirs): 'theirs': TheirsNounProd; |
| 6805 |
grammar possessiveNounPhrase(yours): 'yours' : YoursNounProd; |
| 6806 |
grammar possessiveNounPhrase(mine): 'mine' : MineNounProd; |
| 6807 |
|
| 6808 |
grammar possessiveNounPhrase(npApostropheS): |
| 6809 |
('the' | ) |
| 6810 |
(nounPhrase->np_ tokApostropheS->apost_ |
| 6811 |
| pluralPhrase->np (tokApostropheS->apost_ | tokPluralApostrophe->apost_)) |
| 6812 |
: LayeredNounPhraseProd |
| 6813 |
|
| 6814 |
/* get the original text without the "'s" suffix */ |
| 6815 |
getOrigMainText() |
| 6816 |
{ |
| 6817 |
/* return just the basic noun phrase part */ |
| 6818 |
return np_.getOrigText(); |
| 6819 |
} |
| 6820 |
; |
| 6821 |
|
| 6822 |
|
| 6823 |
/* ------------------------------------------------------------------------ */ |
| 6824 |
/* |
| 6825 |
* Simple plural phrase. This is the most basic plural phrase, which is |
| 6826 |
* simply a plural noun, optionally preceded by one or more adjectives. |
| 6827 |
* |
| 6828 |
* (English doesn't have any sort of adjective declension in number, so |
| 6829 |
* there's no need to distinguish between plural and singular adjectives; |
| 6830 |
* this equivalent rule in languages with adjective-noun agreement in |
| 6831 |
* number would use plural adjectives here as well as plural nouns.) |
| 6832 |
*/ |
| 6833 |
grammar simplePluralPhrase(plural): plural->plural_ : NounPhraseWithVocab |
| 6834 |
/* generate a list of my resolved objects */ |
| 6835 |
getVocabMatchList(resolver, results, extraFlags) |
| 6836 |
{ |
| 6837 |
local lst; |
| 6838 |
|
| 6839 |
/* get the list of matching plurals */ |
| 6840 |
lst = getWordMatches(plural_, &plural, resolver, |
| 6841 |
extraFlags, PluralTruncated); |
| 6842 |
|
| 6843 |
/* get the list of matching 'noun' definitions */ |
| 6844 |
local nLst = getWordMatches(plural_, &noun, resolver, |
| 6845 |
extraFlags, VocabTruncated); |
| 6846 |
|
| 6847 |
/* get the combined list */ |
| 6848 |
local comboLst = combineWordMatches(lst, nLst); |
| 6849 |
|
| 6850 |
/* |
| 6851 |
* If we're in global scope, add in the matches for just plain |
| 6852 |
* 'noun' properties as well. This is important because we'll |
| 6853 |
* sometimes want to define a word that's actually a plural |
| 6854 |
* usage (in terms of the real-world English) under the 'noun' |
| 6855 |
* property. This occurs particularly when a single game-world |
| 6856 |
* object represents a multiplicity of real-world objects. When |
| 6857 |
* the scope is global, it's hard to anticipate all of the |
| 6858 |
* possible interactions with vocabulary along these lines, so |
| 6859 |
* it's easiest just to include the 'noun' matches. |
| 6860 |
*/ |
| 6861 |
if (resolver.isGlobalScope) |
| 6862 |
{ |
| 6863 |
/* keep the combined list */ |
| 6864 |
lst = comboLst; |
| 6865 |
} |
| 6866 |
else if (comboLst.length() > lst.length()) |
| 6867 |
{ |
| 6868 |
/* |
| 6869 |
* ordinary scope, so don't include the noun matches; but |
| 6870 |
* since we found extra items to add, at least mark the |
| 6871 |
* plural matches as potentially ambiguous |
| 6872 |
*/ |
| 6873 |
lst.forEach({x: x.flags_ |= UnclearDisambig}); |
| 6874 |
} |
| 6875 |
|
| 6876 |
/* return the result list */ |
| 6877 |
return lst; |
| 6878 |
} |
| 6879 |
getAdjustedTokens() |
| 6880 |
{ |
| 6881 |
return [plural_, &plural]; |
| 6882 |
} |
| 6883 |
; |
| 6884 |
|
| 6885 |
grammar simplePluralPhrase(adj): adjWord->adj_ simplePluralPhrase->np_ : |
| 6886 |
NounPhraseWithVocab |
| 6887 |
|
| 6888 |
/* resolve my object list */ |
| 6889 |
getVocabMatchList(resolver, results, extraFlags) |
| 6890 |
{ |
| 6891 |
/* |
| 6892 |
* return the list of objects in scope matching our adjective |
| 6893 |
* plus the list from the underlying noun phrase |
| 6894 |
*/ |
| 6895 |
return intersectNounLists( |
| 6896 |
adj_.getVocabMatchList(resolver, results, extraFlags), |
| 6897 |
np_.getVocabMatchList(resolver, results, extraFlags)); |
| 6898 |
} |
| 6899 |
getAdjustedTokens() |
| 6900 |
{ |
| 6901 |
return adj_.getAdjustedTokens() + np_.getAdjustedTokens(); |
| 6902 |
} |
| 6903 |
; |
| 6904 |
|
| 6905 |
grammar simplePluralPhrase(poundNum): |
| 6906 |
poundNumberPhrase->num_ simplePluralPhrase->np_ |
| 6907 |
: NounPhraseWithVocab |
| 6908 |
|
| 6909 |
/* resolve my object list */ |
| 6910 |
getVocabMatchList(resolver, results, extraFlags) |
| 6911 |
{ |
| 6912 |
local baseList; |
| 6913 |
local numList; |
| 6914 |
|
| 6915 |
/* get the base list for the rest of the phrase */ |
| 6916 |
baseList = np_.getVocabMatchList(resolver, results, extraFlags); |
| 6917 |
|
| 6918 |
/* get the numeric matches, including numeric wildcards */ |
| 6919 |
numList = getWordMatches(num_.getStrVal(), &adjective, |
| 6920 |
resolver, extraFlags, VocabTruncated) |
| 6921 |
+ getWordMatches('#', &adjective, |
| 6922 |
resolver, extraFlags, VocabTruncated); |
| 6923 |
|
| 6924 |
/* return the intersection of the lists */ |
| 6925 |
return intersectNounLists(numList, baseList); |
| 6926 |
} |
| 6927 |
getAdjustedTokens() |
| 6928 |
{ |
| 6929 |
return [num_.getStrVal(), &adjective] + np_.getAdjustedTokens(); |
| 6930 |
} |
| 6931 |
; |
| 6932 |
|
| 6933 |
/* |
| 6934 |
* A simple plural phrase can end with an adjective and "ones," as in |
| 6935 |
* "the red ones." |
| 6936 |
*/ |
| 6937 |
grammar simplePluralPhrase(adjAndOnes): adjective->adj_ 'ones' |
| 6938 |
: NounPhraseWithVocab |
| 6939 |
getVocabMatchList(resolver, results, extraFlags) |
| 6940 |
{ |
| 6941 |
/* generate a list of objects matching the adjective */ |
| 6942 |
return getWordMatches(adj_, &adjective, resolver, |
| 6943 |
extraFlags | EndsWithAdj, VocabTruncated); |
| 6944 |
} |
| 6945 |
getAdjustedTokens() |
| 6946 |
{ |
| 6947 |
return [adj_, &adjective]; |
| 6948 |
} |
| 6949 |
; |
| 6950 |
|
| 6951 |
/* |
| 6952 |
* If the command has qualifiers that require a plural, but omits |
| 6953 |
* everything else, we can have an empty simple noun phrase. |
| 6954 |
*/ |
| 6955 |
grammar simplePluralPhrase(empty): [badness 600] : NounPhraseWithVocab |
| 6956 |
getVocabMatchList(resolver, results, extraFlags) |
| 6957 |
{ |
| 6958 |
/* we have an empty noun phrase */ |
| 6959 |
return results.emptyNounPhrase(resolver); |
| 6960 |
} |
| 6961 |
getAdjustedTokens() |
| 6962 |
{ |
| 6963 |
return []; |
| 6964 |
} |
| 6965 |
; |
| 6966 |
|
| 6967 |
/* |
| 6968 |
* A simple plural phrase can match unknown words as a last resort. |
| 6969 |
*/ |
| 6970 |
grammar simplePluralPhrase(misc): |
| 6971 |
[badness 300] miscWordList->lst_ : NounPhraseWithVocab |
| 6972 |
getVocabMatchList(resolver, results, extraFlags) |
| 6973 |
{ |
| 6974 |
/* get the match list from the underlying list */ |
| 6975 |
local lst = lst_.getVocabMatchList(resolver, results, extraFlags); |
| 6976 |
|
| 6977 |
/* |
| 6978 |
* if there are no matches, note in the results that we have an |
| 6979 |
* arbitrary word list that doesn't correspond to any object |
| 6980 |
*/ |
| 6981 |
if (lst == nil || lst.length() == 0) |
| 6982 |
results.noteMiscWordList(lst_.getOrigText()); |
| 6983 |
|
| 6984 |
/* return the vocabulary match list */ |
| 6985 |
return lst; |
| 6986 |
} |
| 6987 |
getAdjustedTokens() |
| 6988 |
{ |
| 6989 |
return lst_.getAdjustedTokens(); |
| 6990 |
} |
| 6991 |
; |
| 6992 |
|
| 6993 |
|
| 6994 |
/* ------------------------------------------------------------------------ */ |
| 6995 |
/* |
| 6996 |
* An "adjective phrase" is a phrase made entirely of adjectives. |
| 6997 |
*/ |
| 6998 |
grammar adjPhrase(adj): adjective->adj_ : AdjPhraseWithVocab |
| 6999 |
getVocabMatchList(resolver, results, extraFlags) |
| 7000 |
{ |
| 7001 |
/* note the adjective ending */ |
| 7002 |
results.noteAdjEnding(); |
| 7003 |
|
| 7004 |
/* return the match list */ |
| 7005 |
local lst = getWordMatches(adj_, &adjective, resolver, |
| 7006 |
extraFlags | EndsWithAdj, VocabTruncated); |
| 7007 |
|
| 7008 |
/* if in global scope, also try a noun interpretation */ |
| 7009 |
if (resolver.isGlobalScope) |
| 7010 |
lst = addNounMatchList(lst, resolver, results, extraFlags); |
| 7011 |
|
| 7012 |
/* return the result */ |
| 7013 |
return lst; |
| 7014 |
} |
| 7015 |
|
| 7016 |
getAdjustedTokens() |
| 7017 |
{ |
| 7018 |
return [adj_, &adjective]; |
| 7019 |
} |
| 7020 |
; |
| 7021 |
|
| 7022 |
grammar adjPhrase(adjAdj): adjective->adj_ adjPhrase->ap_ |
| 7023 |
: NounPhraseWithVocab |
| 7024 |
/* generate a list of my resolved objects */ |
| 7025 |
getVocabMatchList(resolver, results, extraFlags) |
| 7026 |
{ |
| 7027 |
/* |
| 7028 |
* return the list of objects in scope matching our adjective |
| 7029 |
* plus the list from the underlying adjective phrase |
| 7030 |
*/ |
| 7031 |
return intersectWordMatches( |
| 7032 |
adj_, &adjective, resolver, extraFlags, VocabTruncated, |
| 7033 |
ap_.getVocabMatchList(resolver, results, extraFlags)); |
| 7034 |
} |
| 7035 |
getAdjustedTokens() |
| 7036 |
{ |
| 7037 |
return [adj_, &adjective] + ap_.getAdjustedTokens(); |
| 7038 |
} |
| 7039 |
; |
| 7040 |
|
| 7041 |
|
| 7042 |
/* ------------------------------------------------------------------------ */ |
| 7043 |
/* |
| 7044 |
* A "topic" is a special type of noun phrase used in commands like "ask |
| 7045 |
* <actor> about <topic>." We define a topic as simply an ordinary |
| 7046 |
* single-noun phrase. We distinguish this in the grammar to allow games |
| 7047 |
* to add special syntax for these. |
| 7048 |
*/ |
| 7049 |
grammar topicPhrase(main): singleNoun->np_ : TopicProd |
| 7050 |
; |
| 7051 |
|
| 7052 |
/* |
| 7053 |
* Explicitly match a miscellaneous word list as a topic. |
| 7054 |
* |
| 7055 |
* This might seem redundant with the ordinary topicPhrase that accepts a |
| 7056 |
* singleNoun, because singleNoun can match a miscellaneous word list. |
| 7057 |
* The difference is that singleNoun only matches a miscWordList with a |
| 7058 |
* "badness" value, whereas we match a miscWordList here without any |
| 7059 |
* badness. We want to be more tolerant of unrecognized input in topic |
| 7060 |
* phrases than in ordinary noun phrases, because it's in the nature of |
| 7061 |
* topic phrases to go outside of what's implemented directly in the |
| 7062 |
* simulation model. At a grammatical level, we don't want to treat |
| 7063 |
* topic phrases that we can resolve to the simulation model any |
| 7064 |
* differently than we treat those we can't resolve, so we must add this |
| 7065 |
* rule to eliminate the badness that singleNoun associated with a |
| 7066 |
* miscWordList match. |
| 7067 |
* |
| 7068 |
* Note that we do prefer resolvable noun phrase matches to miscWordList |
| 7069 |
* matches, but we handle this preference with the resolver's scoring |
| 7070 |
* mechanism rather than with badness. |
| 7071 |
*/ |
| 7072 |
grammar topicPhrase(misc): miscWordList->np_ : TopicProd |
| 7073 |
resolveNouns(resolver, results) |
| 7074 |
{ |
| 7075 |
/* note in the results that we have an arbitrary word list */ |
| 7076 |
results.noteMiscWordList(np_.getOrigText()); |
| 7077 |
|
| 7078 |
/* inherit the default TopicProd behavior */ |
| 7079 |
return inherited(resolver, results); |
| 7080 |
} |
| 7081 |
; |
| 7082 |
|
| 7083 |
/* ------------------------------------------------------------------------ */ |
| 7084 |
/* |
| 7085 |
* A "quoted string" phrase is a literal enclosed in single or double |
| 7086 |
* quotes. |
| 7087 |
* |
| 7088 |
* Note that this is a separate production from literalPhrase. This |
| 7089 |
* production can be used when *only* a quoted string is allowed. The |
| 7090 |
* literalPhrase production allows both quoted and unquoted text. |
| 7091 |
*/ |
| 7092 |
grammar quotedStringPhrase(main): tokString->str_ : LiteralProd |
| 7093 |
/* |
| 7094 |
* get my string, with the quotes trimmed off (so we return simply |
| 7095 |
* the contents of the string) |
| 7096 |
*/ |
| 7097 |
getStringText() { return stripQuotesFrom(str_); } |
| 7098 |
; |
| 7099 |
|
| 7100 |
/* |
| 7101 |
* Service routine: strip quotes from a *possibly* quoted string. If the |
| 7102 |
* string starts with a quote, we'll remove the open quote. If it starts |
| 7103 |
* with a quote and it ends with a corresponding close quote, we'll |
| 7104 |
* remove that as well. |
| 7105 |
*/ |
| 7106 |
stripQuotesFrom(str) |
| 7107 |
{ |
| 7108 |
local hasOpen; |
| 7109 |
local hasClose; |
| 7110 |
|
| 7111 |
/* presume we won't find open or close quotes */ |
| 7112 |
hasOpen = hasClose = nil; |
| 7113 |
|
| 7114 |
/* |
| 7115 |
* Check for quotes. We'll accept regular ASCII "straight" single |
| 7116 |
* or double quotes, as well as Latin-1 curly single or double |
| 7117 |
* quotes. The curly quotes must be used in their normal |
| 7118 |
*/ |
| 7119 |
if (str.startsWith('\'') || str.startsWith('"')) |
| 7120 |
{ |
| 7121 |
/* single or double quote - check for a matching close quote */ |
| 7122 |
hasOpen = true; |
| 7123 |
hasClose = (str.length() > 2 && str.endsWith(str.substr(1, 1))); |
| 7124 |
} |
| 7125 |
else if (str.startsWith('`')) |
| 7126 |
{ |
| 7127 |
/* single in-slanted quote - check for either type of close */ |
| 7128 |
hasOpen = true; |
| 7129 |
hasClose = (str.length() > 2 |
| 7130 |
&& (str.endsWith('`') || str.endsWith('\''))); |
| 7131 |
} |
| 7132 |
else if (str.startsWith('\u201C')) |
| 7133 |
{ |
| 7134 |
/* it's a curly double quote */ |
| 7135 |
hasOpen = true; |
| 7136 |
hasClose = str.endsWith('\u201D'); |
| 7137 |
} |
| 7138 |
else if (str.startsWith('\u2018')) |
| 7139 |
{ |
| 7140 |
/* it's a curly single quote */ |
| 7141 |
hasOpen = true; |
| 7142 |
hasClose = str.endsWith('\u2019'); |
| 7143 |
} |
| 7144 |
|
| 7145 |
/* trim off the quotes */ |
| 7146 |
if (hasOpen) |
| 7147 |
{ |
| 7148 |
if (hasClose) |
| 7149 |
str = str.substr(2, str.length() - 2); |
| 7150 |
else |
| 7151 |
str = str.substr(2); |
| 7152 |
} |
| 7153 |
|
| 7154 |
/* return the modified text */ |
| 7155 |
return str; |
| 7156 |
} |
| 7157 |
|
| 7158 |
/* ------------------------------------------------------------------------ */ |
| 7159 |
/* |
| 7160 |
* A "literal" is essentially any phrase. This can include a quoted |
| 7161 |
* string, a number, or any set of word tokens. |
| 7162 |
*/ |
| 7163 |
grammar literalPhrase(string): quotedStringPhrase->str_ : LiteralProd |
| 7164 |
getLiteralText(results, action, which) |
| 7165 |
{ |
| 7166 |
/* get the text from our underlying quoted string */ |
| 7167 |
return str_.getStringText(); |
| 7168 |
} |
| 7169 |
|
| 7170 |
getTentativeLiteralText() |
| 7171 |
{ |
| 7172 |
/* |
| 7173 |
* our result will never change, so our tentative text is the |
| 7174 |
* same as our regular literal text |
| 7175 |
*/ |
| 7176 |
return str_.getStringText(); |
| 7177 |
} |
| 7178 |
|
| 7179 |
resolveLiteral(results) |
| 7180 |
{ |
| 7181 |
/* flag the literal text */ |
| 7182 |
results.noteLiteral(str_.getOrigText()); |
| 7183 |
} |
| 7184 |
; |
| 7185 |
|
| 7186 |
grammar literalPhrase(miscList): miscWordList->misc_ : LiteralProd |
| 7187 |
getLiteralText(results, action, which) |
| 7188 |
{ |
| 7189 |
/* get my original text */ |
| 7190 |
local txt = misc_.getOrigText(); |
| 7191 |
|
| 7192 |
/* |
| 7193 |
* if our underlying miscWordList has only one token, strip |
| 7194 |
* quotes, in case that token is a quoted string token |
| 7195 |
*/ |
| 7196 |
if (misc_.getOrigTokenList().length() == 1) |
| 7197 |
txt = stripQuotesFrom(txt); |
| 7198 |
|
| 7199 |
/* return the text */ |
| 7200 |
return txt; |
| 7201 |
} |
| 7202 |
|
| 7203 |
getTentativeLiteralText() |
| 7204 |
{ |
| 7205 |
/* our regular text is permanent, so simply use it now */ |
| 7206 |
return misc_.getOrigText(); |
| 7207 |
} |
| 7208 |
|
| 7209 |
resolveLiteral(results) |
| 7210 |
{ |
| 7211 |
/* |
| 7212 |
* note the length of our literal phrase - when we have a choice |
| 7213 |
* of interpretations, we prefer to choose shorter literal |
| 7214 |
* phrases, since this means that we'll have more of our tokens |
| 7215 |
* being fully interpreted rather than bunched into an |
| 7216 |
* uninterpreted literal |
| 7217 |
*/ |
| 7218 |
results.noteLiteral(misc_.getOrigText()); |
| 7219 |
} |
| 7220 |
; |
| 7221 |
|
| 7222 |
/* |
| 7223 |
* In case we have a verb grammar rule that calls for a literal phrase, |
| 7224 |
* but the player enters a command with nothing in that slot, match an |
| 7225 |
* empty token list as a last resort. Since this phrasing has a badness, |
| 7226 |
* we won't match it unless we don't have any better structural match. |
| 7227 |
*/ |
| 7228 |
grammar literalPhrase(empty): [badness 400]: EmptyLiteralPhraseProd |
| 7229 |
resolveLiteral(results) { } |
| 7230 |
; |
| 7231 |
|
| 7232 |
/* ------------------------------------------------------------------------ */ |
| 7233 |
/* |
| 7234 |
* An miscellaneous word list is a list of one or more words of any kind: |
| 7235 |
* any word, any integer, or any apostrophe-S token will do. Note that |
| 7236 |
* known and unknown words can be mixed in an unknown word list; we care |
| 7237 |
* only that the list is made up of tokWord, tokInt, tokApostropheS, |
| 7238 |
* and/or abbreviation-period tokens. |
| 7239 |
* |
| 7240 |
* Note that this kind of phrase is often used with a 'badness' value. |
| 7241 |
* However, we don't assign any badness here, because a miscellaneous |
| 7242 |
* word list might be perfectly valid in some contexts; instead, any |
| 7243 |
* productions that include a misc word list should specify badness as |
| 7244 |
* desired. |
| 7245 |
*/ |
| 7246 |
grammar miscWordList(wordOrNumber): |
| 7247 |
tokWord->txt_ | tokInt->txt_ | tokApostropheS->txt_ |
| 7248 |
| tokPluralApostrophe->txt_ |
| 7249 |
| tokPoundInt->txt_ | tokString->txt_ | tokAbbrPeriod->txt_ |
| 7250 |
: NounPhraseWithVocab |
| 7251 |
getVocabMatchList(resolver, results, extraFlags) |
| 7252 |
{ |
| 7253 |
/* we don't match anything directly with our vocabulary */ |
| 7254 |
return []; |
| 7255 |
} |
| 7256 |
getAdjustedTokens() |
| 7257 |
{ |
| 7258 |
/* our token type is the special miscellaneous word type */ |
| 7259 |
return [txt_, &miscWord]; |
| 7260 |
} |
| 7261 |
; |
| 7262 |
|
| 7263 |
grammar miscWordList(list): |
| 7264 |
(tokWord->txt_ | tokInt->txt_ | tokApostropheS->txt_ |
| 7265 |
| tokPluralApostrophe->txt_ | tokAbbrPeriod->txt_ |
| 7266 |
| tokPoundInt->txt_ | tokString->txt_) miscWordList->lst_ |
| 7267 |
: NounPhraseWithVocab |
| 7268 |
getVocabMatchList(resolver, results, extraFlags) |
| 7269 |
{ |
| 7270 |
/* we don't match anything directly with our vocabulary */ |
| 7271 |
return []; |
| 7272 |
} |
| 7273 |
getAdjustedTokens() |
| 7274 |
{ |
| 7275 |
/* our token type is the special miscellaneous word type */ |
| 7276 |
return [txt_, &miscWord] + lst_.getAdjustedTokens(); |
| 7277 |
} |
| 7278 |
; |
| 7279 |
|
| 7280 |
/* ------------------------------------------------------------------------ */ |
| 7281 |
/* |
| 7282 |
* A main disambiguation phrase consists of a disambiguation phrase, |
| 7283 |
* optionally terminated with a period. |
| 7284 |
*/ |
| 7285 |
grammar mainDisambigPhrase(main): |
| 7286 |
disambigPhrase->dp_ |
| 7287 |
| disambigPhrase->dp_ '.' |
| 7288 |
: BasicProd |
| 7289 |
resolveNouns(resolver, results) |
| 7290 |
{ |
| 7291 |
return dp_.resolveNouns(resolver, results); |
| 7292 |
} |
| 7293 |
getResponseList() { return dp_.getResponseList(); } |
| 7294 |
; |
| 7295 |
|
| 7296 |
/* |
| 7297 |
* A "disambiguation phrase" is a phrase that answers a disambiguation |
| 7298 |
* question ("which book do you mean..."). |
| 7299 |
* |
| 7300 |
* A disambiguation question can be answered with several types of |
| 7301 |
* syntax: |
| 7302 |
* |
| 7303 |
*. all/everything/all of them |
| 7304 |
*. both/both of them |
| 7305 |
*. any/any of them |
| 7306 |
*. <disambig list> |
| 7307 |
*. the <ordinal list> ones |
| 7308 |
*. the former/the latter |
| 7309 |
* |
| 7310 |
* Note that we assign non-zero badness to all of the ordinal |
| 7311 |
* interpretations, so that we will take an actual vocabulary |
| 7312 |
* interpretation instead of an ordinal interpretation whenever possible. |
| 7313 |
* For example, if an object's name is actually "the third button," this |
| 7314 |
* will give us greater affinity for using "third" as an adjective than |
| 7315 |
* as an ordinal in our own list. |
| 7316 |
*/ |
| 7317 |
grammar disambigPhrase(all): |
| 7318 |
'all' | 'everything' | 'all' 'of' 'them' : DisambigProd |
| 7319 |
resolveNouns(resolver, results) |
| 7320 |
{ |
| 7321 |
/* they want everything we proposed - return the whole list */ |
| 7322 |
return removeAmbigFlags(resolver.getAll(self)); |
| 7323 |
} |
| 7324 |
|
| 7325 |
/* there's only me in the response list */ |
| 7326 |
getResponseList() { return [self]; } |
| 7327 |
; |
| 7328 |
|
| 7329 |
grammar disambigPhrase(both): 'both' | 'both' 'of' 'them' : DisambigProd |
| 7330 |
resolveNouns(resolver, results) |
| 7331 |
{ |
| 7332 |
/* |
| 7333 |
* they want two items - return the whole list (if it has more |
| 7334 |
* than two items, we'll simply act as though they wanted all of |
| 7335 |
* them) |
| 7336 |
*/ |
| 7337 |
return removeAmbigFlags(resolver.getAll(self)); |
| 7338 |
} |
| 7339 |
|
| 7340 |
/* there's only me in the response list */ |
| 7341 |
getResponseList() { return [self]; } |
| 7342 |
; |
| 7343 |
|
| 7344 |
grammar disambigPhrase(any): 'any' | 'any' 'of' 'them' : DisambigProd |
| 7345 |
resolveNouns(resolver, results) |
| 7346 |
{ |
| 7347 |
local lst; |
| 7348 |
|
| 7349 |
/* they want any item - arbitrarily pick the first one */ |
| 7350 |
lst = resolver.matchList.sublist(1, 1); |
| 7351 |
|
| 7352 |
/* |
| 7353 |
* add the "unclear disambiguation" flag to the item we picked, |
| 7354 |
* to indicate that the selection was arbitrary |
| 7355 |
*/ |
| 7356 |
if (lst.length() > 0) |
| 7357 |
lst[1].flags_ |= UnclearDisambig; |
| 7358 |
|
| 7359 |
/* return the result */ |
| 7360 |
return lst; |
| 7361 |
} |
| 7362 |
|
| 7363 |
/* there's only me in the response list */ |
| 7364 |
getResponseList() { return [self]; } |
| 7365 |
; |
| 7366 |
|
| 7367 |
grammar disambigPhrase(list): disambigList->lst_ : DisambigProd |
| 7368 |
resolveNouns(resolver, results) |
| 7369 |
{ |
| 7370 |
return removeAmbigFlags(lst_.resolveNouns(resolver, results)); |
| 7371 |
} |
| 7372 |
|
| 7373 |
/* there's only me in the response list */ |
| 7374 |
getResponseList() { return lst_.getResponseList(); } |
| 7375 |
; |
| 7376 |
|
| 7377 |
grammar disambigPhrase(ordinalList): |
| 7378 |
disambigOrdinalList->lst_ 'ones' |
| 7379 |
| 'the' disambigOrdinalList->lst_ 'ones' |
| 7380 |
: DisambigProd |
| 7381 |
|
| 7382 |
resolveNouns(resolver, results) |
| 7383 |
{ |
| 7384 |
/* return the list with the ambiguity flags removed */ |
| 7385 |
return removeAmbigFlags(lst_.resolveNouns(resolver, results)); |
| 7386 |
} |
| 7387 |
|
| 7388 |
/* the response list consists of my single ordinal list item */ |
| 7389 |
getResponseList() { return [lst_]; } |
| 7390 |
; |
| 7391 |
|
| 7392 |
/* |
| 7393 |
* A disambig list consists of one or more disambig list items, connected |
| 7394 |
* by noun phrase conjunctions. |
| 7395 |
*/ |
| 7396 |
grammar disambigList(single): disambigListItem->item_ : DisambigProd |
| 7397 |
resolveNouns(resolver, results) |
| 7398 |
{ |
| 7399 |
return item_.resolveNouns(resolver, results); |
| 7400 |
} |
| 7401 |
|
| 7402 |
/* the response list consists of my single item */ |
| 7403 |
getResponseList() { return [item_]; } |
| 7404 |
; |
| 7405 |
|
| 7406 |
grammar disambigList(list): |
| 7407 |
disambigListItem->item_ commandOrNounConjunction disambigList->lst_ |
| 7408 |
: DisambigProd |
| 7409 |
|
| 7410 |
resolveNouns(resolver, results) |
| 7411 |
{ |
| 7412 |
return item_.resolveNouns(resolver, results) |
| 7413 |
+ lst_.resolveNouns(resolver, results); |
| 7414 |
} |
| 7415 |
|
| 7416 |
/* my response list consists of each of our list items */ |
| 7417 |
getResponseList() { return [item_] + lst_.getResponseList(); } |
| 7418 |
; |
| 7419 |
|
| 7420 |
/* |
| 7421 |
* Base class for ordinal disambiguation items |
| 7422 |
*/ |
| 7423 |
class DisambigOrdProd: DisambigProd |
| 7424 |
resolveNouns(resolver, results) |
| 7425 |
{ |
| 7426 |
/* note the ordinal match */ |
| 7427 |
results.noteDisambigOrdinal(); |
| 7428 |
|
| 7429 |
/* select the result by the ordinal */ |
| 7430 |
return selectByOrdinal(ord_, resolver, results); |
| 7431 |
} |
| 7432 |
|
| 7433 |
selectByOrdinal(ordTok, resolver, results) |
| 7434 |
{ |
| 7435 |
local idx; |
| 7436 |
local matchList = resolver.ordinalMatchList; |
| 7437 |
|
| 7438 |
/* |
| 7439 |
* look up the meaning of the ordinal word (note that we assume |
| 7440 |
* that each ordinalWord is unique, since we only create one of |
| 7441 |
* each) |
| 7442 |
*/ |
| 7443 |
idx = cmdDict.findWord(ordTok, &ordinalWord)[1].numval; |
| 7444 |
|
| 7445 |
/* |
| 7446 |
* if it's the special value -1, it indicates that we should |
| 7447 |
* select the *last* item in the list |
| 7448 |
*/ |
| 7449 |
if (idx == -1) |
| 7450 |
idx = matchList.length(); |
| 7451 |
|
| 7452 |
/* if it's outside the limits of the match list, it's an error */ |
| 7453 |
if (idx > matchList.length()) |
| 7454 |
{ |
| 7455 |
/* note the problem */ |
| 7456 |
results.noteOrdinalOutOfRange(ordTok); |
| 7457 |
|
| 7458 |
/* no results */ |
| 7459 |
return []; |
| 7460 |
} |
| 7461 |
|
| 7462 |
/* return the selected item as a one-item list */ |
| 7463 |
return matchList.sublist(idx, 1); |
| 7464 |
} |
| 7465 |
; |
| 7466 |
|
| 7467 |
/* |
| 7468 |
* A disambig vocab production is the base class for disambiguation |
| 7469 |
* phrases that involve vocabulary words. |
| 7470 |
*/ |
| 7471 |
class DisambigVocabProd: DisambigProd |
| 7472 |
; |
| 7473 |
|
| 7474 |
/* |
| 7475 |
* A disambig list item consists of: |
| 7476 |
* |
| 7477 |
*. first/second/etc |
| 7478 |
*. the first/second/etc |
| 7479 |
*. first one/second one/etc |
| 7480 |
*. the first one/the second one/etc |
| 7481 |
*. <compound noun phrase> |
| 7482 |
*. possessive |
| 7483 |
*/ |
| 7484 |
|
| 7485 |
grammar disambigListItem(ordinal): |
| 7486 |
ordinalWord->ord_ |
| 7487 |
| ordinalWord->ord_ 'one' |
| 7488 |
| 'the' ordinalWord->ord_ |
| 7489 |
| 'the' ordinalWord->ord_ 'one' |
| 7490 |
: DisambigOrdProd |
| 7491 |
; |
| 7492 |
|
| 7493 |
grammar disambigListItem(noun): |
| 7494 |
completeNounPhraseWithoutAll->np_ |
| 7495 |
| terminalNounPhrase->np_ |
| 7496 |
: DisambigVocabProd |
| 7497 |
resolveNouns(resolver, results) |
| 7498 |
{ |
| 7499 |
/* get the matches for the underlying noun phrase */ |
| 7500 |
local lst = np_.resolveNouns(resolver, results); |
| 7501 |
|
| 7502 |
/* note the matches */ |
| 7503 |
results.noteMatches(lst); |
| 7504 |
|
| 7505 |
/* return the match list */ |
| 7506 |
return lst; |
| 7507 |
} |
| 7508 |
; |
| 7509 |
|
| 7510 |
grammar disambigListItem(plural): |
| 7511 |
pluralPhrase->np_ |
| 7512 |
: DisambigVocabProd |
| 7513 |
resolveNouns(resolver, results) |
| 7514 |
{ |
| 7515 |
local lst; |
| 7516 |
|
| 7517 |
/* |
| 7518 |
* get the underlying match list; since we explicitly have a |
| 7519 |
* plural, the result doesn't need to be unique, so simply |
| 7520 |
* return everything we find |
| 7521 |
*/ |
| 7522 |
lst = np_.resolveNouns(resolver, results); |
| 7523 |
|
| 7524 |
/* |
| 7525 |
* if we didn't get anything, it's an error; otherwise, take |
| 7526 |
* everything, since we explicitly wanted a plural usage |
| 7527 |
*/ |
| 7528 |
if (lst.length() == 0) |
| 7529 |
results.noMatch(resolver.getAction(), np_.getOrigText()); |
| 7530 |
else |
| 7531 |
results.noteMatches(lst); |
| 7532 |
|
| 7533 |
/* return the list */ |
| 7534 |
return lst; |
| 7535 |
} |
| 7536 |
; |
| 7537 |
|
| 7538 |
grammar disambigListItem(possessive): possessiveNounPhrase->poss_ |
| 7539 |
: DisambigPossessiveProd |
| 7540 |
; |
| 7541 |
|
| 7542 |
/* |
| 7543 |
* A disambig ordinal list consists of two or more ordinal words |
| 7544 |
* separated by noun phrase conjunctions. Note that there is a minimum |
| 7545 |
* of two entries in the list. |
| 7546 |
*/ |
| 7547 |
grammar disambigOrdinalList(tail): |
| 7548 |
ordinalWord->ord1_ ('and' | ',') ordinalWord->ord2_ : DisambigOrdProd |
| 7549 |
resolveNouns(resolver, results) |
| 7550 |
{ |
| 7551 |
/* note the pair of ordinal matches */ |
| 7552 |
results.noteDisambigOrdinal(); |
| 7553 |
results.noteDisambigOrdinal(); |
| 7554 |
|
| 7555 |
/* combine the selections of our two ordinals */ |
| 7556 |
return selectByOrdinal(ord1_, resolver, results) |
| 7557 |
+ selectByOrdinal(ord2_, resolver, results); |
| 7558 |
} |
| 7559 |
; |
| 7560 |
|
| 7561 |
grammar disambigOrdinalList(head): |
| 7562 |
ordinalWord->ord_ ('and' | ',') disambigOrdinalList->lst_ |
| 7563 |
: DisambigOrdProd |
| 7564 |
resolveNouns(resolver, results) |
| 7565 |
{ |
| 7566 |
/* note the ordinal match */ |
| 7567 |
results.noteDisambigOrdinal(); |
| 7568 |
|
| 7569 |
/* combine the selections of our ordinal and the sublist */ |
| 7570 |
return selectByOrdinal(ord_, resolver, results) |
| 7571 |
+ lst_.resolveNouns(resolver, results); |
| 7572 |
} |
| 7573 |
; |
| 7574 |
|
| 7575 |
|
| 7576 |
/* ------------------------------------------------------------------------ */ |
| 7577 |
/* |
| 7578 |
* Ordinal words. We define a limited set of these, since we only use |
| 7579 |
* them in a few special contexts where it would be unreasonable to need |
| 7580 |
* even as many as define here. |
| 7581 |
*/ |
| 7582 |
#define defOrdinal(str, val) object ordinalWord=#@str numval=val |
| 7583 |
|
| 7584 |
defOrdinal(former, 1); |
| 7585 |
defOrdinal(first, 1); |
| 7586 |
defOrdinal(second, 2); |
| 7587 |
defOrdinal(third, 3); |
| 7588 |
defOrdinal(fourth, 4); |
| 7589 |
defOrdinal(fifth, 5); |
| 7590 |
defOrdinal(sixth, 6); |
| 7591 |
defOrdinal(seventh, 7); |
| 7592 |
defOrdinal(eighth, 8); |
| 7593 |
defOrdinal(ninth, 9); |
| 7594 |
defOrdinal(tenth, 10); |
| 7595 |
defOrdinal(eleventh, 11); |
| 7596 |
defOrdinal(twelfth, 12); |
| 7597 |
defOrdinal(thirteenth, 13); |
| 7598 |
defOrdinal(fourteenth, 14); |
| 7599 |
defOrdinal(fifteenth, 15); |
| 7600 |
defOrdinal(sixteenth, 16); |
| 7601 |
defOrdinal(seventeenth, 17); |
| 7602 |
defOrdinal(eighteenth, 18); |
| 7603 |
defOrdinal(nineteenth, 19); |
| 7604 |
defOrdinal(twentieth, 20); |
| 7605 |
defOrdinal(1st, 1); |
| 7606 |
defOrdinal(2nd, 2); |
| 7607 |
defOrdinal(3rd, 3); |
| 7608 |
defOrdinal(4th, 4); |
| 7609 |
defOrdinal(5th, 5); |
| 7610 |
defOrdinal(6th, 6); |
| 7611 |
defOrdinal(7th, 7); |
| 7612 |
defOrdinal(8th, 8); |
| 7613 |
defOrdinal(9th, 9); |
| 7614 |
defOrdinal(10th, 10); |
| 7615 |
defOrdinal(11th, 11); |
| 7616 |
defOrdinal(12th, 12); |
| 7617 |
defOrdinal(13th, 13); |
| 7618 |
defOrdinal(14th, 14); |
| 7619 |
defOrdinal(15th, 15); |
| 7620 |
defOrdinal(16th, 16); |
| 7621 |
defOrdinal(17th, 17); |
| 7622 |
defOrdinal(18th, 18); |
| 7623 |
defOrdinal(19th, 19); |
| 7624 |
defOrdinal(20th, 20); |
| 7625 |
|
| 7626 |
/* |
| 7627 |
* the special 'last' ordinal - the value -1 is special to indicate the |
| 7628 |
* last item in a list |
| 7629 |
*/ |
| 7630 |
defOrdinal(last, -1); |
| 7631 |
defOrdinal(latter, -1); |
| 7632 |
|
| 7633 |
|
| 7634 |
/* ------------------------------------------------------------------------ */ |
| 7635 |
/* |
| 7636 |
* A numeric production. These can be either spelled-out numbers (such |
| 7637 |
* as "fifty-seven") or numbers entered in digit form (as in "57"). |
| 7638 |
*/ |
| 7639 |
class NumberProd: BasicProd |
| 7640 |
/* get the numeric (integer) value */ |
| 7641 |
getval() { return 0; } |
| 7642 |
|
| 7643 |
/* |
| 7644 |
* Get the string version of the numeric value. This should return |
| 7645 |
* a string, but the string should be in digit form. If the |
| 7646 |
* original entry was in digit form, then the original entry should |
| 7647 |
* be returned; otherwise, a string should be constructed from the |
| 7648 |
* integer value. By default, we'll do the latter. |
| 7649 |
*/ |
| 7650 |
getStrVal() { return toString(getval()); } |
| 7651 |
; |
| 7652 |
|
| 7653 |
/* |
| 7654 |
* A quantifier is simply a number, entered with numerals or spelled out. |
| 7655 |
*/ |
| 7656 |
grammar numberPhrase(digits): tokInt->num_ : NumberProd |
| 7657 |
/* get the numeric value */ |
| 7658 |
getval() { return toInteger(num_); } |
| 7659 |
|
| 7660 |
/* |
| 7661 |
* get the string version of the numeric value - since the token was |
| 7662 |
* an integer to start with, return the actual integer value |
| 7663 |
*/ |
| 7664 |
getStrVal() { return num_; } |
| 7665 |
; |
| 7666 |
|
| 7667 |
grammar numberPhrase(spelled): spelledNumber->num_ : NumberProd |
| 7668 |
/* get the numeric value */ |
| 7669 |
getval() { return num_.getval(); } |
| 7670 |
; |
| 7671 |
|
| 7672 |
/* |
| 7673 |
* A number phrase preceded by a pound sign. We distinguish this kind of |
| 7674 |
* number phrase from plain numbers, since this kind has a somewhat more |
| 7675 |
* limited set of valid contexts. |
| 7676 |
*/ |
| 7677 |
grammar poundNumberPhrase(main): tokPoundInt->num_ : NumberProd |
| 7678 |
/* |
| 7679 |
* get the numeric value - a tokPoundInt token has a pound sign |
| 7680 |
* followed by digits, so the numeric value is the value of the |
| 7681 |
* substring following the '#' sign |
| 7682 |
*/ |
| 7683 |
getval() { return toInteger(num_.substr(2)); } |
| 7684 |
|
| 7685 |
/* |
| 7686 |
* get the string value - we have a number token following the '#', |
| 7687 |
* so simply return the part after the '#' |
| 7688 |
*/ |
| 7689 |
getStrVal() { return num_.substr(2); } |
| 7690 |
; |
| 7691 |
|
| 7692 |
|
| 7693 |
/* |
| 7694 |
* Number literals. We'll define a set of special objects for numbers: |
| 7695 |
* each object defines a number and a value for the number. |
| 7696 |
*/ |
| 7697 |
#define defDigit(num, val) object digitWord=#@num numval=val |
| 7698 |
#define defTeen(num, val) object teenWord=#@num numval=val |
| 7699 |
#define defTens(num, val) object tensWord=#@num numval=val |
| 7700 |
|
| 7701 |
defDigit(one, 1); |
| 7702 |
defDigit(two, 2); |
| 7703 |
defDigit(three, 3); |
| 7704 |
defDigit(four, 4); |
| 7705 |
defDigit(five, 5); |
| 7706 |
defDigit(six, 6); |
| 7707 |
defDigit(seven, 7); |
| 7708 |
defDigit(eight, 8); |
| 7709 |
defDigit(nine, 9); |
| 7710 |
defTeen(ten, 10); |
| 7711 |
defTeen(eleven, 11); |
| 7712 |
defTeen(twelve, 12); |
| 7713 |
defTeen(thirteen, 13); |
| 7714 |
defTeen(fourteen, 14); |
| 7715 |
defTeen(fifteen, 15); |
| 7716 |
defTeen(sixteen, 16); |
| 7717 |
defTeen(seventeen, 17); |
| 7718 |
defTeen(eighteen, 18); |
| 7719 |
defTeen(nineteen, 19); |
| 7720 |
defTens(twenty, 20); |
| 7721 |
defTens(thirty, 30); |
| 7722 |
defTens(forty, 40); |
| 7723 |
defTens(fifty, 50); |
| 7724 |
defTens(sixty, 60); |
| 7725 |
defTens(seventy, 70); |
| 7726 |
defTens(eighty, 80); |
| 7727 |
defTens(ninety, 90); |
| 7728 |
|
| 7729 |
grammar spelledSmallNumber(digit): digitWord->num_ : NumberProd |
| 7730 |
getval() |
| 7731 |
{ |
| 7732 |
/* |
| 7733 |
* Look up the units word - there should be only one in the |
| 7734 |
* dictionary, since these are our special words. Return the |
| 7735 |
* object's numeric value property 'numval', which gives the |
| 7736 |
* number for the name. |
| 7737 |
*/ |
| 7738 |
return cmdDict.findWord(num_, &digitWord)[1].numval; |
| 7739 |
} |
| 7740 |
; |
| 7741 |
|
| 7742 |
grammar spelledSmallNumber(teen): teenWord->num_ : NumberProd |
| 7743 |
getval() |
| 7744 |
{ |
| 7745 |
/* look up the dictionary word for the number */ |
| 7746 |
return cmdDict.findWord(num_, &teenWord)[1].numval; |
| 7747 |
} |
| 7748 |
; |
| 7749 |
|
| 7750 |
grammar spelledSmallNumber(tens): tensWord->num_ : NumberProd |
| 7751 |
getval() |
| 7752 |
{ |
| 7753 |
/* look up the dictionary word for the number */ |
| 7754 |
return cmdDict.findWord(num_, &tensWord)[1].numval; |
| 7755 |
} |
| 7756 |
; |
| 7757 |
|
| 7758 |
grammar spelledSmallNumber(tensAndUnits): |
| 7759 |
tensWord->tens_ '-'->sep_ digitWord->units_ |
| 7760 |
| tensWord->tens_ digitWord->units_ |
| 7761 |
: NumberProd |
| 7762 |
getval() |
| 7763 |
{ |
| 7764 |
/* look up the words, and add up the values */ |
| 7765 |
return cmdDict.findWord(tens_, &tensWord)[1].numval |
| 7766 |
+ cmdDict.findWord(units_, &digitWord)[1].numval; |
| 7767 |
} |
| 7768 |
; |
| 7769 |
|
| 7770 |
grammar spelledSmallNumber(zero): 'zero' : NumberProd |
| 7771 |
getval() { return 0; } |
| 7772 |
; |
| 7773 |
|
| 7774 |
grammar spelledHundred(small): spelledSmallNumber->num_ : NumberProd |
| 7775 |
getval() { return num_.getval(); } |
| 7776 |
; |
| 7777 |
|
| 7778 |
grammar spelledHundred(hundreds): spelledSmallNumber->hun_ 'hundred' |
| 7779 |
: NumberProd |
| 7780 |
getval() { return hun_.getval() * 100; } |
| 7781 |
; |
| 7782 |
|
| 7783 |
grammar spelledHundred(hundredsPlus): |
| 7784 |
spelledSmallNumber->hun_ 'hundred' spelledSmallNumber->num_ |
| 7785 |
| spelledSmallNumber->hun_ 'hundred' 'and'->and_ spelledSmallNumber->num_ |
| 7786 |
: NumberProd |
| 7787 |
getval() { return hun_.getval() * 100 + num_.getval(); } |
| 7788 |
; |
| 7789 |
|
| 7790 |
grammar spelledHundred(aHundred): 'a' 'hundred' : NumberProd |
| 7791 |
getval() { return 100; } |
| 7792 |
; |
| 7793 |
|
| 7794 |
grammar spelledHundred(aHundredPlus): |
| 7795 |
'a' 'hundred' 'and' spelledSmallNumber->num_ |
| 7796 |
: NumberProd |
| 7797 |
getval() { return 100 + num_.getval(); } |
| 7798 |
; |
| 7799 |
|
| 7800 |
grammar spelledThousand(thousands): spelledHundred->thou_ 'thousand' |
| 7801 |
: NumberProd |
| 7802 |
getval() { return thou_.getval() * 1000; } |
| 7803 |
; |
| 7804 |
|
| 7805 |
grammar spelledThousand(thousandsPlus): |
| 7806 |
spelledHundred->thou_ 'thousand' spelledHundred->num_ |
| 7807 |
: NumberProd |
| 7808 |
getval() { return thou_.getval() * 1000 + num_.getval(); } |
| 7809 |
; |
| 7810 |
|
| 7811 |
grammar spelledThousand(thousandsAndSmall): |
| 7812 |
spelledHundred->thou_ 'thousand' 'and' spelledSmallNumber->num_ |
| 7813 |
: NumberProd |
| 7814 |
getval() { return thou_.getval() * 1000 + num_.getval(); } |
| 7815 |
; |
| 7816 |
|
| 7817 |
grammar spelledThousand(aThousand): 'a' 'thousand' : NumberProd |
| 7818 |
getval() { return 1000; } |
| 7819 |
; |
| 7820 |
|
| 7821 |
grammar spelledThousand(aThousandAndSmall): |
| 7822 |
'a' 'thousand' 'and' spelledSmallNumber->num_ |
| 7823 |
: NumberProd |
| 7824 |
getval() { return 1000 + num_.getval(); } |
| 7825 |
; |
| 7826 |
|
| 7827 |
grammar spelledMillion(millions): spelledHundred->mil_ 'million': NumberProd |
| 7828 |
getval() { return mil_.getval() * 1000000; } |
| 7829 |
; |
| 7830 |
|
| 7831 |
grammar spelledMillion(millionsPlus): |
| 7832 |
spelledHundred->mil_ 'million' |
| 7833 |
(spelledThousand->nxt_ | spelledHundred->nxt_) |
| 7834 |
: NumberProd |
| 7835 |
getval() { return mil_.getval() * 1000000 + nxt_.getval(); } |
| 7836 |
; |
| 7837 |
|
| 7838 |
grammar spelledMillion(aMillion): 'a' 'million' : NumberProd |
| 7839 |
getval() { return 1000000; } |
| 7840 |
; |
| 7841 |
|
| 7842 |
grammar spelledMillion(aMillionAndSmall): |
| 7843 |
'a' 'million' 'and' spelledSmallNumber->num_ |
| 7844 |
: NumberProd |
| 7845 |
getval() { return 1000000 + num_.getval(); } |
| 7846 |
; |
| 7847 |
|
| 7848 |
grammar spelledMillion(millionsAndSmall): |
| 7849 |
spelledHundred->mil_ 'million' 'and' spelledSmallNumber->num_ |
| 7850 |
: NumberProd |
| 7851 |
getval() { return mil_.getval() * 1000000 + num_.getval(); } |
| 7852 |
; |
| 7853 |
|
| 7854 |
grammar spelledNumber(main): |
| 7855 |
spelledHundred->num_ |
| 7856 |
| spelledThousand->num_ |
| 7857 |
| spelledMillion->num_ |
| 7858 |
: NumberProd |
| 7859 |
getval() { return num_.getval(); } |
| 7860 |
; |
| 7861 |
|
| 7862 |
|
| 7863 |
/* ------------------------------------------------------------------------ */ |
| 7864 |
/* |
| 7865 |
* "OOPS" command syntax |
| 7866 |
*/ |
| 7867 |
grammar oopsCommand(main): |
| 7868 |
oopsPhrase->oops_ | oopsPhrase->oops_ '.' : BasicProd |
| 7869 |
getNewTokens() { return oops_.getNewTokens(); } |
| 7870 |
; |
| 7871 |
|
| 7872 |
grammar oopsPhrase(main): |
| 7873 |
'oops' miscWordList->lst_ |
| 7874 |
| 'oops' ',' miscWordList->lst_ |
| 7875 |
| 'o' miscWordList->lst_ |
| 7876 |
| 'o' ',' miscWordList->lst_ |
| 7877 |
: BasicProd |
| 7878 |
getNewTokens() { return lst_.getOrigTokenList(); } |
| 7879 |
; |
| 7880 |
|
| 7881 |
grammar oopsPhrase(missing): |
| 7882 |
'oops' | 'o' |
| 7883 |
: BasicProd |
| 7884 |
getNewTokens() { return nil; } |
| 7885 |
; |
| 7886 |
|
| 7887 |
/* ------------------------------------------------------------------------ */ |
| 7888 |
/* |
| 7889 |
* finishGame options. We provide descriptions and keywords for the |
| 7890 |
* option objects here, because these are inherently language-specific. |
| 7891 |
* |
| 7892 |
* Note that we provide hyperlinks for our descriptions when possible. |
| 7893 |
* When we're in plain text mode, we can't show links, so we'll instead |
| 7894 |
* show an alternate form with the single-letter response highlighted in |
| 7895 |
* the text. We don't highlight the single-letter response in the |
| 7896 |
* hyperlinked version because (a) if the user wants a shortcut, they can |
| 7897 |
* simply click the hyperlink, and (b) most UI's that show hyperlinks |
| 7898 |
* show a distinctive appearance for the hyperlink itself, so adding even |
| 7899 |
* more highlighting within the hyperlink starts to look awfully busy. |
| 7900 |
*/ |
| 7901 |
modify finishOptionQuit |
| 7902 |
desc = "<<aHrefAlt('quit', 'QUIT', '<b>Q</b>UIT', 'Leave the story')>>" |
| 7903 |
responseKeyword = 'quit' |
| 7904 |
responseChar = 'q' |
| 7905 |
; |
| 7906 |
|
| 7907 |
modify finishOptionRestore |
| 7908 |
desc = "<<aHrefAlt('restore', 'RESTORE', '<b>R</b>ESTORE', |
| 7909 |
'Restore a saved position')>> a saved position" |
| 7910 |
responseKeyword = 'restore' |
| 7911 |
responseChar = 'r' |
| 7912 |
; |
| 7913 |
|
| 7914 |
modify finishOptionRestart |
| 7915 |
desc = "<<aHrefAlt('restart', 'RESTART', 'RE<b>S</b>TART', |
| 7916 |
'Start the story over from the beginning')>> the story" |
| 7917 |
responseKeyword = 'restart' |
| 7918 |
responseChar = 's' |
| 7919 |
; |
| 7920 |
|
| 7921 |
modify finishOptionUndo |
| 7922 |
desc = "<<aHrefAlt('undo', 'UNDO', '<b>U</b>NDO', |
| 7923 |
'Undo the last move')>> the last move" |
| 7924 |
responseKeyword = 'undo' |
| 7925 |
responseChar = 'u' |
| 7926 |
; |
| 7927 |
|
| 7928 |
modify finishOptionCredits |
| 7929 |
desc = "see the <<aHrefAlt('credits', 'CREDITS', '<b>C</b>REDITS', |
| 7930 |
'Show credits')>>" |
| 7931 |
responseKeyword = 'credits' |
| 7932 |
responseChar = 'c' |
| 7933 |
; |
| 7934 |
|
| 7935 |
modify finishOptionFullScore |
| 7936 |
desc = "see your <<aHrefAlt('full score', 'FULL SCORE', |
| 7937 |
'<b>F</b>ULL SCORE', 'Show full score')>>" |
| 7938 |
responseKeyword = 'full score' |
| 7939 |
responseChar = 'f' |
| 7940 |
; |
| 7941 |
|
| 7942 |
modify finishOptionAmusing |
| 7943 |
desc = "see some <<aHrefAlt('amusing', 'AMUSING', '<b>A</b>MUSING', |
| 7944 |
'Show some amusing things to try')>> things to try" |
| 7945 |
responseKeyword = 'amusing' |
| 7946 |
responseChar = 'a' |
| 7947 |
; |
| 7948 |
|
| 7949 |
modify restoreOptionStartOver |
| 7950 |
desc = "<<aHrefAlt('start', 'START', '<b>S</b>TART', |
| 7951 |
'Start from the beginning')>> the game from the beginning" |
| 7952 |
responseKeyword = 'start' |
| 7953 |
responseChar = 's' |
| 7954 |
; |
| 7955 |
|
| 7956 |
modify restoreOptionRestoreAnother |
| 7957 |
desc = "<<aHrefAlt('restore', 'RESTORE', '<b>R</b>ESTORE', |
| 7958 |
'Restore a saved position')>> a different saved position" |
| 7959 |
; |
| 7960 |
|
| 7961 |
/* ------------------------------------------------------------------------ */ |
| 7962 |
/* |
| 7963 |
* Context for Action.getVerbPhrase(). This keeps track of pronoun |
| 7964 |
* antecedents in cases where we're stringing together a series of verb |
| 7965 |
* phrases. |
| 7966 |
*/ |
| 7967 |
class GetVerbPhraseContext: object |
| 7968 |
/* get the objective form of an object, using a pronoun as appropriate */ |
| 7969 |
objNameObj(obj) |
| 7970 |
{ |
| 7971 |
/* |
| 7972 |
* if it's the pronoun antecedent, use the pronoun form; |
| 7973 |
* otherwise, use the full name |
| 7974 |
*/ |
| 7975 |
if (obj == pronounObj) |
| 7976 |
return obj.itObj; |
| 7977 |
else |
| 7978 |
return obj.theNameObj; |
| 7979 |
} |
| 7980 |
|
| 7981 |
/* are we showing the given object pronomially? */ |
| 7982 |
isObjPronoun(obj) { return (obj == pronounObj); } |
| 7983 |
|
| 7984 |
/* set the pronoun antecedent */ |
| 7985 |
setPronounObj(obj) { pronounObj = obj; } |
| 7986 |
|
| 7987 |
/* the pronoun antecedent */ |
| 7988 |
pronounObj = nil |
| 7989 |
; |
| 7990 |
|
| 7991 |
/* |
| 7992 |
* Default getVerbPhrase context. This can be used when no other context |
| 7993 |
* is needed. This context instance has no state - it doesn't track any |
| 7994 |
* antecedents. |
| 7995 |
*/ |
| 7996 |
defaultGetVerbPhraseContext: GetVerbPhraseContext |
| 7997 |
/* we don't remember any antecedents */ |
| 7998 |
setPronounObj(obj) { } |
| 7999 |
; |
| 8000 |
|
| 8001 |
/* ------------------------------------------------------------------------ */ |
| 8002 |
/* |
| 8003 |
* Implicit action context. This is passed to the message methods that |
| 8004 |
* generate implicit action announcements, to indicate the context in |
| 8005 |
* which the message is to be used. |
| 8006 |
*/ |
| 8007 |
class ImplicitAnnouncementContext: object |
| 8008 |
/* |
| 8009 |
* Should we use the infinitive form of the verb, or the participle |
| 8010 |
* form for generating the announcement? By default, use use the |
| 8011 |
* participle form: "(first OPENING THE BOX)". |
| 8012 |
*/ |
| 8013 |
useInfPhrase = nil |
| 8014 |
|
| 8015 |
/* is this message going in a list? */ |
| 8016 |
isInList = nil |
| 8017 |
|
| 8018 |
/* |
| 8019 |
* Are we in a sublist of 'just trying' or 'just asking' messages? |
| 8020 |
* (We can only have sublist groupings one level deep, so we don't |
| 8021 |
* need to worry about what kind of sublist we're in.) |
| 8022 |
*/ |
| 8023 |
isInSublist = nil |
| 8024 |
|
| 8025 |
/* our getVerbPhrase context - by default, don't use one */ |
| 8026 |
getVerbCtx = nil |
| 8027 |
|
| 8028 |
/* generate the announcement message given the action description */ |
| 8029 |
buildImplicitAnnouncement(txt) |
| 8030 |
{ |
| 8031 |
/* if we're not in a list, make it a full, stand-alone message */ |
| 8032 |
if (!isInList) |
| 8033 |
txt = '<./p0>\n<.assume>first ' + txt + '<./assume>\n'; |
| 8034 |
|
| 8035 |
/* return the result */ |
| 8036 |
return txt; |
| 8037 |
} |
| 8038 |
; |
| 8039 |
|
| 8040 |
/* the standard implicit action announcement context */ |
| 8041 |
standardImpCtx: ImplicitAnnouncementContext; |
| 8042 |
|
| 8043 |
/* the "just trying" implicit action announcement context */ |
| 8044 |
tryingImpCtx: ImplicitAnnouncementContext |
| 8045 |
/* |
| 8046 |
* The action was merely attempted, so use the infinitive phrase in |
| 8047 |
* the announcement: "(first trying to OPEN THE BOX)". |
| 8048 |
*/ |
| 8049 |
useInfPhrase = true |
| 8050 |
|
| 8051 |
/* build the announcement */ |
| 8052 |
buildImplicitAnnouncement(txt) |
| 8053 |
{ |
| 8054 |
/* |
| 8055 |
* If we're not in a list of 'trying' messages, add the 'trying' |
| 8056 |
* prefix message to the action description. This isn't |
| 8057 |
* necessary if we're in a 'trying' list, since the list itself |
| 8058 |
* will have the 'trying' part. |
| 8059 |
*/ |
| 8060 |
if (!isInSublist) |
| 8061 |
txt = 'trying to ' + txt; |
| 8062 |
|
| 8063 |
/* now build the message into the full text as usual */ |
| 8064 |
return inherited(txt); |
| 8065 |
} |
| 8066 |
; |
| 8067 |
|
| 8068 |
/* |
| 8069 |
* The "asking question" implicit action announcement context. By |
| 8070 |
* default, we generate the message exactly the same way we do for the |
| 8071 |
* 'trying' case. |
| 8072 |
*/ |
| 8073 |
askingImpCtx: tryingImpCtx; |
| 8074 |
|
| 8075 |
/* |
| 8076 |
* A class for messages appearing in a list. Within a list, we want to |
| 8077 |
* keep track of the last direct object, so that we can refer to it with |
| 8078 |
* a pronoun later in the list. |
| 8079 |
*/ |
| 8080 |
class ListImpCtx: ImplicitAnnouncementContext, GetVerbPhraseContext |
| 8081 |
/* |
| 8082 |
* Set the appropriate base context for the given implicit action |
| 8083 |
* announcement report (an ImplicitActionAnnouncement object). |
| 8084 |
*/ |
| 8085 |
setBaseCtx(ctx) |
| 8086 |
{ |
| 8087 |
/* |
| 8088 |
* if this is a failed attempt, use a 'trying' context; |
| 8089 |
* otherwise, use a standard context |
| 8090 |
*/ |
| 8091 |
if (ctx.justTrying) |
| 8092 |
baseCtx = tryingImpCtx; |
| 8093 |
else if (ctx.justAsking) |
| 8094 |
baseCtx = askingImpCtx; |
| 8095 |
else |
| 8096 |
baseCtx = standardImpCtx; |
| 8097 |
} |
| 8098 |
|
| 8099 |
/* we're in a list */ |
| 8100 |
isInList = true |
| 8101 |
|
| 8102 |
/* we are our own getVerbPhrase context */ |
| 8103 |
getVerbCtx = (self) |
| 8104 |
|
| 8105 |
/* delegate the phrase format to our underlying announcement context */ |
| 8106 |
useInfPhrase = (delegated baseCtx) |
| 8107 |
|
| 8108 |
/* build the announcement using our underlying context */ |
| 8109 |
buildImplicitAnnouncement(txt) { return delegated baseCtx(txt); } |
| 8110 |
|
| 8111 |
/* our base context - we delegate some unoverridden behavior to this */ |
| 8112 |
baseCtx = nil |
| 8113 |
; |
| 8114 |
|
| 8115 |
/* ------------------------------------------------------------------------ */ |
| 8116 |
/* |
| 8117 |
* Language-specific Action modifications. |
| 8118 |
*/ |
| 8119 |
modify Action |
| 8120 |
/* |
| 8121 |
* In the English grammar, all 'predicate' grammar definitions |
| 8122 |
* (which are usually made via the VerbRule macro) are associated |
| 8123 |
* with Action match tree objects; in fact, each 'predicate' grammar |
| 8124 |
* match tree is the specific Action subclass associated with the |
| 8125 |
* grammar for the predicate. This means that the Action associated |
| 8126 |
* with a grammar match is simply the grammar match object itself. |
| 8127 |
* Hence, we can resolve the action for a 'predicate' match simply |
| 8128 |
* by returning the match itself: it is the Action as well as the |
| 8129 |
* grammar match. |
| 8130 |
* |
| 8131 |
* This approach ('grammar predicate' matches are based on Action |
| 8132 |
* subclasses) works well for languages like English that encode the |
| 8133 |
* role of each phrase in the word order of the sentence. |
| 8134 |
* |
| 8135 |
* Languages that encode phrase roles using case markers or other |
| 8136 |
* devices tend to be freer with word order. As a result, |
| 8137 |
* 'predicate' grammars for such languages should generally not |
| 8138 |
* attempt to capture all possible word orderings for a given |
| 8139 |
* action, but should instead take the complementary approach of |
| 8140 |
* capturing the possible overall sentence structures independently |
| 8141 |
* of verb phrases, and plug in a verb phrase as a component, just |
| 8142 |
* like noun phrases plug into the English grammar. In these cases, |
| 8143 |
* the match objects will NOT be Action subclasses; the Action |
| 8144 |
* objects will instead be buried down deeper in the match tree. |
| 8145 |
* Hence, resolveAction() must be defined on whatever class is used |
| 8146 |
* to construct 'predicate' grammar matches, instead of on Action, |
| 8147 |
* since Action will not be a 'predicate' match. |
| 8148 |
*/ |
| 8149 |
resolveAction(issuingActor, targetActor) { return self; } |
| 8150 |
|
| 8151 |
/* |
| 8152 |
* Return the interrogative pronoun for a missing object in one of |
| 8153 |
* our object roles. In most cases, this is simply "what", but for |
| 8154 |
* some actions, "whom" is more appropriate (for example, the direct |
| 8155 |
* object of "ask" is implicitly a person, so "whom" is most |
| 8156 |
* appropriate for this role). |
| 8157 |
*/ |
| 8158 |
whatObj(which) |
| 8159 |
{ |
| 8160 |
/* intransitive verbs have no objects, so there's nothing to show */ |
| 8161 |
} |
| 8162 |
|
| 8163 |
/* |
| 8164 |
* Translate an interrogative word for whatObj. If the word is |
| 8165 |
* 'whom', translate to the library message for 'whom'; this allows |
| 8166 |
* authors to use 'who' rather than 'whom' as the objective form of |
| 8167 |
* 'who', which sounds less stuffy to many people. |
| 8168 |
*/ |
| 8169 |
whatTranslate(txt) |
| 8170 |
{ |
| 8171 |
/* |
| 8172 |
* if it's 'whom', translate to the library message for 'whom'; |
| 8173 |
* otherwise, just show the word as is |
| 8174 |
*/ |
| 8175 |
return (txt == 'whom' ? gLibMessages.whomPronoun : txt); |
| 8176 |
} |
| 8177 |
|
| 8178 |
/* |
| 8179 |
* Return a string with the appropriate pronoun (objective form) for |
| 8180 |
* a list of object matches, with the given resolved cardinality. |
| 8181 |
* This list is a list of ResolveInfo objects. |
| 8182 |
*/ |
| 8183 |
objListPronoun(objList) |
| 8184 |
{ |
| 8185 |
local himCnt, herCnt, themCnt; |
| 8186 |
local FirstPersonCnt, SecondPersonCnt; |
| 8187 |
local resolvedNumber; |
| 8188 |
|
| 8189 |
/* if there's no object list at all, just use 'it' */ |
| 8190 |
if (objList == nil || objList == []) |
| 8191 |
return 'it'; |
| 8192 |
|
| 8193 |
/* note the number of objects in the resolved list */ |
| 8194 |
resolvedNumber = objList.length(); |
| 8195 |
|
| 8196 |
/* |
| 8197 |
* In the tentatively resolved object list, we might have hidden |
| 8198 |
* away ambiguous matches. Expand those back into the list so |
| 8199 |
* we have the full list of in-scope matches. |
| 8200 |
*/ |
| 8201 |
foreach (local cur in objList) |
| 8202 |
{ |
| 8203 |
/* |
| 8204 |
* if this one has hidden ambiguous objects, add the hidden |
| 8205 |
* objects back into our list |
| 8206 |
*/ |
| 8207 |
if (cur.extraObjects != nil) |
| 8208 |
objList += cur.extraObjects; |
| 8209 |
} |
| 8210 |
|
| 8211 |
/* |
| 8212 |
* if the desired cardinality is plural and the object list has |
| 8213 |
* more than one object, simply say 'them' |
| 8214 |
*/ |
| 8215 |
if (objList.length() > 1 && resolvedNumber > 1) |
| 8216 |
return 'them'; |
| 8217 |
|
| 8218 |
/* |
| 8219 |
* singular cardinality - count masculine and feminine objects, |
| 8220 |
* and count the referral persons |
| 8221 |
*/ |
| 8222 |
himCnt = herCnt = themCnt = 0; |
| 8223 |
FirstPersonCnt = SecondPersonCnt = 0; |
| 8224 |
foreach (local cur in objList) |
| 8225 |
{ |
| 8226 |
/* if it's masculine, count it */ |
| 8227 |
if (cur.obj_.isHim) |
| 8228 |
++himCnt; |
| 8229 |
|
| 8230 |
/* if it's feminine, count it */ |
| 8231 |
if (cur.obj_.isHer) |
| 8232 |
++herCnt; |
| 8233 |
|
| 8234 |
/* if it has plural usage, count it */ |
| 8235 |
if (cur.obj_.isPlural) |
| 8236 |
++themCnt; |
| 8237 |
|
| 8238 |
/* if it's first person usage, count it */ |
| 8239 |
if (cur.obj_.referralPerson == FirstPerson) |
| 8240 |
++FirstPersonCnt; |
| 8241 |
|
| 8242 |
/* if it's second person usage, count it */ |
| 8243 |
if (cur.obj_.referralPerson == SecondPerson) |
| 8244 |
++SecondPersonCnt; |
| 8245 |
} |
| 8246 |
|
| 8247 |
/* |
| 8248 |
* if they all have plural usage, show "them"; if they're all of |
| 8249 |
* one gender, show "him" or "her" as appropriate; if they're |
| 8250 |
* all neuter, show "it"; otherwise, show "them" |
| 8251 |
*/ |
| 8252 |
if (themCnt == objList.length()) |
| 8253 |
return 'them'; |
| 8254 |
else if (FirstPersonCnt == objList.length()) |
| 8255 |
return 'myself'; |
| 8256 |
else if (SecondPersonCnt == objList.length()) |
| 8257 |
return 'yourself'; |
| 8258 |
else if (himCnt == objList.length() && herCnt == 0) |
| 8259 |
return 'him'; |
| 8260 |
else if (herCnt == objList.length() && himCnt == 0) |
| 8261 |
return 'her'; |
| 8262 |
else if (herCnt == 0 && himCnt == 0) |
| 8263 |
return 'it'; |
| 8264 |
else |
| 8265 |
return 'them'; |
| 8266 |
} |
| 8267 |
|
| 8268 |
/* |
| 8269 |
* Announce a default object used with this action. |
| 8270 |
* |
| 8271 |
* 'resolvedAllObjects' indicates where we are in the command |
| 8272 |
* processing: this is true if we've already resolved all of the |
| 8273 |
* other objects in the command, nil if not. We use this |
| 8274 |
* information to get the phrasing right according to the situation. |
| 8275 |
*/ |
| 8276 |
announceDefaultObject(obj, whichObj, resolvedAllObjects) |
| 8277 |
{ |
| 8278 |
/* |
| 8279 |
* the basic action class takes no objects, so there can be no |
| 8280 |
* default announcement |
| 8281 |
*/ |
| 8282 |
return ''; |
| 8283 |
} |
| 8284 |
|
| 8285 |
/* |
| 8286 |
* Announce all defaulted objects in the action. By default, we |
| 8287 |
* show nothing. |
| 8288 |
*/ |
| 8289 |
announceAllDefaultObjects(allResolved) { } |
| 8290 |
|
| 8291 |
/* |
| 8292 |
* Return a phrase describing the action performed implicitly, as a |
| 8293 |
* participle phrase. 'ctx' is an ImplicitAnnouncementContext object |
| 8294 |
* describing the context in which we're generating the phrase. |
| 8295 |
* |
| 8296 |
* This comes in two forms: if the context indicates we're only |
| 8297 |
* attempting the action, we'll return an infinitive phrase ("open |
| 8298 |
* the box") for use in a larger participle phrase describing the |
| 8299 |
* attempt ("trying to..."). Otherwise, we'll be describing the |
| 8300 |
* action as actually having been performed, so we'll return a |
| 8301 |
* present participle phrase ("opening the box"). |
| 8302 |
*/ |
| 8303 |
getImplicitPhrase(ctx) |
| 8304 |
{ |
| 8305 |
/* |
| 8306 |
* Get the phrase. Use the infinitive or participle form, as |
| 8307 |
* indicated in the context. |
| 8308 |
*/ |
| 8309 |
return getVerbPhrase(ctx.useInfPhrase, ctx.getVerbCtx); |
| 8310 |
} |
| 8311 |
|
| 8312 |
/* |
| 8313 |
* Get the infinitive form of the action. We are NOT to include the |
| 8314 |
* infinitive complementizer (i.e., "to") as part of the result, |
| 8315 |
* since the complementizer isn't used in all contexts in which we |
| 8316 |
* might want to use the infinitive; for example, we don't want a |
| 8317 |
* "to" in phrases involving an auxiliary verb, such as "he can open |
| 8318 |
* the box." |
| 8319 |
*/ |
| 8320 |
getInfPhrase() |
| 8321 |
{ |
| 8322 |
/* return the verb phrase in infinitive form */ |
| 8323 |
return getVerbPhrase(true, nil); |
| 8324 |
} |
| 8325 |
|
| 8326 |
/* |
| 8327 |
* Get the root infinitive form of our verb phrase as part of a |
| 8328 |
* question in which one of the verb's objects is the "unknown" of |
| 8329 |
* the interrogative. 'which' is one of the role markers |
| 8330 |
* (DirectObject, IndirectObject, etc), indicating which object is |
| 8331 |
* the subject of the interrogative. |
| 8332 |
* |
| 8333 |
* For example, for the verb UNLOCK <dobj> WITH <iobj>, if the |
| 8334 |
* unknown is the direct object, the phrase we'd return would be |
| 8335 |
* "unlock": this would plug into contexts such as "what do you want |
| 8336 |
* to unlock." If the indirect object is the unknown for the same |
| 8337 |
* verb, the phrase would be "unlock it with", which would plug in as |
| 8338 |
* "what do you want to unlock it with". |
| 8339 |
* |
| 8340 |
* Note that we are NOT to include the infinitive complementizer |
| 8341 |
* (i.e., "to") as part of the phrase we generate, since the |
| 8342 |
* complementizer isn't used in some contexts where the infinitive |
| 8343 |
* conjugation is needed (for example, "what should I <infinitive>"). |
| 8344 |
*/ |
| 8345 |
getQuestionInf(which) |
| 8346 |
{ |
| 8347 |
/* |
| 8348 |
* for a verb without objects, this is the same as the basic |
| 8349 |
* infinitive |
| 8350 |
*/ |
| 8351 |
return getInfPhrase(); |
| 8352 |
} |
| 8353 |
|
| 8354 |
/* |
| 8355 |
* Get a string describing the full action in present participle |
| 8356 |
* form, using the current command objects: "taking the watch", |
| 8357 |
* "putting the book on the shelf" |
| 8358 |
*/ |
| 8359 |
getParticiplePhrase() |
| 8360 |
{ |
| 8361 |
/* return the verb phrase in participle form */ |
| 8362 |
return getVerbPhrase(nil, nil); |
| 8363 |
} |
| 8364 |
|
| 8365 |
/* |
| 8366 |
* Get the full verb phrase in either infinitive or participle |
| 8367 |
* format. This is a common handler for getInfinitivePhrase() and |
| 8368 |
* getParticiplePhrase(). |
| 8369 |
* |
| 8370 |
* 'ctx' is a GetVerbPhraseContext object, which lets us keep track |
| 8371 |
* of antecedents when we're stringing together multiple verb |
| 8372 |
* phrases. 'ctx' can be nil if the verb phrase is being used in |
| 8373 |
* isolation. |
| 8374 |
*/ |
| 8375 |
getVerbPhrase(inf, ctx) |
| 8376 |
{ |
| 8377 |
/* |
| 8378 |
* parse the verbPhrase into the parts before and after the |
| 8379 |
* slash, and any additional text following the slash part |
| 8380 |
*/ |
| 8381 |
rexMatch('(.*)/(<alphanum|-|squote>+)(.*)', verbPhrase); |
| 8382 |
|
| 8383 |
/* return the appropriate parts */ |
| 8384 |
if (inf) |
| 8385 |
{ |
| 8386 |
/* |
| 8387 |
* infinitive - we want the part before the slash, plus the |
| 8388 |
* extra prepositions (or whatever) after the switched part |
| 8389 |
*/ |
| 8390 |
return rexGroup(1)[3] + rexGroup(3)[3]; |
| 8391 |
} |
| 8392 |
else |
| 8393 |
{ |
| 8394 |
/* participle - it's the part after the slash */ |
| 8395 |
return rexGroup(2)[3] + rexGroup(3)[3]; |
| 8396 |
} |
| 8397 |
} |
| 8398 |
|
| 8399 |
/* |
| 8400 |
* Show the "noMatch" library message. For most verbs, we use the |
| 8401 |
* basic "you can't see that here". Verbs that are mostly used with |
| 8402 |
* intangible objects, such as LISTEN TO and SMELL, might want to |
| 8403 |
* override this to use a less visually-oriented message. |
| 8404 |
*/ |
| 8405 |
noMatch(msgObj, actor, txt) { msgObj.noMatchCannotSee(actor, txt); } |
| 8406 |
|
| 8407 |
/* |
| 8408 |
* Verb flags - these are used to control certain aspects of verb |
| 8409 |
* formatting. By default, we have no special flags. |
| 8410 |
*/ |
| 8411 |
verbFlags = 0 |
| 8412 |
|
| 8413 |
/* add a space prefix/suffix to a string if the string is non-empty */ |
| 8414 |
spPrefix(str) { return (str == '' ? str : ' ' + str); } |
| 8415 |
spSuffix(str) { return (str == '' ? str : str + ' '); } |
| 8416 |
; |
| 8417 |
|
| 8418 |
/* |
| 8419 |
* English-specific additions for single-object verbs. |
| 8420 |
*/ |
| 8421 |
modify TAction |
| 8422 |
/* return an interrogative word for an object of the action */ |
| 8423 |
whatObj(which) |
| 8424 |
{ |
| 8425 |
/* |
| 8426 |
* Show the interrogative for our direct object - this is the |
| 8427 |
* last word enclosed in parentheses in our verbPhrase string. |
| 8428 |
*/ |
| 8429 |
rexSearch('<lparen>.*?(<alpha>+)<rparen>', verbPhrase); |
| 8430 |
return whatTranslate(rexGroup(1)[3]); |
| 8431 |
} |
| 8432 |
|
| 8433 |
/* announce a default object used with this action */ |
| 8434 |
announceDefaultObject(obj, whichObj, resolvedAllObjects) |
| 8435 |
{ |
| 8436 |
/* |
| 8437 |
* get any direct object preposition - this is the part inside |
| 8438 |
* the "(what)" specifier parens, excluding the last word |
| 8439 |
*/ |
| 8440 |
rexSearch('<lparen>(.*<space>+)?<alpha>+<rparen>', verbPhrase); |
| 8441 |
local prep = (rexGroup(1) == nil ? '' : rexGroup(1)[3]); |
| 8442 |
|
| 8443 |
/* do any verb-specific adjustment of the preposition */ |
| 8444 |
if (prep != nil) |
| 8445 |
prep = adjustDefaultObjectPrep(prep, obj); |
| 8446 |
|
| 8447 |
/* |
| 8448 |
* get the object name - we need to distinguish from everything |
| 8449 |
* else in scope, since we considered everything in scope when |
| 8450 |
* making our pick |
| 8451 |
*/ |
| 8452 |
local nm = obj.getAnnouncementDistinguisher( |
| 8453 |
gActor.scopeList()).theName(obj); |
| 8454 |
|
| 8455 |
/* show the preposition (if any) and the object */ |
| 8456 |
return (prep == '' ? nm : prep + nm); |
| 8457 |
} |
| 8458 |
|
| 8459 |
/* |
| 8460 |
* Adjust the preposition. In some cases, the verb will want to vary |
| 8461 |
* the preposition according to the object. This method can return a |
| 8462 |
* custom preposition in place of the one in the verbPhrase. By |
| 8463 |
* default, we just use the fixed preposition from the verbPhrase, |
| 8464 |
* which is passed in to us in 'prep'. |
| 8465 |
*/ |
| 8466 |
adjustDefaultObjectPrep(prep, obj) { return prep; } |
| 8467 |
|
| 8468 |
/* announce all defaulted objects */ |
| 8469 |
announceAllDefaultObjects(allResolved) |
| 8470 |
{ |
| 8471 |
/* announce a defaulted direct object if appropriate */ |
| 8472 |
maybeAnnounceDefaultObject(dobjList_, DirectObject, allResolved); |
| 8473 |
} |
| 8474 |
|
| 8475 |
/* show the verb's basic infinitive form for an interrogative */ |
| 8476 |
getQuestionInf(which) |
| 8477 |
{ |
| 8478 |
/* |
| 8479 |
* Show the present-tense verb form (removing the participle |
| 8480 |
* part - the "/xxxing" part). Include any prepositions |
| 8481 |
* attached to the verb itself or to the direct object (inside |
| 8482 |
* the "(what)" parens). |
| 8483 |
*/ |
| 8484 |
rexSearch('(.*)/<alphanum|-|squote>+(.*?)<space>+' |
| 8485 |
+ '<lparen>(.*?)<space>*?<alpha>+<rparen>', |
| 8486 |
verbPhrase); |
| 8487 |
return rexGroup(1)[3] + spPrefix(rexGroup(2)[3]) |
| 8488 |
+ spPrefix(rexGroup(3)[3]); |
| 8489 |
} |
| 8490 |
|
| 8491 |
/* get the verb phrase in infinitive or participle form */ |
| 8492 |
getVerbPhrase(inf, ctx) |
| 8493 |
{ |
| 8494 |
local dobj; |
| 8495 |
local dobjText; |
| 8496 |
local dobjIsPronoun; |
| 8497 |
local ret; |
| 8498 |
|
| 8499 |
/* use the default pronoun context if one wasn't supplied */ |
| 8500 |
if (ctx == nil) |
| 8501 |
ctx = defaultGetVerbPhraseContext; |
| 8502 |
|
| 8503 |
/* get the direct object */ |
| 8504 |
dobj = getDobj(); |
| 8505 |
|
| 8506 |
/* note if it's a pronoun */ |
| 8507 |
dobjIsPronoun = ctx.isObjPronoun(dobj); |
| 8508 |
|
| 8509 |
/* get the direct object name */ |
| 8510 |
dobjText = ctx.objNameObj(dobj); |
| 8511 |
|
| 8512 |
/* get the phrasing */ |
| 8513 |
ret = getVerbPhrase1(inf, verbPhrase, dobjText, dobjIsPronoun); |
| 8514 |
|
| 8515 |
/* set the pronoun antecedent to my direct object */ |
| 8516 |
ctx.setPronounObj(dobj); |
| 8517 |
|
| 8518 |
/* return the result */ |
| 8519 |
return ret; |
| 8520 |
} |
| 8521 |
|
| 8522 |
/* |
| 8523 |
* Given the text of the direct object phrase, build the verb phrase |
| 8524 |
* for a one-object verb. This is a class method that can be used by |
| 8525 |
* other kinds of verbs (i.e., non-TActions) that use phrasing like a |
| 8526 |
* single object. |
| 8527 |
* |
| 8528 |
* 'inf' is a flag indicating whether to use the infinitive form |
| 8529 |
* (true) or the present participle form (nil); 'vp' is the |
| 8530 |
* verbPhrase string; 'dobjText' is the direct object phrase's text; |
| 8531 |
* and 'dobjIsPronoun' is true if the dobj text is rendered as a |
| 8532 |
* pronoun. |
| 8533 |
*/ |
| 8534 |
getVerbPhrase1(inf, vp, dobjText, dobjIsPronoun) |
| 8535 |
{ |
| 8536 |
local ret; |
| 8537 |
local dprep; |
| 8538 |
local vcomp; |
| 8539 |
|
| 8540 |
/* |
| 8541 |
* parse the verbPhrase: pick out the 'infinitive/participle' |
| 8542 |
* part, the complementizer part up to the '(what)' direct |
| 8543 |
* object placeholder, and any preposition within the '(what)' |
| 8544 |
* specifier |
| 8545 |
*/ |
| 8546 |
rexMatch('(.*)/(<alphanum|-|squote>+)(.*) ' |
| 8547 |
+ '<lparen>(.*?)<space>*?<alpha>+<rparen>(.*)', |
| 8548 |
vp); |
| 8549 |
|
| 8550 |
/* start off with the infinitive or participle, as desired */ |
| 8551 |
if (inf) |
| 8552 |
ret = rexGroup(1)[3]; |
| 8553 |
else |
| 8554 |
ret = rexGroup(2)[3]; |
| 8555 |
|
| 8556 |
/* get the prepositional complementizer */ |
| 8557 |
vcomp = rexGroup(3)[3]; |
| 8558 |
|
| 8559 |
/* get the direct object preposition */ |
| 8560 |
dprep = rexGroup(4)[3]; |
| 8561 |
|
| 8562 |
/* do any verb-specific adjustment of the preposition */ |
| 8563 |
if (dprep != nil) |
| 8564 |
dprep = adjustDefaultObjectPrep(dprep, getDobj()); |
| 8565 |
|
| 8566 |
/* |
| 8567 |
* if the direct object is not a pronoun, put the complementizer |
| 8568 |
* BEFORE the direct object (the 'up' in "PICKING UP THE BOX") |
| 8569 |
*/ |
| 8570 |
if (!dobjIsPronoun) |
| 8571 |
ret += spPrefix(vcomp); |
| 8572 |
|
| 8573 |
/* add the direct object preposition */ |
| 8574 |
ret += spPrefix(dprep); |
| 8575 |
|
| 8576 |
/* add the direct object, using the pronoun form if applicable */ |
| 8577 |
ret += ' ' + dobjText; |
| 8578 |
|
| 8579 |
/* |
| 8580 |
* if the direct object is a pronoun, put the complementizer |
| 8581 |
* AFTER the direct object (the 'up' in "PICKING IT UP") |
| 8582 |
*/ |
| 8583 |
if (dobjIsPronoun) |
| 8584 |
ret += spPrefix(vcomp); |
| 8585 |
|
| 8586 |
/* |
| 8587 |
* if there's any suffix following the direct object |
| 8588 |
* placeholder, add it at the end of the phrase |
| 8589 |
*/ |
| 8590 |
ret += rexGroup(5)[3]; |
| 8591 |
|
| 8592 |
/* return the complete phrase string */ |
| 8593 |
return ret; |
| 8594 |
} |
| 8595 |
; |
| 8596 |
|
| 8597 |
/* |
| 8598 |
* English-specific additions for two-object verbs. |
| 8599 |
*/ |
| 8600 |
modify TIAction |
| 8601 |
/* |
| 8602 |
* Flag: omit the indirect object in a query for a missing direct |
| 8603 |
* object. For many verbs, if we already know the indirect object |
| 8604 |
* and we need to ask for the direct object, the query sounds best |
| 8605 |
* when it includes the indirect object: "what do you want to put in |
| 8606 |
* it?" or "what do you want to take from it?". This is the |
| 8607 |
* default phrasing. |
| 8608 |
* |
| 8609 |
* However, the corresponding query for some verbs sounds weird: |
| 8610 |
* "what do you want to dig in with it?" or "whom do you want to ask |
| 8611 |
* about it?". For such actions, this property should be set to |
| 8612 |
* true to indicate that the indirect object should be omitted from |
| 8613 |
* the queries, which will change the phrasing to "what do you want |
| 8614 |
* to dig in", "whom do you want to ask", and so on. |
| 8615 |
*/ |
| 8616 |
omitIobjInDobjQuery = nil |
| 8617 |
|
| 8618 |
/* |
| 8619 |
* For VerbRules: does this verb rule have a prepositional or |
| 8620 |
* structural phrasing of the direct and indirect object slots? That |
| 8621 |
* is, are the object slots determined by a prepositional marker, or |
| 8622 |
* purely by word order? For most English verbs with two objects, |
| 8623 |
* the indirect object is marked by a preposition: GIVE BOOK TO BOB, |
| 8624 |
* PUT BOOK IN BOX. There are a few English verbs that don't include |
| 8625 |
* any prespositional markers for the objects, though, and assign the |
| 8626 |
* noun phrase roles purely by the word order: GIVE BOB BOOK, SHOW |
| 8627 |
* BOB BOOK, THROW BOB BOOK. We define these phrasings with separate |
| 8628 |
* verb rules, which we mark with this property. |
| 8629 |
* |
| 8630 |
* We use this in ranking verb matches. Non-prepositional verb |
| 8631 |
* structures are especially prone to matching where they shouldn't, |
| 8632 |
* because we can often find a way to pick out words to fill the |
| 8633 |
* slots in the absence of any marker words. For example, GIVE GREEN |
| 8634 |
* BOOK could be interpreted as GIVE BOOK TO GREEN, where GREEN is |
| 8635 |
* assumed to be an adjective-ending noun phrase; but the player |
| 8636 |
* probably means to give the green book to someone who they assumed |
| 8637 |
* would be filled in as a default. So, whenever we find an |
| 8638 |
* interpretation that involves a non-prespositional phrasing, we'll |
| 8639 |
* use this flag to know we should be suspicious of it and try |
| 8640 |
* alternative phrasing first. |
| 8641 |
* |
| 8642 |
* Most two-object verbs in English use prepositional markers, so |
| 8643 |
* we'll set this as the default. Individual VerbRules that use |
| 8644 |
* purely structural phrasing should override this. |
| 8645 |
*/ |
| 8646 |
isPrepositionalPhrasing = true |
| 8647 |
|
| 8648 |
/* resolve noun phrases */ |
| 8649 |
resolveNouns(issuingActor, targetActor, results) |
| 8650 |
{ |
| 8651 |
/* |
| 8652 |
* If we're a non-prepositional phrasing, it means that we have |
| 8653 |
* the VERB IOBJ DOBJ word ordering (as in GIVE BOB BOX or THROW |
| 8654 |
* BOB COIN). For grammar match ranking purposes, give these |
| 8655 |
* phrasings a lower match probability when the dobj phrase |
| 8656 |
* doesn't have a clear qualifier. If the dobj phrase starts |
| 8657 |
* with 'the' or a qualifier word like that (GIVE BOB THE BOX), |
| 8658 |
* then it's pretty clear that the structural phrasing is right |
| 8659 |
* after all; but if there's no qualifier, we could reading too |
| 8660 |
* much into the word order. We could have something like GIVE |
| 8661 |
* GREEN BOX, where we *could* treat this as two objects, but we |
| 8662 |
* could just as well have a missing indirect object phrase. |
| 8663 |
*/ |
| 8664 |
if (!isPrepositionalPhrasing) |
| 8665 |
{ |
| 8666 |
/* |
| 8667 |
* If the direct object phrase starts with 'a', 'an', 'the', |
| 8668 |
* 'some', or 'any', the grammar is pretty clearly a good |
| 8669 |
* match for the non-prepositional phrasing. Otherwise, it's |
| 8670 |
* suspect, so rank it accordingly. |
| 8671 |
*/ |
| 8672 |
if (rexMatch('(a|an|the|some|any)<space>', |
| 8673 |
dobjMatch.getOrigText()) == nil) |
| 8674 |
{ |
| 8675 |
/* note this as weak phrasing level 100 */ |
| 8676 |
results.noteWeakPhrasing(100); |
| 8677 |
} |
| 8678 |
} |
| 8679 |
|
| 8680 |
/* inherit the base handling */ |
| 8681 |
inherited(issuingActor, targetActor, results); |
| 8682 |
} |
| 8683 |
|
| 8684 |
/* get the interrogative for one of our objects */ |
| 8685 |
whatObj(which) |
| 8686 |
{ |
| 8687 |
switch (which) |
| 8688 |
{ |
| 8689 |
case DirectObject: |
| 8690 |
/* |
| 8691 |
* the direct object interrogative is the first word in |
| 8692 |
* parentheses in our verbPhrase string |
| 8693 |
*/ |
| 8694 |
rexSearch('<lparen>.*?(<alpha>+)<rparen>', verbPhrase); |
| 8695 |
break; |
| 8696 |
|
| 8697 |
case IndirectObject: |
| 8698 |
/* |
| 8699 |
* the indirect object interrogative is the second |
| 8700 |
* parenthesized word in our verbPhrase string |
| 8701 |
*/ |
| 8702 |
rexSearch('<rparen>.*<lparen>.*?(<alpha>+)<rparen>', verbPhrase); |
| 8703 |
break; |
| 8704 |
} |
| 8705 |
|
| 8706 |
/* show the group match */ |
| 8707 |
return whatTranslate(rexGroup(1)[3]); |
| 8708 |
} |
| 8709 |
|
| 8710 |
/* announce a default object used with this action */ |
| 8711 |
announceDefaultObject(obj, whichObj, resolvedAllObjects) |
| 8712 |
{ |
| 8713 |
/* presume we won't have a verb or preposition */ |
| 8714 |
local verb = ''; |
| 8715 |
local prep = ''; |
| 8716 |
|
| 8717 |
/* |
| 8718 |
* Check the full phrasing - if we're showing the direct object, |
| 8719 |
* but an indirect object was supplied, use the verb's |
| 8720 |
* participle form ("asking bob") in the default string, since |
| 8721 |
* we must clarify that we're not tagging the default string on |
| 8722 |
* to the command line. Don't include the participle form if we |
| 8723 |
* don't know all the objects yet, since in this case we are in |
| 8724 |
* fact tagging the default string onto the command so far, as |
| 8725 |
* there's nothing else in the command to get in the way. |
| 8726 |
*/ |
| 8727 |
if (whichObj == DirectObject && resolvedAllObjects) |
| 8728 |
{ |
| 8729 |
/* |
| 8730 |
* extract the verb's participle form (including any |
| 8731 |
* complementizer phrase) |
| 8732 |
*/ |
| 8733 |
rexSearch('/(<^lparen>+) <lparen>', verbPhrase); |
| 8734 |
verb = rexGroup(1)[3] + ' '; |
| 8735 |
} |
| 8736 |
|
| 8737 |
/* get the preposition to use, if any */ |
| 8738 |
switch(whichObj) |
| 8739 |
{ |
| 8740 |
case DirectObject: |
| 8741 |
/* use the preposition in the first "(what)" phrase */ |
| 8742 |
rexSearch('<lparen>(.*?)<space>*<alpha>+<rparen>', verbPhrase); |
| 8743 |
prep = rexGroup(1)[3]; |
| 8744 |
break; |
| 8745 |
|
| 8746 |
case IndirectObject: |
| 8747 |
/* use the preposition in the second "(what)" phrase */ |
| 8748 |
rexSearch('<rparen>.*<lparen>(.*?)<space>*<alpha>+<rparen>', |
| 8749 |
verbPhrase); |
| 8750 |
prep = rexGroup(1)[3]; |
| 8751 |
break; |
| 8752 |
} |
| 8753 |
|
| 8754 |
/* |
| 8755 |
* get the object name - we need to distinguish from everything |
| 8756 |
* else in scope, since we considered everything in scope when |
| 8757 |
* making our pick |
| 8758 |
*/ |
| 8759 |
local nm = obj.getAnnouncementDistinguisher( |
| 8760 |
gActor.scopeList()).theName(obj); |
| 8761 |
|
| 8762 |
/* build and return the complete phrase */ |
| 8763 |
return spSuffix(verb) + spSuffix(prep) + nm; |
| 8764 |
} |
| 8765 |
|
| 8766 |
/* announce all defaulted objects */ |
| 8767 |
announceAllDefaultObjects(allResolved) |
| 8768 |
{ |
| 8769 |
/* announce a defaulted direct object if appropriate */ |
| 8770 |
maybeAnnounceDefaultObject(dobjList_, DirectObject, allResolved); |
| 8771 |
|
| 8772 |
/* announce a defaulted indirect object if appropriate */ |
| 8773 |
maybeAnnounceDefaultObject(iobjList_, IndirectObject, allResolved); |
| 8774 |
} |
| 8775 |
|
| 8776 |
/* show the verb's basic infinitive form for an interrogative */ |
| 8777 |
getQuestionInf(which) |
| 8778 |
{ |
| 8779 |
local ret; |
| 8780 |
local vcomp; |
| 8781 |
local dprep; |
| 8782 |
local iprep; |
| 8783 |
local pro; |
| 8784 |
|
| 8785 |
/* |
| 8786 |
* Our verb phrase can one of three formats, depending on which |
| 8787 |
* object role we're asking about (the part in <angle brackets> |
| 8788 |
* is the part we're responsible for generating). In these |
| 8789 |
* formats, 'verb' is the verb infinitive; 'comp' is the |
| 8790 |
* complementizer, if any (e.g., the 'up' in 'pick up'); 'dprep' |
| 8791 |
* is the direct object preposition (the 'in' in 'dig in x with |
| 8792 |
* y'); and 'iprep' is the indirect object preposition (the |
| 8793 |
* 'with' in 'dig in x with y'). |
| 8794 |
* |
| 8795 |
* asking for dobj: verb vcomp dprep iprep it ('what do you want |
| 8796 |
* to <open with it>?', '<dig in with it>', '<look up in it>'). |
| 8797 |
* |
| 8798 |
* asking for dobj, but suppressing the iobj part: verb vcomp |
| 8799 |
* dprep ('what do you want to <turn>?', '<look up>?', '<dig |
| 8800 |
* in>') |
| 8801 |
* |
| 8802 |
* asking for iobj: verb dprep it vcomp iprep ('what do you want |
| 8803 |
* to <open it with>', '<dig in it with>', '<look it up in>' |
| 8804 |
*/ |
| 8805 |
|
| 8806 |
/* parse the verbPhrase into its component parts */ |
| 8807 |
rexMatch('(.*)/<alphanum|-|squote>+(?:<space>+(<^lparen>*))?' |
| 8808 |
+ '<space>+<lparen>(.*?)<space>*<alpha>+<rparen>' |
| 8809 |
+ '<space>+<lparen>(.*?)<space>*<alpha>+<rparen>', |
| 8810 |
verbPhrase); |
| 8811 |
|
| 8812 |
/* pull out the verb */ |
| 8813 |
ret = rexGroup(1)[3]; |
| 8814 |
|
| 8815 |
/* pull out the verb complementizer */ |
| 8816 |
vcomp = (rexGroup(2) == nil ? '' : rexGroup(2)[3]); |
| 8817 |
|
| 8818 |
/* pull out the direct and indirect object prepositions */ |
| 8819 |
dprep = rexGroup(3)[3]; |
| 8820 |
iprep = rexGroup(4)[3]; |
| 8821 |
|
| 8822 |
/* get the pronoun for the other object phrase */ |
| 8823 |
pro = getOtherMessageObjectPronoun(which); |
| 8824 |
|
| 8825 |
/* check what we're asking about */ |
| 8826 |
if (which == DirectObject) |
| 8827 |
{ |
| 8828 |
/* add the <vcomp dprep> part in all cases */ |
| 8829 |
ret += spPrefix(vcomp) + spPrefix(dprep); |
| 8830 |
|
| 8831 |
/* add the <iprep it> part if we want the indirect object part */ |
| 8832 |
if (!omitIobjInDobjQuery && pro != nil) |
| 8833 |
ret += spPrefix(iprep) + ' ' + pro; |
| 8834 |
} |
| 8835 |
else |
| 8836 |
{ |
| 8837 |
/* add the <dprep it> part if appropriate */ |
| 8838 |
if (pro != nil) |
| 8839 |
ret += spPrefix(dprep) + ' ' + pro; |
| 8840 |
|
| 8841 |
/* add the <vcomp iprep> part */ |
| 8842 |
ret += spPrefix(vcomp) + spPrefix(iprep); |
| 8843 |
} |
| 8844 |
|
| 8845 |
/* return the result */ |
| 8846 |
return ret; |
| 8847 |
} |
| 8848 |
|
| 8849 |
/* |
| 8850 |
* Get the pronoun for the message object in the given role. |
| 8851 |
*/ |
| 8852 |
getOtherMessageObjectPronoun(which) |
| 8853 |
{ |
| 8854 |
local lst; |
| 8855 |
|
| 8856 |
/* |
| 8857 |
* Get the resolution list (or tentative resolution list) for the |
| 8858 |
* *other* object, since we want to show a pronoun representing |
| 8859 |
* the other object. If we don't have a fully-resolved list for |
| 8860 |
* the other object, use the tentative resolution list, which |
| 8861 |
* we're guaranteed to have by the time we start resolving |
| 8862 |
* anything (and thus by the time we need to ask for objects). |
| 8863 |
*/ |
| 8864 |
lst = (which == DirectObject ? iobjList_ : dobjList_); |
| 8865 |
if (lst == nil || lst == []) |
| 8866 |
lst = (which == DirectObject |
| 8867 |
? tentativeIobj_ : tentativeDobj_); |
| 8868 |
|
| 8869 |
/* if we found an object list, use the pronoun for the list */ |
| 8870 |
if (lst != nil && lst != []) |
| 8871 |
{ |
| 8872 |
/* we got a list - return a suitable pronoun for this list */ |
| 8873 |
return objListPronoun(lst); |
| 8874 |
} |
| 8875 |
else |
| 8876 |
{ |
| 8877 |
/* there's no object list, so there's no pronoun */ |
| 8878 |
return nil; |
| 8879 |
} |
| 8880 |
} |
| 8881 |
|
| 8882 |
/* get the verb phrase in infinitive or participle form */ |
| 8883 |
getVerbPhrase(inf, ctx) |
| 8884 |
{ |
| 8885 |
local dobj, dobjText, dobjIsPronoun; |
| 8886 |
local iobj, iobjText; |
| 8887 |
local ret; |
| 8888 |
|
| 8889 |
/* use the default context if one wasn't supplied */ |
| 8890 |
if (ctx == nil) |
| 8891 |
ctx = defaultGetVerbPhraseContext; |
| 8892 |
|
| 8893 |
/* get the direct object information */ |
| 8894 |
dobj = getDobj(); |
| 8895 |
dobjText = ctx.objNameObj(dobj); |
| 8896 |
dobjIsPronoun = ctx.isObjPronoun(dobj); |
| 8897 |
|
| 8898 |
/* get the indirect object information */ |
| 8899 |
iobj = getIobj(); |
| 8900 |
iobjText = (iobj != nil ? ctx.objNameObj(iobj) : nil); |
| 8901 |
|
| 8902 |
/* get the phrasing */ |
| 8903 |
ret = getVerbPhrase2(inf, verbPhrase, |
| 8904 |
dobjText, dobjIsPronoun, iobjText); |
| 8905 |
|
| 8906 |
/* |
| 8907 |
* Set the antecedent for the next verb phrase. Our direct |
| 8908 |
* object is normally the antecedent; however, if the indirect |
| 8909 |
* object matches the current antecedent, keep the current |
| 8910 |
* antecedent, so that 'it' (or whatever) remains the same for |
| 8911 |
* the next verb phrase. |
| 8912 |
*/ |
| 8913 |
if (ctx.pronounObj != iobj) |
| 8914 |
ctx.setPronounObj(dobj); |
| 8915 |
|
| 8916 |
/* return the result */ |
| 8917 |
return ret; |
| 8918 |
} |
| 8919 |
|
| 8920 |
/* |
| 8921 |
* Get the verb phrase for a two-object (dobj + iobj) phrasing. This |
| 8922 |
* is a class method, so that it can be reused by unrelated (i.e., |
| 8923 |
* non-TIAction) classes that also use two-object syntax but with |
| 8924 |
* other internal structures. This is the two-object equivalent of |
| 8925 |
* TAction.getVerbPhrase1(). |
| 8926 |
*/ |
| 8927 |
getVerbPhrase2(inf, vp, dobjText, dobjIsPronoun, iobjText) |
| 8928 |
{ |
| 8929 |
local ret; |
| 8930 |
local vcomp; |
| 8931 |
local dprep, iprep; |
| 8932 |
|
| 8933 |
/* parse the verbPhrase into its component parts */ |
| 8934 |
rexMatch('(.*)/(<alphanum|-|squote>+)(?:<space>+(<^lparen>*))?' |
| 8935 |
+ '<space>+<lparen>(.*?)<space>*<alpha>+<rparen>' |
| 8936 |
+ '<space>+<lparen>(.*?)<space>*<alpha>+<rparen>', |
| 8937 |
vp); |
| 8938 |
|
| 8939 |
/* start off with the infinitive or participle, as desired */ |
| 8940 |
if (inf) |
| 8941 |
ret = rexGroup(1)[3]; |
| 8942 |
else |
| 8943 |
ret = rexGroup(2)[3]; |
| 8944 |
|
| 8945 |
/* get the complementizer */ |
| 8946 |
vcomp = (rexGroup(3) == nil ? '' : rexGroup(3)[3]); |
| 8947 |
|
| 8948 |
/* get the direct and indirect object prepositions */ |
| 8949 |
dprep = rexGroup(4)[3]; |
| 8950 |
iprep = rexGroup(5)[3]; |
| 8951 |
|
| 8952 |
/* |
| 8953 |
* add the complementizer BEFORE the direct object, if the |
| 8954 |
* direct object is being shown as a full name ("PICK UP BOX") |
| 8955 |
*/ |
| 8956 |
if (!dobjIsPronoun) |
| 8957 |
ret += spPrefix(vcomp); |
| 8958 |
|
| 8959 |
/* |
| 8960 |
* add the direct object and its preposition, using a pronoun if |
| 8961 |
* applicable |
| 8962 |
*/ |
| 8963 |
ret += spPrefix(dprep) + ' ' + dobjText; |
| 8964 |
|
| 8965 |
/* |
| 8966 |
* add the complementizer AFTER the direct object, if the direct |
| 8967 |
* object is shown as a pronoun ("PICK IT UP") |
| 8968 |
*/ |
| 8969 |
if (dobjIsPronoun) |
| 8970 |
ret += spPrefix(vcomp); |
| 8971 |
|
| 8972 |
/* if we have an indirect object, add it with its preposition */ |
| 8973 |
if (iobjText != nil) |
| 8974 |
ret += spPrefix(iprep) + ' ' + iobjText; |
| 8975 |
|
| 8976 |
/* return the result phrase */ |
| 8977 |
return ret; |
| 8978 |
} |
| 8979 |
; |
| 8980 |
|
| 8981 |
/* |
| 8982 |
* English-specific additions for verbs taking a literal phrase as the |
| 8983 |
* sole object. |
| 8984 |
*/ |
| 8985 |
modify LiteralAction |
| 8986 |
/* provide a base verbPhrase, in case an instance leaves it out */ |
| 8987 |
verbPhrase = 'verb/verbing (what)' |
| 8988 |
|
| 8989 |
/* get an interrogative word for an object of the action */ |
| 8990 |
whatObj(which) |
| 8991 |
{ |
| 8992 |
/* use the same processing as TAction */ |
| 8993 |
return delegated TAction(which); |
| 8994 |
} |
| 8995 |
|
| 8996 |
getVerbPhrase(inf, ctx) |
| 8997 |
{ |
| 8998 |
/* handle this as though the literal were a direct object phrase */ |
| 8999 |
return TAction.getVerbPhrase1(inf, verbPhrase, gLiteral, nil); |
| 9000 |
} |
| 9001 |
|
| 9002 |
getQuestionInf(which) |
| 9003 |
{ |
| 9004 |
/* use the same handling as for a regular one-object action */ |
| 9005 |
return delegated TAction(which); |
| 9006 |
} |
| 9007 |
|
| 9008 |
; |
| 9009 |
|
| 9010 |
/* |
| 9011 |
* English-specific additions for verbs of a direct object and a literal |
| 9012 |
* phrase. |
| 9013 |
*/ |
| 9014 |
modify LiteralTAction |
| 9015 |
announceDefaultObject(obj, whichObj, resolvedAllObjects) |
| 9016 |
{ |
| 9017 |
/* |
| 9018 |
* Use the same handling as for a regular two-object action. We |
| 9019 |
* can only default the actual object in this kind of verb; the |
| 9020 |
* actual object always fills the DirectObject slot, but in |
| 9021 |
* message generation it might use a different slot, so use the |
| 9022 |
* message generation slot here. |
| 9023 |
*/ |
| 9024 |
return delegated TIAction(obj, whichMessageObject, |
| 9025 |
resolvedAllObjects); |
| 9026 |
} |
| 9027 |
|
| 9028 |
whatObj(which) |
| 9029 |
{ |
| 9030 |
/* use the same handling we use for a regular two-object action */ |
| 9031 |
return delegated TIAction(which); |
| 9032 |
} |
| 9033 |
|
| 9034 |
getQuestionInf(which) |
| 9035 |
{ |
| 9036 |
/* |
| 9037 |
* use the same handling as for a two-object action (but note |
| 9038 |
* that we override getMessageObjectPronoun(), which will affect |
| 9039 |
* the way we present the verb infinitive in some cases) |
| 9040 |
*/ |
| 9041 |
return delegated TIAction(which); |
| 9042 |
} |
| 9043 |
|
| 9044 |
/* |
| 9045 |
* When we want to show a verb infinitive phrase that involves a |
| 9046 |
* pronoun for the literal phrase, refer to the literal as 'that' |
| 9047 |
* rather than 'it' or anything else. |
| 9048 |
*/ |
| 9049 |
getOtherMessageObjectPronoun(which) |
| 9050 |
{ |
| 9051 |
/* |
| 9052 |
* If we're asking about the literal phrase, then the other |
| 9053 |
* pronoun is for the resolved object: so, return the pronoun |
| 9054 |
* for the direct object phrase, because we *always* store the |
| 9055 |
* non-literal in the direct object slot, regardless of the |
| 9056 |
* actual phrasing of the action. |
| 9057 |
* |
| 9058 |
* If we're asking about the resolved object (i.e., not the |
| 9059 |
* literal phrase), then return 'that' as the pronoun for the |
| 9060 |
* literal phrase. |
| 9061 |
*/ |
| 9062 |
if (which == whichMessageLiteral) |
| 9063 |
{ |
| 9064 |
/* |
| 9065 |
* we're asking about the literal, so the other pronoun is |
| 9066 |
* for the resolved object, which is always in the direct |
| 9067 |
* object slot (so the 'other' slot is effectively the |
| 9068 |
* indirect object) |
| 9069 |
*/ |
| 9070 |
return delegated TIAction(IndirectObject); |
| 9071 |
} |
| 9072 |
else |
| 9073 |
{ |
| 9074 |
/* |
| 9075 |
* We're asking about the resolved object, so the other |
| 9076 |
* pronoun is for the literal phrase: always use 'that' to |
| 9077 |
* refer to the literal phrase. |
| 9078 |
*/ |
| 9079 |
return 'that'; |
| 9080 |
} |
| 9081 |
} |
| 9082 |
|
| 9083 |
getVerbPhrase(inf, ctx) |
| 9084 |
{ |
| 9085 |
local dobj, dobjText, dobjIsPronoun; |
| 9086 |
local litText; |
| 9087 |
local ret; |
| 9088 |
|
| 9089 |
/* use the default context if one wasn't supplied */ |
| 9090 |
if (ctx == nil) |
| 9091 |
ctx = defaultGetVerbPhraseContext; |
| 9092 |
|
| 9093 |
/* get the direct object information */ |
| 9094 |
dobj = getDobj(); |
| 9095 |
dobjText = ctx.objNameObj(dobj); |
| 9096 |
dobjIsPronoun = ctx.isObjPronoun(dobj); |
| 9097 |
|
| 9098 |
/* get our literal text */ |
| 9099 |
litText = gLiteral; |
| 9100 |
|
| 9101 |
/* |
| 9102 |
* Use the standard two-object phrasing. The order of the |
| 9103 |
* phrasing depends on whether our literal phrase is in the |
| 9104 |
* direct or indirect object slot. |
| 9105 |
*/ |
| 9106 |
if (whichMessageLiteral == DirectObject) |
| 9107 |
ret = TIAction.getVerbPhrase2(inf, verbPhrase, |
| 9108 |
litText, nil, dobjText); |
| 9109 |
else |
| 9110 |
ret = TIAction.getVerbPhrase2(inf, verbPhrase, |
| 9111 |
dobjText, dobjIsPronoun, litText); |
| 9112 |
|
| 9113 |
/* use the direct object as the antecedent for the next phrase */ |
| 9114 |
ctx.setPronounObj(dobj); |
| 9115 |
|
| 9116 |
/* return the result */ |
| 9117 |
return ret; |
| 9118 |
} |
| 9119 |
; |
| 9120 |
|
| 9121 |
/* |
| 9122 |
* English-specific additions for verbs taking a topic phrase as the sole |
| 9123 |
* object. |
| 9124 |
*/ |
| 9125 |
modify TopicAction |
| 9126 |
/* get an interrogative word for an object of the action */ |
| 9127 |
whatObj(which) |
| 9128 |
{ |
| 9129 |
/* use the same processing as TAction */ |
| 9130 |
return delegated TAction(which); |
| 9131 |
} |
| 9132 |
|
| 9133 |
getVerbPhrase(inf, ctx) |
| 9134 |
{ |
| 9135 |
/* handle this as though the topic text were a direct object phrase */ |
| 9136 |
return TAction.getVerbPhrase1( |
| 9137 |
inf, verbPhrase, getTopic().getTopicText().toLower(), nil); |
| 9138 |
} |
| 9139 |
|
| 9140 |
getQuestionInf(which) |
| 9141 |
{ |
| 9142 |
/* use the same handling as for a regular one-object action */ |
| 9143 |
return delegated TAction(which); |
| 9144 |
} |
| 9145 |
|
| 9146 |
; |
| 9147 |
|
| 9148 |
/* |
| 9149 |
* English-specific additions for verbs with topic phrases. |
| 9150 |
*/ |
| 9151 |
modify TopicTAction |
| 9152 |
announceDefaultObject(obj, whichObj, resolvedAllObjects) |
| 9153 |
{ |
| 9154 |
/* |
| 9155 |
* Use the same handling as for a regular two-object action. We |
| 9156 |
* can only default the actual object in this kind of verb; the |
| 9157 |
* actual object always fills the DirectObject slot, but in |
| 9158 |
* message generation it might use a different slot, so use the |
| 9159 |
* message generation slot here. |
| 9160 |
*/ |
| 9161 |
return delegated TIAction(obj, whichMessageObject, |
| 9162 |
resolvedAllObjects); |
| 9163 |
} |
| 9164 |
|
| 9165 |
whatObj(which) |
| 9166 |
{ |
| 9167 |
/* use the same handling we use for a regular two-object action */ |
| 9168 |
return delegated TIAction(which); |
| 9169 |
} |
| 9170 |
|
| 9171 |
getQuestionInf(which) |
| 9172 |
{ |
| 9173 |
/* use the same handling as for a regular two-object action */ |
| 9174 |
return delegated TIAction(which); |
| 9175 |
} |
| 9176 |
|
| 9177 |
getOtherMessageObjectPronoun(which) |
| 9178 |
{ |
| 9179 |
/* |
| 9180 |
* If we're asking about the topic, then the other pronoun is |
| 9181 |
* for the resolved object, which is always in the direct object |
| 9182 |
* slot. If we're asking about the resolved object, then return |
| 9183 |
* a pronoun for the topic. |
| 9184 |
*/ |
| 9185 |
if (which == whichMessageTopic) |
| 9186 |
{ |
| 9187 |
/* |
| 9188 |
* we want the pronoun for the resolved object, which is |
| 9189 |
* always in the direct object slot (so the 'other' slot is |
| 9190 |
* effectively the indirect object) |
| 9191 |
*/ |
| 9192 |
return delegated TIAction(IndirectObject); |
| 9193 |
} |
| 9194 |
else |
| 9195 |
{ |
| 9196 |
/* return a generic pronoun for the topic */ |
| 9197 |
return 'that'; |
| 9198 |
} |
| 9199 |
} |
| 9200 |
|
| 9201 |
getVerbPhrase(inf, ctx) |
| 9202 |
{ |
| 9203 |
local dobj, dobjText, dobjIsPronoun; |
| 9204 |
local topicText; |
| 9205 |
local ret; |
| 9206 |
|
| 9207 |
/* use the default context if one wasn't supplied */ |
| 9208 |
if (ctx == nil) |
| 9209 |
ctx = defaultGetVerbPhraseContext; |
| 9210 |
|
| 9211 |
/* get the direct object information */ |
| 9212 |
dobj = getDobj(); |
| 9213 |
dobjText = ctx.objNameObj(dobj); |
| 9214 |
dobjIsPronoun = ctx.isObjPronoun(dobj); |
| 9215 |
|
| 9216 |
/* get our topic phrase */ |
| 9217 |
topicText = getTopic().getTopicText().toLower(); |
| 9218 |
|
| 9219 |
/* |
| 9220 |
* Use the standard two-object phrasing. The order of the |
| 9221 |
* phrasing depends on whether our topic phrase is in the direct |
| 9222 |
* or indirect object slot. |
| 9223 |
*/ |
| 9224 |
if (whichMessageTopic == DirectObject) |
| 9225 |
ret = TIAction.getVerbPhrase2(inf, verbPhrase, |
| 9226 |
topicText, nil, dobjText); |
| 9227 |
else |
| 9228 |
ret = TIAction.getVerbPhrase2(inf, verbPhrase, |
| 9229 |
dobjText, dobjIsPronoun, topicText); |
| 9230 |
|
| 9231 |
/* use the direct object as the antecedent for the next phrase */ |
| 9232 |
ctx.setPronounObj(dobj); |
| 9233 |
|
| 9234 |
/* return the result */ |
| 9235 |
return ret; |
| 9236 |
} |
| 9237 |
; |
| 9238 |
|
| 9239 |
/* ------------------------------------------------------------------------ */ |
| 9240 |
/* |
| 9241 |
* Verbs. |
| 9242 |
* |
| 9243 |
* The actual body of each of our verbs is defined in the main |
| 9244 |
* language-independent part of the library. We only define the |
| 9245 |
* language-specific grammar rules here. |
| 9246 |
*/ |
| 9247 |
|
| 9248 |
VerbRule(Take) |
| 9249 |
('take' | 'pick' 'up' | 'get') dobjList |
| 9250 |
| 'pick' dobjList 'up' |
| 9251 |
: TakeAction |
| 9252 |
verbPhrase = 'take/taking (what)' |
| 9253 |
; |
| 9254 |
|
| 9255 |
VerbRule(TakeFrom) |
| 9256 |
('take' | 'get') dobjList |
| 9257 |
('from' | 'out' 'of' | 'off' | 'off' 'of') singleIobj |
| 9258 |
| 'remove' dobjList 'from' singleIobj |
| 9259 |
: TakeFromAction |
| 9260 |
verbPhrase = 'take/taking (what) (from what)' |
| 9261 |
; |
| 9262 |
|
| 9263 |
VerbRule(Remove) |
| 9264 |
'remove' dobjList |
| 9265 |
: RemoveAction |
| 9266 |
verbPhrase = 'remove/removing (what)' |
| 9267 |
; |
| 9268 |
|
| 9269 |
VerbRule(Drop) |
| 9270 |
('drop' | 'put' 'down' | 'set' 'down') dobjList |
| 9271 |
| ('put' | 'set') dobjList 'down' |
| 9272 |
: DropAction |
| 9273 |
verbPhrase = 'drop/dropping (what)' |
| 9274 |
; |
| 9275 |
|
| 9276 |
VerbRule(Examine) |
| 9277 |
('examine' | 'inspect' | 'x' |
| 9278 |
| 'look' 'at' | 'l' 'at' | 'look' | 'l') dobjList |
| 9279 |
: ExamineAction |
| 9280 |
verbPhrase = 'examine/examining (what)' |
| 9281 |
; |
| 9282 |
|
| 9283 |
VerbRule(Read) |
| 9284 |
'read' dobjList |
| 9285 |
: ReadAction |
| 9286 |
verbPhrase = 'read/reading (what)' |
| 9287 |
; |
| 9288 |
|
| 9289 |
VerbRule(LookIn) |
| 9290 |
('look' | 'l') ('in' | 'inside') dobjList |
| 9291 |
: LookInAction |
| 9292 |
verbPhrase = 'look/looking (in what)' |
| 9293 |
; |
| 9294 |
|
| 9295 |
VerbRule(Search) |
| 9296 |
'search' dobjList |
| 9297 |
: SearchAction |
| 9298 |
verbPhrase = 'search/searching (what)' |
| 9299 |
; |
| 9300 |
|
| 9301 |
VerbRule(LookThrough) |
| 9302 |
('look' | 'l') ('through' | 'thru' | 'out') dobjList |
| 9303 |
: LookThroughAction |
| 9304 |
verbPhrase = 'look/looking (through what)' |
| 9305 |
; |
| 9306 |
|
| 9307 |
VerbRule(LookUnder) |
| 9308 |
('look' | 'l') 'under' dobjList |
| 9309 |
: LookUnderAction |
| 9310 |
verbPhrase = 'look/looking (under what)' |
| 9311 |
; |
| 9312 |
|
| 9313 |
VerbRule(LookBehind) |
| 9314 |
('look' | 'l') 'behind' dobjList |
| 9315 |
: LookBehindAction |
| 9316 |
verbPhrase = 'look/looking (behind what)' |
| 9317 |
; |
| 9318 |
|
| 9319 |
VerbRule(Feel) |
| 9320 |
('feel' | 'touch') dobjList |
| 9321 |
: FeelAction |
| 9322 |
verbPhrase = 'touch/touching (what)' |
| 9323 |
; |
| 9324 |
|
| 9325 |
VerbRule(Taste) |
| 9326 |
'taste' dobjList |
| 9327 |
: TasteAction |
| 9328 |
verbPhrase = 'taste/tasting (what)' |
| 9329 |
; |
| 9330 |
|
| 9331 |
VerbRule(Smell) |
| 9332 |
('smell' | 'sniff') dobjList |
| 9333 |
: SmellAction |
| 9334 |
verbPhrase = 'smell/smelling (what)' |
| 9335 |
|
| 9336 |
/* |
| 9337 |
* use the "not aware" version of the no-match message - the object |
| 9338 |
* of SMELL is often intangible, so the default "you can't see that" |
| 9339 |
* message is often incongruous for this verb |
| 9340 |
*/ |
| 9341 |
noMatch(msgObj, actor, txt) { msgObj.noMatchNotAware(actor, txt); } |
| 9342 |
; |
| 9343 |
|
| 9344 |
VerbRule(SmellImplicit) |
| 9345 |
'smell' | 'sniff' |
| 9346 |
: SmellImplicitAction |
| 9347 |
verbPhrase = 'smell/smelling' |
| 9348 |
; |
| 9349 |
|
| 9350 |
VerbRule(ListenTo) |
| 9351 |
('hear' | 'listen' 'to' ) dobjList |
| 9352 |
: ListenToAction |
| 9353 |
verbPhrase = 'listen/listening (to what)' |
| 9354 |
|
| 9355 |
/* |
| 9356 |
* use the "not aware" version of the no-match message - the object |
| 9357 |
* of LISTEN TO is often intangible, so the default "you can't see |
| 9358 |
* that" message is often incongruous for this verb |
| 9359 |
*/ |
| 9360 |
noMatch(msgObj, actor, txt) { msgObj.noMatchNotAware(actor, txt); } |
| 9361 |
; |
| 9362 |
|
| 9363 |
VerbRule(ListenImplicit) |
| 9364 |
'listen' | 'hear' |
| 9365 |
: ListenImplicitAction |
| 9366 |
verbPhrase = 'listen/listening' |
| 9367 |
; |
| 9368 |
|
| 9369 |
VerbRule(PutIn) |
| 9370 |
('put' | 'place' | 'set') dobjList |
| 9371 |
('in' | 'into' | 'in' 'to' | 'inside' | 'inside' 'of') singleIobj |
| 9372 |
: PutInAction |
| 9373 |
verbPhrase = 'put/putting (what) (in what)' |
| 9374 |
askIobjResponseProd = inSingleNoun |
| 9375 |
; |
| 9376 |
|
| 9377 |
VerbRule(PutOn) |
| 9378 |
('put' | 'place' | 'drop' | 'set') dobjList |
| 9379 |
('on' | 'onto' | 'on' 'to' | 'upon') singleIobj |
| 9380 |
| 'put' dobjList 'down' 'on' singleIobj |
| 9381 |
: PutOnAction |
| 9382 |
verbPhrase = 'put/putting (what) (on what)' |
| 9383 |
askIobjResponseProd = onSingleNoun |
| 9384 |
; |
| 9385 |
|
| 9386 |
VerbRule(PutUnder) |
| 9387 |
('put' | 'place' | 'set') dobjList 'under' singleIobj |
| 9388 |
: PutUnderAction |
| 9389 |
verbPhrase = 'put/putting (what) (under what)' |
| 9390 |
; |
| 9391 |
|
| 9392 |
VerbRule(PutBehind) |
| 9393 |
('put' | 'place' | 'set') dobjList 'behind' singleIobj |
| 9394 |
: PutBehindAction |
| 9395 |
verbPhrase = 'put/putting (what) (behind what)' |
| 9396 |
; |
| 9397 |
|
| 9398 |
VerbRule(PutInWhat) |
| 9399 |
[badness 500] ('put' | 'place') dobjList |
| 9400 |
: PutInAction |
| 9401 |
verbPhrase = 'put/putting (what) (in what)' |
| 9402 |
construct() |
| 9403 |
{ |
| 9404 |
/* set up the empty indirect object phrase */ |
| 9405 |
iobjMatch = new EmptyNounPhraseProd(); |
| 9406 |
iobjMatch.responseProd = inSingleNoun; |
| 9407 |
} |
| 9408 |
; |
| 9409 |
|
| 9410 |
VerbRule(Wear) |
| 9411 |
('wear' | 'don' | 'put' 'on') dobjList |
| 9412 |
| 'put' dobjList 'on' |
| 9413 |
: WearAction |
| 9414 |
verbPhrase = 'wear/wearing (what)' |
| 9415 |
; |
| 9416 |
|
| 9417 |
VerbRule(Doff) |
| 9418 |
('doff' | 'take' 'off') dobjList |
| 9419 |
| 'take' dobjList 'off' |
| 9420 |
: DoffAction |
| 9421 |
verbPhrase = 'take/taking off (what)' |
| 9422 |
; |
| 9423 |
|
| 9424 |
VerbRule(Kiss) |
| 9425 |
'kiss' singleDobj |
| 9426 |
: KissAction |
| 9427 |
verbPhrase = 'kiss/kissing (whom)' |
| 9428 |
; |
| 9429 |
|
| 9430 |
VerbRule(AskFor) |
| 9431 |
('ask' | 'a') singleDobj 'for' singleTopic |
| 9432 |
| ('ask' | 'a') 'for' singleTopic 'from' singleDobj |
| 9433 |
: AskForAction |
| 9434 |
verbPhrase = 'ask/asking (whom) (for what)' |
| 9435 |
omitIobjInDobjQuery = true |
| 9436 |
askDobjResponseProd = singleNoun |
| 9437 |
askIobjResponseProd = forSingleNoun |
| 9438 |
; |
| 9439 |
|
| 9440 |
VerbRule(AskWhomFor) |
| 9441 |
('ask' | 'a') 'for' singleTopic |
| 9442 |
: AskForAction |
| 9443 |
verbPhrase = 'ask/asking (whom) (for what)' |
| 9444 |
omitIobjInDobjQuery = true |
| 9445 |
construct() |
| 9446 |
{ |
| 9447 |
/* set up the empty direct object phrase */ |
| 9448 |
dobjMatch = new EmptyNounPhraseProd(); |
| 9449 |
dobjMatch.responseProd = singleNoun; |
| 9450 |
} |
| 9451 |
; |
| 9452 |
|
| 9453 |
VerbRule(AskAbout) |
| 9454 |
('ask' | 'a') singleDobj 'about' singleTopic |
| 9455 |
: AskAboutAction |
| 9456 |
verbPhrase = 'ask/asking (whom) (about what)' |
| 9457 |
omitIobjInDobjQuery = true |
| 9458 |
askDobjResponseProd = singleNoun |
| 9459 |
; |
| 9460 |
|
| 9461 |
VerbRule(AskAboutImplicit) |
| 9462 |
'a' singleTopic |
| 9463 |
: AskAboutAction |
| 9464 |
verbPhrase = 'ask/asking (whom) (about what)' |
| 9465 |
omitIobjInDobjQuery = true |
| 9466 |
construct() |
| 9467 |
{ |
| 9468 |
/* set up the empty direct object phrase */ |
| 9469 |
dobjMatch = new EmptyNounPhraseProd(); |
| 9470 |
dobjMatch.responseProd = singleNoun; |
| 9471 |
} |
| 9472 |
; |
| 9473 |
|
| 9474 |
VerbRule(AskAboutWhat) |
| 9475 |
[badness 500] 'ask' singleDobj |
| 9476 |
: AskAboutAction |
| 9477 |
verbPhrase = 'ask/asking (whom) (about what)' |
| 9478 |
askDobjResponseProd = singleNoun |
| 9479 |
omitIobjInDobjQuery = true |
| 9480 |
construct() |
| 9481 |
{ |
| 9482 |
/* set up the empty topic phrase */ |
| 9483 |
topicMatch = new EmptyNounPhraseProd(); |
| 9484 |
topicMatch.responseProd = aboutTopicPhrase; |
| 9485 |
} |
| 9486 |
; |
| 9487 |
|
| 9488 |
|
| 9489 |
VerbRule(TellAbout) |
| 9490 |
('tell' | 't') singleDobj 'about' singleTopic |
| 9491 |
: TellAboutAction |
| 9492 |
verbPhrase = 'tell/telling (whom) (about what)' |
| 9493 |
askDobjResponseProd = singleNoun |
| 9494 |
omitIobjInDobjQuery = true |
| 9495 |
; |
| 9496 |
|
| 9497 |
VerbRule(TellAboutImplicit) |
| 9498 |
't' singleTopic |
| 9499 |
: TellAboutAction |
| 9500 |
verbPhrase = 'tell/telling (whom) (about what)' |
| 9501 |
omitIobjInDobjQuery = true |
| 9502 |
construct() |
| 9503 |
{ |
| 9504 |
/* set up the empty direct object phrase */ |
| 9505 |
dobjMatch = new EmptyNounPhraseProd(); |
| 9506 |
dobjMatch.responseProd = singleNoun; |
| 9507 |
} |
| 9508 |
; |
| 9509 |
|
| 9510 |
VerbRule(TellAboutWhat) |
| 9511 |
[badness 500] 'tell' singleDobj |
| 9512 |
: TellAboutAction |
| 9513 |
verbPhrase = 'tell/telling (whom) (about what)' |
| 9514 |
askDobjResponseProd = singleNoun |
| 9515 |
omitIobjInDobjQuery = true |
| 9516 |
construct() |
| 9517 |
{ |
| 9518 |
/* set up the empty topic phrase */ |
| 9519 |
topicMatch = new EmptyNounPhraseProd(); |
| 9520 |
topicMatch.responseProd = aboutTopicPhrase; |
| 9521 |
} |
| 9522 |
; |
| 9523 |
|
| 9524 |
VerbRule(AskVague) |
| 9525 |
[badness 500] 'ask' singleDobj singleTopic |
| 9526 |
: AskVagueAction |
| 9527 |
verbPhrase = 'ask/asking (whom)' |
| 9528 |
; |
| 9529 |
|
| 9530 |
VerbRule(TellVague) |
| 9531 |
[badness 500] 'tell' singleDobj singleTopic |
| 9532 |
: AskVagueAction |
| 9533 |
verbPhrase = 'tell/telling (whom)' |
| 9534 |
; |
| 9535 |
|
| 9536 |
VerbRule(TalkTo) |
| 9537 |
('greet' | 'say' 'hello' 'to' | 'talk' 'to') singleDobj |
| 9538 |
: TalkToAction |
| 9539 |
verbPhrase = 'talk/talking (to whom)' |
| 9540 |
askDobjResponseProd = singleNoun |
| 9541 |
; |
| 9542 |
|
| 9543 |
VerbRule(TalkToWhat) |
| 9544 |
[badness 500] 'talk' |
| 9545 |
: TalkToAction |
| 9546 |
verbPhrase = 'talk/talking (to whom)' |
| 9547 |
askDobjResponseProd = singleNoun |
| 9548 |
|
| 9549 |
construct() |
| 9550 |
{ |
| 9551 |
/* set up the empty direct object phrase */ |
| 9552 |
dobjMatch = new EmptyNounPhraseProd(); |
| 9553 |
dobjMatch.responseProd = onSingleNoun; |
| 9554 |
} |
| 9555 |
; |
| 9556 |
|
| 9557 |
VerbRule(Topics) |
| 9558 |
'topics' |
| 9559 |
: TopicsAction |
| 9560 |
verbPhrase = 'show/showing topics' |
| 9561 |
; |
| 9562 |
|
| 9563 |
VerbRule(Hello) |
| 9564 |
('say' | ) ('hello' | 'hallo' | 'hi') |
| 9565 |
: HelloAction |
| 9566 |
verbPhrase = 'say/saying hello' |
| 9567 |
; |
| 9568 |
|
| 9569 |
VerbRule(Goodbye) |
| 9570 |
('say' | ()) ('goodbye' | 'good-bye' | 'good' 'bye' | 'bye') |
| 9571 |
: GoodbyeAction |
| 9572 |
verbPhrase = 'say/saying goodbye' |
| 9573 |
; |
| 9574 |
|
| 9575 |
VerbRule(Yes) |
| 9576 |
'yes' | 'affirmative' | 'say' 'yes' |
| 9577 |
: YesAction |
| 9578 |
verbPhrase = 'say/saying yes' |
| 9579 |
; |
| 9580 |
|
| 9581 |
VerbRule(No) |
| 9582 |
'no' | 'negative' | 'say' 'no' |
| 9583 |
: NoAction |
| 9584 |
verbPhrase = 'say/saying no' |
| 9585 |
; |
| 9586 |
|
| 9587 |
VerbRule(Yell) |
| 9588 |
'yell' | 'scream' | 'shout' | 'holler' |
| 9589 |
: YellAction |
| 9590 |
verbPhrase = 'yell/yelling' |
| 9591 |
; |
| 9592 |
|
| 9593 |
VerbRule(GiveTo) |
| 9594 |
('give' | 'offer') dobjList 'to' singleIobj |
| 9595 |
: GiveToAction |
| 9596 |
verbPhrase = 'give/giving (what) (to whom)' |
| 9597 |
askIobjResponseProd = toSingleNoun |
| 9598 |
; |
| 9599 |
|
| 9600 |
VerbRule(GiveToType2) |
| 9601 |
('give' | 'offer') singleIobj dobjList |
| 9602 |
: GiveToAction |
| 9603 |
verbPhrase = 'give/giving (what) (to whom)' |
| 9604 |
askIobjResponseProd = toSingleNoun |
| 9605 |
|
| 9606 |
/* this is a non-prepositional phrasing */ |
| 9607 |
isPrepositionalPhrasing = nil |
| 9608 |
; |
| 9609 |
|
| 9610 |
VerbRule(GiveToWhom) |
| 9611 |
('give' | 'offer') dobjList |
| 9612 |
: GiveToAction |
| 9613 |
verbPhrase = 'give/giving (what) (to whom)' |
| 9614 |
construct() |
| 9615 |
{ |
| 9616 |
/* set up the empty indirect object phrase */ |
| 9617 |
iobjMatch = new ImpliedActorNounPhraseProd(); |
| 9618 |
iobjMatch.responseProd = toSingleNoun; |
| 9619 |
} |
| 9620 |
; |
| 9621 |
|
| 9622 |
VerbRule(ShowTo) |
| 9623 |
'show' dobjList 'to' singleIobj |
| 9624 |
: ShowToAction |
| 9625 |
verbPhrase = 'show/showing (what) (to whom)' |
| 9626 |
askIobjResponseProd = toSingleNoun |
| 9627 |
; |
| 9628 |
|
| 9629 |
VerbRule(ShowToType2) |
| 9630 |
'show' singleIobj dobjList |
| 9631 |
: ShowToAction |
| 9632 |
verbPhrase = 'show/showing (what) (to whom)' |
| 9633 |
askIobjResponseProd = toSingleNoun |
| 9634 |
|
| 9635 |
/* this is a non-prepositional phrasing */ |
| 9636 |
isPrepositionalPhrasing = nil |
| 9637 |
; |
| 9638 |
|
| 9639 |
VerbRule(ShowToWhom) |
| 9640 |
'show' dobjList |
| 9641 |
: ShowToAction |
| 9642 |
verbPhrase = 'show/showing (what) (to whom)' |
| 9643 |
construct() |
| 9644 |
{ |
| 9645 |
/* set up the empty indirect object phrase */ |
| 9646 |
iobjMatch = new ImpliedActorNounPhraseProd(); |
| 9647 |
iobjMatch.responseProd = toSingleNoun; |
| 9648 |
} |
| 9649 |
; |
| 9650 |
|
| 9651 |
VerbRule(Throw) |
| 9652 |
('throw' | 'toss') dobjList |
| 9653 |
: ThrowAction |
| 9654 |
verbPhrase = 'throw/throwing (what)' |
| 9655 |
; |
| 9656 |
|
| 9657 |
VerbRule(ThrowAt) |
| 9658 |
('throw' | 'toss') dobjList 'at' singleIobj |
| 9659 |
: ThrowAtAction |
| 9660 |
verbPhrase = 'throw/throwing (what) (at what)' |
| 9661 |
askIobjResponseProd = atSingleNoun |
| 9662 |
; |
| 9663 |
|
| 9664 |
VerbRule(ThrowTo) |
| 9665 |
('throw' | 'toss') dobjList 'to' singleIobj |
| 9666 |
: ThrowToAction |
| 9667 |
verbPhrase = 'throw/throwing (what) (to whom)' |
| 9668 |
askIobjResponseProd = toSingleNoun |
| 9669 |
; |
| 9670 |
|
| 9671 |
VerbRule(ThrowToType2) |
| 9672 |
'throw' singleIobj dobjList |
| 9673 |
: ThrowToAction |
| 9674 |
verbPhrase = 'throw/throwing (what) (to whom)' |
| 9675 |
askIobjResponseProd = toSingleNoun |
| 9676 |
|
| 9677 |
/* this is a non-prepositional phrasing */ |
| 9678 |
isPrepositionalPhrasing = nil |
| 9679 |
; |
| 9680 |
|
| 9681 |
VerbRule(ThrowDir) |
| 9682 |
('throw' | 'toss') dobjList ('to' ('the' | ) | ) singleDir |
| 9683 |
: ThrowDirAction |
| 9684 |
verbPhrase = ('throw/throwing (what) ' + dirMatch.dir.name) |
| 9685 |
; |
| 9686 |
|
| 9687 |
/* a special rule for THROW DOWN <dobj> */ |
| 9688 |
VerbRule(ThrowDirDown) |
| 9689 |
'throw' ('down' | 'd') dobjList |
| 9690 |
: ThrowDirAction |
| 9691 |
verbPhrase = ('throw/throwing (what) down') |
| 9692 |
|
| 9693 |
/* the direction is fixed as 'down' for this phrasing */ |
| 9694 |
getDirection() { return downDirection; } |
| 9695 |
; |
| 9696 |
|
| 9697 |
VerbRule(Follow) |
| 9698 |
'follow' singleDobj |
| 9699 |
: FollowAction |
| 9700 |
verbPhrase = 'follow/following (whom)' |
| 9701 |
askDobjResponseProd = singleNoun |
| 9702 |
; |
| 9703 |
|
| 9704 |
VerbRule(Attack) |
| 9705 |
('attack' | 'kill' | 'hit' | 'kick' | 'punch') singleDobj |
| 9706 |
: AttackAction |
| 9707 |
verbPhrase = 'attack/attacking (whom)' |
| 9708 |
askDobjResponseProd = singleNoun |
| 9709 |
; |
| 9710 |
|
| 9711 |
VerbRule(AttackWith) |
| 9712 |
('attack' | 'kill' | 'hit' | 'kick' | 'punch' | 'strike') |
| 9713 |
singleDobj |
| 9714 |
'with' singleIobj |
| 9715 |
: AttackWithAction |
| 9716 |
verbPhrase = 'attack/attacking (whom) (with what)' |
| 9717 |
askDobjResponseProd = singleNoun |
| 9718 |
askIobjResponseProd = withSingleNoun |
| 9719 |
; |
| 9720 |
|
| 9721 |
VerbRule(Inventory) |
| 9722 |
'i' | 'inventory' | 'take' 'inventory' |
| 9723 |
: InventoryAction |
| 9724 |
verbPhrase = 'take/taking inventory' |
| 9725 |
; |
| 9726 |
|
| 9727 |
VerbRule(InventoryTall) |
| 9728 |
'i' 'tall' | 'inventory' 'tall' |
| 9729 |
: InventoryTallAction |
| 9730 |
verbPhrase = 'take/taking "tall" inventory' |
| 9731 |
; |
| 9732 |
|
| 9733 |
VerbRule(InventoryWide) |
| 9734 |
'i' 'wide' | 'inventory' 'wide' |
| 9735 |
: InventoryWideAction |
| 9736 |
verbPhrase = 'take/taking "wide" inventory' |
| 9737 |
; |
| 9738 |
|
| 9739 |
VerbRule(Wait) |
| 9740 |
'z' | 'wait' |
| 9741 |
: WaitAction |
| 9742 |
verbPhrase = 'wait/waiting' |
| 9743 |
; |
| 9744 |
|
| 9745 |
VerbRule(Look) |
| 9746 |
'look' | 'look' 'around' | 'l' | 'l' 'around' |
| 9747 |
: LookAction |
| 9748 |
verbPhrase = 'look/looking around' |
| 9749 |
; |
| 9750 |
|
| 9751 |
VerbRule(Quit) |
| 9752 |
'quit' | 'q' |
| 9753 |
: QuitAction |
| 9754 |
verbPhrase = 'quit/quitting' |
| 9755 |
; |
| 9756 |
|
| 9757 |
VerbRule(Again) |
| 9758 |
'again' | 'g' |
| 9759 |
: AgainAction |
| 9760 |
verbPhrase = 'repeat/repeating the last command' |
| 9761 |
; |
| 9762 |
|
| 9763 |
VerbRule(Footnote) |
| 9764 |
('footnote' | 'note') singleNumber |
| 9765 |
: FootnoteAction |
| 9766 |
verbPhrase = 'show/showing a footnote' |
| 9767 |
; |
| 9768 |
|
| 9769 |
VerbRule(FootnotesFull) |
| 9770 |
'footnotes' 'full' |
| 9771 |
: FootnotesFullAction |
| 9772 |
verbPhrase = 'enable/enabling all footnotes' |
| 9773 |
; |
| 9774 |
|
| 9775 |
VerbRule(FootnotesMedium) |
| 9776 |
'footnotes' 'medium' |
| 9777 |
: FootnotesMediumAction |
| 9778 |
verbPhrase = 'enable/enabling new footnotes' |
| 9779 |
; |
| 9780 |
|
| 9781 |
VerbRule(FootnotesOff) |
| 9782 |
'footnotes' 'off' |
| 9783 |
: FootnotesOffAction |
| 9784 |
verbPhrase = 'hide/hiding footnotes' |
| 9785 |
; |
| 9786 |
|
| 9787 |
VerbRule(FootnotesStatus) |
| 9788 |
'footnotes' |
| 9789 |
: FootnotesStatusAction |
| 9790 |
verbPhrase = 'show/showing footnote status' |
| 9791 |
; |
| 9792 |
|
| 9793 |
VerbRule(TipsOn) |
| 9794 |
('tips' | 'tip') 'on' |
| 9795 |
: TipModeAction |
| 9796 |
|
| 9797 |
stat_ = true |
| 9798 |
|
| 9799 |
verbPhrase = 'turn/turning tips on' |
| 9800 |
; |
| 9801 |
|
| 9802 |
VerbRule(TipsOff) |
| 9803 |
('tips' | 'tip') 'off' |
| 9804 |
: TipModeAction |
| 9805 |
|
| 9806 |
stat_ = nil |
| 9807 |
|
| 9808 |
verbPhrase = 'turn/turning tips off' |
| 9809 |
; |
| 9810 |
|
| 9811 |
VerbRule(Verbose) |
| 9812 |
'verbose' |
| 9813 |
: VerboseAction |
| 9814 |
verbPhrase = 'enter/entering VERBOSE mode' |
| 9815 |
; |
| 9816 |
|
| 9817 |
VerbRule(Terse) |
| 9818 |
'terse' | 'brief' |
| 9819 |
: TerseAction |
| 9820 |
verbPhrase = 'enter/entering BRIEF mode' |
| 9821 |
; |
| 9822 |
|
| 9823 |
VerbRule(Score) |
| 9824 |
'score' | 'status' |
| 9825 |
: ScoreAction |
| 9826 |
verbPhrase = 'show/showing score' |
| 9827 |
; |
| 9828 |
|
| 9829 |
VerbRule(FullScore) |
| 9830 |
'full' 'score' | 'fullscore' | 'full' |
| 9831 |
: FullScoreAction |
| 9832 |
verbPhrase = 'show/showing full score' |
| 9833 |
; |
| 9834 |
|
| 9835 |
VerbRule(Notify) |
| 9836 |
'notify' |
| 9837 |
: NotifyAction |
| 9838 |
verbPhrase = 'show/showing notification status' |
| 9839 |
; |
| 9840 |
|
| 9841 |
VerbRule(NotifyOn) |
| 9842 |
'notify' 'on' |
| 9843 |
: NotifyOnAction |
| 9844 |
verbPhrase = 'turn/turning on score notification' |
| 9845 |
; |
| 9846 |
|
| 9847 |
VerbRule(NotifyOff) |
| 9848 |
'notify' 'off' |
| 9849 |
: NotifyOffAction |
| 9850 |
verbPhrase = 'turn/turning off score notification' |
| 9851 |
; |
| 9852 |
|
| 9853 |
VerbRule(Save) |
| 9854 |
'save' |
| 9855 |
: SaveAction |
| 9856 |
verbPhrase = 'save/saving' |
| 9857 |
; |
| 9858 |
|
| 9859 |
VerbRule(SaveString) |
| 9860 |
'save' quotedStringPhrase->fname_ |
| 9861 |
: SaveStringAction |
| 9862 |
verbPhrase = 'save/saving' |
| 9863 |
; |
| 9864 |
|
| 9865 |
VerbRule(Restore) |
| 9866 |
'restore' |
| 9867 |
: RestoreAction |
| 9868 |
verbPhrase = 'restore/restoring' |
| 9869 |
; |
| 9870 |
|
| 9871 |
VerbRule(RestoreString) |
| 9872 |
'restore' quotedStringPhrase->fname_ |
| 9873 |
: RestoreStringAction |
| 9874 |
verbPhrase = 'restore/restoring' |
| 9875 |
; |
| 9876 |
|
| 9877 |
VerbRule(SaveDefaults) |
| 9878 |
'save' 'defaults' |
| 9879 |
: SaveDefaultsAction |
| 9880 |
verbPhrase = 'save/saving defaults' |
| 9881 |
; |
| 9882 |
|
| 9883 |
VerbRule(RestoreDefaults) |
| 9884 |
'restore' 'defaults' |
| 9885 |
: RestoreDefaultsAction |
| 9886 |
verbPhrase = 'restore/restoring defaults' |
| 9887 |
; |
| 9888 |
|
| 9889 |
VerbRule(Restart) |
| 9890 |
'restart' |
| 9891 |
: RestartAction |
| 9892 |
verbPhrase = 'restart/restarting' |
| 9893 |
; |
| 9894 |
|
| 9895 |
VerbRule(Pause) |
| 9896 |
'pause' |
| 9897 |
: PauseAction |
| 9898 |
verbPhrase = 'pause/pausing' |
| 9899 |
; |
| 9900 |
|
| 9901 |
VerbRule(Undo) |
| 9902 |
'undo' |
| 9903 |
: UndoAction |
| 9904 |
verbPhrase = 'undo/undoing' |
| 9905 |
; |
| 9906 |
|
| 9907 |
VerbRule(Version) |
| 9908 |
'version' |
| 9909 |
: VersionAction |
| 9910 |
verbPhrase = 'show/showing version' |
| 9911 |
; |
| 9912 |
|
| 9913 |
VerbRule(Credits) |
| 9914 |
'credits' |
| 9915 |
: CreditsAction |
| 9916 |
verbPhrase = 'show/showing credits' |
| 9917 |
; |
| 9918 |
|
| 9919 |
VerbRule(About) |
| 9920 |
'about' |
| 9921 |
: AboutAction |
| 9922 |
verbPhrase = 'show/showing story information' |
| 9923 |
; |
| 9924 |
|
| 9925 |
VerbRule(Script) |
| 9926 |
'script' | 'script' 'on' |
| 9927 |
: ScriptAction |
| 9928 |
verbPhrase = 'start/starting scripting' |
| 9929 |
; |
| 9930 |
|
| 9931 |
VerbRule(ScriptString) |
| 9932 |
'script' quotedStringPhrase->fname_ |
| 9933 |
: ScriptStringAction |
| 9934 |
verbPhrase = 'start/starting scripting' |
| 9935 |
; |
| 9936 |
|
| 9937 |
VerbRule(ScriptOff) |
| 9938 |
'script' 'off' | 'unscript' |
| 9939 |
: ScriptOffAction |
| 9940 |
verbPhrase = 'end/ending scripting' |
| 9941 |
; |
| 9942 |
|
| 9943 |
VerbRule(Record) |
| 9944 |
'record' | 'record' 'on' |
| 9945 |
: RecordAction |
| 9946 |
verbPhrase = 'start/starting command recording' |
| 9947 |
; |
| 9948 |
|
| 9949 |
VerbRule(RecordString) |
| 9950 |
'record' quotedStringPhrase->fname_ |
| 9951 |
: RecordStringAction |
| 9952 |
verbPhrase = 'start/starting command recording' |
| 9953 |
; |
| 9954 |
|
| 9955 |
VerbRule(RecordEvents) |
| 9956 |
'record' 'events' | 'record' 'events' 'on' |
| 9957 |
: RecordEventsAction |
| 9958 |
verbPhrase = 'start/starting event recording' |
| 9959 |
; |
| 9960 |
|
| 9961 |
VerbRule(RecordEventsString) |
| 9962 |
'record' 'events' quotedStringPhrase->fname_ |
| 9963 |
: RecordEventsStringAction |
| 9964 |
verbPhrase = 'start/starting command recording' |
| 9965 |
; |
| 9966 |
|
| 9967 |
VerbRule(RecordOff) |
| 9968 |
'record' 'off' |
| 9969 |
: RecordOffAction |
| 9970 |
verbPhrase = 'end/ending command recording' |
| 9971 |
; |
| 9972 |
|
| 9973 |
VerbRule(ReplayString) |
| 9974 |
'replay' ('quiet'->quiet_ | 'nonstop'->nonstop_ | ) |
| 9975 |
(quotedStringPhrase->fname_ | ) |
| 9976 |
: ReplayStringAction |
| 9977 |
verbPhrase = 'replay/replaying command recording' |
| 9978 |
|
| 9979 |
/* set the appropriate option flags */ |
| 9980 |
scriptOptionFlags = ((quiet_ != nil ? ScriptFileQuiet : 0) |
| 9981 |
| (nonstop_ != nil ? ScriptFileNonstop : 0)) |
| 9982 |
; |
| 9983 |
VerbRule(ReplayQuiet) |
| 9984 |
'rq' (quotedStringPhrase->fname_ | ) |
| 9985 |
: ReplayStringAction |
| 9986 |
|
| 9987 |
scriptOptionFlags = ScriptFileQuiet |
| 9988 |
; |
| 9989 |
|
| 9990 |
VerbRule(VagueTravel) 'go' | 'walk' : VagueTravelAction |
| 9991 |
verbPhrase = 'go/going' |
| 9992 |
; |
| 9993 |
|
| 9994 |
VerbRule(Travel) |
| 9995 |
'go' singleDir | singleDir |
| 9996 |
: TravelAction |
| 9997 |
verbPhrase = ('go/going ' + dirMatch.dir.name) |
| 9998 |
; |
| 9999 |
|
| 10000 |
/* |
| 10001 |
* Create a TravelVia subclass merely so we can supply a verbPhrase. |
| 10002 |
* (The parser looks for subclasses of each specific Action class to find |
| 10003 |
* its verb phrase, since the language-specific Action definitions are |
| 10004 |
* always in the language module's 'grammar' subclasses. We don't need |
| 10005 |
* an actual grammar rule, since this isn't an input-able verb, so we |
| 10006 |
* merely need to create a regular subclass in order for the verbPhrase |
| 10007 |
* to get found.) |
| 10008 |
*/ |
| 10009 |
class EnTravelVia: TravelViaAction |
| 10010 |
verbPhrase = 'use/using (what)' |
| 10011 |
; |
| 10012 |
|
| 10013 |
VerbRule(Port) |
| 10014 |
'go' 'to' ('port' | 'p') |
| 10015 |
: PortAction |
| 10016 |
dirMatch: DirectionProd { dir = portDirection } |
| 10017 |
verbPhrase = 'go/going to port' |
| 10018 |
; |
| 10019 |
|
| 10020 |
VerbRule(Starboard) |
| 10021 |
'go' 'to' ('starboard' | 'sb') |
| 10022 |
: StarboardAction |
| 10023 |
dirMatch: DirectionProd { dir = starboardDirection } |
| 10024 |
verbPhrase = 'go/going to starboard' |
| 10025 |
; |
| 10026 |
|
| 10027 |
VerbRule(In) |
| 10028 |
'enter' |
| 10029 |
: InAction |
| 10030 |
dirMatch: DirectionProd { dir = inDirection } |
| 10031 |
verbPhrase = 'enter/entering' |
| 10032 |
; |
| 10033 |
|
| 10034 |
VerbRule(Out) |
| 10035 |
'exit' | 'leave' |
| 10036 |
: OutAction |
| 10037 |
dirMatch: DirectionProd { dir = outDirection } |
| 10038 |
verbPhrase = 'exit/exiting' |
| 10039 |
; |
| 10040 |
|
| 10041 |
VerbRule(GoThrough) |
| 10042 |
('walk' | 'go' ) ('through' | 'thru') |
| 10043 |
singleDobj |
| 10044 |
: GoThroughAction |
| 10045 |
verbPhrase = 'go/going (through what)' |
| 10046 |
askDobjResponseProd = singleNoun |
| 10047 |
; |
| 10048 |
|
| 10049 |
VerbRule(Enter) |
| 10050 |
('enter' | 'in' | 'into' | 'in' 'to' |
| 10051 |
| ('walk' | 'go') ('to' | 'in' | 'in' 'to' | 'into')) |
| 10052 |
singleDobj |
| 10053 |
: EnterAction |
| 10054 |
verbPhrase = 'enter/entering (what)' |
| 10055 |
askDobjResponseProd = singleNoun |
| 10056 |
; |
| 10057 |
|
| 10058 |
VerbRule(GoBack) |
| 10059 |
'back' | 'go' 'back' | 'return' |
| 10060 |
: GoBackAction |
| 10061 |
verbPhrase = 'go/going back' |
| 10062 |
; |
| 10063 |
|
| 10064 |
VerbRule(Dig) |
| 10065 |
('dig' | 'dig' 'in') singleDobj |
| 10066 |
: DigAction |
| 10067 |
verbPhrase = 'dig/digging (in what)' |
| 10068 |
askDobjResponseProd = inSingleNoun |
| 10069 |
; |
| 10070 |
|
| 10071 |
VerbRule(DigWith) |
| 10072 |
('dig' | 'dig' 'in') singleDobj 'with' singleIobj |
| 10073 |
: DigWithAction |
| 10074 |
verbPhrase = 'dig/digging (in what) (with what)' |
| 10075 |
omitIobjInDobjQuery = true |
| 10076 |
askDobjResponseProd = inSingleNoun |
| 10077 |
askIobjResponseProd = withSingleNoun |
| 10078 |
; |
| 10079 |
|
| 10080 |
VerbRule(Jump) |
| 10081 |
'jump' |
| 10082 |
: JumpAction |
| 10083 |
verbPhrase = 'jump/jumping' |
| 10084 |
; |
| 10085 |
|
| 10086 |
VerbRule(JumpOffI) |
| 10087 |
'jump' 'off' |
| 10088 |
: JumpOffIAction |
| 10089 |
verbPhrase = 'jump/jumping off' |
| 10090 |
; |
| 10091 |
|
| 10092 |
VerbRule(JumpOff) |
| 10093 |
'jump' 'off' singleDobj |
| 10094 |
: JumpOffAction |
| 10095 |
verbPhrase = 'jump/jumping (off what)' |
| 10096 |
askDobjResponseProd = singleNoun |
| 10097 |
; |
| 10098 |
|
| 10099 |
VerbRule(JumpOver) |
| 10100 |
('jump' | 'jump' 'over') singleDobj |
| 10101 |
: JumpOverAction |
| 10102 |
verbPhrase = 'jump/jumping (over what)' |
| 10103 |
askDobjResponseProd = singleNoun |
| 10104 |
; |
| 10105 |
|
| 10106 |
VerbRule(Push) |
| 10107 |
('push' | 'press') dobjList |
| 10108 |
: PushAction |
| 10109 |
verbPhrase = 'push/pushing (what)' |
| 10110 |
; |
| 10111 |
|
| 10112 |
VerbRule(Pull) |
| 10113 |
'pull' dobjList |
| 10114 |
: PullAction |
| 10115 |
verbPhrase = 'pull/pulling (what)' |
| 10116 |
; |
| 10117 |
|
| 10118 |
VerbRule(Move) |
| 10119 |
'move' dobjList |
| 10120 |
: MoveAction |
| 10121 |
verbPhrase = 'move/moving (what)' |
| 10122 |
; |
| 10123 |
|
| 10124 |
VerbRule(MoveTo) |
| 10125 |
('push' | 'move') dobjList ('to' | 'under') singleIobj |
| 10126 |
: MoveToAction |
| 10127 |
verbPhrase = 'move/moving (what) (to what)' |
| 10128 |
askIobjResponseProd = toSingleNoun |
| 10129 |
omitIobjInDobjQuery = true |
| 10130 |
; |
| 10131 |
|
| 10132 |
VerbRule(MoveWith) |
| 10133 |
'move' singleDobj 'with' singleIobj |
| 10134 |
: MoveWithAction |
| 10135 |
verbPhrase = 'move/moving (what) (with what)' |
| 10136 |
askDobjResponseProd = singleNoun |
| 10137 |
askIobjResponseProd = withSingleNoun |
| 10138 |
omitIobjInDobjQuery = true |
| 10139 |
; |
| 10140 |
|
| 10141 |
VerbRule(Turn) |
| 10142 |
('turn' | 'twist' | 'rotate') dobjList |
| 10143 |
: TurnAction |
| 10144 |
verbPhrase = 'turn/turning (what)' |
| 10145 |
; |
| 10146 |
|
| 10147 |
VerbRule(TurnWith) |
| 10148 |
('turn' | 'twist' | 'rotate') singleDobj 'with' singleIobj |
| 10149 |
: TurnWithAction |
| 10150 |
verbPhrase = 'turn/turning (what) (with what)' |
| 10151 |
askDobjResponseProd = singleNoun |
| 10152 |
askIobjResponseProd = withSingleNoun |
| 10153 |
; |
| 10154 |
|
| 10155 |
VerbRule(TurnTo) |
| 10156 |
('turn' | 'twist' | 'rotate') singleDobj |
| 10157 |
'to' singleLiteral |
| 10158 |
: TurnToAction |
| 10159 |
verbPhrase = 'turn/turning (what) (to what)' |
| 10160 |
askDobjResponseProd = singleNoun |
| 10161 |
omitIobjInDobjQuery = true |
| 10162 |
; |
| 10163 |
|
| 10164 |
VerbRule(Set) |
| 10165 |
'set' dobjList |
| 10166 |
: SetAction |
| 10167 |
verbPhrase = 'set/setting (what)' |
| 10168 |
; |
| 10169 |
|
| 10170 |
VerbRule(SetTo) |
| 10171 |
'set' singleDobj 'to' singleLiteral |
| 10172 |
: SetToAction |
| 10173 |
verbPhrase = 'set/setting (what) (to what)' |
| 10174 |
askDobjResponseProd = singleNoun |
| 10175 |
omitIobjInDobjQuery = true |
| 10176 |
; |
| 10177 |
|
| 10178 |
VerbRule(TypeOn) |
| 10179 |
'type' 'on' singleDobj |
| 10180 |
: TypeOnAction |
| 10181 |
verbPhrase = 'type/typing (on what)' |
| 10182 |
; |
| 10183 |
|
| 10184 |
VerbRule(TypeLiteralOn) |
| 10185 |
'type' singleLiteral 'on' singleDobj |
| 10186 |
: TypeLiteralOnAction |
| 10187 |
verbPhrase = 'type/typing (what) (on what)' |
| 10188 |
askDobjResponseProd = singleNoun |
| 10189 |
; |
| 10190 |
|
| 10191 |
VerbRule(TypeLiteralOnWhat) |
| 10192 |
[badness 500] 'type' singleLiteral |
| 10193 |
: TypeLiteralOnAction |
| 10194 |
verbPhrase = 'type/typing (what) (on what)' |
| 10195 |
construct() |
| 10196 |
{ |
| 10197 |
/* set up the empty direct object phrase */ |
| 10198 |
dobjMatch = new EmptyNounPhraseProd(); |
| 10199 |
dobjMatch.responseProd = onSingleNoun; |
| 10200 |
} |
| 10201 |
; |
| 10202 |
|
| 10203 |
VerbRule(EnterOn) |
| 10204 |
'enter' singleLiteral |
| 10205 |
('on' | 'in' | 'in' 'to' | 'into' | 'with') singleDobj |
| 10206 |
: EnterOnAction |
| 10207 |
verbPhrase = 'enter/entering (what) (on what)' |
| 10208 |
askDobjResponseProd = singleNoun |
| 10209 |
; |
| 10210 |
|
| 10211 |
VerbRule(EnterOnWhat) |
| 10212 |
'enter' singleLiteral |
| 10213 |
: EnterOnAction |
| 10214 |
verbPhrase = 'enter/entering (what) (on what)' |
| 10215 |
construct() |
| 10216 |
{ |
| 10217 |
/* |
| 10218 |
* ENTER <text> is a little special, because it could mean ENTER |
| 10219 |
* <text> ON <keypad>, or it could mean GO INTO <object>. It's |
| 10220 |
* hard to tell which based on the grammar alone, so we have to |
| 10221 |
* do some semantic analysis to make a good decision about it. |
| 10222 |
* |
| 10223 |
* We'll start by assuming it's the ENTER <text> ON <iobj> form |
| 10224 |
* of the command, and we'll look for a suitable default object |
| 10225 |
* to serve as the iobj. If we can't find a suitable default, we |
| 10226 |
* won't prompt for the missing object as we usually would. |
| 10227 |
* Instead, we'll try re-parsing the command as GO INTO. To do |
| 10228 |
* this, use our custom "asker" - this won't actually prompt for |
| 10229 |
* the missing object, but will instead retry the command as a GO |
| 10230 |
* INTO command. |
| 10231 |
*/ |
| 10232 |
dobjMatch = new EmptyNounPhraseProd(); |
| 10233 |
dobjMatch.setPrompt(onSingleNoun, enterOnWhatAsker); |
| 10234 |
} |
| 10235 |
; |
| 10236 |
|
| 10237 |
/* our custom "asker" for the missing iobj in an "ENTER <text>" command */ |
| 10238 |
enterOnWhatAsker: ResolveAsker |
| 10239 |
askMissingObject(targetActor, action, which) |
| 10240 |
{ |
| 10241 |
/* |
| 10242 |
* This method is called when the resolver has failed to find a |
| 10243 |
* suitable default for the missing indirect object of ENTER |
| 10244 |
* <text> ON <iobj>. |
| 10245 |
* |
| 10246 |
* Instead of issuing the prompt that we'd normally issue under |
| 10247 |
* these circumstances, assume that we're totally wrong about the |
| 10248 |
* way we've been interpreting the command: assume that it's not |
| 10249 |
* meant as ENTER <text> ON <iobj> after all, but was actually |
| 10250 |
* meant as GO IN <object>. So, rephrase the command as such and |
| 10251 |
* start over with the new phrasing. |
| 10252 |
*/ |
| 10253 |
throw new ReplacementCommandStringException( |
| 10254 |
'get in ' + action.getLiteral(), gIssuingActor, gActor); |
| 10255 |
} |
| 10256 |
; |
| 10257 |
|
| 10258 |
VerbRule(Consult) |
| 10259 |
'consult' singleDobj : ConsultAction |
| 10260 |
verbPhrase = 'consult/consulting (what)' |
| 10261 |
askDobjResponseProd = singleNoun |
| 10262 |
; |
| 10263 |
|
| 10264 |
VerbRule(ConsultAbout) |
| 10265 |
'consult' singleDobj ('on' | 'about') singleTopic |
| 10266 |
| 'search' singleDobj 'for' singleTopic |
| 10267 |
| (('look' | 'l') ('up' | 'for') |
| 10268 |
| 'find' |
| 10269 |
| 'search' 'for' |
| 10270 |
| 'read' 'about') |
| 10271 |
singleTopic 'in' singleDobj |
| 10272 |
| ('look' | 'l') singleTopic 'up' 'in' singleDobj |
| 10273 |
: ConsultAboutAction |
| 10274 |
verbPhrase = 'consult/consulting (what) (about what)' |
| 10275 |
omitIobjInDobjQuery = true |
| 10276 |
askDobjResponseProd = singleNoun |
| 10277 |
; |
| 10278 |
|
| 10279 |
VerbRule(ConsultWhatAbout) |
| 10280 |
(('look' | 'l') ('up' | 'for') |
| 10281 |
| 'find' |
| 10282 |
| 'search' 'for' |
| 10283 |
| 'read' 'about') |
| 10284 |
singleTopic |
| 10285 |
| ('look' | 'l') singleTopic 'up' |
| 10286 |
: ConsultAboutAction |
| 10287 |
verbPhrase = 'look/looking up (what) (in what)' |
| 10288 |
whichMessageTopic = DirectObject |
| 10289 |
construct() |
| 10290 |
{ |
| 10291 |
/* set up the empty direct object phrase */ |
| 10292 |
dobjMatch = new EmptyNounPhraseProd(); |
| 10293 |
dobjMatch.responseProd = inSingleNoun; |
| 10294 |
} |
| 10295 |
; |
| 10296 |
|
| 10297 |
VerbRule(Switch) |
| 10298 |
'switch' dobjList |
| 10299 |
: SwitchAction |
| 10300 |
verbPhrase = 'switch/switching (what)' |
| 10301 |
; |
| 10302 |
|
| 10303 |
VerbRule(Flip) |
| 10304 |
'flip' dobjList |
| 10305 |
: FlipAction |
| 10306 |
verbPhrase = 'flip/flipping (what)' |
| 10307 |
; |
| 10308 |
|
| 10309 |
VerbRule(TurnOn) |
| 10310 |
('activate' | ('turn' | 'switch') 'on') dobjList |
| 10311 |
| ('turn' | 'switch') dobjList 'on' |
| 10312 |
: TurnOnAction |
| 10313 |
verbPhrase = 'turn/turning on (what)' |
| 10314 |
; |
| 10315 |
|
| 10316 |
VerbRule(TurnOff) |
| 10317 |
('deactivate' | ('turn' | 'switch') 'off') dobjList |
| 10318 |
| ('turn' | 'switch') dobjList 'off' |
| 10319 |
: TurnOffAction |
| 10320 |
verbPhrase = 'turn/turning off (what)' |
| 10321 |
; |
| 10322 |
|
| 10323 |
VerbRule(Light) |
| 10324 |
'light' dobjList |
| 10325 |
: LightAction |
| 10326 |
verbPhrase = 'light/lighting (what)' |
| 10327 |
; |
| 10328 |
|
| 10329 |
DefineTAction(Strike); |
| 10330 |
VerbRule(Strike) |
| 10331 |
'strike' dobjList |
| 10332 |
: StrikeAction |
| 10333 |
verbPhrase = 'strike/striking (what)' |
| 10334 |
; |
| 10335 |
|
| 10336 |
VerbRule(Burn) |
| 10337 |
('burn' | 'ignite' | 'set' 'fire' 'to') dobjList |
| 10338 |
: BurnAction |
| 10339 |
verbPhrase = 'light/lighting (what)' |
| 10340 |
; |
| 10341 |
|
| 10342 |
VerbRule(BurnWith) |
| 10343 |
('light' | 'burn' | 'ignite' | 'set' 'fire' 'to') singleDobj |
| 10344 |
'with' singleIobj |
| 10345 |
: BurnWithAction |
| 10346 |
verbPhrase = 'light/lighting (what) (with what)' |
| 10347 |
omitIobjInDobjQuery = true |
| 10348 |
askDobjResponseProd = singleNoun |
| 10349 |
askIobjResponseProd = withSingleNoun |
| 10350 |
; |
| 10351 |
|
| 10352 |
VerbRule(Extinguish) |
| 10353 |
('extinguish' | 'douse' | 'put' 'out' | 'blow' 'out') dobjList |
| 10354 |
| ('blow' | 'put') dobjList 'out' |
| 10355 |
: ExtinguishAction |
| 10356 |
verbPhrase = 'extinguish/extinguishing (what)' |
| 10357 |
; |
| 10358 |
|
| 10359 |
VerbRule(Break) |
| 10360 |
('break' | 'ruin' | 'destroy' | 'wreck') dobjList |
| 10361 |
: BreakAction |
| 10362 |
verbPhrase = 'break/breaking (what)' |
| 10363 |
; |
| 10364 |
|
| 10365 |
VerbRule(CutWithWhat) |
| 10366 |
[badness 500] 'cut' singleDobj |
| 10367 |
: CutWithAction |
| 10368 |
verbPhrase = 'cut/cutting (what) (with what)' |
| 10369 |
construct() |
| 10370 |
{ |
| 10371 |
/* set up the empty indirect object phrase */ |
| 10372 |
iobjMatch = new EmptyNounPhraseProd(); |
| 10373 |
iobjMatch.responseProd = withSingleNoun; |
| 10374 |
} |
| 10375 |
; |
| 10376 |
|
| 10377 |
VerbRule(CutWith) |
| 10378 |
'cut' singleDobj 'with' singleIobj |
| 10379 |
: CutWithAction |
| 10380 |
verbPhrase = 'cut/cutting (what) (with what)' |
| 10381 |
askDobjResponseProd = singleNoun |
| 10382 |
askIobjResponseProd = withSingleNoun |
| 10383 |
; |
| 10384 |
|
| 10385 |
VerbRule(Eat) |
| 10386 |
('eat' | 'consume') dobjList |
| 10387 |
: EatAction |
| 10388 |
verbPhrase = 'eat/eating (what)' |
| 10389 |
; |
| 10390 |
|
| 10391 |
VerbRule(Drink) |
| 10392 |
('drink' | 'quaff' | 'imbibe') dobjList |
| 10393 |
: DrinkAction |
| 10394 |
verbPhrase = 'drink/drinking (what)' |
| 10395 |
; |
| 10396 |
|
| 10397 |
VerbRule(Pour) |
| 10398 |
'pour' dobjList |
| 10399 |
: PourAction |
| 10400 |
verbPhrase = 'pour/pouring (what)' |
| 10401 |
; |
| 10402 |
|
| 10403 |
VerbRule(PourInto) |
| 10404 |
'pour' dobjList ('in' | 'into' | 'in' 'to') singleIobj |
| 10405 |
: PourIntoAction |
| 10406 |
verbPhrase = 'pour/pouring (what) (into what)' |
| 10407 |
askIobjResponseProd = inSingleNoun |
| 10408 |
; |
| 10409 |
|
| 10410 |
VerbRule(PourOnto) |
| 10411 |
'pour' dobjList ('on' | 'onto' | 'on' 'to') singleIobj |
| 10412 |
: PourOntoAction |
| 10413 |
verbPhrase = 'pour/pouring (what) (onto what)' |
| 10414 |
askIobjResponseProd = onSingleNoun |
| 10415 |
; |
| 10416 |
|
| 10417 |
VerbRule(Climb) |
| 10418 |
'climb' singleDobj |
| 10419 |
: ClimbAction |
| 10420 |
verbPhrase = 'climb/climbing (what)' |
| 10421 |
askDobjResponseProd = singleNoun |
| 10422 |
; |
| 10423 |
|
| 10424 |
VerbRule(ClimbUp) |
| 10425 |
('climb' | 'go' | 'walk') 'up' singleDobj |
| 10426 |
: ClimbUpAction |
| 10427 |
verbPhrase = 'climb/climbing (up what)' |
| 10428 |
askDobjResponseProd = singleNoun |
| 10429 |
; |
| 10430 |
|
| 10431 |
VerbRule(ClimbUpWhat) |
| 10432 |
[badness 200] ('climb' | 'go' | 'walk') 'up' |
| 10433 |
: ClimbUpAction |
| 10434 |
verbPhrase = 'climb/climbing (up what)' |
| 10435 |
askDobjResponseProd = singleNoun |
| 10436 |
construct() |
| 10437 |
{ |
| 10438 |
dobjMatch = new EmptyNounPhraseProd(); |
| 10439 |
dobjMatch.responseProd = onSingleNoun; |
| 10440 |
} |
| 10441 |
; |
| 10442 |
|
| 10443 |
VerbRule(ClimbDown) |
| 10444 |
('climb' | 'go' | 'walk') 'down' singleDobj |
| 10445 |
: ClimbDownAction |
| 10446 |
verbPhrase = 'climb/climbing (down what)' |
| 10447 |
askDobjResponseProd = singleNoun |
| 10448 |
; |
| 10449 |
|
| 10450 |
VerbRule(ClimbDownWhat) |
| 10451 |
[badness 200] ('climb' | 'go' | 'walk') 'down' |
| 10452 |
: ClimbDownAction |
| 10453 |
verbPhrase = 'climb/climbing (down what)' |
| 10454 |
askDobjResponseProd = singleNoun |
| 10455 |
construct() |
| 10456 |
{ |
| 10457 |
dobjMatch = new EmptyNounPhraseProd(); |
| 10458 |
dobjMatch.responseProd = onSingleNoun; |
| 10459 |
} |
| 10460 |
; |
| 10461 |
|
| 10462 |
VerbRule(Clean) |
| 10463 |
'clean' dobjList |
| 10464 |
: CleanAction |
| 10465 |
verbPhrase = 'clean/cleaning (what)' |
| 10466 |
; |
| 10467 |
|
| 10468 |
VerbRule(CleanWith) |
| 10469 |
'clean' dobjList 'with' singleIobj |
| 10470 |
: CleanWithAction |
| 10471 |
verbPhrase = 'clean/cleaning (what) (with what)' |
| 10472 |
askIobjResponseProd = withSingleNoun |
| 10473 |
omitIobjInDobjQuery = true |
| 10474 |
; |
| 10475 |
|
| 10476 |
VerbRule(AttachTo) |
| 10477 |
('attach' | 'connect') dobjList 'to' singleIobj |
| 10478 |
: AttachToAction |
| 10479 |
askIobjResponseProd = toSingleNoun |
| 10480 |
verbPhrase = 'attach/attaching (what) (to what)' |
| 10481 |
; |
| 10482 |
|
| 10483 |
VerbRule(AttachToWhat) |
| 10484 |
[badness 500] ('attach' | 'connect') dobjList |
| 10485 |
: AttachToAction |
| 10486 |
verbPhrase = 'attach/attaching (what) (to what)' |
| 10487 |
construct() |
| 10488 |
{ |
| 10489 |
/* set up the empty indirect object phrase */ |
| 10490 |
iobjMatch = new EmptyNounPhraseProd(); |
| 10491 |
iobjMatch.responseProd = toSingleNoun; |
| 10492 |
} |
| 10493 |
; |
| 10494 |
|
| 10495 |
VerbRule(DetachFrom) |
| 10496 |
('detach' | 'disconnect') dobjList 'from' singleIobj |
| 10497 |
: DetachFromAction |
| 10498 |
verbPhrase = 'detach/detaching (what) (from what)' |
| 10499 |
askIobjResponseProd = fromSingleNoun |
| 10500 |
; |
| 10501 |
|
| 10502 |
VerbRule(Detach) |
| 10503 |
('detach' | 'disconnect') dobjList |
| 10504 |
: DetachAction |
| 10505 |
verbPhrase = 'detach/detaching (what)' |
| 10506 |
; |
| 10507 |
|
| 10508 |
VerbRule(Open) |
| 10509 |
'open' dobjList |
| 10510 |
: OpenAction |
| 10511 |
verbPhrase = 'open/opening (what)' |
| 10512 |
; |
| 10513 |
|
| 10514 |
VerbRule(Close) |
| 10515 |
('close' | 'shut') dobjList |
| 10516 |
: CloseAction |
| 10517 |
verbPhrase = 'close/closing (what)' |
| 10518 |
; |
| 10519 |
|
| 10520 |
VerbRule(Lock) |
| 10521 |
'lock' dobjList |
| 10522 |
: LockAction |
| 10523 |
verbPhrase = 'lock/locking (what)' |
| 10524 |
; |
| 10525 |
|
| 10526 |
VerbRule(Unlock) |
| 10527 |
'unlock' dobjList |
| 10528 |
: UnlockAction |
| 10529 |
verbPhrase = 'unlock/unlocking (what)' |
| 10530 |
; |
| 10531 |
|
| 10532 |
VerbRule(LockWith) |
| 10533 |
'lock' singleDobj 'with' singleIobj |
| 10534 |
: LockWithAction |
| 10535 |
verbPhrase = 'lock/locking (what) (with what)' |
| 10536 |
omitIobjInDobjQuery = true |
| 10537 |
askDobjResponseProd = singleNoun |
| 10538 |
askIobjResponseProd = withSingleNoun |
| 10539 |
; |
| 10540 |
|
| 10541 |
VerbRule(UnlockWith) |
| 10542 |
'unlock' singleDobj 'with' singleIobj |
| 10543 |
: UnlockWithAction |
| 10544 |
verbPhrase = 'unlock/unlocking (what) (with what)' |
| 10545 |
omitIobjInDobjQuery = true |
| 10546 |
askDobjResponseProd = singleNoun |
| 10547 |
askIobjResponseProd = withSingleNoun |
| 10548 |
; |
| 10549 |
|
| 10550 |
VerbRule(SitOn) |
| 10551 |
'sit' ('on' | 'in' | 'down' 'on' | 'down' 'in') |
| 10552 |
singleDobj |
| 10553 |
: SitOnAction |
| 10554 |
verbPhrase = 'sit/sitting (on what)' |
| 10555 |
askDobjResponseProd = singleNoun |
| 10556 |
|
| 10557 |
/* use the actorInPrep, if there's a direct object available */ |
| 10558 |
adjustDefaultObjectPrep(prep, obj) |
| 10559 |
{ return (obj != nil ? obj.actorInPrep + ' ' : prep); } |
| 10560 |
; |
| 10561 |
|
| 10562 |
VerbRule(Sit) |
| 10563 |
'sit' ( | 'down') : SitAction |
| 10564 |
verbPhrase = 'sit/sitting down' |
| 10565 |
; |
| 10566 |
|
| 10567 |
VerbRule(LieOn) |
| 10568 |
'lie' ('on' | 'in' | 'down' 'on' | 'down' 'in') |
| 10569 |
singleDobj |
| 10570 |
: LieOnAction |
| 10571 |
verbPhrase = 'lie/lying (on what)' |
| 10572 |
askDobjResponseProd = singleNoun |
| 10573 |
|
| 10574 |
/* use the actorInPrep, if there's a direct object available */ |
| 10575 |
adjustDefaultObjectPrep(prep, obj) |
| 10576 |
{ return (obj != nil ? obj.actorInPrep + ' ' : prep); } |
| 10577 |
; |
| 10578 |
|
| 10579 |
VerbRule(Lie) |
| 10580 |
'lie' ( | 'down') : LieAction |
| 10581 |
verbPhrase = 'lie/lying down' |
| 10582 |
; |
| 10583 |
|
| 10584 |
VerbRule(StandOn) |
| 10585 |
('stand' ('on' | 'in' | 'onto' | 'on' 'to' | 'into' | 'in' 'to') |
| 10586 |
| 'climb' ('on' | 'onto' | 'on' 'to')) |
| 10587 |
singleDobj |
| 10588 |
: StandOnAction |
| 10589 |
verbPhrase = 'stand/standing (on what)' |
| 10590 |
askDobjResponseProd = singleNoun |
| 10591 |
|
| 10592 |
/* use the actorInPrep, if there's a direct object available */ |
| 10593 |
adjustDefaultObjectPrep(prep, obj) |
| 10594 |
{ return (obj != nil ? obj.actorInPrep + ' ' : prep); } |
| 10595 |
; |
| 10596 |
|
| 10597 |
VerbRule(Stand) |
| 10598 |
'stand' | 'stand' 'up' | 'get' 'up' |
| 10599 |
: StandAction |
| 10600 |
verbPhrase = 'stand/standing up' |
| 10601 |
; |
| 10602 |
|
| 10603 |
VerbRule(GetOutOf) |
| 10604 |
('out' 'of' | 'get' 'out' 'of' | 'climb' 'out' 'of' | 'leave' | 'exit') |
| 10605 |
singleDobj |
| 10606 |
: GetOutOfAction |
| 10607 |
verbPhrase = 'get/getting (out of what)' |
| 10608 |
askDobjResponseProd = singleNoun |
| 10609 |
|
| 10610 |
/* use the actorOutOfPrep, if there's a direct object available */ |
| 10611 |
adjustDefaultObjectPrep(prep, obj) |
| 10612 |
{ return (obj != nil ? obj.actorOutOfPrep + ' ' : prep); } |
| 10613 |
; |
| 10614 |
|
| 10615 |
VerbRule(GetOffOf) |
| 10616 |
'get' ('off' | 'off' 'of' | 'down' 'from') singleDobj |
| 10617 |
: GetOffOfAction |
| 10618 |
verbPhrase = 'get/getting (off of what)' |
| 10619 |
askDobjResponseProd = singleNoun |
| 10620 |
|
| 10621 |
/* use the actorOutOfPrep, if there's a direct object available */ |
| 10622 |
adjustDefaultObjectPrep(prep, obj) |
| 10623 |
{ return (obj != nil ? obj.actorOutOfPrep + ' ' : prep); } |
| 10624 |
; |
| 10625 |
|
| 10626 |
VerbRule(GetOut) |
| 10627 |
'get' 'out' |
| 10628 |
| 'get' 'off' |
| 10629 |
| 'get' 'down' |
| 10630 |
| 'disembark' |
| 10631 |
| 'climb' 'out' |
| 10632 |
: GetOutAction |
| 10633 |
verbPhrase = 'get/getting out' |
| 10634 |
; |
| 10635 |
|
| 10636 |
VerbRule(Board) |
| 10637 |
('board' |
| 10638 |
| ('get' ('in' | 'into' | 'in' 'to' | 'on' | 'onto' | 'on' 'to')) |
| 10639 |
| ('climb' ('in' | 'into' | 'in' 'to'))) |
| 10640 |
singleDobj |
| 10641 |
: BoardAction |
| 10642 |
verbPhrase = 'get/getting (in what)' |
| 10643 |
askDobjResponseProd = singleNoun |
| 10644 |
; |
| 10645 |
|
| 10646 |
VerbRule(Sleep) |
| 10647 |
'sleep' |
| 10648 |
: SleepAction |
| 10649 |
verbPhrase = 'sleep/sleeping' |
| 10650 |
; |
| 10651 |
|
| 10652 |
VerbRule(Fasten) |
| 10653 |
('fasten' | 'buckle' | 'buckle' 'up') dobjList |
| 10654 |
: FastenAction |
| 10655 |
verbPhrase = 'fasten/fastening (what)' |
| 10656 |
; |
| 10657 |
|
| 10658 |
VerbRule(FastenTo) |
| 10659 |
('fasten' | 'buckle') dobjList 'to' singleIobj |
| 10660 |
: FastenToAction |
| 10661 |
verbPhrase = 'fasten/fastening (what) (to what)' |
| 10662 |
askIobjResponseProd = toSingleNoun |
| 10663 |
; |
| 10664 |
|
| 10665 |
VerbRule(Unfasten) |
| 10666 |
('unfasten' | 'unbuckle') dobjList |
| 10667 |
: UnfastenAction |
| 10668 |
verbPhrase = 'unfasten/unfastening (what)' |
| 10669 |
; |
| 10670 |
|
| 10671 |
VerbRule(UnfastenFrom) |
| 10672 |
('unfasten' | 'unbuckle') dobjList 'from' singleIobj |
| 10673 |
: UnfastenFromAction |
| 10674 |
verbPhrase = 'unfasten/unfastening (what) (from what)' |
| 10675 |
askIobjResponseProd = fromSingleNoun |
| 10676 |
; |
| 10677 |
|
| 10678 |
VerbRule(PlugInto) |
| 10679 |
'plug' dobjList ('in' | 'into' | 'in' 'to') singleIobj |
| 10680 |
: PlugIntoAction |
| 10681 |
verbPhrase = 'plug/plugging (what) (into what)' |
| 10682 |
askIobjResponseProd = inSingleNoun |
| 10683 |
; |
| 10684 |
|
| 10685 |
VerbRule(PlugIntoWhat) |
| 10686 |
[badness 500] 'plug' dobjList |
| 10687 |
: PlugIntoAction |
| 10688 |
verbPhrase = 'plug/plugging (what) (into what)' |
| 10689 |
construct() |
| 10690 |
{ |
| 10691 |
/* set up the empty indirect object phrase */ |
| 10692 |
iobjMatch = new EmptyNounPhraseProd(); |
| 10693 |
iobjMatch.responseProd = inSingleNoun; |
| 10694 |
} |
| 10695 |
; |
| 10696 |
|
| 10697 |
VerbRule(PlugIn) |
| 10698 |
'plug' dobjList 'in' |
| 10699 |
| 'plug' 'in' dobjList |
| 10700 |
: PlugInAction |
| 10701 |
verbPhrase = 'plug/plugging (what)' |
| 10702 |
; |
| 10703 |
|
| 10704 |
VerbRule(UnplugFrom) |
| 10705 |
'unplug' dobjList 'from' singleIobj |
| 10706 |
: UnplugFromAction |
| 10707 |
verbPhrase = 'unplug/unplugging (what) (from what)' |
| 10708 |
askIobjResponseProd = fromSingleNoun |
| 10709 |
; |
| 10710 |
|
| 10711 |
VerbRule(Unplug) |
| 10712 |
'unplug' dobjList |
| 10713 |
: UnplugAction |
| 10714 |
verbPhrase = 'unplug/unplugging (what)' |
| 10715 |
; |
| 10716 |
|
| 10717 |
VerbRule(Screw) |
| 10718 |
'screw' dobjList |
| 10719 |
: ScrewAction |
| 10720 |
verbPhrase = 'screw/screwing (what)' |
| 10721 |
; |
| 10722 |
|
| 10723 |
VerbRule(ScrewWith) |
| 10724 |
'screw' dobjList 'with' singleIobj |
| 10725 |
: ScrewWithAction |
| 10726 |
verbPhrase = 'screw/screwing (what) (with what)' |
| 10727 |
omitIobjInDobjQuery = true |
| 10728 |
askIobjResponseProd = withSingleNoun |
| 10729 |
; |
| 10730 |
|
| 10731 |
VerbRule(Unscrew) |
| 10732 |
'unscrew' dobjList |
| 10733 |
: UnscrewAction |
| 10734 |
verbPhrase = 'unscrew/unscrewing (what)' |
| 10735 |
; |
| 10736 |
|
| 10737 |
VerbRule(UnscrewWith) |
| 10738 |
'unscrew' dobjList 'with' singleIobj |
| 10739 |
: UnscrewWithAction |
| 10740 |
verbPhrase = 'unscrew/unscrewing (what) (with what)' |
| 10741 |
omitIobjInDobjQuery = true |
| 10742 |
askIobjResponseProd = withSingleNoun |
| 10743 |
; |
| 10744 |
|
| 10745 |
VerbRule(PushTravelDir) |
| 10746 |
('push' | 'pull' | 'drag' | 'move') singleDobj singleDir |
| 10747 |
: PushTravelDirAction |
| 10748 |
verbPhrase = ('push/pushing (what) ' + dirMatch.dir.name) |
| 10749 |
; |
| 10750 |
|
| 10751 |
VerbRule(PushTravelThrough) |
| 10752 |
('push' | 'pull' | 'drag' | 'move') singleDobj |
| 10753 |
('through' | 'thru') singleIobj |
| 10754 |
: PushTravelThroughAction |
| 10755 |
verbPhrase = 'push/pushing (what) (through what)' |
| 10756 |
; |
| 10757 |
|
| 10758 |
VerbRule(PushTravelEnter) |
| 10759 |
('push' | 'pull' | 'drag' | 'move') singleDobj |
| 10760 |
('in' | 'into' | 'in' 'to') singleIobj |
| 10761 |
: PushTravelEnterAction |
| 10762 |
verbPhrase = 'push/pushing (what) (into what)' |
| 10763 |
; |
| 10764 |
|
| 10765 |
VerbRule(PushTravelGetOutOf) |
| 10766 |
('push' | 'pull' | 'drag' | 'move') singleDobj |
| 10767 |
'out' ('of' | ) singleIobj |
| 10768 |
: PushTravelGetOutOfAction |
| 10769 |
verbPhrase = 'push/pushing (what) (out of what)' |
| 10770 |
; |
| 10771 |
|
| 10772 |
|
| 10773 |
VerbRule(PushTravelClimbUp) |
| 10774 |
('push' | 'pull' | 'drag' | 'move') singleDobj |
| 10775 |
'up' singleIobj |
| 10776 |
: PushTravelClimbUpAction |
| 10777 |
verbPhrase = 'push/pushing (what) (up what)' |
| 10778 |
omitIobjInDobjQuery = true |
| 10779 |
; |
| 10780 |
|
| 10781 |
VerbRule(PushTravelClimbDown) |
| 10782 |
('push' | 'pull' | 'drag' | 'move') singleDobj |
| 10783 |
'down' singleIobj |
| 10784 |
: PushTravelClimbDownAction |
| 10785 |
verbPhrase = 'push/pushing (what) (down what)' |
| 10786 |
; |
| 10787 |
|
| 10788 |
VerbRule(Exits) |
| 10789 |
'exits' |
| 10790 |
: ExitsAction |
| 10791 |
verbPhrase = 'exits/showing exits' |
| 10792 |
; |
| 10793 |
|
| 10794 |
VerbRule(ExitsMode) |
| 10795 |
'exits' ('on'->on_ | 'all'->on_ |
| 10796 |
| 'off'->off_ | 'none'->off_ |
| 10797 |
| ('status' ('line' | ) | 'statusline') 'look'->on_ |
| 10798 |
| 'look'->on_ ('status' ('line' | ) | 'statusline') |
| 10799 |
| 'status'->stat_ ('line' | ) | 'statusline'->stat_ |
| 10800 |
| 'look'->look_) |
| 10801 |
: ExitsModeAction |
| 10802 |
verbPhrase = 'turn/turning off exits display' |
| 10803 |
; |
| 10804 |
|
| 10805 |
VerbRule(HintsOff) |
| 10806 |
'hints' 'off' |
| 10807 |
: HintsOffAction |
| 10808 |
verbPhrase = 'disable/disabling hints' |
| 10809 |
; |
| 10810 |
|
| 10811 |
VerbRule(Hint) |
| 10812 |
'hint' | 'hints' |
| 10813 |
: HintAction |
| 10814 |
verbPhrase = 'show/showing hints' |
| 10815 |
; |
| 10816 |
|
| 10817 |
VerbRule(Oops) |
| 10818 |
('oops' | 'o') singleLiteral |
| 10819 |
: OopsAction |
| 10820 |
verbPhrase = 'oops/correcting (what)' |
| 10821 |
; |
| 10822 |
|
| 10823 |
VerbRule(OopsOnly) |
| 10824 |
('oops' | 'o') |
| 10825 |
: OopsIAction |
| 10826 |
verbPhrase = 'oops/correcting' |
| 10827 |
; |
| 10828 |
|
| 10829 |
/* ------------------------------------------------------------------------ */ |
| 10830 |
/* |
| 10831 |
* "debug" verb - special verb to break into the debugger. We'll only |
| 10832 |
* compile this into the game if we're compiling a debug version to begin |
| 10833 |
* with, since a non-debug version can't be run under the debugger. |
| 10834 |
*/ |
| 10835 |
#ifdef __DEBUG |
| 10836 |
|
| 10837 |
VerbRule(Debug) |
| 10838 |
'debug' |
| 10839 |
: DebugAction |
| 10840 |
verbPhrase = 'debug/debugging' |
| 10841 |
; |
| 10842 |
|
| 10843 |
#endif /* __DEBUG */ |
| 10844 |
|