From: Michael Granger Date: 2012-10-11T01:14:49+09:00 Subject: [ANN] linguistics 2.0.0 Released --=_MailMate_CEC0FD86-07DE-4E23-AE28-ACD6BFCAA3FB_= Content-Type: text/plain; charset=utf-8; format=flowed; markup=markdown Content-Transfer-Encoding: 8bit linguistics version 2.0.0 has been released! * docs: * project: * github: Linguistics is a framework for building linguistic utilities for Ruby objects in any language. It includes a generic language-independant front end, a module for mapping language codes into language names, and a module which contains various English-language utilities. Version 2.0 has been rewritten to be more modular, easier to extend and maintain, and to work better under 1.9. Version 2 is Ruby 1.9-only. = Examples Here's some examples of what the English-language module can do: == Pluralization "box".en.plural # => "boxes" "mouse".en.plural # => "mice" "ruby".en.plural # => "rubies" == Indefinite Articles "book".en.a # => "a book" "article".en.a # => "an article" == Present Participles "runs".en.present_participle # => "running" "eats".en.present_participle # => "eating" "spies".en.present_participle # => "spying" == Ordinal Numbers 5.en.ordinal # => "5th" 2004.en.ordinal # => "2004th" == Numbers to Words 5.en.numwords # => "five" 2004.en.numwords # => "two thousand and four" 2385762345876.en.numwords # => "two trillion, three hundred and eighty-five billion, seven hundred and # sixty-two million, three hundred and forty-five thousand, eight hundred # and seventy-six" == Quantification "cow".en.quantify( 5 ) # => "several cows" "cow".en.quantify( 1005 ) # => "thousands of cows" "cow".en.quantify( 20_432_123_000_000 ) # => "tens of trillions of cows" == Conjunctions animals = %w{dog cow ox chicken goose goat cow dog rooster llama pig goat dog cat cat dog cow goat goose goose ox alpaca} "The farm has: " + animals.en.conjunction # => "The farm has: four dogs, three cows, three geese, three goats, two # oxen, two cats, a chicken, a rooster, a llama, a pig, and an alpaca" Note that 'goose' and 'ox' are both correctly pluralized, and the correct indefinite article 'an' has been used for 'alpaca'. You can also use the generalization function of the #quantify method to give general descriptions of object lists instead of literal counts: allobjs = [] ObjectSpace::each_object {|obj| allobjs << obj.class.name } puts "The current Ruby objectspace contains: " + allobjs.en.conjunction( :generalize => true ) Outputs: The current Ruby objectspace contains: hundreds of thousands of Strings, thousands of RubyVM::InstructionSequences, thousands of Arrays, thousands of Hashes, hundreds of Procs, hundreds of Regexps, [...], a SystemStackError, a Random, an ARGF.class, a Data, a fatal, an OptionParser::List, a YAML::EngineManager, a URI::Parser, a Rational, and a Gem::Platform == Infinitives "leaving".en.infinitive # => "leave" "left".en.infinitive # => "leave" "leaving".en.infinitive.suffix # => "ing" == Conjugation Conjugate a verb given an infinitive: "run".en.past_tense # => "ran" "run".en.past_participle # => "run" "run".en.present_tense # => "run" "run".en.present_participle # => "running" Conjugate an infinitive with an explicit tense and grammatical person: "be".en.conjugate( :present, :third_person_singular ) # => "is" "be".en.conjugate( :present, :first_person_singular ) # => "am" "be".en.conjugate( :past, :first_person_singular ) # => "was" The functionality is a port of the verb conjugation portion of Morph Adorner (http://morphadorner.northwestern.edu/). It includes a good number of irregular verbs, but it's not going to be 100% correct every time. == WordNet速 Integration If you have the 'wordnet' gem installed, you can look up WordNet synsets using the Linguistics interface: Test to be sure the WordNet module loaded okay. Linguistics::EN.has_wordnet? # => true Fetch the default synset for the word "balance" "balance".en.synset # => # Fetch the synset for the first verb sense of "balance" "balance".en.synset( :verb ) # => # Fetch the second noun sense "balance".en.synset( 2, :noun ) # => # Fetch the second noun sense's hypernyms (more-general words, like a superclass) "balance".en.synset( 2, :noun ).hypernyms # => [#] A simpler way of doing the same thing: "balance".en.hypernyms( 2, :noun ) # => [#] Fetch the first hypernym's hypernyms "balance".en.synset( 2, :noun ).hypernyms.first.hypernyms # => [#] Find the synset to which both the second noun sense of "balance" and the default sense of "shovel" belong. ("balance".en.synset( 2, :noun ) | "shovel".en.synset) # => # Fetch words for the specific kinds of (device-ish) "instruments" "instrument".en.hyponyms( "device" ).collect( &:words ).flatten.join(', ') # => "analyser, analyzer, cauterant, cautery, drafting instrument, engine, # extractor, instrument of execution, instrument of punishment, measuring # device, measuring instrument, measuring system, medical instrument, # navigational instrument, optical instrument, plotter, scientific # instrument, sonograph, surveying instrument, surveyor's instrument, # tracer, arm, weapon, weapon system, whip" ..or musical instruments "instrument".en.hyponyms( "musical" ).collect( &:words ).flatten.join(', ') # => "barrel organ, grind organ, hand organ, hurdy-gurdy, hurdy gurdy, # street organ, bass, calliope, steam organ, electronic instrument, # electronic musical instrument, jew's harp, jews' harp, mouth bow, keyboard # instrument, music box, musical box, percussion instrument, percussive # instrument, stringed instrument, wind, wind instrument" There are many more WordNet methods supported--too many to list here. See the WordNet::Synset API documentation for the complete list. == LinkParser Integration If you have the 'linkparser' gem installed, you can create linkages from English sentences that let you query for parts of speech: Test to see whether or not the link parser is loaded. Linguistics::EN.has_linkparser? # => true Diagram the first linkage for a test sentence puts "he is a big dog".en.sentence.linkages.first.diagram Outputs: +-----Ost----+ | +----Ds---+ +-Ss+ | +--A--+ | | | | | he is.v a big.a dog.n Find the verb in the sentence "he is a big dog".en.sentence.verb.to_s # => "is" Combined infinitive + LinkParser: Find the infinitive form of the verb of the given sentence. "he is a big dog".en.sentence.verb.en.infinitive # => "be" Find the direct object of the sentence "he is a big dog".en.sentence.object.to_s # => "dog" Combine WordNet + LinkParser to find the definition of the direct object of the sentence "he is a big dog".en.sentence.object.en.definition # => "a member of the genus Canis (probably descended from the common wolf) # that has been domesticated by man since prehistoric times; occurs in many # breeds" = Installation gem install linguistics -- Michael Granger Rubymage, Architect, Believer The FaerieMUD Consortium --=_MailMate_CEC0FD86-07DE-4E23-AE28-ACD6BFCAA3FB_= Content-Type: text/html; charset=utf-8 Content-Transfer-Encoding: quoted-printable

linguistics version 2.0.0 has been released!

Linguistics is a framework for building linguistic utilities for Ruby<= br> objects in any language. It includes a generic language-independant
front end, a module for mapping language codes into language names, and a module which contains various English-language utilities.

Version 2.0 has been rewritten to be more modular, easier to extend an= d
maintain, and to work better under 1.9.

Version 2 is Ruby 1.9-only.

=3D Examples

Here's some examples of what the English-language module can do:

=3D=3D Pluralization

"box".en.plural
# =3D> "boxes"

"mouse".en.plural
# =3D> "mice"

"ruby".en.plural
# =3D> "rubies"

=3D=3D Indefinite Articles

"book".en.a
# =3D> "a book"

"article".en.a
# =3D> "an article"

=3D=3D Present Participles

"runs".en.present_participle
# =3D> "running"

"eats".en.present_participle
# =3D> "eating"

"spies".en.present_participle
# =3D> "spying"

=3D=3D Ordinal Numbers

5.en.ordinal
# =3D> "5th"

2004.en.ordinal
# =3D> "2004th"

=3D=3D Numbers to Words

5.en.numwords
# =3D> "five"

2004.en.numwords
# =3D> "two thousand and four"

2385762345876.en.numwords
# =3D> "two trillion, three hundred and eighty-five billion, seve=
n hundred and
#     sixty-two million, three hundred and forty-five thousand, eight hun=
dred
#     and seventy-six"

=3D=3D Quantification

"cow".en.quantify( 5 )
# =3D> "several cows"

"cow".en.quantify( 1005 )
# =3D> "thousands of cows"

"cow".en.quantify( 20_432_123_000_000 )
# =3D> "tens of trillions of cows"

=3D=3D Conjunctions

animals =3D %w{dog cow ox chicken goose goat cow dog rooster l=
lama pig goat
             dog cat cat dog cow goat goose goose ox alpaca}
"The farm has: " + animals.en.conjunction
# =3D> "The farm has: four dogs, three cows, three geese, three g=
oats, two
#     oxen, two cats, a chicken, a rooster, a llama, a pig, and an alpaca=
"

Note that 'goose' and 'ox' are both correctly pluraliz= ed, and the correct
indefinite article 'an' has been used for 'alpaca'.

You can also use the generalization function of the #quantify method t= o give
general descriptions of object lists instead of literal counts:

allobjs =3D []
ObjectSpace::each_object {|obj| allobjs << obj.class.name }
puts "The current Ruby objectspace contains: " +
     allobjs.en.conjunction( :generalize =3D> true )

Outputs:

The current Ruby objectspace contains: hundreds of thousands o=
f Strings,
thousands of RubyVM::InstructionSequences, thousands of Arrays, thousands=

of Hashes, hundreds of Procs, hundreds of Regexps, [...], a
SystemStackError, a Random, an ARGF.class, a Data, a fatal, an
OptionParser::List, a YAML::EngineManager, a URI::Parser, a Rational, and=

a Gem::Platform

=3D=3D Infinitives

"leaving".en.infinitive
# =3D> "leave"

"left".en.infinitive
# =3D> "leave"

"leaving".en.infinitive.suffix
# =3D> "ing"

=3D=3D Conjugation

Conjugate a verb given an infinitive:

"run".en.past_tense
# =3D> "ran"

"run".en.past_participle
# =3D> "run"

"run".en.present_tense
# =3D> "run"

"run".en.present_participle
# =3D> "running"

Conjugate an infinitive with an explicit tense and grammatical person:=

"be".en.conjugate( :present, :third_person_singular =
)
# =3D> "is"

"be".en.conjugate( :present, :first_person_singular )
# =3D> "am"

"be".en.conjugate( :past, :first_person_singular )
# =3D> "was"

The functionality is a port of the verb conjugation portion of Morph Adorner (http://morphadorner.northwestern.edu/).

It includes a good number of irregular verbs, but it's not going t= o be
100% correct every time.

=3D=3D WordNet=C2=AE Integration

If you have the 'wordnet' gem installed, you can look up WordN= et synsets using
the Linguistics interface:

Test to be sure the WordNet module loaded okay.

Linguistics::EN.has_wordnet?
# =3D> true

Fetch the default synset for the word "balance"

"balance".en.synset
# =3D> #<WordNet::Synset:0x7f9fb11012f8 {102777100} 'balance=
9; (noun):
#    [noun.artifact] a scale for weighing; depends on pull of gravity>=

Fetch the synset for the first verb sense of "balance"

"balance".en.synset( :verb )
# =3D> #<WordNet::Synset:0x7f9fb10f3fb8 {201602318} 'balance, p=
oise' (verb):
#    [verb.contact] hold or carry in equilibrium>

Fetch the second noun sense

"balance".en.synset( 2, :noun )
# =3D> #<WordNet::Synset:0x7f9fb10ebbd8 {102777402} 'balance, b=
alance wheel'
#     (noun): [noun.artifact] a wheel that regulates the rate of movement=
 in a
#     machine; especially a wheel oscillating against the hairspring of a=

#     timepiece to regulate its beat>

Fetch the second noun sense's hypernyms (more-general words, like = a
superclass)

"balance".en.synset( 2, :noun ).hypernyms
# =3D> [#<WordNet::Synset:0x7f9fb10dd100 {104574999} 'wheel'=
; (noun):
#    [noun.artifact] a simple machine consisting of a circular frame with=

#    spokes (or a solid disc) that can rotate on a shaft or axle (as in
#    vehicles or other machines)>]

A simpler way of doing the same thing:

"balance".en.hypernyms( 2, :noun )
# =3D> [#<WordNet::Synset:0x7f9fb10d24d0 {104574999} 'wheel'=
; (noun):
#    [noun.artifact] a simple machine consisting of a circular frame with=

#    spokes (or a solid disc) that can rotate on a shaft or axle (as in
#    vehicles or other machines)>]

Fetch the first hypernym's hypernyms

"balance".en.synset( 2, :noun ).hypernyms.first.hype=
rnyms
# =3D> [#<WordNet::Synset:0x7f9fb10c5190 {103700963} 'machine, =
simple machine'
#    (noun): [noun.artifact] a device for overcoming resistance at one po=
int by
#    applying force at some other point>]

Find the synset to which both the second noun sense of "balance&q= uot; and the
default sense of "shovel" belong.

("balance".en.synset( 2, :noun ) | "shovel"=
;.en.synset)
# =3D> #<WordNet::Synset:0x7f9fb1091e58 {103183080} 'device'=
; (noun):
#    [noun.artifact] an instrumentality invented for a particular purpose=
>

Fetch words for the specific kinds of (device-ish) "instruments&q= uot;

"instrument".en.hyponyms( "device" ).colle=
ct( &:words ).flatten.join(', ')
# =3D> "analyser, analyzer, cauterant, cautery, drafting instrume=
nt, engine,
#    extractor, instrument of execution, instrument of punishment, measur=
ing
#    device, measuring instrument, measuring system, medical instrument,
#    navigational instrument, optical instrument, plotter, scientific
#    instrument, sonograph, surveying instrument, surveyor's instrume=
nt,
#    tracer, arm, weapon, weapon system, whip"

...or musical instruments

"instrument".en.hyponyms( "musical" ).coll=
ect( &:words ).flatten.join(', ')
# =3D> "barrel organ, grind organ, hand organ, hurdy-gurdy, hurdy=
 gurdy,
#    street organ, bass, calliope, steam organ, electronic instrument,
#    electronic musical instrument, jew's harp, jews' harp, mouth=
 bow, keyboard
#    instrument, music box, musical box, percussion instrument, percussiv=
e
#    instrument, stringed instrument, wind, wind instrument"

There are many more WordNet methods supported--too many to list here. = See the
WordNet::Synset API documentation for the complete list.

=3D=3D LinkParser Integration

If you have the 'linkparser' gem installed, you can create lin= kages
from English sentences that let you query for parts of speech:

Test to see whether or not the link parser is loaded.

Linguistics::EN.has_linkparser?
# =3D> true

Diagram the first linkage for a test sentence

puts "he is a big dog".en.sentence.linkages.first.di=
agram

Outputs:

     +-----Ost----+
     |  +----Ds---+
 +-Ss+  |   +--A--+
 |   |  |   |     |
he is.v a big.a dog.n

Find the verb in the sentence

"he is a big dog".en.sentence.verb.to_s
# =3D> "is"

Combined infinitive + LinkParser: Find the infinitive form of the verb= of the
given sentence.

"he is a big dog".en.sentence.verb.en.infinitive
# =3D> "be"

Find the direct object of the sentence

"he is a big dog".en.sentence.object.to_s
# =3D> "dog"

Combine WordNet + LinkParser to find the definition of the direct obje= ct of
the sentence

"he is a big dog".en.sentence.object.en.definition
# =3D> "a member of the genus Canis (probably descended from the =
common wolf)
#    that has been domesticated by man since prehistoric times; occurs in=
 many
#    breeds"

=3D Installation

gem install linguistics

Michael Granger ged@FaerieMUD.org=
Rubymage, Architect, Believer
The FaerieMUD Consortium http://= ;faeriemud.org/

= --=_MailMate_CEC0FD86-07DE-4E23-AE28-ACD6BFCAA3FB_=--