Holds language mappings and functions to handle natuaral language
thingies for parsing.
Imported modules
|
|
import constants import formatter import stdlib import stdprops import string import utils
|
Functions
|
|
|
|
addDefiniteArticle
|
addDefiniteArticle ( text )
Adds a definite article to the text. yourself or the .
arguments:
-
text
- (string)
returns:
(string) definite article + text |
|
addPluralIndefiniteArticle
|
addPluralIndefiniteArticle ( text )
If the token is you , it returns of you . If the token
anything else, returns some <text> . arguments:
-
text
- (string) the text to add the plural indefinite article to
returns:
(string) the text with the plural indefinite article
|
|
addQuantifiedPluralIndefiniteArticle
|
addQuantifiedPluralIndefiniteArticle ( text, tuple )
A tuple is a tuple structure that contains a quantity as a first
element and an example of the item as the second element. This is for adding quantified plural indefinite articles to the
front of a heap of something. some coins, a heap of cards, an
army of men....
arguments:
-
text
- (string) ???
-
tuple
- (??)
returns:
??
|
|
addSingularIndefiniteArticle
|
addSingularIndefiniteArticle ( text )
This method oversimplifies. It assumes that if the word begins
with a vowel, then it should be preceeded with an and if it
starts with a (non-capitalized) consonant, then it should be
preceeded with a . While this is correct the vast majority
of the time, there are exceptions. What actually matters in
English grammer isn't the letter, but the sound. So, for
example, the phrase "one stop shop" should be preceeded with
a , not an . Likewise, the abbreviation RCI should be
preceeded with an , not a . arguments:
-
text
- (string) the text to add the article to
returns:
(string) text with the article
|
|
capitalize
|
capitalize ( text )
The Python capitalize method makes everything in the string
lowercase (other than the first letter, of course). This is
undesired behavior given that the string can contain proper
nouns. This implementation capitalizes the first letter, but
leaves the rest of the string unchanged. arguments:
-
text
- (string) the text to capitalize
returns:
(string) capitalized text
|
|
compositeDescription
|
compositeDescription (
objects,
useDefiniteArticles=0,
ignoreNotShown=0,
)
Generates a text description of a group of objects. If
useDefiniteArticles is set to true, then definite articles will
be used to describe to singular objects (indefinite articles are
the default). If ignoreNotShown is set to true, all objects will
be included in the description, even if they possess the
stdprops.IS_NOT_SHOWN property (the default is to not include
these objects in the description). |
|
format
|
format ( descriptions )
|
|
genderText
|
genderText ( living )
Returns the text description of the gender of the given living.
eg, "male" for males and "female" for females.
arguments:
-
living
- (mudlib.living.Living) object in question
returns:
(string) "male" or "female" or "neuter" |
|
getAdverbs
|
getAdverbs ( None )
|
|
intToCardinal
|
intToCardinal ( value )
Converts an int to a cardinal.
arguments:
-
value
- (int) the int to convert to a cardinal
returns:
(string) the cardinal text |
|
isAdverb
|
isAdverb ( text )
Returns whether the incoming text is an adverb.
We figure this out by whether the adverb is in our
massive list of adverbs. arguments:
-
text
- (string) text to test adverb-hood
returns:
(int) 1 if adverb, 0 if not
|
|
isArticle
|
isArticle ( text )
Tests whether the text is an article (a , an , the , or some ).
arguments:
-
text
- (string) the item to test article-ity
returns:
(int) 1 if it is an article, 0 if not |
|
isCardinal
|
isCardinal ( text )
For a number to be cardinal, all numbers in the text must be
cardinal. A cardinal is a text string like forty-five . arguments:
-
text
- (string) the text to test cardinality on
returns:
(int) 1 if cardinal, 0 if not
|
|
isNumber
|
isNumber ( text )
Tests whether this text is either a cardinal or ordinal number.
arguments:
-
text
- (string) the text to test
returns:
(int) 1 if it's a number, 0 if not |
|
isOrdinal
|
isOrdinal ( text )
This is a bit more complex, since twenty-first is an ordinal
number, but contains a cardinal number (twenty). Therefore, if
any number in the text is ordinal, we say the whole thing is,
as long as each token is a number string. arguments:
-
text
- (string) the text to test ordinality on
returns:
(int) 1 if ordinal, 0 if not
|
|
personalProunoun
|
personalProunoun ( living )
Returns the appropriate personal pronoun based
on the gender (him , her or it ). arguments:
-
living
- (mudlib.living.Living) object in question
returns:
(string) "him" or "her" or "it"
|
|
plural
|
plural ( text )
Attempts to pluralize the text. Adds s or es to the end of
the text. This doesn't handle words like moose -> meese, or
words where the plural is the same as the singular. arguments:
-
text
- (string) the text to pluralize
returns:
(string) the pluralized text
|
|
possessive
|
possessive ( living )
Returns the appropriate posessive for this living based
on the gender (his , her , or its ). arguments:
-
living
- (mudlib.living.Living) object in question
returns:
(string) "his" or "her" or "its" or "your"
|
|
pronoun
|
pronoun ( living )
Returns the appropriate pronoun for this living based
on the gender (you , he , she , or it ). arguments:
-
living
- (mudlib.living.Living) the object in question
returns:
(string) "you" or "he" or "she" or "it"
|
|
pronounAndLinkingVerb
|
pronounAndLinkingVerb ( living )
Returns the appropriate pronoun for this living based
on the gender, along with a suitable linking verb
(you are , he is , she is , or it is ). arguments:
-
living
- (mudlib.living.Living) object in question
returns:
(string) "you are" or "he is" or "she is" or "it is"
|
|
reflexivePronoun
|
reflexivePronoun ( living )
Returns the appropriate reflexive pronoun based on the
gender (himself , herself , or itself ). arguments:
-
living
- (mudlib.living.Living) object in question
returns:
(string) "himself" or "herself" or "itself"
|
|
resolveAdverb
|
resolveAdverb ( text )
|
|
textToInteger
|
textToInteger ( text )
Converts text (forty-five , one ...) to an integer.
How this works: we iterate over each word in the text. The word
could either be a value or a modifier (per the dictionaries above).
Values we add together. Modifiers we need to multiply by its
corresponding value and then add. To maintain this, we keep a
total quantity and working quantity. The working quantity represents
the work in progress. When it's safe, we add the working quantity
to the total.
arguments:
-
text
- (string) the text to convert
returns:
(int) |