Module | Linguistics::EN |
In: |
lib/linguistics/en/infinitive.rb
lib/linguistics/en/linkparser.rb lib/linguistics/en/wordnet.rb lib/linguistics/en.rb |
This module contains English-language linguistic functions for the Linguistics module. It can be either loaded directly, or by passing some variant of ‘en’ or ‘eng’ to the Linguistics::use method.
The functions contained by the module provide:
Plural forms of all nouns, most verbs, and some adjectives are provided. Where appropriate, "classical" variants (for example: "brother" -> "brethren", "dogma" -> "dogmata", etc.) are also provided.
These can be accessed via the #plural, #plural_noun, #plural_verb, and #plural_adjective methods.
Pronunciation-based "a"/"an" selection is provided for all English words, and most initialisms.
Conversion from Numeric values to words are supported using the American "thousands" system. E.g., 2561 => "two thousand, five hundred and sixty-one".
See the #numwords method.
It is also possible to inflect numerals (1,2,3) and number words ("one", "two", "three") to ordinals (1st, 2nd, 3rd) and ordinates ("first", "second", "third").
This module also supports the creation of English conjunctions from Arrays of Strings or objects which respond to the #to_s message. Eg.,
%w{cow pig chicken cow dog cow duck duck moose}.en.conjunction ==> "three cows, two ducks, a pig, a chicken, a dog, and a moose"
Returns the infinitive form of English verbs:
"dodging".en.infinitive ==> "dodge"
The inflection functions of this module were adapted from Damien Conway‘s Lingua::EN::Inflect Perl module:
Copyright (c) 1997-2000, Damian Conway. All Rights Reserved. This module is free software. It may be used, redistributed and/or modified under the same terms as Perl itself.
The conjunctions code was adapted from the Lingua::Conjunction Perl module written by Robert Rothenberg and Damian Conway, which has no copyright statement included.
Copyright (c) 2003-2008, Michael Granger All rights reserved.
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of the author/s, nor the names of the project's contributors may be used to endorse or promote products derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
lprintf_formatters | [RW] |
If #has_link_parser? returns false, this can be called to fetch the exception which was raised when trying to load LinkParser.
If #haveWordnet? returns false, this can be called to fetch the exception which was raised when WordNet was loaded.
Turns a camel-case string ("camelCaseToEnglish") to plain English ("camel case to english"). Each word is decapitalized.
Return the specified obj (which must support the #collect method) as a conjunction. Each item is converted to a String if it is not already (using #to_s) unless a block is given, in which case it is called once for each object in the array, and the stringified return value from the block is used instead. Returning nil causes that particular element to be omitted from the resulting conjunction. The following options can be used to control the makeup of the returned conjunction String:
%w{duck, cow, dog}.en.conjunction # => "a duck, a cow, and a dog" %w{duck cow dog}.en.conjunction( :penultimate => false ) "a duck, a cow and a dog"
Default to true.
%w{goose cow goose dog}.en.conjunction # => "two geese, a cow, and a dog" %w{goose cow goose dog}.en.conjunction( :combine => false ) # => "a goose, a cow, a goose, and a dog"
ary = %w{goose pig dog horse goose reindeer goose dog horse} ary.en.conjunction # => "three geese, two dogs, two horses, a pig, and a reindeer" ary.en.conjunction( :generalize => true ) # => "several geese, several dogs, several horses, a pig, and a reindeer"
See the #quantify method for specifics on how quantities are generalized. Generalization defaults to false, and has no effect if :combine is false.
Returns the given word with a prepended indefinite article, unless count is non-nil and not singular.
Format the given fmt string by replacing %-escaped sequences with the result of performing a specified operation on the corresponding argument, ala Kernel.sprintf.
%PL: | Plural. |
%A, %AN: | Prepend indefinite article. |
%NO: | Zero-quantified phrase. |
%NUMWORDS: | Convert a number into the corresponding words. |
%CONJUNCT: | Conjunction. |
Return the specified number as english words. One or more configuration values may be passed to control the returned String:
Do normal/classical switching and match capitalization in inflected by examining the original input.
Returns the proper noun form of a string by capitalizing most of the words.
Examples:
English.proper_noun("bosnia and herzegovina") -> "Bosnia and Herzegovina" English.proper_noun("macedonia, the former yugoslav republic of") -> "Macedonia, the Former Yugoslav Republic of" English.proper_noun("virgin islands, u.s.") -> "Virgin Islands, U.S."
Return a phrase describing the specified number of objects in the given phrase in general terms. The following options can be used to control the makeup of the returned quantity String:
Transform the specified number of hundreds-, tens-, and units-place numerals into a word phrase. If the number of thousands (thousands) is greater than 0, it will be used to determine where the decimal point is in relation to the hundreds-place number.
Transform the specified number of tens- and units-place numerals into a word-phrase at the given number of thousands places.
Transform the specified number into one or more words like ‘thousand’, ‘million’, etc. Uses the thousands (American) system.
Transform the specified number of units-place numerals into a word-phrase at the given number of thousands places.