METADATA 49 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393
  1. Metadata-Version: 2.0
  2. Name: inflect
  3. Version: 0.2.5
  4. Summary: Correctly generate plurals, singular nouns, ordinals, indefinite articles; convert numbers to words
  5. Home-page: http://pypi.python.org/pypi/inflect
  6. Author: Alex Gronholm
  7. Author-email: alex.gronholm@nextday.fi
  8. License: UNKNOWN
  9. Keywords: plural,inflect,participle
  10. Platform: UNKNOWN
  11. Classifier: Development Status :: 3 - Alpha
  12. Classifier: Programming Language :: Python
  13. Classifier: Programming Language :: Python :: 2.6
  14. Classifier: Programming Language :: Python :: 2.7
  15. Classifier: Programming Language :: Python :: 3
  16. Classifier: Programming Language :: Python :: 3.2
  17. Classifier: Programming Language :: Python :: 3.3
  18. Classifier: Intended Audience :: Developers
  19. Classifier: License :: OSI Approved :: GNU Affero General Public License v3
  20. Classifier: Natural Language :: English
  21. Classifier: Operating System :: OS Independent
  22. Classifier: Topic :: Software Development :: Libraries :: Python Modules
  23. Classifier: Topic :: Text Processing :: Linguistic
  24. Provides: inflect
  25. ==========
  26. inflect.py
  27. ==========
  28. NAME
  29. ====
  30. inflect.py - Correctly generate plurals, singular nouns, ordinals, indefinite articles; convert numbers to words.
  31. VERSION
  32. =======
  33. This document describes version 0.2.4 of inflect.py
  34. INSTALLATION
  35. ============
  36. ``pip install -e git+https://github.com/pwdyson/inflect.py#egg=inflect``
  37. SYNOPSIS
  38. ========
  39. ::
  40. import inflect
  41. p = inflect.engine()
  42. # METHODS:
  43. # plural plural_noun plural_verb plural_adj singular_noun no num
  44. # compare compare_nouns compare_nouns compare_adjs
  45. # a an
  46. # present_participle
  47. # ordinal number_to_words
  48. # join
  49. # inflect classical gender
  50. # defnoun defverb defadj defa defan
  51. # UNCONDITIONALLY FORM THE PLURAL
  52. print("The plural of ", word, " is ", p.plural(word))
  53. # CONDITIONALLY FORM THE PLURAL
  54. print("I saw", cat_count, p.plural("cat",cat_count))
  55. # FORM PLURALS FOR SPECIFIC PARTS OF SPEECH
  56. print(p.plural_noun("I",N1), p.plural_verb("saw",N1), p.plural_adj("my",N2), \)
  57. p.plural_noun("saw",N2)
  58. # FORM THE SINGULAR OF PLURAL NOUNS
  59. print("The singular of ", word, " is ", p.singular_noun(word))
  60. # SELECT THE GENDER OF SINGULAR PRONOUNS
  61. print(p.singular_noun('they') # 'it')
  62. p.gender('f')
  63. print(p.singular_noun('they') # 'she')
  64. # DEAL WITH "0/1/N" -> "no/1/N" TRANSLATION:
  65. print("There ", p.plural_verb("was",errors), p.no(" error",errors))
  66. # USE DEFAULT COUNTS:
  67. print(p.num(N1,""), p.plural("I"), p.plural_verb(" saw"), p.num(N2), p.plural_noun(" saw"))
  68. print("There ", p.num(errors,''), p.plural_verb("was"), p.no(" error"))
  69. # COMPARE TWO WORDS "NUMBER-INSENSITIVELY":
  70. print("same\n" if p.compare(word1, word2))
  71. print("same noun\n" if p.compare_nouns(word1, word2))
  72. print("same verb\n" if p.compare_verbs(word1, word2))
  73. print("same adj.\n" if p.compare_adjs(word1, word2))
  74. # ADD CORRECT "a" OR "an" FOR A GIVEN WORD:
  75. print("Did you want ", p.a(thing), " or ", p.an(idea))
  76. # CONVERT NUMERALS INTO ORDINALS (i.e. 1->1st, 2->2nd, 3->3rd, etc.)
  77. print("It was", p.ordinal(position), " from the left\n")
  78. # CONVERT NUMERALS TO WORDS (i.e. 1->"one", 101->"one hundred and one", etc.)
  79. # RETURNS A SINGLE STRING...
  80. words = p.number_to_words(1234) # "one thousand, two hundred and thirty-four"
  81. words = p.number_to_words(p.ordinal(1234)) # "one thousand, two hundred and thirty-fourth"
  82. # GET BACK A LIST OF STRINGS, ONE FOR EACH "CHUNK"...
  83. words = p.number_to_words(1234, getlist=True) # ("one thousand","two hundred and thirty-four")
  84. # OPTIONAL PARAMETERS CHANGE TRANSLATION:
  85. words = p.number_to_words(12345, group=1)
  86. # "one, two, three, four, five"
  87. words = p.number_to_words(12345, group=2)
  88. # "twelve, thirty-four, five"
  89. words = p.number_to_words(12345, group=3)
  90. # "one twenty-three, forty-five"
  91. words = p.number_to_words(1234, andword='')
  92. # "one thousand, two hundred thirty-four"
  93. words = p.number_to_words(1234, andword=', plus')
  94. # "one thousand, two hundred, plus thirty-four" #TODO: I get no comma before plus: check perl
  95. words = p.number_to_words(555_1202, group=1, zero='oh')
  96. # "five, five, five, one, two, oh, two"
  97. words = p.number_to_words(555_1202, group=1, one='unity')
  98. # "five, five, five, unity, two, oh, two"
  99. words = p.number_to_words(123.456, group=1, decimal='mark')
  100. # "one two three mark four five six" #TODO: DOCBUG: perl gives commas here as do I
  101. # LITERAL STYLE ONLY NAMES NUMBERS LESS THAN A CERTAIN THRESHOLD...
  102. words = p.number_to_words( 9, threshold=10); # "nine"
  103. words = p.number_to_words( 10, threshold=10); # "ten"
  104. words = p.number_to_words( 11, threshold=10); # "11"
  105. words = p.number_to_words(1000, threshold=10); # "1,000"
  106. # JOIN WORDS INTO A LIST:
  107. mylist = join(("apple", "banana", "carrot"))
  108. # "apple, banana, and carrot"
  109. mylist = join(("apple", "banana"))
  110. # "apple and banana"
  111. mylist = join(("apple", "banana", "carrot"), final_sep="")
  112. # "apple, banana and carrot"
  113. # REQUIRE "CLASSICAL" PLURALS (EG: "focus"->"foci", "cherub"->"cherubim")
  114. p.classical() # USE ALL CLASSICAL PLURALS
  115. p.classical(all=True) # USE ALL CLASSICAL PLURALS
  116. p.classical(all=False) # SWITCH OFF CLASSICAL MODE
  117. p.classical(zero=True) # "no error" INSTEAD OF "no errors"
  118. p.classical(zero=False) # "no errors" INSTEAD OF "no error"
  119. p.classical(herd=True) # "2 buffalo" INSTEAD OF "2 buffalos"
  120. p.classical(herd=False) # "2 buffalos" INSTEAD OF "2 buffalo"
  121. p.classical(persons=True) # "2 chairpersons" INSTEAD OF "2 chairpeople"
  122. p.classical(persons=False) # "2 chairpeople" INSTEAD OF "2 chairpersons"
  123. p.classical(ancient=True) # "2 formulae" INSTEAD OF "2 formulas"
  124. p.classical(ancient=False) # "2 formulas" INSTEAD OF "2 formulae"
  125. # INTERPOLATE "plural()", "plural_noun()", "plural_verb()", "plural_adj()", "singular_noun()",
  126. # a()", "an()", "num()" AND "ordinal()" WITHIN STRINGS:
  127. print(p.inflect("The plural of {0} is plural({0})".format(word)))
  128. print(p.inflect("The singular of {0} is singular_noun({0})".format(word)))
  129. print(p.inflect("I saw {0} plural("cat",{0})".format(cat_count)))
  130. print(p.inflect("plural(I,{0}) plural_verb(saw,{0}) plural(a,{1}) plural_noun(saw,{1})".format(N1, N2)))
  131. print(p.inflect("num({0},)plural(I) plural_verb(saw) num({1},)plural(a) plural_noun(saw)".format(N1, N2)))
  132. print(p.inflect("I saw num({0}) plural("cat")\nnum()".format(cat_count)))
  133. print(p.inflect("There plural_verb(was,{0}) no(error,{0})".format(errors)))
  134. print(p.inflect("There num({0},) plural_verb(was) no(error)".format(errors)))
  135. print(p.inflect("Did you want a({0}) or an({1})".format(thing, idea)))
  136. print(p.inflect("It was ordinal({0}) from the left".format(position)))
  137. # ADD USER-DEFINED INFLECTIONS (OVERRIDING INBUILT RULES):
  138. p.defnoun( "VAX", "VAXen" ) # SINGULAR => PLURAL
  139. p.defverb( "will" , "shall", # 1ST PERSON SINGULAR => PLURAL
  140. "will" , "will", # 2ND PERSON SINGULAR => PLURAL
  141. "will" , "will") # 3RD PERSON SINGULAR => PLURAL
  142. p.defadj( "hir" , "their") # SINGULAR => PLURAL
  143. p.defa("h") # "AY HALWAYS SEZ 'HAITCH'!"
  144. p.defan( "horrendous.*" ) # "AN HORRENDOUS AFFECTATION"
  145. DESCRIPTION
  146. ===========
  147. The methods of the class ``engine`` in module ``inflect.py`` provide plural
  148. inflections, singular noun inflections, "a"/"an" selection for English words,
  149. and manipulation of numbers as words.
  150. Plural forms of all nouns, most verbs, and some adjectives are
  151. provided. Where appropriate, "classical" variants (for example: "brother" ->
  152. "brethren", "dogma" -> "dogmata", etc.) are also provided.
  153. Single forms of nouns are also provided. The gender of singular pronouns
  154. can be chosen (for example "they" -> "it" or "she" or "he" or "they").
  155. Pronunciation-based "a"/"an" selection is provided for all English
  156. words, and most initialisms.
  157. It is also possible to inflect numerals (1,2,3) to ordinals (1st, 2nd, 3rd)
  158. and to english words ("one", "two", "three").
  159. In generating these inflections, ``inflect.py`` follows the Oxford
  160. English Dictionary and the guidelines in Fowler's Modern English
  161. Usage, preferring the former where the two disagree.
  162. The module is built around standard British spelling, but is designed
  163. to cope with common American variants as well. Slang, jargon, and
  164. other English dialects are *not* explicitly catered for.
  165. Where two or more inflected forms exist for a single word (typically a
  166. "classical" form and a "modern" form), ``inflect.py`` prefers the
  167. more common form (typically the "modern" one), unless "classical"
  168. processing has been specified
  169. (see `MODERN VS CLASSICAL INFLECTIONS`).
  170. FORMING PLURALS AND SINGULARS
  171. =============================
  172. Inflecting Plurals and Singulars
  173. --------------------------------
  174. All of the ``plural...`` plural inflection methods take the word to be
  175. inflected as their first argument and return the corresponding inflection.
  176. Note that all such methods expect the *singular* form of the word. The
  177. results of passing a plural form are undefined (and unlikely to be correct).
  178. Similarly, the ``si...`` singular inflection method expects the *plural*
  179. form of the word.
  180. The ``plural...`` methods also take an optional second argument,
  181. which indicates the grammatical "number" of the word (or of another word
  182. with which the word being inflected must agree). If the "number" argument is
  183. supplied and is not ``1`` (or ``"one"`` or ``"a"``, or some other adjective that
  184. implies the singular), the plural form of the word is returned. If the
  185. "number" argument *does* indicate singularity, the (uninflected) word
  186. itself is returned. If the number argument is omitted, the plural form
  187. is returned unconditionally.
  188. The ``si...`` method takes a second argument in a similar fashion. If it is
  189. some form of the number ``1``, or is omitted, the singular form is returned.
  190. Otherwise the plural is returned unaltered.
  191. The various methods of ``inflect.engine`` are:
  192. ``plural_noun(word, count=None)``
  193. The method ``plural_noun()`` takes a *singular* English noun or
  194. pronoun and returns its plural. Pronouns in the nominative ("I" ->
  195. "we") and accusative ("me" -> "us") cases are handled, as are
  196. possessive pronouns ("mine" -> "ours").
  197. ``plural_verb(word, count=None)``
  198. The method ``plural_verb()`` takes the *singular* form of a
  199. conjugated verb (that is, one which is already in the correct "person"
  200. and "mood") and returns the corresponding plural conjugation.
  201. ``plural_adj(word, count=None)``
  202. The method ``plural_adj()`` takes the *singular* form of
  203. certain types of adjectives and returns the corresponding plural form.
  204. Adjectives that are correctly handled include: "numerical" adjectives
  205. ("a" -> "some"), demonstrative adjectives ("this" -> "these", "that" ->
  206. "those"), and possessives ("my" -> "our", "cat's" -> "cats'", "child's"
  207. -> "childrens'", etc.)
  208. ``plural(word, count=None)``
  209. The method ``plural()`` takes a *singular* English noun,
  210. pronoun, verb, or adjective and returns its plural form. Where a word
  211. has more than one inflection depending on its part of speech (for
  212. example, the noun "thought" inflects to "thoughts", the verb "thought"
  213. to "thought"), the (singular) noun sense is preferred to the (singular)
  214. verb sense.
  215. Hence ``plural("knife")`` will return "knives" ("knife" having been treated
  216. as a singular noun), whereas ``plural("knifes")`` will return "knife"
  217. ("knifes" having been treated as a 3rd person singular verb).
  218. The inherent ambiguity of such cases suggests that,
  219. where the part of speech is known, ``plural_noun``, ``plural_verb``, and
  220. ``plural_adj`` should be used in preference to ``plural``.
  221. ``singular_noun(word, count=None)``
  222. The method ``singular_noun()`` takes a *plural* English noun or
  223. pronoun and returns its singular. Pronouns in the nominative ("we" ->
  224. "I") and accusative ("us" -> "me") cases are handled, as are
  225. possessive pronouns ("ours" -> "mine"). When third person
  226. singular pronouns are returned they take the neuter gender by default
  227. ("they" -> "it"), not ("they"-> "she") nor ("they" -> "he"). This can be
  228. changed with ``gender()``.
  229. Note that all these methods ignore any whitespace surrounding the
  230. word being inflected, but preserve that whitespace when the result is
  231. returned. For example, ``plural(" cat ")`` returns " cats ".
  232. ``gender(genderletter)``
  233. The third person plural pronoun takes the same form for the female, male and
  234. neuter (e.g. "they"). The singular however, depends upon gender (e.g. "she",
  235. "he", "it" and "they" -- "they" being the gender neutral form.) By default
  236. ``singular_noun`` returns the neuter form, however, the gender can be selected with
  237. the ``gender`` method. Pass the first letter of the gender to
  238. ``gender`` to return the f(eminine), m(asculine), n(euter) or t(hey)
  239. form of the singular. e.g.
  240. gender('f') followed by singular_noun('themselves') returns 'herself'.
  241. Numbered plurals
  242. ----------------
  243. The ``plural...`` methods return only the inflected word, not the count that
  244. was used to inflect it. Thus, in order to produce "I saw 3 ducks", it
  245. is necessary to use::
  246. print("I saw", N, p.plural_noun(animal,N))
  247. Since the usual purpose of producing a plural is to make it agree with
  248. a preceding count, inflect.py provides a method
  249. (``no(word, count)``) which, given a word and a(n optional) count, returns the
  250. count followed by the correctly inflected word. Hence the previous
  251. example can be rewritten::
  252. print("I saw ", p.no(animal,N))
  253. In addition, if the count is zero (or some other term which implies
  254. zero, such as ``"zero"``, ``"nil"``, etc.) the count is replaced by the
  255. word "no". Hence, if ``N`` had the value zero, the previous example
  256. would print(the somewhat more elegant::)
  257. I saw no animals
  258. rather than::
  259. I saw 0 animals
  260. Note that the name of the method is a pun: the method
  261. returns either a number (a *No.*) or a ``"no"``, in front of the
  262. inflected word.
  263. Reducing the number of counts required
  264. --------------------------------------
  265. In some contexts, the need to supply an explicit count to the various
  266. ``plural...`` methods makes for tiresome repetition. For example::
  267. print(plural_adj("This",errors), plural_noun(" error",errors), \)
  268. plural_verb(" was",errors), " fatal."
  269. inflect.py therefore provides a method
  270. (``num(count=None, show=None)``) which may be used to set a persistent "default number"
  271. value. If such a value is set, it is subsequently used whenever an
  272. optional second "number" argument is omitted. The default value thus set
  273. can subsequently be removed by calling ``num()`` with no arguments.
  274. Hence we could rewrite the previous example::
  275. p.num(errors)
  276. print(p.plural_adj("This"), p.plural_noun(" error"), p.plural_verb(" was"), "fatal.")
  277. p.num()
  278. Normally, ``num()`` returns its first argument, so that it may also
  279. be "inlined" in contexts like::
  280. print(p.num(errors), p.plural_noun(" error"), p.plural_verb(" was"), " detected.")
  281. if severity > 1:
  282. print(p.plural_adj("This"), p.plural_noun(" error"), p.plural_verb(" was"), "fatal.")
  283. However, in certain contexts (see `INTERPOLATING INFLECTIONS IN STRINGS`)
  284. it is preferable that ``num()`` return an empty string. Hence ``num()``
  285. provides an optional second argument. If that argument is supplied (that is, if
  286. it is defined) and evaluates to false, ``num`` returns an empty string
  287. instead of its first argument. For example::
  288. print(p.num(errors,0), p.no("error"), p.plural_verb(" was"), " detected.")
  289. if severity > 1:
  290. print(p.plural_adj("This"), p.plural_noun(" error"), p.plural_verb(" was"), "fatal.")
  291. Number-insensitive equality
  292. ---------------------------
  293. inflect.py also provides a solution to the problem
  294. of comparing words of differing plurality through the methods
  295. ``compare(word1, word2)``, ``compare_nouns(word1, word2)``,
  296. ``compare_verbs(word1, word2)``, and ``compare_adjs(word1, word2)``.
  297. Each of these methods takes two strings, and compares them
  298. using the corresponding plural-inflection method (``plural()``, ``plural_noun()``,
  299. ``plural_verb()``, and ``plural_adj()`` respectively).
  300. The comparison returns true if:
  301. - the strings are equal, or
  302. - one string is equal to a plural form of the other, or
  303. - the strings are two different plural forms of the one word.
  304. Hence all of the following return true::
  305. p.compare("index","index") # RETURNS "eq"
  306. p.compare("index","indexes") # RETURNS "s:p"
  307. p.compare("index","indices") # RETURNS "s:p"
  308. p.compare("indexes","index") # RETURNS "p:s"
  309. p.compare("indices","index") # RETURNS "p:s"
  310. p.compare("indices","indexes") # RETURNS "p:p"
  311. p.compare("indexes","indices") # RETURNS "p:p"
  312. p.compare("indices","indices") # RETURNS "eq"
  313. As indicated by the comments in the previous example, the actual value
  314. returned by the various ``compare`` methods encodes which of the
  315. three equality rules succeeded: "eq" is returned if the strings were
  316. identical, "s:p" if the strings were singular and plural respectively,
  317. "p:s" for plural and singular, and "p:p" for two distinct plurals.
  318. Inequality is indicated by returning an empty string.
  319. It should be noted that two distinct singular words which happen to take
  320. the same plural form are *not* considered equal, nor are cases where
  321. one (singular) word's plural is the other (plural) word's singular.
  322. Hence all of the following return false::
  323. p.compare("base","basis") # ALTHOUGH BOTH -> "bases"
  324. p.compare("syrinx","syringe") # ALTHOUGH BOTH -> "syringes"
  325. p.compare("she","he") # ALTHOUGH BOTH -> "they"
  326. p.compare("opus","operas") # ALTHOUGH "opus" -> "opera" -> "operas"
  327. p.compare("taxi","taxes") # ALTHOUGH "taxi" -> "taxis" -> "taxes"
  328. Note too that, although the comparison is "number-insensitive" it is *not*
  329. case-insensitive (that is, ``plural("time","Times")`` returns false. To obtain
  330. both number and case insensitivity, use the ``lower()`` method on both strings
  331. (that is, ``plural("time".lower(), "Times".lower())`` returns true).
  332. OTHER VERB FORMS
  333. ================
  334. Present participles
  335. -------------------
  336. ``inflect.py`` also provides the ``present_participle`` method,
  337. which can take a 3rd person singular verb and
  338. correctly inflect it to its present participle::
  339. p.present_participle("runs") # "running"
  340. p.present_participle("loves") # "loving"
  341. p.present_participle("eats") # "eating"
  342. p.present_participle("bats") # "batting"
  343. p.present_participle("spies") # "spying"
  344. PROVIDING INDEFINITE ARTICLES
  345. =============================
  346. Selecting indefinite articles
  347. -----------------------------
  348. inflect.py provides two methods (``a(word, count=None)`` and
  349. ``an(word, count=None)``) which will correctly prepend the appropriate indefinite
  350. article to a word, depending on its pronunciation. For example::
  351. p.a("cat") # -> "a cat"
  352. p.an("cat") # -> "a cat"
  353. p.a("euphemism") # -> "a euphemism"
  354. p.a("Euler number") # -> "an Euler number"
  355. p.a("hour") # -> "an hour"
  356. p.a("houri") # -> "a houri"
  357. The two methods are *identical* in function and may be used
  358. interchangeably. The only reason that two versions are provided is to
  359. enhance the readability of code such as::
  360. print("That is ", an(errortype), " error)
  361. print("That is ", a(fataltype), " fatal error)
  362. Note that in both cases the actual article provided depends *only* on
  363. the pronunciation of the first argument, *not* on the name of the
  364. method.
  365. ``a()`` and ``an()`` will ignore any indefinite article that already
  366. exists at the start of the string. Thus::
  367. half_arked = [
  368. "a elephant",
  369. "a giraffe",
  370. "an ewe",
  371. "a orangutan",
  372. ]
  373. for txt in half_arked:
  374. print(p.a(txt))
  375. # prints:
  376. # an elephant
  377. # a giraffe
  378. # a ewe
  379. # an orangutan
  380. ``a()`` and ``an()`` both take an optional second argument. As with the
  381. ``plural...`` methods, this second argument is a "number" specifier. If
  382. its value is ``1`` (or some other value implying singularity), ``a()`` and
  383. ``an()`` insert "a" or "an" as appropriate. If the number specifier
  384. implies plurality, (``a()`` and ``an()`` insert the actual second argument instead.
  385. For example::
  386. p.a("cat",1) # -> "a cat"
  387. p.a("cat",2) # -> "2 cat"
  388. p.a("cat","one") # -> "one cat"
  389. p.a("cat","no") # -> "no cat"
  390. Note that, as implied by the previous examples, ``a()`` and
  391. ``an()`` both assume that their job is merely to provide the correct
  392. qualifier for a word (that is: "a", "an", or the specified count).
  393. In other words, they assume that the word they are given has
  394. already been correctly inflected for plurality. Hence, if ``N``
  395. has the value 2, then::
  396. print(p.a("cat",N))
  397. prints "2 cat", instead of "2 cats". The correct approach is to use::
  398. print(p.a(p.plural("cat",N),N))
  399. or, better still::
  400. print(p.no("cat",N))
  401. Note too that, like the various ``plural...`` methods, whenever ``a()``
  402. and ``an()`` are called with only one argument they are subject to the
  403. effects of any preceding call to ``num()``. Hence, another possible
  404. solution is::
  405. p.num(N)
  406. print(p.a(p.plural("cat")))
  407. Indefinite articles and initialisms
  408. -----------------------------------
  409. "Initialisms" (sometimes inaccurately called "acronyms") are terms which
  410. have been formed from the initial letters of words in a phrase (for
  411. example, "NATO", "NBL", "S.O.S.", "SCUBA", etc.)
  412. Such terms present a particular challenge when selecting between "a"
  413. and "an", since they are sometimes pronounced as if they were a single
  414. word ("nay-tow", "sku-ba") and sometimes as a series of letter names
  415. ("en-eff-ell", "ess-oh-ess").
  416. ``a()`` and ``an()`` cope with this dichotomy using a series of inbuilt
  417. rules, which may be summarized as:
  418. If the word starts with a single letter, followed by a period or dash
  419. (for example, "R.I.P.", "C.O.D.", "e-mail", "X-ray", "T-square"), then
  420. choose the appropriate article for the *sound* of the first letter
  421. ("an R.I.P.", "a C.O.D.", "an e-mail", "an X-ray", "a T-square").
  422. If the first two letters of the word are capitals,
  423. consonants, and do not appear at the start of any known English word,
  424. (for example, "LCD", "XML", "YWCA"), then once again choose "a" or
  425. "an" depending on the *sound* of the first letter ("an LCD", "an
  426. XML", "a YWCA").
  427. Otherwise, assume the string is a capitalized word or a
  428. pronounceable initialism (for example, "LED", "OPEC", "FAQ", "UNESCO"), and
  429. therefore takes "a" or "an" according to the (apparent) pronunciation of
  430. the entire word ("a LED", "an OPEC", "a FAQ", "a UNESCO").
  431. Note that rules 1 and 3 together imply that the presence or absence of
  432. punctuation may change the selection of indefinite article for a
  433. particular initialism (for example, "a FAQ" but "an F.A.Q.").
  434. Indefinite articles and "soft H's"
  435. ----------------------------------
  436. Words beginning in the letter 'H' present another type of difficulty
  437. when selecting a suitable indefinite article. In a few such words
  438. (for example, "hour", "honour", "heir") the 'H' is not voiced at
  439. all, and so such words inflect with "an". The remaining cases
  440. ("voiced H's") may be divided into two categories:
  441. "hard H's" (such as "hangman", "holograph", "hat", etc.) and
  442. "soft H's" (such as "hysterical", "horrendous", "holy", etc.)
  443. Hard H's always take "a" as their indefinite article, and soft
  444. H's normally do so as well. But *some* English speakers prefer
  445. "an" for soft H's (although the practice is now generally considered an
  446. affectation, rather than a legitimate grammatical alternative).
  447. At present, the ``a()`` and ``an()`` methods ignore soft H's and use
  448. "a" for any voiced 'H'. The author would, however, welcome feedback on
  449. this decision (envisaging a possible future "soft H" mode).
  450. INFLECTING ORDINALS
  451. ===================
  452. Occasionally it is useful to present an integer value as an ordinal
  453. rather than as a numeral. For example::
  454. Enter password (1st attempt): ********
  455. Enter password (2nd attempt): *********
  456. Enter password (3rd attempt): *********
  457. No 4th attempt. Access denied.
  458. To this end, inflect.py provides the ``ordinal()`` method.
  459. ``ordinal()`` takes a single argument and forms its ordinal equivalent.
  460. If the argument isn't a numerical integer, it just adds "-th".
  461. CONVERTING NUMBERS TO WORDS
  462. ===========================
  463. The method ``number_to_words`` takes a number (cardinal or ordinal)
  464. and returns an English representation of that number.
  465. ::
  466. word = p.number_to_words(1234567)
  467. puts the string::
  468. "one million, two hundred and thirty-four thousand, five hundred and sixty-seven"
  469. into ``words``.
  470. A list can be return where each comma-separated chunk is returned as a separate element.
  471. Hence::
  472. words = p.number_to_words(1234567, wantlist=True)
  473. puts the list::
  474. ["one million",
  475. "two hundred and thirty-four thousand",
  476. "five hundred and sixty-seven"]
  477. into ``words``.
  478. Non-digits (apart from an optional leading plus or minus sign,
  479. any decimal points, and ordinal suffixes -- see below) are silently
  480. ignored, so the following all produce identical results::
  481. p.number_to_words(5551202)
  482. p.number_to_words(5_551_202)
  483. p.number_to_words("5,551,202")
  484. p.number_to_words("555-1202")
  485. That last case is a little awkward since it's almost certainly a phone number,
  486. and "five million, five hundred and fifty-one thousand, two hundred and two"
  487. probably isn't what's wanted.
  488. To overcome this, ``number_to_words()`` takes an optional argument, 'group',
  489. which changes how numbers are translated. The argument must be a
  490. positive integer less than four, which indicated how the digits of the
  491. number are to be grouped. If the argument is ``1``, then each digit is
  492. translated separately. If the argument is ``2``, pairs of digits
  493. (starting from the *left*) are grouped together. If the argument is
  494. ``3``, triples of numbers (again, from the *left*) are grouped. Hence::
  495. p.number_to_words("555-1202", group=1)
  496. returns ``"five, five, five, one, two, zero, two"``, whilst::
  497. p.number_to_words("555-1202", group=2)
  498. returns ``"fifty-five, fifty-one, twenty, two"``, and::
  499. p.number_to_words("555-1202", group=3)
  500. returns ``"five fifty-five, one twenty, two"``.
  501. Phone numbers are often written in words as
  502. ``"five..five..five..one..two..zero..two"``, which is also easy to
  503. achieve::
  504. join '..', p.number_to_words("555-1202", group=>1)
  505. ``number_to_words`` also handles decimal fractions. Hence::
  506. p.number_to_words("1.2345")
  507. returns ``"one point two three four five"`` in a scalar context
  508. and ``("one","point","two","three","four","five")``) in an array context.
  509. Exponent form (``"1.234e56"``) is not yet handled.
  510. Multiple decimal points are only translated in one of the "grouping" modes.
  511. Hence::
  512. p.number_to_words(101.202.303)
  513. returns ``"one hundred and one point two zero two three zero three"``,
  514. whereas::
  515. p.number_to_words(101.202.303, group=1)
  516. returns ``"one zero one point two zero two point three zero three"``.
  517. The digit ``'0'`` is unusual in that in may be translated to English as "zero",
  518. "oh", or "nought". To cater for this diversity, ``number_to_words`` may be passed
  519. a named argument, 'zero', which may be set to
  520. the desired translation of ``'0'``. For example::
  521. print(join "..", p.number_to_words("555-1202", group=3, zero='oh'))
  522. prints ``"five..five..five..one..two..oh..two"``.
  523. By default, zero is rendered as "zero".
  524. Likewise, the digit ``'1'`` may be rendered as "one" or "a/an" (or very
  525. occasionally other variants), depending on the context. So there is a
  526. ``'one'`` argument as well::
  527. for num in [3,2,1,0]:
  528. print(p.number_to_words(num, one='a solitary', zero='no more'),)
  529. p.plural(" bottle of beer on the wall", num)
  530. # prints:
  531. # three bottles of beer on the wall
  532. # two bottles of beer on the wall
  533. # a solitary bottle of beer on the wall
  534. # no more bottles of beer on the wall
  535. Care is needed if the word "a/an" is to be used as a ``'one'`` value.
  536. Unless the next word is known in advance, it's almost always necessary
  537. to use the ``A`` function as well::
  538. for word in ["cat aardvark ewe hour".split()]:
  539. print(p.a("{0} {1}".format(p.number_to_words(1, one='a'), word)))
  540. # prints:
  541. # a cat
  542. # an aardvark
  543. # a ewe
  544. # an hour
  545. Another major regional variation in number translation is the use of
  546. "and" in certain contexts. The named argument 'and'
  547. allows the programmer to specify how "and" should be handled. Hence::
  548. print(scalar p.number_to_words("765", andword=''))
  549. prints "seven hundred sixty-five", instead of "seven hundred and sixty-five".
  550. By default, the "and" is included.
  551. The translation of the decimal point is also subject to variation
  552. (with "point", "dot", and "decimal" being the favorites).
  553. The named argument 'decimal' allows the
  554. programmer to how the decimal point should be rendered. Hence::
  555. print(scalar p.number_to_words("666.124.64.101", group=3, decimal='dot'))
  556. prints "six sixty-six, dot, one twenty-four, dot, sixty-four, dot, one zero one"
  557. By default, the decimal point is rendered as "point".
  558. ``number_to_words`` also handles the ordinal forms of numbers. So::
  559. print(p.number_to_words('1st'))
  560. print(p.number_to_words('3rd'))
  561. print(p.number_to_words('202nd'))
  562. print(p.number_to_words('1000000th'))
  563. prints::
  564. first
  565. third
  566. two hundred and twenty-second
  567. one millionth
  568. Two common idioms in this regard are::
  569. print(p.number_to_words(ordinal(number)))
  570. and::
  571. print(p.ordinal(p.number_to_words(number)))
  572. These are identical in effect, except when ``number`` contains a decimal::
  573. number = 99.09
  574. print(p.number_to_words(p.ordinal(number)); # ninety-ninth point zero nine)
  575. print(p.ordinal(p.number_to_words(number)); # ninety-nine point zero ninth)
  576. Use whichever you feel is most appropriate.
  577. CONVERTING LISTS OF WORDS TO PHRASES
  578. ====================================
  579. When creating a list of words, commas are used between adjacent items,
  580. except if the items contain commas, in which case semicolons are used.
  581. But if there are less than two items, the commas/semicolons are omitted
  582. entirely. The final item also has a conjunction (usually "and" or "or")
  583. before it. And although it's technically incorrect (and sometimes
  584. misleading), some people prefer to omit the comma before that final
  585. conjunction, even when there are more than two items.
  586. That's complicated enough to warrant its own method: ``join()``.
  587. This method expects a tuple of words, possibly with one or more
  588. options. It returns a string that joins the list
  589. together in the normal English usage. For example::
  590. print("You chose ", p.join(selected_items))
  591. # You chose barley soup, roast beef, and Yorkshire pudding
  592. print("You chose ", p.join(selected_items, final_sep=>""))
  593. # You chose barley soup, roast beef and Yorkshire pudding
  594. print("Please chose ", p.join(side_orders, conj=>"or"))
  595. # Please chose salad, vegetables, or ice-cream
  596. The available options are::
  597. Option named Specifies Default value
  598. conj Final conjunction "and"
  599. sep Inter-item separator ","
  600. last_sep Final separator value of 'sep' option
  601. sep_spaced Space follows sep True
  602. conj_spaced Spaces around conj True
  603. INTERPOLATING INFLECTIONS IN STRINGS
  604. ====================================
  605. By far the commonest use of the inflection methods is to
  606. produce message strings for various purposes. For example::
  607. print(p.num(errors), p.plural_noun(" error"), p.plural_verb(" was"), " detected.")
  608. if severity > 1:
  609. print(p.plural_adj("This"), p.plural_noun(" error"), p.plural_verb(" was"), "fatal.")
  610. Unfortunately the need to separate each method call detracts
  611. significantly from the readability of the resulting code. To ameliorate
  612. this problem, inflect.py provides a string-interpolating
  613. method (``inflect(txt)``), which recognizes calls to the various inflection
  614. methods within a string and interpolates them appropriately.
  615. Using ``inflect`` the previous example could be rewritten::
  616. print(p.inflect("num({0}) plural_noun(error) plural_verb(was) detected.".format(errors)))
  617. if severity > 1:
  618. print(p.inflect("plural_adj(This) plural_noun(error) plural_verb(was) fatal."))
  619. Note that ``inflect`` also correctly handles calls to the ``num()`` method
  620. (whether interpolated or antecedent). The ``inflect()`` method has
  621. a related extra feature, in that it *automatically* cancels any "default
  622. number" value before it returns its interpolated string. This means that
  623. calls to ``num()`` which are embedded in an ``inflect()``-interpolated
  624. string do not "escape" and interfere with subsequent inflections.
  625. MODERN VS CLASSICAL INFLECTIONS
  626. ===============================
  627. Certain words, mainly of Latin or Ancient Greek origin, can form
  628. plurals either using the standard English "-s" suffix, or with
  629. their original Latin or Greek inflections. For example::
  630. p.plural("stigma") # -> "stigmas" or "stigmata"
  631. p.plural("torus") # -> "toruses" or "tori"
  632. p.plural("index") # -> "indexes" or "indices"
  633. p.plural("millennium") # -> "millenniums" or "millennia"
  634. p.plural("ganglion") # -> "ganglions" or "ganglia"
  635. p.plural("octopus") # -> "octopuses" or "octopodes"
  636. inflect.py caters to such words by providing an
  637. "alternate state" of inflection known as "classical mode".
  638. By default, words are inflected using their contemporary English
  639. plurals, but if classical mode is invoked, the more traditional
  640. plural forms are returned instead.
  641. The method ``classical()`` controls this feature.
  642. If ``classical()`` is called with no arguments, it unconditionally
  643. invokes classical mode. If it is called with a single argument, it
  644. turns all classical inflects on or off (depending on whether the argument is
  645. true or false). If called with two or more arguments, those arguments
  646. specify which aspects of classical behaviour are to be used.
  647. Thus::
  648. p.classical() # SWITCH ON CLASSICAL MODE
  649. print(p.plural("formula") # -> "formulae")
  650. p.classical(all=False) # SWITCH OFF CLASSICAL MODE
  651. print(p.plural("formula") # -> "formulas")
  652. p.classical(cmode=True) # CLASSICAL MODE IFF cmode
  653. print(p.plural("formula") # -> "formulae" (IF cmode))
  654. # -> "formulas" (OTHERWISE)
  655. p.classical(herd=True) # SWITCH ON CLASSICAL MODE FOR "HERD" NOUNS
  656. print(p.plural("wilderbeest") # -> "wilderbeest")
  657. p.classical(names=True) # SWITCH ON CLASSICAL MODE FOR NAMES
  658. print(p.plural("sally") # -> "sallies")
  659. print(p.plural("Sally") # -> "Sallys")
  660. Note however that ``classical()`` has no effect on the inflection of words which
  661. are now fully assimilated. Hence::
  662. p.plural("forum") # ALWAYS -> "forums"
  663. p.plural("criterion") # ALWAYS -> "criteria"
  664. LEI assumes that a capitalized word is a person's name. So it forms the
  665. plural according to the rules for names (which is that you don't
  666. inflect, you just add -s or -es). You can choose to turn that behaviour
  667. off (it's on by the default, even when the module isn't in classical
  668. mode) by calling `` classical(names=0) ``
  669. USER-DEFINED INFLECTIONS
  670. ========================
  671. Adding plurals at run-time
  672. --------------------------
  673. inflect.py provides five methods which allow
  674. the programmer to override the module's behaviour for specific cases:
  675. ``defnoun(singular, plural)``
  676. The ``defnoun`` method takes a pair of string arguments: the singular and the
  677. plural forms of the noun being specified. The singular form
  678. specifies a pattern to be interpolated (as ``m/^(?:$first_arg)$/i``).
  679. Any noun matching this pattern is then replaced by the string in the
  680. second argument. The second argument specifies a string which is
  681. interpolated after the match succeeds, and is then used as the plural
  682. form. For example::
  683. defnoun( 'cow' , 'kine')
  684. defnoun( '(.+i)o' , '$1i')
  685. defnoun( 'spam(mer)?' , '\\$\\%\\@#\\$\\@#!!')
  686. Note that both arguments should usually be specified in single quotes,
  687. so that they are not interpolated when they are specified, but later (when
  688. words are compared to them). As indicated by the last example, care
  689. also needs to be taken with certain characters in the second argument,
  690. to ensure that they are not unintentionally interpolated during comparison.
  691. The second argument string may also specify a second variant of the plural
  692. form, to be used when "classical" plurals have been requested. The beginning
  693. of the second variant is marked by a '|' character::
  694. defnoun( 'cow' , 'cows|kine')
  695. defnoun( '(.+i)o' , '$1os|$1i')
  696. defnoun( 'spam(mer)?' , '\\$\\%\\@#\\$\\@#!!|varmints')
  697. If no classical variant is given, the specified plural form is used in
  698. both normal and "classical" modes.
  699. ..
  700. #TODO: check that the following paragraph is implemented
  701. If the second argument is ``None`` instead of a string, then the
  702. current user definition for the first argument is removed, and the
  703. standard plural inflection(s) restored.
  704. Note that in all cases, later plural definitions for a particular
  705. singular form replace earlier definitions of the same form. For example::
  706. # FIRST, HIDE THE MODERN FORM....
  707. defnoun( 'aviatrix' , 'aviatrices')
  708. # LATER, HIDE THE CLASSICAL FORM...
  709. defnoun( 'aviatrix' , 'aviatrixes')
  710. # FINALLY, RESTORE THE DEFAULT BEHAVIOUR...
  711. defnoun( 'aviatrix' , undef)
  712. Special care is also required when defining general patterns and
  713. associated specific exceptions: put the more specific cases *after*
  714. the general pattern. For example::
  715. defnoun( '(.+)us' , '$1i') # EVERY "-us" TO "-i"
  716. defnoun( 'bus' , 'buses') # EXCEPT FOR "bus"
  717. This "try-most-recently-defined-first" approach to matching
  718. user-defined words is also used by ``defverb``, ``defa`` and ``defan``.
  719. ``defverb(s1, p1, s2, p2, s3, p3)``
  720. The ``defverb`` method takes three pairs of string arguments (that is, six
  721. arguments in total), specifying the singular and plural forms of the three
  722. "persons" of verb. As with ``defnoun``, the singular forms are specifications of
  723. run-time-interpolated patterns, whilst the plural forms are specifications of
  724. (up to two) run-time-interpolated strings::
  725. defverb('am' , 'are',
  726. 'are' , 'are|art",
  727. 'is' , 'are')
  728. defverb('have' , 'have',
  729. 'have' , 'have",
  730. 'ha(s|th)' , 'have')
  731. Note that as with ``defnoun``, modern/classical variants of plurals
  732. may be separately specified, subsequent definitions replace previous
  733. ones, and ``None``'ed plural forms revert to the standard behaviour.
  734. ``defadj(singular, plural)``
  735. The ``defadj`` method takes a pair of string arguments, which specify
  736. the singular and plural forms of the adjective being defined.
  737. As with ``defnoun`` and ``defadj``, the singular forms are specifications of
  738. run-time-interpolated patterns, whilst the plural forms are specifications of
  739. (up to two) run-time-interpolated strings::
  740. defadj( 'this' , 'these')
  741. defadj( 'red' , 'red|gules')
  742. As previously, modern/classical variants of plurals
  743. may be separately specified, subsequent definitions replace previous
  744. ones, and ``None``'ed plural forms revert to the standard behaviour.
  745. ``defa(pattern)`` and ``defan(pattern)``
  746. The ``defa`` and ``defan`` methods each take a single argument, which
  747. specifies a pattern. If a word passed to ``a()`` or ``an()`` matches this
  748. pattern, it will be prefixed (unconditionally) with the corresponding indefinite
  749. article. For example::
  750. defa( 'error')
  751. defa( 'in.+')
  752. defan('mistake')
  753. defan('error')
  754. As with the other ``def_...`` methods, such redefinitions are sequential
  755. in effect so that, after the above example, "error" will be inflected with "an".
  756. The ``<$HOME/.inflectrc`` file
  757. ------------------------------
  758. THIS HAS NOT BEEN IMPLEMENTED IN THE PYTHON VERSION YET
  759. When it is imported, inflect.py executes (as Perl code)
  760. the contents of any file named ``.inflectrc`` which it finds in the
  761. in the directory where ``Lingua/EN/Inflect.pm`` is installed,
  762. or in the current home directory (``$ENV{HOME}``), or in both.
  763. Note that the code is executed within the inflect.py
  764. namespace.
  765. Hence the user or the local Perl guru can make appropriate calls to
  766. ``defnoun``, ``defverb``, etc. in one of these ``.inflectrc`` files, to
  767. permanently and universally modify the behaviour of the module. For example
  768. > cat /usr/local/lib/perl5/Text/Inflect/.inflectrc
  769. defnoun "UNIX" => "UN*X|UNICES"
  770. defverb "teco" => "teco", # LITERALLY: "to edit with TECO"
  771. "teco" => "teco",
  772. "tecos" => "teco"
  773. defa "Euler.*"; # "Yewler" TURNS IN HIS GRAVE
  774. Note that calls to the ``def_...`` methods from within a program
  775. will take precedence over the contents of the home directory
  776. F<.inflectrc> file, which in turn takes precedence over the system-wide
  777. F<.inflectrc> file.
  778. DIAGNOSTICS
  779. ===========
  780. THIS HAS NOT BEEN IMPLEMENTED IN THE PYTHON VERSION YET
  781. On loading, if the Perl code in a ``.inflectrc`` file is invalid
  782. (syntactically or otherwise), an appropriate fatal error is issued.
  783. A common problem is not ending the file with something that
  784. evaluates to true (as the five ``def_...`` methods do).
  785. Using the five ``def_...`` methods directly in a program may also
  786. result in fatal diagnostics, if a (singular) pattern or an interpolated
  787. (plural) string is somehow invalid.
  788. Specific diagnostics related to user-defined inflections are:
  789. ``"Bad user-defined singular pattern:\t %s"``
  790. The singular form of a user-defined noun or verb
  791. (as defined by a call to ``defnoun``, ``defverb``, ``defadj``,
  792. ``defa`` or ``defan``) is not a valid Perl regular expression. The
  793. actual Perl error message is also given.
  794. ``"Bad user-defined plural string: '%s'"``
  795. The plural form(s) of a user-defined noun or verb
  796. (as defined by a call to ``defnoun``, ``defverb`` or ``defadj``)
  797. is not a valid Perl interpolated string (usually because it
  798. interpolates some undefined variable).
  799. ``"Bad .inflectrc file (%s): %s"``
  800. Some other problem occurred in loading the named local
  801. or global F<.inflectrc> file. The Perl error message (including
  802. the line number) is also given.
  803. There are *no* diagnosable run-time error conditions for the actual
  804. inflection methods, except ``number_to_words`` and hence no run-time
  805. diagnostics. If the inflection methods are unable to form a plural
  806. via a user-definition or an inbuilt rule, they just "guess" the
  807. commonest English inflection: adding "-s" for nouns, removing "-s" for
  808. verbs, and no inflection for adjectives.
  809. ``inflect.py`` can raise the following execeptions:
  810. ``BadChunkingOptionError``
  811. The optional argument to ``number_to_words()`` wasn't 1, 2 or 3.
  812. ``NumOutOfRangeError``
  813. ``number_to_words()`` was passed a number larger than
  814. 999,999,999,999,999,999,999,999,999,999,999,999 (that is: nine hundred
  815. and ninety-nine decillion, nine hundred and ninety-nine nonillion, nine
  816. hundred and ninety-nine octillion, nine hundred and ninety-nine
  817. septillion, nine hundred and ninety-nine sextillion, nine hundred and
  818. ninety-nine quintillion, nine hundred and ninety-nine quadrillion, nine
  819. hundred and ninety-nine trillion, nine hundred and ninety-nine billion,
  820. nine hundred and ninety-nine million, nine hundred and ninety-nine
  821. thousand, nine hundred and ninety-nine :-)
  822. The problem is that ``number_to_words`` doesn't know any
  823. words for number components bigger than "decillion".
  824. ..
  825. #TODO expand these
  826. ``UnknownClassicalModeError``
  827. ``BadNumValueError``
  828. ``BadUserDefinedPatternError``
  829. ``BadRcFileError``
  830. OTHER ISSUES
  831. ============
  832. 2nd Person precedence
  833. ---------------------
  834. If a verb has identical 1st and 2nd person singular forms, but
  835. different 1st and 2nd person plural forms, then when its plural is
  836. constructed, the 2nd person plural form is always preferred.
  837. The author is not currently aware of any such verbs in English, but is
  838. not quite arrogant enough to assume *ipso facto* that none exist.
  839. Nominative precedence
  840. ---------------------
  841. The singular pronoun "it" presents a special problem because its plural form
  842. can vary, depending on its "case". For example::
  843. It ate my homework -> They ate my homework
  844. It ate it -> They ate them
  845. I fed my homework to it -> I fed my homework to them
  846. As a consequence of this ambiguity, ``plural()`` or ``plural_noun`` have been implemented
  847. so that they always return the *nominative* plural (that is, "they").
  848. However, when asked for the plural of an unambiguously *accusative*
  849. "it" (namely, ``plural("to it")``, ``plural_noun("from it")``, ``plural("with it")``,
  850. etc.), both methods will correctly return the accusative plural
  851. ("to them", "from them", "with them", etc.)
  852. The plurality of zero
  853. ---------------------
  854. The rules governing the choice between::
  855. There were no errors.
  856. and
  857. ::
  858. There was no error.
  859. are complex and often depend more on *intent* rather than *content*.
  860. Hence it is infeasible to specify such rules algorithmically.
  861. Therefore, inflect.py contents itself with the following compromise: If
  862. the governing number is zero, inflections always return the plural form
  863. unless the appropriate "classical" inflection is in effect, in which case the
  864. singular form is always returned.
  865. Thus, the sequence::
  866. p.num(0)
  867. print(p.inflect("There plural(was) no(choice)"))
  868. produces "There were no choices", whereas::
  869. p.classical(zero=True)
  870. p.num(0)
  871. print(p.inflect("There plural(was) no(choice)"))
  872. it will print("There was no choice".)
  873. Homographs with heterogeneous plurals
  874. -------------------------------------
  875. Another context in which intent (and not content) sometimes determines
  876. plurality is where two distinct meanings of a word require different
  877. plurals. For example::
  878. Three basses were stolen from the band's equipment trailer.
  879. Three bass were stolen from the band's aquarium.
  880. I put the mice next to the cheese.
  881. I put the mouses next to the computers.
  882. Several thoughts about leaving crossed my mind.
  883. Several thought about leaving across my lawn.
  884. inflect.py handles such words in two ways:
  885. - If both meanings of the word are the *same* part of speech (for
  886. example, "bass" is a noun in both sentences above), then one meaning
  887. is chosen as the "usual" meaning, and only that meaning's plural is
  888. ever returned by any of the inflection methods.
  889. - If each meaning of the word is a different part of speech (for
  890. example, "thought" is both a noun and a verb), then the noun's
  891. plural is returned by ``plural()`` and ``plural_noun()`` and the verb's plural is
  892. returned only by ``plural_verb()``.
  893. Such contexts are, fortunately, uncommon (particularly
  894. "same-part-of-speech" examples). An informal study of nearly 600
  895. "difficult plurals" indicates that ``plural()`` can be relied upon to "get
  896. it right" about 98% of the time (although, of course, ichthyophilic
  897. guitarists or cyber-behaviouralists may experience higher rates of
  898. confusion).
  899. If the choice of a particular "usual inflection" is considered
  900. inappropriate, it can always be reversed with a preliminary call
  901. to the corresponding ``def_...`` method.
  902. NOTE
  903. ====
  904. There will be no further correspondence on:
  905. "octopi".
  906. Despite the populist pandering of certain New World dictionaries, the
  907. plural is "octopuses" or (for the pendantic classicist) "octopodes". The
  908. suffix "-pus" is Greek, not Latin, so the plural is "-podes", not "pi".
  909. "virus".
  910. Had no plural in Latin (possibly because it was a mass noun).
  911. The only plural is the Anglicized "viruses".
  912. AUTHORS
  913. =======
  914. Thorben Krüger (github@benthor.name)
  915. * established Python 3 compatibility
  916. Paul Dyson (pwdyson@yahoo.com)
  917. * converted code from Perl to Python
  918. * added singular_noun functionality
  919. Original Perl version of the code and documentation:
  920. Damian Conway (damian@conway.org),
  921. Matthew Persico (ORD inflection)
  922. BUGS AND IRRITATIONS
  923. ====================
  924. The endless inconsistencies of English.
  925. (*Please* report words for which the correct plural or
  926. indefinite article is not formed, so that the reliability
  927. of inflect.py can be improved.)
  928. COPYRIGHT
  929. =========
  930. Copyright (C) 2010 Paul Dyson
  931. Based upon the Perl module Lingua::EN::Inflect by Damian Conway.
  932. This program is free software: you can redistribute it and/or modify
  933. it under the terms of the GNU Affero General Public License as published by
  934. the Free Software Foundation, either version 3 of the License, or
  935. (at your option) any later version.
  936. This program is distributed in the hope that it will be useful,
  937. but WITHOUT ANY WARRANTY; without even the implied warranty of
  938. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  939. GNU General Public License for more details.
  940. You should have received a copy of the GNU Affero General Public License
  941. along with this program. If not, see <http://www.gnu.org/licenses/>.
  942. The original Perl module Lingua::EN::Inflect by Damian Conway is
  943. available from http://search.cpan.org/~dconway/
  944. This module can be downloaded at http://pypi.python.org/pypi/inflect
  945. This module can be installed via ``easy_install inflect``
  946. Repository available at http://github.com/pwdyson/inflect.py