├── work ├── deprecated │ ├── meta │ │ ├── name │ │ ├── version │ │ ├── created │ │ ├── requires │ │ ├── collection │ │ ├── released │ │ ├── summary │ │ ├── homepage │ │ ├── requisites │ │ │ ├── production │ │ │ │ └── requires │ │ │ └── development │ │ │ │ └── requires │ │ ├── contact │ │ ├── repository │ │ ├── authors │ │ └── description │ ├── test │ │ ├── test_similarity.rb │ │ ├── test_stylize.rb │ │ ├── test_humanize.rb │ │ ├── test_levenshtein.rb │ │ └── test_style_orm.rb │ ├── patterns.rb │ ├── censor.rb │ ├── textfilter.rb │ ├── stylize.rb │ ├── humanize.rb │ ├── words.rb │ ├── stylize2.rb │ ├── case.rb │ └── style.rb ├── reference │ └── grammer.bak │ │ ├── grammer.css │ │ ├── gramdex.html │ │ ├── gramex01.html │ │ ├── gramex14.html │ │ └── gramex16.html └── consider │ ├── join_sentence.rb │ └── test_censor.rb ├── .gitignore ├── lib ├── english │ ├── mixin.rb │ ├── words.rb │ ├── censor.rb │ ├── participle.rb │ ├── class.rb │ ├── jumble.rb │ ├── dresner.rb │ ├── ordinal.rb │ ├── conjunction.rb │ ├── numeral.rb │ ├── soundex.rb │ ├── namecase.rb │ ├── porter.rb │ └── inflect.rb ├── en.rb └── english.rb ├── site ├── assets │ ├── images │ │ ├── pen.jpg │ │ ├── corner.png │ │ ├── spiral.png │ │ ├── english.png │ │ ├── letter-e.jpg │ │ ├── itcamefrom.png │ │ ├── english_red_white.png │ │ ├── english_green_white.png │ │ └── english_purple_black.png │ ├── ads │ │ └── rdoc.html │ └── style.css ├── .rsync-filter ├── grammar │ ├── grammer.css │ ├── gramdex.html │ ├── gramex01.html │ ├── gramex14.html │ ├── gramex16.html │ └── gramirr.html └── index.html ├── test ├── fixture │ ├── soundex.txt │ ├── metaphone.txt │ └── metaphone_lp.txt ├── test_dresner.rb ├── test_soundex.rb ├── test_porter.rb ├── test_namecase.rb ├── test_metaphone.rb ├── test_inflect.rb └── test_infinitive.rb ├── AUTHORS ├── PROFILE ├── Rakefile ├── MANIFEST ├── LICENSE ├── Syckfile ├── .ruby ├── README.rdoc ├── .gemspec ├── NOTICE └── HISTORY.rdoc /work/deprecated/meta/name: -------------------------------------------------------------------------------- 1 | english 2 | -------------------------------------------------------------------------------- /work/deprecated/meta/version: -------------------------------------------------------------------------------- 1 | 0.6.0 2 | -------------------------------------------------------------------------------- /work/deprecated/meta/created: -------------------------------------------------------------------------------- 1 | 2007-08-01 2 | -------------------------------------------------------------------------------- /work/deprecated/meta/requires: -------------------------------------------------------------------------------- 1 | language 2 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | log 2 | ri 3 | pkg 4 | site/docs 5 | -------------------------------------------------------------------------------- /work/deprecated/meta/collection: -------------------------------------------------------------------------------- 1 | rubyworks 2 | -------------------------------------------------------------------------------- /work/deprecated/meta/released: -------------------------------------------------------------------------------- 1 | 2009-06-06 2 | -------------------------------------------------------------------------------- /lib/english/mixin.rb: -------------------------------------------------------------------------------- 1 | require 'language/mixin' 2 | -------------------------------------------------------------------------------- /work/deprecated/meta/summary: -------------------------------------------------------------------------------- 1 | English Code Kit 2 | -------------------------------------------------------------------------------- /lib/en.rb: -------------------------------------------------------------------------------- 1 | require File.dirname(__FILE__) + '/english.rb' 2 | -------------------------------------------------------------------------------- /work/deprecated/meta/homepage: -------------------------------------------------------------------------------- 1 | http://english.rubyforge.org 2 | -------------------------------------------------------------------------------- /work/deprecated/meta/requisites/production/requires: -------------------------------------------------------------------------------- 1 | language 2 | -------------------------------------------------------------------------------- /work/deprecated/meta/contact: -------------------------------------------------------------------------------- 1 | rubyworks-mailinglist@googlegroups.com 2 | -------------------------------------------------------------------------------- /work/deprecated/meta/repository: -------------------------------------------------------------------------------- 1 | git://github.com/rubyworks/english.git 2 | -------------------------------------------------------------------------------- /lib/english/words.rb: -------------------------------------------------------------------------------- 1 | require 'english/class' 2 | require 'language/words' 3 | 4 | -------------------------------------------------------------------------------- /work/deprecated/meta/authors: -------------------------------------------------------------------------------- 1 | 7rans 2 | George Moschovitis 3 | -------------------------------------------------------------------------------- /work/deprecated/meta/requisites/development/requires: -------------------------------------------------------------------------------- 1 | language 2 | qed 3 | rcov 4 | -------------------------------------------------------------------------------- /site/assets/images/pen.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rubyworks/english/master/site/assets/images/pen.jpg -------------------------------------------------------------------------------- /site/assets/images/corner.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rubyworks/english/master/site/assets/images/corner.png -------------------------------------------------------------------------------- /site/assets/images/spiral.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rubyworks/english/master/site/assets/images/spiral.png -------------------------------------------------------------------------------- /site/assets/images/english.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rubyworks/english/master/site/assets/images/english.png -------------------------------------------------------------------------------- /site/assets/images/letter-e.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rubyworks/english/master/site/assets/images/letter-e.jpg -------------------------------------------------------------------------------- /site/assets/images/itcamefrom.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rubyworks/english/master/site/assets/images/itcamefrom.png -------------------------------------------------------------------------------- /site/assets/images/english_red_white.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rubyworks/english/master/site/assets/images/english_red_white.png -------------------------------------------------------------------------------- /site/.rsync-filter: -------------------------------------------------------------------------------- 1 | - .svn 2 | - scrap 3 | P wiki 4 | P robot.txt 5 | P robots.txt 6 | P statcvs 7 | P statsvn 8 | P usage 9 | 10 | -------------------------------------------------------------------------------- /site/assets/images/english_green_white.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rubyworks/english/master/site/assets/images/english_green_white.png -------------------------------------------------------------------------------- /site/assets/images/english_purple_black.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rubyworks/english/master/site/assets/images/english_purple_black.png -------------------------------------------------------------------------------- /work/deprecated/meta/description: -------------------------------------------------------------------------------- 1 | English is an general purpose English language processing library. 2 | It includes a number of useful libraries, such as inflect.rb, 3 | similarity.rb, metaphone.rb, and so on. 4 | -------------------------------------------------------------------------------- /test/fixture/soundex.txt: -------------------------------------------------------------------------------- 1 | # 2 | # Test data for soundex algorithm. 3 | # 4 | Euler: E460 5 | Ellery: E460 6 | Gauss: G200 7 | Ghosh: G200 8 | Hilbert: H416 9 | Heilbronn: H416 10 | Knuth: K530 11 | Kant: K530 12 | Lloyd: L300 13 | Ladd: L300 14 | Lukasiewicz: L222 15 | Lissajous: L222 16 | -------------------------------------------------------------------------------- /lib/english/censor.rb: -------------------------------------------------------------------------------- 1 | require 'language/censor' 2 | 3 | class English 4 | 5 | def self.dirty_words 6 | %w{fuck shit cunt pussy dick asshole niger} 7 | end 8 | 9 | class Censor < Language::Censor 10 | # 11 | def self.default_words 12 | English.dirty_words 13 | end 14 | end 15 | 16 | end 17 | -------------------------------------------------------------------------------- /work/deprecated/test/test_similarity.rb: -------------------------------------------------------------------------------- 1 | require 'english/similarity' 2 | require 'test/unit' 3 | 4 | class TestSimilarity < Test::Unit::TestCase 5 | 6 | # TODO: Need to test better. 7 | 8 | def test_similarity 9 | assert_nothing_raised { "Hello World!".similarity( "helo wrld" ) } 10 | end 11 | 12 | end 13 | 14 | -------------------------------------------------------------------------------- /work/reference/grammer.bak/grammer.css: -------------------------------------------------------------------------------- 1 | body { 2 | background: #222244; 3 | text-align: center; 4 | font-family: Microsoft sans-serif, sans-serif; 5 | font-size: 11pt; 6 | line-height: 15pt; 7 | } 8 | 9 | #adhispanic { 10 | margin: 0 auto; 11 | width: 900px; 12 | text-align: left; 13 | background: white; 14 | padding: 20px; 15 | } 16 | 17 | -------------------------------------------------------------------------------- /test/test_dresner.rb: -------------------------------------------------------------------------------- 1 | require 'english/dresner' 2 | require 'test/unit' 3 | 4 | class TC_Dresner < Test::Unit::TestCase 5 | 6 | def test_dresner 7 | # assert_still_legible ;-) 8 | assert_nothing_raised { "How are you today?".en.dresner } 9 | end 10 | 11 | #def test_dresner 12 | # # assert_still_legible ;-) 13 | # assert_nothing_raised { "How are you today?".dresner! } 14 | #end 15 | 16 | end 17 | 18 | -------------------------------------------------------------------------------- /work/consider/join_sentence.rb: -------------------------------------------------------------------------------- 1 | class String 2 | 3 | # 4 | 5 | def join_sentence(sep=nil, last=nil) 6 | sep ||= ',' 7 | last ||= 'and' 8 | 9 | sep, last = *[sep, last].collect do |w| 10 | case w 11 | when /^\w.*?\w$/ 12 | " #{w} " 13 | else 14 | "#{w} " 15 | end 16 | end 17 | 18 | seps = [sep] * (size - 1) 19 | seps[-1] = last 20 | zip(seps).join 21 | end 22 | 23 | end 24 | -------------------------------------------------------------------------------- /work/consider/test_censor.rb: -------------------------------------------------------------------------------- 1 | require 'test/unit' 2 | require 'english/censor' 3 | 4 | class TC_String_Censor < Test::Unit::TestCase 5 | 6 | def test_word_filter 7 | s = "this is a test" 8 | n = s.word_filter{ |w| "#{w}1" } 9 | assert_equal( 'this1 is1 a1 test1', n ) 10 | end 11 | 12 | def test_word_filter! 13 | s = "this is a test" 14 | s.word_filter!{ |w| "#{w}1" } 15 | assert_equal( 'this1 is1 a1 test1', s ) 16 | end 17 | 18 | end 19 | -------------------------------------------------------------------------------- /AUTHORS: -------------------------------------------------------------------------------- 1 | = AUTHORS 2 | 3 | As with many good programming libraries, portions were derived from 4 | the efforts of many good programmers. English owes it's existence 5 | to the hard work of following developers: 6 | 7 | * Paul Battley 8 | * Kurt Dresner 9 | * Michael Granger 10 | * George Moschovitis 11 | * Michael Neumann 12 | * Glenn P. Parker 13 | * Aaron Patterson 14 | * Ray Pereda 15 | * Lawrence Philips 16 | * Martin Porter 17 | * Thomas Sawyer 18 | * Louis J Scoras 19 | * Stephen Woodbridge 20 | 21 | -------------------------------------------------------------------------------- /site/assets/ads/rdoc.html: -------------------------------------------------------------------------------- 1 |
2 | 12 | 15 |
16 | -------------------------------------------------------------------------------- /site/grammar/grammer.css: -------------------------------------------------------------------------------- 1 | body { 2 | background: #000000; 3 | text-align: center; 4 | font-family: Microsoft sans-serif, sans-serif; 5 | font-size: 10pt; 6 | line-height: 20pt; 7 | } 8 | 9 | table { 10 | width: 100%; 11 | } 12 | 13 | #ad { 14 | } 15 | 16 | #adhispanic { 17 | margin: 0 auto; 18 | width: 900px; 19 | text-align: left; 20 | background: white; 21 | padding: 20px; 22 | } 23 | 24 | .chtitle { 25 | background: black; 26 | width: 100%; 27 | } 28 | 29 | .navbar { 30 | background: white; 31 | } 32 | 33 | -------------------------------------------------------------------------------- /lib/english.rb: -------------------------------------------------------------------------------- 1 | require 'english/class' 2 | 3 | require 'english/conjunction' 4 | require 'english/infinitive' 5 | require 'english/inflect' 6 | require 'english/namecase' 7 | 8 | require 'english/numeral' 9 | require 'english/ordinal' 10 | 11 | require 'english/dresner' 12 | require 'english/jumble' 13 | 14 | require 'english/metaphone' 15 | require 'english/soundex' 16 | require 'english/porter' 17 | 18 | require 'english/words' 19 | require 'english/censor' 20 | 21 | require 'english/mixin' 22 | 23 | Language.default = 'en' #$language ||= 'en' 24 | -------------------------------------------------------------------------------- /lib/english/participle.rb: -------------------------------------------------------------------------------- 1 | class English 2 | 3 | def self.present_participle(word) 4 | plural = plural_verb(word.to_s, 2) 5 | 6 | plural.sub!( /ie$/, 'y' ) or 7 | plural.sub!( /ue$/, 'u' ) or 8 | plural.sub!( /([auy])e$/, '$1' ) or 9 | plural.sub!( /i$/, '' ) or 10 | plural.sub!( /([^e])e$/, "\\1" ) or 11 | /er$/.match( plural ) or 12 | plural.sub!( /([^aeiou][aeiouy]([bdgmnprst]))$/, "\\1\\2" ) 13 | 14 | return "#{plural}ing" 15 | end 16 | 17 | #alias_method :part_pres, :present_participle 18 | 19 | end 20 | 21 | -------------------------------------------------------------------------------- /test/test_soundex.rb: -------------------------------------------------------------------------------- 1 | require 'english/soundex' 2 | 3 | require 'test/unit' 4 | require 'yaml' 5 | 6 | class TC_Soundex < Test::Unit::TestCase 7 | 8 | DIR = File.dirname(__FILE__) 9 | DATA = YAML::load(File.read(File.join(DIR,'fixture/soundex.txt'))) 10 | 11 | def test_cases 12 | DATA.each do |input, expected_output| 13 | assert_equal expected_output, English.soundex(input) 14 | end 15 | end 16 | 17 | end 18 | 19 | class TC_String_Soundex < Test::Unit::TestCase 20 | 21 | def test_soundex 22 | assert_equal("Ruby".en.soundex, "R100") 23 | end 24 | 25 | end 26 | -------------------------------------------------------------------------------- /lib/english/class.rb: -------------------------------------------------------------------------------- 1 | require 'language/class' 2 | 3 | class English < Language 4 | # 5 | def self.abbreviation 6 | 'en' 7 | end 8 | end 9 | 10 | class String 11 | # Higher-order function to invoke English functions. 12 | def en 13 | English.instance(self) 14 | end 15 | end 16 | 17 | class Array 18 | # Higher-order function to invoke English functions. 19 | def en 20 | English.instance(self) 21 | end 22 | end 23 | 24 | class Integer 25 | # Higher-order function to invoke English functions. 26 | def en 27 | English.instance(self) 28 | end 29 | end 30 | 31 | -------------------------------------------------------------------------------- /lib/english/jumble.rb: -------------------------------------------------------------------------------- 1 | require 'english/class' 2 | 3 | class English 4 | 5 | # Jumble letter casing. 6 | # 7 | # "superman".jumble #=> "SUpeRmAn" 8 | # 9 | #-- 10 | # TODO: This isn't so much English specific. Maybe it 11 | # should be deprecated or moved to Langauge? 12 | #++ 13 | 14 | def self.jumble(string) 15 | j = '' 16 | string.to_s.split(//).each_with_index{ |c,i| j << ( i % 2 == 0 ? c.downcase : c.upcase ) } 17 | j 18 | end 19 | 20 | # Jumble letter casing. 21 | # 22 | # "superman".jumble #=> "SUpeRmAn" 23 | # 24 | def jumble 25 | self.class.jumble(@self) 26 | end 27 | 28 | end 29 | 30 | -------------------------------------------------------------------------------- /test/test_porter.rb: -------------------------------------------------------------------------------- 1 | require 'english/porter' 2 | 3 | require 'test/unit' 4 | 5 | class TC_PorterStemmer < Test::Unit::TestCase 6 | 7 | DIR = File.dirname(__FILE__) 8 | DATA_INPUT = File.read(File.join(DIR,'fixture/porter_stemming_input.txt')).split(/\n/) 9 | DATA_OUTPUT = File.read(File.join(DIR,'fixture/porter_stemming_output.txt')).split(/\n/) 10 | 11 | #def slurp(*path) 12 | # File.read(File.join(DIR,*path)).split(/\n/) 13 | #end 14 | 15 | def test_cases 16 | cases = DATA_INPUT.zip(DATA_OUTPUT) 17 | cases.each do |word, expected_output| 18 | assert_equal expected_output, English::PorterStemmer.stem(word) 19 | end 20 | end 21 | 22 | end 23 | -------------------------------------------------------------------------------- /PROFILE: -------------------------------------------------------------------------------- 1 | --- 2 | title : English 3 | suite : rubyworks 4 | summary: English Code Kit 5 | license: MIT 6 | contact: trans 7 | created: 2007-08-01 8 | 9 | authors: 10 | - Thomas Sawyer 11 | 12 | description: 13 | English is an general purpose English language processing library. 14 | It includes a number of useful libraries, such as inflect.rb, 15 | metaphone.rb, ordinal.rb, and so on. 16 | 17 | requires: 18 | - language 19 | - syckle (build) 20 | 21 | resources: 22 | home: http://rubyworks.github.com/english 23 | code: http://github.com/rubyworks/english 24 | mail: http://groups.google.com/group/rubyworks-mailinglist 25 | host: http://rubygems.org/english 26 | 27 | repositories: 28 | public: git://github.com/rubyworks/english.git 29 | 30 | copyright: 31 | Copyright (c) 2007 Thomas Sawyer 32 | -------------------------------------------------------------------------------- /work/deprecated/patterns.rb: -------------------------------------------------------------------------------- 1 | module English 2 | 3 | # = Patterns Function Module 4 | # 5 | # Returns a Regexp pattern based on the given 6 | # pattern string or symbolic name. 7 | # 8 | # They are also recognizied in plural form. 9 | 10 | module Patterns 11 | 12 | module_function 13 | 14 | # Character 15 | 16 | def char 17 | // 18 | end 19 | 20 | alias_method :chars, :char 21 | alias_method :character, :char 22 | alias_method :characters, :char 23 | 24 | # Word 25 | 26 | def word 27 | /\s+|\Z/ 28 | end 29 | 30 | alias_method :words, :word 31 | 32 | # Line 33 | 34 | def line 35 | /\Z/ 36 | end 37 | 38 | alias_method :lines, :line 39 | 40 | # Sentence FIXME 41 | 42 | def sentence 43 | /[.]\ / 44 | end 45 | 46 | end 47 | 48 | end 49 | 50 | -------------------------------------------------------------------------------- /Rakefile: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | 3 | desc 'generate rdocs' 4 | task :rdoc do 5 | cmd = %[rdoc --op=doc/rdoc --title="English" --main=README --merge --inline-source [A_Z]* lib] 6 | sh cmd 7 | end 8 | 9 | desc 'run tests' 10 | task :test do 11 | unless EVN['LIVE'] 12 | $LOAD_PATH.unshift(File.expand_path('lib')) 13 | end 14 | 15 | puts "Ruby Version: #{RUBY_VERSION}" 16 | 17 | #if find = ARGV.select{|e| e !~ /^[-]/ }[0] 18 | # unless File.file?(find) 19 | # find = File.join(find, '**', 'test_*.rb') 20 | # end 21 | #else 22 | find = 'test/**/test_*.rb' 23 | #end 24 | 25 | files = Dir.glob(find) 26 | files.each do |file| 27 | next if File.directory?(file) 28 | begin 29 | puts "Loading: #{file}" if $DEBUG 30 | load(file) 31 | rescue LoadError 32 | puts "Error loading: #{file}" 33 | end 34 | end 35 | end 36 | 37 | -------------------------------------------------------------------------------- /test/fixture/metaphone.txt: -------------------------------------------------------------------------------- 1 | # 2 | # Based on the table at http://aspell.net/metaphone/metaphone-kuhn.txt, 3 | # with surprising results changed to 'correct' ones (according to my interpretation 4 | # of the algorithm description), and some more results from around the web: 5 | # 6 | ANASTHA: ANS0 7 | DAVIS-CARTER: TFSKRTR 8 | ESCARMANT: ESKRMNT 9 | MCCALL: MKL 10 | MCCROREY: MKRR 11 | MERSEAL: MRSL 12 | PIEURISSAINT: PRSNT 13 | ROTMAN: RTMN 14 | SCHEVEL: SXFL 15 | SCHROM: SXRM 16 | SEAL: SL 17 | SPARR: SPR 18 | STARLEPER: STRLPR 19 | THRASH: 0RX 20 | LOGGING: LKNK 21 | LOGIC: LJK 22 | JUDGES: JJS 23 | SHOOS: XS 24 | SHOES: XS 25 | CHUTE: XT 26 | SCHUSS: SXS 27 | OTTO: OT 28 | ERIC: ERK 29 | DAVE: TF 30 | CATHERINE: K0RN 31 | KATHERINE: K0RN 32 | AUBREY: ABR 33 | BRYAN: BRYN 34 | BRYCE: BRS 35 | STEVEN: STFN 36 | RICHARD: RXRT 37 | HEIDI: HT 38 | AUTO: AT 39 | MAURICE: MRS 40 | RANDY: RNT 41 | CAMBRILLO: KMBRL 42 | BRIAN: BRN 43 | RAY: R 44 | GEOFF: JF 45 | BOB: BB 46 | AHA: AH 47 | AAH: A 48 | PAUL: PL 49 | BATTLEY: BTL 50 | WROTE: RT 51 | THIS: 0S 52 | -------------------------------------------------------------------------------- /test/fixture/metaphone_lp.txt: -------------------------------------------------------------------------------- 1 | # 2 | # Based on the table at http://aspell.net/metaphone/metaphone-kuhn.txt, 3 | # this mimics the behaviour of Lawrence Philips's BASIC implementation, 4 | # which appears to contain bugs when compared to his description of the 5 | # algorithm. 6 | # 7 | ANASTHA: ANS0 8 | DAVIS-CARTER: TFSKRTR 9 | ESCARMANT: ESKRMNT 10 | MCCALL: MKKL 11 | MCCROREY: MKKRR 12 | MERSEAL: MRSL 13 | PIEURISSAINT: PRSNT 14 | ROTMAN: RTMN 15 | SCHEVEL: SXFL 16 | SCHROM: SXRM 17 | SEAL: SL 18 | SPARR: SPR 19 | STARLEPER: STRLPR 20 | THRASH: 0RX 21 | LOGGING: LKNK 22 | LOGIC: LJK 23 | JUDGES: JJS 24 | SHOOS: XS 25 | SHOES: XS 26 | CHUTE: XT 27 | SCHUSS: SXS 28 | OTTO: OT 29 | ERIC: ERK 30 | DAVE: TF 31 | CATHERINE: K0RN 32 | KATHERINE: K0RN 33 | AUBREY: ABR 34 | BRYAN: BRYN 35 | BRYCE: BRS 36 | STEVEN: STFN 37 | RICHARD: RXRT 38 | HEIDI: HT 39 | AUTO: AT 40 | MAURICE: MRS 41 | RANDY: RNT 42 | CAMBRILLO: KMRL 43 | BRIAN: BRN 44 | RAY: R 45 | GEOFF: JF 46 | BOB: BB 47 | AHA: AH 48 | AAH: A 49 | PAUL: PL 50 | BATTLEY: BTL 51 | WROTE: RT 52 | THIS: 0S 53 | -------------------------------------------------------------------------------- /MANIFEST: -------------------------------------------------------------------------------- 1 | #!mast .ruby lib meta test [A-Z]* 2 | .ruby 3 | lib/en.rb 4 | lib/english/censor.rb 5 | lib/english/class.rb 6 | lib/english/conjunction.rb 7 | lib/english/dresner.rb 8 | lib/english/infinitive.rb 9 | lib/english/inflect.rb 10 | lib/english/jumble.rb 11 | lib/english/metaphone.rb 12 | lib/english/mixin.rb 13 | lib/english/namecase.rb 14 | lib/english/numeral.rb 15 | lib/english/ordinal.rb 16 | lib/english/participle.rb 17 | lib/english/porter.rb 18 | lib/english/soundex.rb 19 | lib/english/words.rb 20 | lib/english.rb 21 | test/fixture/double_metaphone.txt 22 | test/fixture/metaphone.txt 23 | test/fixture/metaphone_lp.txt 24 | test/fixture/porter_stemming_input.txt 25 | test/fixture/porter_stemming_output.txt 26 | test/fixture/soundex.txt 27 | test/test_dresner.rb 28 | test/test_infinitive.rb 29 | test/test_inflect.rb 30 | test/test_metaphone.rb 31 | test/test_namecase.rb 32 | test/test_porter.rb 33 | test/test_soundex.rb 34 | Rakefile 35 | HISTORY.rdoc 36 | PROFILE 37 | LICENSE 38 | README.rdoc 39 | AUTHORS 40 | Gemfile 41 | NOTICE 42 | Syckfile 43 | -------------------------------------------------------------------------------- /lib/english/dresner.rb: -------------------------------------------------------------------------------- 1 | require 'english/class' 2 | 3 | class English 4 | 5 | # Scramble the inner characters of words leaving the text still readable 6 | # (research at Cambridge University, code by KurtDresner). 7 | # 8 | # For example, the above text may result in: 9 | # 10 | # Srblamce the iennr cchrteaars of wodrs lvenaig the txet stlil rbeaadle 11 | # (rreceash at Cbamigdre Uverintisy, cdoe by KrneruestDr?) 12 | # 13 | # CREDIT: Kurt Dresener 14 | 15 | def self.dresner(string) 16 | string.to_s.gsub(/\B\w+\B/){$&.split(//).sort_by{rand}} 17 | end 18 | 19 | # Scramble the inner characters of words leaving the text still readable 20 | # (research at Cambridge University, code by KurtDresner). 21 | # 22 | # For example, the above text may result in: 23 | # 24 | # Srblamce the iennr cchrteaars of wodrs lvenaig the txet stlil rbeaadle 25 | # (rreceash at Cbamigdre Uverintisy, cdoe by KrneruestDr?) 26 | # 27 | # CREDIT: Kurt Dresener 28 | def dresner 29 | self.class.dresner(@self) 30 | end 31 | 32 | end 33 | -------------------------------------------------------------------------------- /work/deprecated/test/test_stylize.rb: -------------------------------------------------------------------------------- 1 | require 'english/stylize' 2 | require 'test/unit' 3 | 4 | #$:.unshift File.join(File.dirname(__FILE__), "..", "lib") 5 | #$:.unshift File.join(File.dirname(__FILE__), "..", "test") 6 | 7 | class Test_Stylize < Test::Unit::TestCase 8 | 9 | def test_modulize 10 | assert_equal( 'MyModule::MyClass', 'my_module__my_class'.modulize ) 11 | assert_equal( '::MyModule::MyClass', '__my_module__my_class'.modulize ) 12 | assert_equal( 'MyModule::MyClass', 'my_module/my_class'.modulize ) 13 | assert_equal( '::MyModule::MyClass', '/my_module/my_class'.modulize ) 14 | end 15 | 16 | def test_methodize 17 | assert_equal( 'hello_world', 'HelloWorld'.methodize ) 18 | assert_equal( '__unix_path', '/unix_path'.methodize ) 19 | end 20 | 21 | def test_pathize 22 | assert_equal( 'my_module/my_class', 'MyModule::MyClass'.pathize ) 23 | assert_equal( 'uri', 'URI'.pathize ) # Hmm... this is reversible? 24 | assert_equal( '/my_class', '::MyClass'.pathize ) 25 | assert_equal( '/my_module/my_class/', '/my_module/my_class/'.pathize ) 26 | end 27 | 28 | end 29 | 30 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License 2 | 3 | English, Copyright (c) 2010 Thomas Sawyer 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in 13 | all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | THE SOFTWARE. 22 | 23 | -------------------------------------------------------------------------------- /work/deprecated/test/test_humanize.rb: -------------------------------------------------------------------------------- 1 | require 'english/humanize' 2 | require 'test/unit' 3 | 4 | #$:.unshift File.join(File.dirname(__FILE__), "..", "lib") 5 | #$:.unshift File.join(File.dirname(__FILE__), "..", "test") 6 | 7 | class Test_Humanize < Test::Unit::TestCase 8 | 9 | def test_demodulize_01 10 | a = "Down::Bottom" 11 | assert_equal( "Bottom", a.demodulize ) 12 | end 13 | 14 | def test_demodulize_02 15 | b = "Further::Down::Bottom" 16 | assert_equal( "Bottom", b.demodulize ) 17 | end 18 | 19 | def test_demodulize_03 20 | assert_equal( "Unit", "Test::Unit".demodulize ) 21 | end 22 | 23 | def test_camelize 24 | assert_equal( 'ThisIsIt', 'this_is_it'.camelize ) 25 | end 26 | 27 | def test_humanize 28 | assert_equal( 'This is it', 'this_is_it'.humanize ) 29 | end 30 | 31 | def test_demodulize_01 32 | a = "Down::Bottom" 33 | assert_equal( "Bottom", a.demodulize ) 34 | end 35 | 36 | def test_demodulize_02 37 | b = "Further::Down::Bottom" 38 | assert_equal( "Bottom", b.demodulize ) 39 | end 40 | 41 | def test_demodulize_03 42 | assert_equal( "Unit", "Test::Unit".demodulize ) 43 | end 44 | 45 | end 46 | 47 | -------------------------------------------------------------------------------- /Syckfile: -------------------------------------------------------------------------------- 1 | --- 2 | email: 3 | service : Email 4 | file : ~ 5 | subject : ~ 6 | mailto : ruby-talk@ruby-lang.org 7 | active : true 8 | 9 | grancher: 10 | active: true 11 | 12 | box: 13 | service: Box 14 | types : [gem] 15 | active : true 16 | 17 | testrb: 18 | service : Testrb 19 | tests : ~ 20 | exclude : ~ 21 | loadpath : ~ 22 | requires : ~ 23 | live : false 24 | active : true 25 | 26 | syntax: 27 | service : Syntax 28 | loadpath : ~ 29 | exclude : ~ 30 | active : false 31 | 32 | dnote: 33 | service : DNote 34 | loadpath : ~ 35 | labels : ~ 36 | output : ~ 37 | format : ~ 38 | active : false 39 | 40 | rdoc: 41 | service : RDoc 42 | template : newfish 43 | include : ~ 44 | exclude : [Syckfile] 45 | main : ~ 46 | extra : ~ 47 | output : site/docs/api 48 | active : true 49 | 50 | ridoc: 51 | service : RIDoc 52 | include : ~ 53 | exclude : ~ 54 | output : ri 55 | active : true 56 | 57 | stats: 58 | service : Stats 59 | title : ~ 60 | loadpath : ~ 61 | exclude : ~ 62 | output : ~ 63 | active : true 64 | 65 | vclog: 66 | service : VClog 67 | format : html # xml, txt 68 | layout : rel # gnu 69 | typed : false 70 | output : ~ 71 | active : false 72 | 73 | #rubyforge: 74 | # service : Rubyforge 75 | # unixname: <%= project %> 76 | # groupid : ~ 77 | # package : <%= package %> 78 | # sitemap: 79 | # doc/rdoc: <%= package %> 80 | # active : false 81 | 82 | 83 | -------------------------------------------------------------------------------- /lib/english/ordinal.rb: -------------------------------------------------------------------------------- 1 | require 'english/class' 2 | 3 | class English 4 | 5 | # Ordinalize turns a number string into an ordinal string 6 | # used to denote the position in an ordered sequence such 7 | # as 1st, 2nd, 3rd, 4th. 8 | # 9 | # English.ordinal('1') #=> "1st" 10 | # English.ordinal('2') #=> "2nd" 11 | # English.ordinal(102) #=> "102nd" 12 | # English.ordinal(103) #=> "103rd" 13 | # 14 | def self.ordinal(number) 15 | number_string = number.to_s.strip 16 | if md = /\d{1,2}$/.match(number_string) 17 | n = md[0].to_i 18 | if (11..13).include?(number.to_i % 100) 19 | "#{number}th" 20 | else 21 | case n % 10 22 | when 1; "#{number}st" 23 | when 2; "#{number}nd" 24 | when 3; "#{number}rd" 25 | else "#{number}th" 26 | end 27 | end 28 | #number_string.sub(/\d{1,2}$/, r) 29 | else 30 | number_string 31 | end 32 | end 33 | 34 | # Ordinalize turns a number string into an ordinal string 35 | # used to denote the position in an ordered sequence such 36 | # as 1st, 2nd, 3rd, 4th. 37 | # 38 | # '1'.ordinal # => "1st" 39 | # '2'.ordinal # => "2nd" 40 | # '102'.ordinal # => "102nd" 41 | # '103'.ordinal # => "103rd" 42 | # 43 | # 1.ordinal # => "1st" 44 | # 2.ordinal # => "2nd" 45 | # 102.ordinal # => "102nd" 46 | # 103.ordinal # => "103rd" 47 | # 48 | def ordinal 49 | self.class.ordinal(@self) 50 | end 51 | 52 | end 53 | 54 | -------------------------------------------------------------------------------- /lib/english/conjunction.rb: -------------------------------------------------------------------------------- 1 | require 'english/class' 2 | 3 | class English 4 | 5 | # English conjunciton. 6 | # 7 | # This is more advanced form of #join, as it allows for an 8 | # English-based terminating separator. 9 | # 10 | # The default type of conjunction --the terminating separator, 11 | # is "and", and the default regualt separator is ",". 12 | # 13 | # [1,2,3].conjunction 14 | # => "1, 2 and 3 15 | # 16 | # [1,2,3].conjunction(:or) 17 | # => "1, 2 or 3 18 | # 19 | # [1,2,3].conjunction(:or, ';') 20 | # => "1; 2 or 3 21 | # 22 | #-- 23 | # TODO: Maybe separate into #and, #or and #but ? 24 | #++ 25 | 26 | def self.conjunction(array, type=:and, seperator=",") 27 | array = array.to_a 28 | type = type.to_s 29 | separator = separator.to_s 30 | space = space.to_s 31 | 32 | case array.length 33 | when 0 34 | "" 35 | when 1 36 | array[0] 37 | when 2 38 | "#{array[0]} #{type} #{array[1]}" 39 | else 40 | [array[0..-2].join("#{separator} "), array[-1]].join(" #{type} ") 41 | end 42 | end 43 | 44 | # This is more advanced form of #join, as it allows for an 45 | # English-based terminating separator. 46 | # 47 | # The default type of conjunction --the terminating separator, 48 | # is "and", and the default regualt separator is ",". 49 | # 50 | # [1,2,3].conjunction 51 | # => "1, 2 and 3 52 | # 53 | # [1,2,3].conjunction(:or) 54 | # => "1, 2 or 3 55 | # 56 | # [1,2,3].conjunction(:or, ';') 57 | # => "1; 2 or 3 58 | # 59 | def conjunction(type=:and, seperator=",") 60 | self.class.conjunction(@self, type, separator) 61 | end 62 | 63 | end 64 | 65 | -------------------------------------------------------------------------------- /lib/english/numeral.rb: -------------------------------------------------------------------------------- 1 | require 'english/class' 2 | 3 | class English 4 | 5 | ONES = %w[ zero one two three four five six seven eight nine ] 6 | 7 | TEEN = %w[ ten eleven twelve thirteen fourteen fifteen 8 | sixteen seventeen eighteen nineteen ] 9 | 10 | TENS = %w[ zero ten twenty thirty forty fifty 11 | sixty seventy eighty ninety ] 12 | 13 | MEGA = %w[ none thousand million billion ] 14 | 15 | # Convert an integer to the english spelling of that number. 16 | def self.numeral(integer) 17 | places = integer.to_i.to_s.split(//).collect{|s| s.to_i}.reverse 18 | name = [] 19 | ((places.length + 2) / 3).times do |p| 20 | strings = trio(places[p * 3, 3]) 21 | name.push(MEGA[p]) if strings.length > 0 and p > 0 22 | name += strings 23 | end 24 | name.push(ONES[0]) unless name.length > 0 25 | name.reverse.join(" ") 26 | end 27 | 28 | # 29 | def self.trio(places) 30 | strings = [] 31 | if places[1] == 1 32 | strings.push(TEEN[places[0]]) 33 | elsif places[1] and places[1] > 0 34 | strings.push(places[0] == 0 ? TENS[places[1]] : "#{TENS[places[1]]}-#{ONES[places[0]]}") 35 | elsif places[0] > 0 36 | strings.push(ONES[places[0]]) 37 | end 38 | if places[2] and places[2] > 0 39 | strings.push("hundred", ONES[places[2]]) 40 | end 41 | strings 42 | end 43 | 44 | # Convert to the english spelling of a number. 45 | # 46 | # 10.numeral #=> "10" 47 | # 48 | def numeral 49 | self.class.numeral(@self) 50 | end 51 | 52 | # Credit goes to Glenn P. Parker 53 | # 54 | # TODO: Get English#numeral to handle decicmal fractions. 55 | # 56 | # TODO: Get English#numeral to handle larger groups of thousands. 57 | 58 | end 59 | 60 | -------------------------------------------------------------------------------- /lib/english/soundex.rb: -------------------------------------------------------------------------------- 1 | require 'english/class' 2 | 3 | class English 4 | 5 | # Ruby implementation of the Soundex algorithm, 6 | # as described by Knuth in volume 3 of The Art 7 | # of Computer Programming. 8 | # 9 | # Returns nil if the value couldn't be calculated 10 | # b/c of empty-string or invalid character. 11 | # 12 | # "Ruby".soundex #=> "R100" 13 | # 14 | # Based on work by Michael Neumann (neumann@s-direktnet.de) 15 | 16 | def self.soundex(string) 17 | return nil if string.empty? 18 | 19 | str = string.upcase 20 | last_code = soundex_code(str[0,1]) 21 | soundex_code = str[0,1] 22 | 23 | for index in 1...(str.size) do 24 | return soundex_code if soundex_code.size == 4 25 | 26 | code = soundex_code(str[index,1]) 27 | 28 | if code == "0" then 29 | last_code = nil 30 | elsif code == nil then 31 | return nil 32 | elsif code != last_code then 33 | soundex_code += code 34 | last_code = code 35 | end 36 | end 37 | 38 | return soundex_code + "000"[0,4-soundex_code.size] 39 | end 40 | 41 | # Support function for #soundex. 42 | # Returns code for a single character. 43 | # 44 | def self.soundex_code(char) 45 | char.tr! "AEIOUYWHBPFVCSKGJQXZDTLMNR", "00000000111122222222334556" 46 | end 47 | 48 | # Ruby implementation of the Soundex algorithm, 49 | # as described by Knuth in volume 3 of The Art 50 | # of Computer Programming. 51 | # 52 | # Returns nil if the value couldn't be calculated 53 | # b/c of empty-string or invalid character. 54 | # 55 | # "Ruby".soundex #=> "R100" 56 | # 57 | # Based on work by Michael Neumann (neumann@s-direktnet.de) 58 | def soundex 59 | self.class.soundex(@self) 60 | end 61 | 62 | end 63 | 64 | -------------------------------------------------------------------------------- /test/test_namecase.rb: -------------------------------------------------------------------------------- 1 | require 'english/namecase' 2 | require 'test/unit' 3 | 4 | class TC_Namecase < Test::Unit::TestCase 5 | 6 | def setup 7 | @proper_names = [ 8 | "Keith", "Leigh-Williams", "McCarthy", 9 | "O'Callaghan", "St. John", "von Streit", 10 | "van Dyke", "Van", "ap Llwyd Dafydd", 11 | "al Fahd", "Al", 12 | "el Grecco", 13 | "ben Gurion", "Ben", 14 | "da Vinci", 15 | "di Caprio", "du Pont", "de Legate", 16 | "del Crond", "der Sind", "van der Post", 17 | "von Trapp", "la Poisson", "le Figaro", 18 | "Mack Knife", "Dougal MacDonald", 19 | # Mac exceptions 20 | "Machin", "Machlin", "Machar", 21 | "Mackle", "Macklin", "Mackie", 22 | "Macquarie", "Machado", "Macevicius", 23 | "Maciulis", "Macias", "MacMurdo", 24 | # Roman numerals 25 | "Henry VIII", "Louis III", "Louis XIV", 26 | "Charles II", "Fred XLIX" 27 | ] 28 | end 29 | 30 | def test_namecase 31 | @proper_names.each do |name| 32 | assert_equal(name, name.en.namecase) 33 | assert_equal(name, name.downcase.en.namecase) 34 | end 35 | end 36 | 37 | def test_namecase_modify 38 | @proper_names.each do |name| 39 | assert_equal(name, name.en.namecase) 40 | assert_equal(name, name.downcase.en.namecase) 41 | end 42 | end 43 | 44 | def test_namecase_multibyte 45 | $KCODE = 'u' 46 | proper_cased = 'Iñtërnâtiônàlizætiøn' 47 | assert_equal(proper_cased, proper_cased.en.namecase) 48 | assert_equal(proper_cased, proper_cased.downcase.en.namecase) 49 | end 50 | end 51 | 52 | #class Test_Case < Test::Unit::TestCase 53 | # 54 | # def test_titlecase 55 | # assert_equal('Title Case', 'title case'.titlecase) 56 | # end 57 | # 58 | #end 59 | 60 | -------------------------------------------------------------------------------- /.ruby: -------------------------------------------------------------------------------- 1 | --- 2 | name: english 3 | spec_version: 1.0.0 4 | repositories: 5 | public: git://github.com/rubyworks/english.git 6 | title: English 7 | contact: trans 8 | requires: 9 | - group: [] 10 | 11 | name: language 12 | version: 0+ 13 | - group: 14 | - build 15 | name: syckle 16 | version: 0+ 17 | resources: 18 | code: http://github.com/rubyworks/english 19 | mail: http://groups.google.com/group/rubyworks-mailinglist 20 | host: http://rubygems.org/english 21 | home: http://rubyworks.github.com/english 22 | suite: rubyworks 23 | manifest: 24 | - .ruby 25 | - lib/en.rb 26 | - lib/english/censor.rb 27 | - lib/english/class.rb 28 | - lib/english/conjunction.rb 29 | - lib/english/dresner.rb 30 | - lib/english/infinitive.rb 31 | - lib/english/inflect.rb 32 | - lib/english/jumble.rb 33 | - lib/english/metaphone.rb 34 | - lib/english/mixin.rb 35 | - lib/english/namecase.rb 36 | - lib/english/numeral.rb 37 | - lib/english/ordinal.rb 38 | - lib/english/participle.rb 39 | - lib/english/porter.rb 40 | - lib/english/soundex.rb 41 | - lib/english/words.rb 42 | - lib/english.rb 43 | - test/fixture/double_metaphone.txt 44 | - test/fixture/metaphone.txt 45 | - test/fixture/metaphone_lp.txt 46 | - test/fixture/porter_stemming_input.txt 47 | - test/fixture/porter_stemming_output.txt 48 | - test/fixture/soundex.txt 49 | - test/test_dresner.rb 50 | - test/test_infinitive.rb 51 | - test/test_inflect.rb 52 | - test/test_metaphone.rb 53 | - test/test_namecase.rb 54 | - test/test_porter.rb 55 | - test/test_soundex.rb 56 | - Rakefile 57 | - HISTORY.rdoc 58 | - PROFILE 59 | - LICENSE 60 | - README.rdoc 61 | - AUTHORS 62 | - Gemfile 63 | - NOTICE 64 | - Syckfile 65 | version: "" 66 | licenses: 67 | - MIT 68 | copyright: Copyright (c) 2007 Thomas Sawyer 69 | description: English is an general purpose English language processing library. It includes a number of useful libraries, such as inflect.rb, metaphone.rb, ordinal.rb, and so on. 70 | summary: English Code Kit 71 | authors: 72 | - Thomas Sawyer 73 | created: 2007-08-01 74 | -------------------------------------------------------------------------------- /work/deprecated/test/test_levenshtein.rb: -------------------------------------------------------------------------------- 1 | require 'english/levenshtein' 2 | 3 | require 'test/unit' 4 | 5 | class TC_Levenshtein < Test::Unit::TestCase 6 | 7 | include English::Levenshtein 8 | 9 | TEST_CASES = { 10 | :easy => [ 11 | ['test', 'test', 0], 12 | ['test', 'tent', 1], 13 | ['gumbo', 'gambol', 2], 14 | ['kitten', 'sitting', 3] 15 | ], 16 | :empty => [ 17 | ['foo', '', 3], 18 | ['', '', 0], 19 | ['a', '', 1] 20 | ], 21 | :utf8 => [ 22 | ["f\303\266o", 'foo', 1], 23 | ["fran\303\247ais", 'francais', 1], 24 | ["fran\303\247ais", "fran\303\246ais", 1], 25 | [ 26 | "\347\247\201\343\201\256\345\220\215\345\211\215\343\201\257"<< 27 | "\343\203\235\343\203\274\343\203\253\343\201\247\343\201\231", 28 | "\343\201\274\343\201\217\343\201\256\345\220\215\345\211\215\343\201"<< 29 | "\257\343\203\235\343\203\274\343\203\253\343\201\247\343\201\231", 30 | 2 31 | ] # Japanese 32 | ], 33 | :iso_8859_1 => [ 34 | ["f\366o", 'foo', 1], 35 | ["fran\347ais", 'francais', 1], 36 | ["fran\347ais", "fran\346ais", 1] 37 | ], 38 | :edge => [ 39 | ['a', 'a', 0], 40 | ['0123456789', 'abcdefghijklmnopqrstuvwxyz', 26] 41 | ] 42 | } 43 | 44 | def assert_set(name) 45 | TEST_CASES[name].each do |s, t, x| 46 | assert_equal x, distance(s, t) 47 | assert_equal x, distance(t, s) 48 | end 49 | end 50 | 51 | def with_kcode(k) 52 | old_kcode = $KCODE 53 | $KCODE = k 54 | yield 55 | $KCODE = old_kcode 56 | end 57 | 58 | def test_easy_cases 59 | assert_set(:easy) 60 | end 61 | 62 | def test_empty_cases 63 | assert_set(:empty) 64 | end 65 | 66 | def test_edge_cases 67 | assert_set(:edge) 68 | end 69 | 70 | def test_utf8_cases 71 | with_kcode('U') do 72 | assert_set(:utf8) 73 | end 74 | end 75 | 76 | def test_iso_8859_1_cases 77 | with_kcode('NONE') do 78 | assert_set(:iso_8859_1) 79 | end 80 | end 81 | 82 | end 83 | -------------------------------------------------------------------------------- /work/deprecated/censor.rb: -------------------------------------------------------------------------------- 1 | warn "English censor.rb will be deprecated. Use Facets Censor class or String extensions instead." 2 | 3 | # = TITLE: 4 | # Censor 5 | # 6 | # = SYNOPIS: 7 | # Very basic extension to string for weeding out text. 8 | # 9 | # AUTHORS: 10 | # - George Moschovitis 11 | # - Trans 12 | # 13 | # TODO: 14 | # - Deprecate in favor or, or rewrite to use, textfilter.rb ? 15 | 16 | class String #:nodoc: 17 | 18 | # Apply a set of rules (regular expression matches) to the string. 19 | # 20 | # The rules must be applied in order! So we cannot use a 21 | # hash because the ordering is not guaranteed! we use an 22 | # array instead. 23 | 24 | def censor(rules) 25 | raise ArgumentError.new('rules parameter is nil') unless rules # gmosx: helps to find bugs 26 | s = dup 27 | rules.each do |match,edit| 28 | s.gsub!(match,edit) 29 | end 30 | return s 31 | end 32 | 33 | alias_method :rewrite, :censor 34 | 35 | # Make sure the string passes a collection of censorship rules 36 | # defined with reqular expressions. 37 | 38 | def censored?(rules) 39 | for r in rules 40 | return true if self =~ r 41 | end 42 | return false 43 | end 44 | 45 | # Filters out words from a string based on block test. 46 | # 47 | # "a string".word_filter { |word| word =~ /^a/ } #=> "string" 48 | # 49 | def censor_words( &blk ) 50 | s = self.dup 51 | s.censor_words!( &blk ) 52 | end 53 | 54 | alias_method :word_filter, :censor_words 55 | 56 | # In place version of #word_filter. 57 | # 58 | # "a string".word_filter { |word| ... } 59 | # 60 | # TODO: Surely this can be written better. 61 | 62 | def censor_words! #:yield: 63 | rest_of_string = self 64 | wordfind = /(\w+)/ 65 | offset = 0 66 | while wmatch = wordfind.match(rest_of_string) 67 | word = wmatch[0] 68 | range = offset+wmatch.begin(0) ... offset+wmatch.end(0) 69 | rest_of_string = wmatch.post_match 70 | self[range] = yield( word ).to_s 71 | offset = self.length - rest_of_string.length 72 | end 73 | self 74 | end 75 | 76 | alias_method :word_filter!, :censor_words! 77 | 78 | end 79 | 80 | -------------------------------------------------------------------------------- /test/test_metaphone.rb: -------------------------------------------------------------------------------- 1 | require 'english/metaphone' 2 | 3 | require 'test/unit' 4 | require 'yaml' 5 | 6 | class TC_Metaphone < Test::Unit::TestCase 7 | 8 | DIR = File.dirname(__FILE__) 9 | 10 | DATA = YAML::load(File.read(File.join(DIR,'fixture/metaphone.txt'))) 11 | DATA_ALT = YAML::load(File.read(File.join(DIR,'fixture/metaphone_lp.txt'))) 12 | 13 | def test_cases 14 | DATA.each do |input, expected_output| 15 | assert_equal expected_output, English::Metaphone.metaphone(input) 16 | end 17 | end 18 | 19 | def test_cases_for_alternate_implementation 20 | DATA_ALT.each do |input, expected_output| 21 | assert_equal expected_output, English::Metaphone.metaphone(input, true) 22 | end 23 | end 24 | 25 | def test_junk 26 | assert_equal English::Metaphone.metaphone('foobar'), 27 | English::Metaphone.metaphone('%^@#$^f%^&o%^o@b#a@#r%^^&') 28 | assert_equal English::Metaphone.metaphone('foobar', true), 29 | English::Metaphone.metaphone('%^@#$^f%^&o%^o@b#a@#r%^^&', true) 30 | end 31 | 32 | def test_caps 33 | assert_equal English::Metaphone.metaphone('foobar'), 34 | English::Metaphone.metaphone('FOOBAR') 35 | assert_equal English::Metaphone.metaphone('foobar', true), 36 | English::Metaphone.metaphone('FOOBAR', true) 37 | end 38 | 39 | def test_string 40 | assert_equal 'F BR BS', English::Metaphone.metaphone('foo bar baz') 41 | assert_equal 'N WT', English::Metaphone.metaphone('gnu what') 42 | assert_equal 'F BR BS', English::Metaphone.metaphone('foo bar baz', true) 43 | assert_equal 'N WT', English::Metaphone.metaphone('gnu what', true) 44 | end 45 | 46 | end 47 | 48 | 49 | class TC_DoubleMetaphone < Test::Unit::TestCase 50 | 51 | DIR = File.dirname(__FILE__) 52 | DATA = File.read(File.join(DIR,'fixture/double_metaphone.txt')).split(/\n/) 53 | 54 | DATA.each_with_index do |line, i| 55 | row = *line.split(', ') 56 | #primary, secondary = English::Metaphone[row[0]] 57 | primary, secondary = English::Metaphone.double_metaphone(row[0]) 58 | 59 | define_method("test_#{i}") do 60 | assert_equal row[1], primary 61 | assert_equal row[2], (secondary.nil?? primary : secondary) 62 | end 63 | end 64 | 65 | end 66 | 67 | -------------------------------------------------------------------------------- /work/deprecated/test/test_style_orm.rb: -------------------------------------------------------------------------------- 1 | require 'english/style_orm' 2 | require 'test/unit' 3 | 4 | #$:.unshift File.join(File.dirname(__FILE__), "..", "lib") 5 | #$:.unshift File.join(File.dirname(__FILE__), "..", "test") 6 | 7 | class Test_StyleORM < Test::Unit::TestCase 8 | 9 | def test_demodulize_01 10 | a = "Down::Bottom" 11 | assert_equal( "Bottom", a.demodulize ) 12 | end 13 | 14 | def test_demodulize_02 15 | b = "Further::Down::Bottom" 16 | assert_equal( "Bottom", b.demodulize ) 17 | end 18 | 19 | def test_demodulize_03 20 | assert_equal( "Unit", "Test::Unit".demodulize ) 21 | end 22 | 23 | def test_camelize 24 | assert_equal( 'ThisIsIt', 'this_is_it'.camelize ) 25 | end 26 | 27 | def test_humanize 28 | assert_equal( 'This is it', 'this_is_it'.humanize ) 29 | end 30 | 31 | def test_demodulize_01 32 | a = "Down::Bottom" 33 | assert_equal( "Bottom", a.demodulize ) 34 | end 35 | 36 | def test_demodulize_02 37 | b = "Further::Down::Bottom" 38 | assert_equal( "Bottom", b.demodulize ) 39 | end 40 | 41 | def test_demodulize_03 42 | assert_equal( "Unit", "Test::Unit".demodulize ) 43 | end 44 | 45 | def test_modulize 46 | assert_equal( 'MyModule::MyClass', 'my_module__my_class'.modulize ) 47 | assert_equal( '::MyModule::MyClass', '__my_module__my_class'.modulize ) 48 | assert_equal( 'MyModule::MyClass', 'my_module/my_class'.modulize ) 49 | assert_equal( '::MyModule::MyClass', '/my_module/my_class'.modulize ) 50 | end 51 | 52 | #def test_methodize 53 | # assert_equal( 'hello_world', 'HelloWorld'.methodize ) 54 | # assert_equal( '__unix_path', '/unix_path'.methodize ) 55 | #end 56 | 57 | #def test_pathize 58 | # assert_equal( 'my_module/my_class', 'MyModule::MyClass'.pathize ) 59 | # assert_equal( 'uri', 'URI'.pathize ) # Hmm... this is reversible? 60 | # assert_equal( '/my_class', '::MyClass'.pathize ) 61 | # assert_equal( '/my_module/my_class/', '/my_module/my_class/'.pathize ) 62 | #end 63 | 64 | #def test_dresner 65 | # # assert_still_legible ;-) 66 | # assert_nothing_raised { "How are you today?".dresner } 67 | #end 68 | 69 | #def test_dresner 70 | # # assert_still_legible ;-) 71 | # assert_nothing_raised { "How are you today?".dresner! } 72 | #end 73 | 74 | end 75 | 76 | -------------------------------------------------------------------------------- /work/deprecated/textfilter.rb: -------------------------------------------------------------------------------- 1 | warn "English::Filter will be deprecated. Use Facets Censor class instead." 2 | 3 | # = TITLE: 4 | # 5 | # Text Filter 6 | # 7 | # = DESCRIPTION: 8 | # 9 | # == WARNING: This call is being deprecated. Use Facets Censor class instead. 10 | # 11 | # Reusable class for filtering and rewriting strings. 12 | # 13 | # = AUTHORS: 14 | # 15 | # - George Moschovitis 16 | # - Trans 17 | 18 | module English #:nodoc: 19 | 20 | class Filter 21 | 22 | attr :rules 23 | 24 | attr :word_rules 25 | 26 | # 27 | 28 | def initialize() 29 | @rules = [] 30 | @word_rules = [] 31 | end 32 | 33 | # Create new rule. A rule consists of a string or regexp 34 | # to match against. 35 | # 36 | # NOTE: The rules must be applied in order! So we cannot 37 | # use a hash because the ordering is not guaranteed. So 38 | # an array is used instead. 39 | 40 | def rule(match, &edit) 41 | edit = lambda{''} unless edit 42 | @rules << [match, edit] 43 | end 44 | 45 | # Rules that apply only to words. This takes the regular 46 | # expression and add word boundry matches to either side. 47 | # 48 | # filter.word_rule(/damn/){ |w| 'darn' } 49 | # 50 | # Is equivalent to teh regular rule: 51 | # 52 | # filter.rule(/\bdamn\b/){ |w| 'darn' } 53 | 54 | def word_rule(match, &edit) 55 | edit = lambda{''} unless edit 56 | @word_rules << [/\b#{match}\b/, edit] 57 | end 58 | 59 | # Apply the set of rules (regular expression matches) to 60 | # a string. 61 | 62 | def filter(string) 63 | rewritten_string = string.dup 64 | rules.each do |match,edit| 65 | rewritten_string.gsub!(match,edit) 66 | end 67 | return (rewritten_string or string) 68 | end 69 | 70 | alias_method :apply, :filter 71 | 72 | # Is the string clear of any matching rules? 73 | # 74 | # Note that running a filter does not necessarily clear a 75 | # a string of all matches, since the filter could apply 76 | # edits that would also match the filter expressions. 77 | 78 | def censored?(string) 79 | case string 80 | when *matches 81 | false 82 | else 83 | true 84 | end 85 | end 86 | 87 | # 88 | 89 | def matches 90 | rules.collect{ |match, modify| match } 91 | end 92 | 93 | end 94 | 95 | end 96 | -------------------------------------------------------------------------------- /site/assets/style.css: -------------------------------------------------------------------------------- 1 | 2 | img { 3 | border: 0; 4 | } 5 | 6 | body { 7 | padding: 0; 8 | margin: 0; 9 | background: #000; 10 | color: white; 11 | text-align: center; 12 | background: url(images/pen.jpg) no-repeat top left black; 13 | } 14 | 15 | pre { 16 | margin-left: -20px; 17 | font: 10pt monospace; 18 | color: blue; 19 | } 20 | 21 | a { 22 | color: red; 23 | font: bold 9pt sans-serif; 24 | } 25 | 26 | h2 { 27 | margin-bottom: 0px; 28 | } 29 | 30 | .section { 31 | margin-top: 20px; 32 | margin-bottom: 40px; 33 | } 34 | 35 | #container { 36 | width: 805px; 37 | margin: 0 auto; 38 | position: relative; 39 | } 40 | 41 | #menu { 42 | margin: 0px 40px; 43 | margin-top: 0px; 44 | padding: 3px; 45 | text-align: right; 46 | } 47 | 48 | #menu a { 49 | text-decoration: none; 50 | color: #DFF0AA; 51 | margin: 5px 0px 5px 10px; 52 | background: transparent; 53 | } 54 | 55 | #menu a:hover { 56 | text-decoration: underline; 57 | color: white; 58 | } 59 | 60 | #table { 61 | padding: 10px 20px; 62 | } 63 | 64 | #notebook { 65 | margin-left: 0px; 66 | padding-left: 60px; 67 | position: relative; 68 | background: url(images/spiral.png) repeat-y transparent; 69 | border-right: 2px solid gray; 70 | } 71 | 72 | #page { 73 | padding: 30px 50px 30px 20px; 74 | background: url(images/corner.png) 100% 100% no-repeat white; 75 | color: black; 76 | text-align: left; 77 | position: relative; 78 | } 79 | 80 | #stick { 81 | position: absolute; 82 | right: 50px; 83 | top: 70px; 84 | z-index: 10; 85 | } 86 | 87 | #title { 88 | margin: 0 auto; 89 | margin-bottom: 20px; 90 | } 91 | 92 | #name { 93 | font: bold 85px serif; 94 | color: black; 95 | text-align: left; 96 | } 97 | 98 | #brief { 99 | font: 14pt helvetica; 100 | color: black; 101 | text-align: center; 102 | } 103 | 104 | #content { 105 | font: 10pt sans-serif; 106 | color: black; 107 | } 108 | 109 | #resource { 110 | font: 10pt sans-serif; 111 | color: black; 112 | margin-top: 20px; 113 | margin-bottom: 40px; 114 | } 115 | 116 | #ad { 117 | margin-top: 20px; 118 | margin-bottom: 40px; 119 | } 120 | 121 | #copyright { 122 | padding-bottom: 20px; 123 | font: 6pt serif; 124 | background: transparent; 125 | } 126 | 127 | -------------------------------------------------------------------------------- /lib/english/namecase.rb: -------------------------------------------------------------------------------- 1 | require 'english/class' 2 | 3 | class English 4 | 5 | # Returns a new +String+ with the contents properly namecased. 6 | # 7 | # Perl Version Copyright (c) Mark Summerfield 1998-2002 8 | # 9 | # 10 | # Ruby Version Copyright (c) Aaron Patterson 2006 11 | 12 | def self.namecase(name) 13 | localstring = name.downcase 14 | localstring.gsub!(/\b\w/) { |first| first.upcase } 15 | localstring.gsub!(/\'\w\b/) { |c| c.downcase } # Lowercase 's 16 | 17 | # Fixes for "Mac". 18 | if localstring =~ /\bMac[A-Za-z]{2,}[^aciozj]\b/ or localstring =~ /\bMc/ 19 | localstring.gsub!(/\b(Ma?c)([A-Za-z]+)/) { |match| $1 + $2.capitalize } 20 | localstring.gsub!(/\bMacEvicius/, 'Macevicius') 21 | localstring.gsub!(/\bMacHado/, 'Machado') 22 | localstring.gsub!(/\bMacHar/, 'Machar') 23 | localstring.gsub!(/\bMacHin/, 'Machin') 24 | localstring.gsub!(/\bMacHlin/, 'Machlin') 25 | localstring.gsub!(/\bMacIas/, 'Macias') 26 | localstring.gsub!(/\bMacIulis/, 'Maciulis') 27 | localstring.gsub!(/\bMacKie/, 'Mackie') 28 | localstring.gsub!(/\bMacKle/, 'Mackle') 29 | localstring.gsub!(/\bMacKlin/, 'Macklin') 30 | localstring.gsub!(/\bMacQuarie/, 'Macquarie') 31 | end 32 | localstring.gsub!('Macmurdo','MacMurdo') 33 | 34 | # Fixes for "son (daughter) of" etc. 35 | localstring.gsub!(/\bAl(?=\s+\w)/, 'al') # al Arabic or forename Al. 36 | localstring.gsub!(/\bAp\b/, 'ap') # ap Welsh. 37 | localstring.gsub!(/\bBen(?=\s+\w)/,'ben') # ben Hebrew or forename Ben. 38 | localstring.gsub!(/\bDell([ae])\b/,'dell\1') # della and delle Italian. 39 | localstring.gsub!(/\bD([aeiu])\b/,'d\1') # da, de, di Italian; du French. 40 | localstring.gsub!(/\bDe([lr])\b/,'de\1') # del Italian; der Dutch/Flemish. 41 | localstring.gsub!(/\bEl\b/,'el') # el Greek or El Spanish. 42 | localstring.gsub!(/\bLa\b/,'la') # la French or La Spanish. 43 | localstring.gsub!(/\bL([eo])\b/,'l\1') # lo Italian; le French. 44 | localstring.gsub!(/\bVan(?=\s+\w)/,'van') # van German or forename Van. 45 | localstring.gsub!(/\bVon\b/,'von') # von Dutch/Flemish 46 | 47 | # Fix roman numeral names 48 | localstring.gsub!( 49 | / \b ( (?: [Xx]{1,3} | [Xx][Ll] | [Ll][Xx]{0,3} )? 50 | (?: [Ii]{1,3} | [Ii][VvXx] | [Vv][Ii]{0,3} )? ) \b /x 51 | ) { |match| match.upcase } 52 | 53 | localstring 54 | end 55 | 56 | # Returns a new +String+ with the contents properly namecased. 57 | def namecase 58 | self.class.namecase(@self) 59 | end 60 | 61 | end 62 | 63 | -------------------------------------------------------------------------------- /test/test_inflect.rb: -------------------------------------------------------------------------------- 1 | require 'language/mixin' 2 | require 'english/inflect' 3 | require 'test/unit' 4 | 5 | class TestInflect < Test::Unit::TestCase 6 | 7 | tests = [ 8 | [ "Americans", "American" ], 9 | [ "analyses", "analysis" ], 10 | [ "archives", "archive" ], 11 | [ "bays", "bay" ], 12 | [ "bureaus", "bureau" ], 13 | [ "businesses", "business" ], 14 | [ "cacti", "cactus" ], 15 | [ "cactuses", "cactus" ], 16 | [ "calves", "calf" ], 17 | [ "carpets", "carpet" ], 18 | [ "chiefs", "chief" ], 19 | [ "choruses", "chorus" ], 20 | [ "churches", "church" ], 21 | [ "companies", "company" ], 22 | [ "courses", "course" ], 23 | [ "cows", "cow" ], 24 | [ "crashes", "crash" ], 25 | [ "criteria", "criterion" ], 26 | [ "discos", "disco" ], 27 | [ "doors", "door" ], 28 | [ "factories", "factory" ], 29 | [ "farms", "farm" ], 30 | [ "farmers", "farmer" ], 31 | [ "faxes", "fax" ], 32 | [ "firemen", "fireman" ], 33 | [ "fish", "fish" ], 34 | [ "flowers", "flower" ], 35 | [ "forum", "fora" ], 36 | [ "forks", "fork" ], 37 | [ "foxes", "fox" ], 38 | [ "friends", "friend" ], 39 | [ "garages", "garage" ], 40 | [ "gardens", "garden" ], 41 | [ "geese", "goose" ], 42 | [ "girls", "girl" ], 43 | [ "grown-ups", "grown-up" ], 44 | [ "halves", "half" ], 45 | [ "heroes", "hero" ], 46 | [ "highways", "highway" ], 47 | [ "hives", "hive" ], 48 | [ "horses", "horse" ], 49 | [ "hovercraft", "hovercraft" ], 50 | [ "indexes", "index" ], 51 | [ "indices", "index" ], 52 | [ "kisses", "kiss" ], 53 | [ "lives", "life" ], 54 | [ "lights", "light" ], 55 | [ "loaves", "loaf" ], 56 | [ "memos", "memo" ], 57 | [ "men", "man" ], 58 | [ "mountains", "mountain" ], 59 | [ "mice", "mouse" ], 60 | [ "ovens", "oven" ], 61 | [ "oxen", "ox" ], 62 | [ "parties", "party" ], 63 | [ "pens", "pen" ], 64 | [ "pennies", "penny" ], 65 | [ "potatoes", "potato" ], 66 | [ "prizes", "prize" ], 67 | [ "proofs", "proof" ], 68 | [ "scarves", "scarf" ], 69 | [ "series", "series" ], 70 | [ "staples", "staple" ], 71 | [ "statuses", "status" ], 72 | [ "stores", "store" ], 73 | [ "Swiss", "Swiss" ], 74 | [ "tables", "table" ], 75 | [ "take-offs", "take-off" ], 76 | [ "teachers", "teacher" ], 77 | [ "theses", "thesis" ], 78 | [ "thieves", "thief" ], 79 | [ "tomatoes", "tomato" ], 80 | [ "torpedoes", "torpedo" ], 81 | [ "videos", "video" ], 82 | [ "watches", "watch" ] 83 | ] 84 | 85 | tests.each do |(p, s)| 86 | define_method("test_singular_of_#{p}") do 87 | assert_equal(s, p.en.singular) 88 | end 89 | 90 | define_method("test_plural_of_#{s}") do 91 | assert_equal(p, s.en.plural) 92 | end 93 | end 94 | end 95 | -------------------------------------------------------------------------------- /README.rdoc: -------------------------------------------------------------------------------- 1 | = English 2 | 3 | * home: http://rubyworks.github.com/english 4 | * work: http://github.com/rubyworks/english 5 | 6 | 7 | == DESCRIPTION 8 | 9 | English is a spin-off of Facets, collecting together all English 10 | language libraries together under a single unified project. The English 11 | project intends to provided a general purpose set of English-oriented 12 | text manipulation and natural language processing Ruby libraries in one 13 | convenient package. 14 | 15 | 16 | == RELEASE NOTES 17 | 18 | Please see the HISTORY file. 19 | 20 | 21 | == SYNOPSIS 22 | 23 | The primary means of usage is via the English::String class. 24 | A normal Ruby +String+ can be quickly concerted to an +English::String+ 25 | class using the +#en+ method. With the converted object you can 26 | call any of the string-based English methods. 27 | 28 | require 'english/inflect' 29 | 30 | "Goose".en.plural #=> "Geese" 31 | 32 | By loading the 'language/mixin' library, you can further remove 33 | the need for the #en method. Instead the Language module will 34 | use whatever language is set as *current*. By default 'en' is 35 | the current language setting. 36 | 37 | require 'language/mixin' 38 | 39 | "Goose".plural #=> "Geese" 40 | 41 | To load the entire English library, including the 'lanaguage/mixin' 42 | script, simply use: 43 | 44 | require 'english' 45 | 46 | See Language project for more information on support for other languages. 47 | For details on all the methods the English library supplies see the 48 | API documentation. 49 | 50 | NOTE: If your system has a case insensitive file system, an alternative 51 | to +english.rb+ is provided. Use +en.rb+ instead: 52 | 53 | require 'en' 54 | 55 | 56 | == INSTALLATION 57 | 58 | Using RubyGems 59 | 60 | $ sudo gem install english 61 | 62 | We do not recommend site installations any longer, but if you need 63 | to do so, you can download the .tar.gz file from GitHub and use 64 | Ruby Setup to install 65 | English manually: 66 | 67 | $ tar -xvzf english-1.0.0.tar.gz 68 | $ cd english-1.0.0 69 | $ sudo setup.rb 70 | 71 | For Windows users the last line needs to be 'ruby setup.rb'. 72 | 73 | 74 | == TESTING 75 | 76 | To run the test suite without installing, you can use: 77 | 78 | $ script/test 79 | 80 | 81 | == AUTHORS 82 | 83 | Many developers, both directly and indirectly, made English possible. 84 | See the AUTHORS file for a list of specific acknowledgements. 85 | 86 | 87 | == COPYING 88 | 89 | English, Copyright (c) 2006–2010 Thomas Sawyer 90 | 91 | Some libraries within English are copyrighted to respective authors, 92 | or are derivatives of such acknowledged work. See the library files 93 | for copyright notices. 94 | 95 | The English collection is distributed under the terms of the MIT license. 96 | 97 | -------------------------------------------------------------------------------- /.gemspec: -------------------------------------------------------------------------------- 1 | --- !ruby/object:Gem::Specification 2 | name: english 3 | version: !ruby/object:Gem::Version 4 | hash: 0 5 | prerelease: false 6 | segments: [] 7 | 8 | version: "" 9 | platform: ruby 10 | authors: 11 | - Thomas Sawyer 12 | autorequire: 13 | bindir: bin 14 | cert_chain: [] 15 | 16 | date: 2011-04-10 00:00:00 -04:00 17 | default_executable: 18 | dependencies: 19 | - !ruby/object:Gem::Dependency 20 | version_requirements: &id001 !ruby/object:Gem::Requirement 21 | none: false 22 | requirements: 23 | - - ">=" 24 | - !ruby/object:Gem::Version 25 | hash: 3 26 | segments: 27 | - 0 28 | version: "0" 29 | requirement: *id001 30 | prerelease: false 31 | type: :runtime 32 | name: language 33 | description: English is an general purpose English language processing library. It includes a number of useful libraries, such as inflect.rb, metaphone.rb, ordinal.rb, and so on. 34 | email: transfire@gmail.com 35 | executables: [] 36 | 37 | extensions: [] 38 | 39 | extra_rdoc_files: 40 | - README.rdoc 41 | files: 42 | - .ruby 43 | - lib/en.rb 44 | - lib/english/censor.rb 45 | - lib/english/class.rb 46 | - lib/english/conjunction.rb 47 | - lib/english/dresner.rb 48 | - lib/english/infinitive.rb 49 | - lib/english/inflect.rb 50 | - lib/english/jumble.rb 51 | - lib/english/metaphone.rb 52 | - lib/english/mixin.rb 53 | - lib/english/namecase.rb 54 | - lib/english/numeral.rb 55 | - lib/english/ordinal.rb 56 | - lib/english/participle.rb 57 | - lib/english/porter.rb 58 | - lib/english/soundex.rb 59 | - lib/english/words.rb 60 | - lib/english.rb 61 | - test/fixture/double_metaphone.txt 62 | - test/fixture/metaphone.txt 63 | - test/fixture/metaphone_lp.txt 64 | - test/fixture/porter_stemming_input.txt 65 | - test/fixture/porter_stemming_output.txt 66 | - test/fixture/soundex.txt 67 | - test/test_dresner.rb 68 | - test/test_infinitive.rb 69 | - test/test_inflect.rb 70 | - test/test_metaphone.rb 71 | - test/test_namecase.rb 72 | - test/test_porter.rb 73 | - test/test_soundex.rb 74 | - Rakefile 75 | - HISTORY.rdoc 76 | - PROFILE 77 | - LICENSE 78 | - README.rdoc 79 | - AUTHORS 80 | - Gemfile 81 | - NOTICE 82 | - Syckfile 83 | has_rdoc: true 84 | homepage: http://rubyworks.github.com/english 85 | licenses: 86 | - MIT 87 | post_install_message: 88 | rdoc_options: 89 | - --title 90 | - English API 91 | - --main 92 | - README.rdoc 93 | require_paths: 94 | - lib 95 | required_ruby_version: !ruby/object:Gem::Requirement 96 | none: false 97 | requirements: 98 | - - ">=" 99 | - !ruby/object:Gem::Version 100 | hash: 3 101 | segments: 102 | - 0 103 | version: "0" 104 | required_rubygems_version: !ruby/object:Gem::Requirement 105 | none: false 106 | requirements: 107 | - - ">=" 108 | - !ruby/object:Gem::Version 109 | hash: 3 110 | segments: 111 | - 0 112 | version: "0" 113 | requirements: [] 114 | 115 | rubyforge_project: english 116 | rubygems_version: 1.3.7 117 | signing_key: 118 | specification_version: 3 119 | summary: English Code Kit 120 | test_files: 121 | - test/test_dresner.rb 122 | - test/test_infinitive.rb 123 | - test/test_inflect.rb 124 | - test/test_metaphone.rb 125 | - test/test_namecase.rb 126 | - test/test_porter.rb 127 | - test/test_soundex.rb 128 | -------------------------------------------------------------------------------- /NOTICE: -------------------------------------------------------------------------------- 1 | = COPYRIGHT NOTICES 2 | 3 | == Text 4 | 5 | Props to Paul Battley, Michael Neumann, and Tim Fletcher for the Text project. 6 | Some features of English owe their code to thier excellent work. 7 | 8 | Copyright (c) 2006 Paul Battley, Michael Neumann, Tim Fletcher 9 | 10 | (Ruby License) 11 | 12 | Text[https://github.com/threedaymonk/text] 13 | 14 | 15 | == Ruby Linguistics 16 | 17 | Thanks goes to Michael Granger and Martin Chase for the Ruby Linguistics 18 | project, which provided some inspiration for English, notabley the idea of 19 | the #en fluent notation. 20 | 21 | Copyright (c) 2003-2009, Michael Granger 22 | All rights reserved. 23 | 24 | Redistribution and use in source and binary forms, with or without 25 | modification, are permitted provided that the following conditions are met: 26 | 27 | * Redistributions of source code must retain the above copyright notice, 28 | this list of conditions and the following disclaimer. 29 | 30 | * Redistributions in binary form must reproduce the above copyright notice, 31 | this list of conditions and the following disclaimer in the documentation 32 | and/or other materials provided with the distribution. 33 | 34 | * Neither the name of the author/s, nor the names of the project's 35 | contributors may be used to endorse or promote products derived from this 36 | software without specific prior written permission. 37 | 38 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 39 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 40 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 41 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE 42 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 43 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 44 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 45 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 46 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 47 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 48 | 49 | {Ruby Linguistics}[http://deveiate.org/projects/Linguistics] 50 | 51 | 52 | = ActiveSupport 53 | 54 | Finally thanks to ActiveSupport library for a few of it's convenient String 55 | methods and the some early design ideas for inflections. 56 | 57 | Copyright (c) 2005-2011 David Heinemeier Hansson 58 | 59 | (MIT License) 60 | 61 | Permission is hereby granted, free of charge, to any person obtaining 62 | a copy of this software and associated documentation files (the 63 | "Software"), to deal in the Software without restriction, including 64 | without limitation the rights to use, copy, modify, merge, publish, 65 | distribute, sublicense, and/or sell copies of the Software, and to 66 | permit persons to whom the Software is furnished to do so, subject to 67 | the following conditions: 68 | 69 | The above copyright notice and this permission notice shall be 70 | included in all copies or substantial portions of the Software. 71 | 72 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 73 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 74 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 75 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 76 | LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 77 | OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 78 | WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 79 | 80 | {ActiveSupport}[https://github.com/rails/rails/tree/master/activesupport] 81 | 82 | -------------------------------------------------------------------------------- /work/reference/grammer.bak/gramdex.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | English Grammar 8 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 |
21 | 22 | 23 | 24 |
ENGLISH GRAMMAR:

25 |
EXPLANATIONS AND EXERCISES
26 |

27 |
by Mary Ansell

28 |
Second edition, copyright © 2000
29 |
30 | 31 |
32 | 33 | The material in this book may be used freely for any non-commercial purpose, 34 | however no changes to the content may be made without the express permission of the author. 35 | Questions, comments or corrections may be sent to
stirling@dbis.ns.ca. 37 |

38 | The contents of the book can be seen at a glance from the Table of Contents, which contains links to all of the material covered. There is also an Index. 39 |
40 |
41 | Anyone who would like to download the material in order to use it more conveniently is welcome to do so. Simply save this file: grammar.exe (421Kb). This is a self-expanding file. Once you have saved the file, if you then double-click on it, and click on "Start" and "OK", grammar.exe will expand into 61 files which can be read on your browser. You will then have the whole book on your computer, and can use it in electronic form or print it out, as you wish. In order for the links to work correctly, all of the files should be kept in a single directory. 42 |

43 | 44 |
TO THE READER
45 |

46 | 47 | This book has the following features:
48 |
49 | * All of the essential points of English grammar are covered.
50 |
51 | * Each point of grammar is clearly explained, and is illustrated 52 | by examples.
53 |
54 | * For every important point of grammar, one or more exercises are 55 | provided, to make it easier to learn and remember the material.
56 |
57 | * Answers for the exercises are provided.
58 |
59 | * A summary of the uses and formation of the English verb tenses is given for easy reference.
60 |
61 | * Grammatically determined rules for spelling, pronunciation, and 62 | punctuation are included.
63 |
64 | * The grammar of North American English is emphasized.
65 |
66 | * Grammatical differences between formal and informal English are 67 | pointed out.

68 | 69 |

70 | 71 | 78 | 79 | 80 |
81 |
Table of Contents | Index
82 |
Next Page
83 |

84 | 85 | 86 |

87 | 88 | 89 | 90 | 91 | -------------------------------------------------------------------------------- /site/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Ruby English 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 16 | 17 | 18 | 19 | 20 |
21 | 22 | 29 | 30 | 37 | 38 |
39 |
40 |
41 | 42 |
43 | 44 |
45 | 46 | English
47 | Text and Language Processing 48 | 49 |

50 | 51 |

Welcome

52 | 53 |
54 |

English is a collection English-related text manipulation and natural language 55 | processing libraries for the Ruby programming language. Over time the project hopes 56 | to provide a fairly comprehensive set of tools for working with English language data.

57 | 58 |

Probably the most typical example of it use is:

59 | 60 |
 61 |         require 'english/inflect'
 62 | 
 63 |         "boy".en.plural      #=> "boys"
 64 |         "boys".en.singular   #=> "boy"
 65 | 
 66 |         "ox".en.plural       #=> "oxen"
 67 |         "oxen".en.singular   #=> "ox"
 68 |       
69 | 70 |

By default the $language global variable is set to 'en'. 71 | If the english/mixin library is loadeds the #en method call 72 | can be left out and the same result achieved.

73 | 74 |
 75 |         require 'english/mixin'
 76 | 
 77 |         "boy".plural      #=> "boys"
 78 |         "boys".singular   #=> "boy"
 79 | 
 80 |         "ox".plural       #=> "oxen"
 81 |         "oxen".singular   #=> "ox"
 82 |       
83 | 84 |

English includes many other useful methods and also a few useful classes. 85 |

Each library can be utilized independently. Or all libraries can be loaded with 86 | the single require.

87 | 88 |
 89 |         require 'english'
 90 |       
91 | 92 |

For more details see the Wiki 93 | or the RDoc API documentation.

94 |
95 | 96 |

Resources

97 | 98 |
99 | 100 |
101 | English Grammar
102 | Explanations and Exercises written by Mary Ansell. 103 |
104 | 105 | 112 | 113 |

114 | 115 |
116 |
117 |
118 | 119 | 123 | 124 |
125 | 126 | 127 | 128 | -------------------------------------------------------------------------------- /site/grammar/gramdex.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | English Grammar 8 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 34 | 35 |
36 | 37 | 38 |
ENGLISH GRAMMAR:

39 |
EXPLANATIONS AND EXERCISES
40 |

41 |
by Mary Ansell

42 |
Second edition, copyright © 2000
43 |
44 | 45 |
46 | 47 | The material in this book may be used freely for any non-commercial purpose, 48 | however no changes to the content may be made without the express permission of the author. 49 | Questions, comments or corrections may be sent to stirling@dbis.ns.ca. 51 |

52 | The contents of the book can be seen at a glance from the Table of Contents, which contains links to all of the material covered. There is also an Index. 53 |
54 |
55 | Anyone who would like to download the material in order to use it more conveniently is welcome to do so. Simply save this file: grammar.exe (421Kb). This is a self-expanding file. Once you have saved the file, if you then double-click on it, and click on "Start" and "OK", grammar.exe will expand into 61 files which can be read on your browser. You will then have the whole book on your computer, and can use it in electronic form or print it out, as you wish. In order for the links to work correctly, all of the files should be kept in a single directory. 56 |

57 | 58 |
TO THE READER
59 |

60 | 61 | This book has the following features:
62 |
63 | * All of the essential points of English grammar are covered.
64 |
65 | * Each point of grammar is clearly explained, and is illustrated 66 | by examples.
67 |
68 | * For every important point of grammar, one or more exercises are 69 | provided, to make it easier to learn and remember the material.
70 |
71 | * Answers for the exercises are provided.
72 |
73 | * A summary of the uses and formation of the English verb tenses is given for easy reference.
74 |
75 | * Grammatically determined rules for spelling, pronunciation, and 76 | punctuation are included.
77 |
78 | * The grammar of North American English is emphasized.
79 |
80 | * Grammatical differences between formal and informal English are 81 | pointed out.

82 | 83 |

84 | 85 | 92 | 93 | 94 |
96 |
Next Page
97 |

98 | 99 | 100 |

101 | 102 | 103 | 104 | 105 | -------------------------------------------------------------------------------- /HISTORY.rdoc: -------------------------------------------------------------------------------- 1 | = RELEASE HISTORY 2 | 3 | == 0.6.3 / 2010-09-21 4 | 5 | This release allows the english library to be loaded via require 'en'. 6 | This offeres a way to get around Ruby's own English.rb library on case insensitive 7 | systems. 8 | 9 | Changes: 10 | 11 | * Add `en.rb` redirection script. 12 | * Ruby Facets is no longer needed as a dependency. 13 | 14 | 15 | == 0.6.2 / 2010-06-19 16 | 17 | Restored last #singularize and #pluralize aliases for #singular and #plural. 18 | 19 | Changes: 20 | 21 | * Restored common aliases #singularize and #pluralize. 22 | 23 | 24 | == 0.6.1 / 2010-06-05 25 | 26 | This release entails two enhancments. A simple bug fix for 27 | the #conjunction method, and the completion of integrating 28 | Michael Granger's Infinitive module into the library. 29 | 30 | Changes: 31 | 32 | * Integrated Infinitive module. 33 | * Fixed #conjunction method. 34 | 35 | 36 | == 0.6.0 / 2010-05-29 37 | 38 | This release is a significant milestone and short of any bug reports 39 | will become the 1.0 release in the coming months. The biggest change 40 | is the dependency on Language library, which is a spin-off of English 41 | to house language neutral and multi-language code. 42 | 43 | Changes: 44 | 45 | * Major Enhancments 46 | 47 | * Language library spun-off. 48 | * Reduced three class design to a single class. 49 | 50 | 51 | == 0.5.0 / 2009-10-03 52 | 53 | Initial progress towards a more elegant design. This release 54 | it turns out is a little premature. I do not recommed using 55 | it in production. But it does provide a feel for were 56 | English is headed. 57 | 58 | Changes: 59 | 60 | * 3 Major Enhancements 61 | 62 | * New three class design (English::String, English::Array, English::Integer). 63 | * Use #method_missing to dispatch language methods to correct language module. 64 | * Split obfustcate.rb back out to dresner.rb and jumble.rb. 65 | 66 | * 1 Deprecation 67 | 68 | * Deprecated roman.rb (put back in Ruby Facets). 69 | 70 | 71 | == 0.4.0 / 2009-06-06 72 | 73 | This version of English (v0.4.0) is the first step in a two part 74 | process to scale the library back to it's "pure English" roots. 75 | With limited exceptions, library scripts that are not strictly related 76 | to providing routines for working with the English language will be 77 | deprecated. Any useful deprecated functionality will most likely be 78 | supported in Ruby Facets instead. 79 | 80 | Changes: 81 | 82 | * 3 Major Enhancements 83 | 84 | * dresner.rb and jumble.rb are deprecated (use obfuscate.rb instead). 85 | * string.rb has been renamed words.rb 86 | * created namecase.rb (used to be in case.rb) 87 | 88 | 89 | == 0.3.0 / 2008-09-27 90 | 91 | English's Inflect performance has been greatly improved. 92 | Inflect had used sorting and a comparision loop to find matches 93 | for singular and plural conversions. Now it uses a single Regexp 94 | which handles all the matching grunt work on it's own and 95 | provides a 10x performance gain! Thanks goes to Wycats 96 | for this superb work on this. 97 | 98 | English has also gained a new Style module which extends the 99 | String class. This mixin provides an assortment of String 100 | alteration methods such as titlecase, jumble, pathize, etc; 101 | all the ones you would expect and then some. 102 | 103 | Changes: 104 | 105 | * 3 Major Enhancements 106 | 107 | * Applied wycats improvements to inflect.rb. Now 10x faster! 108 | * Renamed database.rb to orm.rb and metacode.rb to code.rb. 109 | * Added style.rb from Facets. 110 | 111 | * 5 Minor Enhancements 112 | 113 | * Added warning to old jumble.rb and dresner.rb. 114 | * Added rule 'ess', 'esses' to inflect.rb. 115 | * Fixed vertex plural. 116 | * Fixed similarity require. 117 | * Minor adjustments to English::Filter. 118 | 119 | 120 | == 0.2.0 / 2008-02-07 121 | 122 | Continued work in general orginaization, deciding what will and will not 123 | be included, what the best names for things are, etc. 124 | 125 | Changes: 126 | 127 | * 7 Major Enhancements 128 | 129 | * Added roman.rb 130 | * Added jumble.rb. 131 | * Added porter_stemmingrb 132 | * Added levenshtien.rb. 133 | * Merged wordfilter.rb into censor.rb. 134 | * Renamed metaphone.rb to double_metaphone.rb. 135 | * Merged rewrite.rb into censor.rb. 136 | 137 | * 3 Minor Enhancements 138 | 139 | * Improved soundex.rb. 140 | * Added grammer reference to docs. 141 | * Added double_metaphone test. 142 | 143 | 144 | == 0.1.0 / 2007-08-01 145 | 146 | English is a spin-off project from Ruby Facets, collecting 147 | a number of english-related libraries under a single unified 148 | package. This is the first stab at pulling these libraries 149 | together. 150 | 151 | Changes: 152 | 153 | * Happy Birthday! 154 | 155 | -------------------------------------------------------------------------------- /work/deprecated/stylize.rb: -------------------------------------------------------------------------------- 1 | warn "English::Stylize is being deprecated. Use Facets instead." 2 | 3 | module English 4 | 5 | # = String Stylization 6 | # 7 | # == WARNING: This module is being deprecated. These methods are generally available via Facets. 8 | # 9 | # The Stylize mixin provides common transformation to strings. 10 | # 11 | # This module is automatically mixed into the String class, but 12 | # the mixin is designed in such a way that it can be mixed into 13 | # any class that supports the #to_s method. 14 | # 15 | # Examples 16 | # 17 | # "super_man".dasherize #=> "super-man" 18 | # 19 | #-- 20 | # TODO: With #pathize, is downcasing really needed? After all paths 21 | # can have capitalize letters ;p 22 | # 23 | # TODO: With #methodize, is downcasing any but the first letter 24 | # really needed? Desipite Matz preference methods can have 25 | # capitalized letters. 26 | #++ 27 | module Stylize 28 | 29 | # Replaces underscores with dashes in the string. 30 | # 31 | # "puni_puni".dasherize #=> "puni-puni" 32 | # 33 | def dasherize 34 | to_s.gsub(/_/, '-') 35 | end 36 | 37 | # The reverse of +camelize+. Makes an underscored, lowercase form from 38 | # the expression in the string. 39 | # 40 | # Changes '::' to '/' to convert namespaces to paths. 41 | # 42 | # "ActiveRecord".underscore #=> "active_record" 43 | # "ActiveRecord::Errors".underscore #=> active_record/errors 44 | # 45 | def underscore 46 | to_s. 47 | gsub(/::/, '/'). 48 | gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2'). 49 | gsub(/([a-z\d])([A-Z])/,'\1_\2'). 50 | tr("-", "_"). 51 | downcase 52 | end 53 | 54 | # Converts a module or method name into a unix pathname. 55 | # This method is geared toward code reflection. 56 | # 57 | # "MyModule::MyClass".pathize #=> my_module/my_class 58 | # "my_module__my_class".pathize #=> my_module/my_class 59 | # 60 | # TODO: Make sure that all scenarios return a valid unix path. 61 | # TODO: Make sure it is revertible. 62 | # 63 | # See also #modulize, #methodize 64 | def pathize 65 | to_s. 66 | gsub(/__/, '/'). 67 | gsub(/::/, '/'). 68 | gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2'). 69 | gsub(/([a-z\d])([A-Z])/,'\1_\2'). 70 | tr("-", "_"). 71 | downcase 72 | end 73 | 74 | # Converts a module name into a valid method name. 75 | # This method is geared toward code reflection. 76 | # 77 | # Examples 78 | # "SuperMan".methodize #=> "super_man" 79 | # "SuperMan::Errors".methodize #=> "super_man__errors 80 | # "MyModule::MyClass".methodize #=> "my_module__my_class" 81 | # 82 | # See also #modulize, #pathize 83 | def methodize 84 | to_s. 85 | gsub(/\//, '__'). 86 | gsub(/::/, '__'). 87 | gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2'). 88 | gsub(/([a-z\d])([A-Z])/,'\1_\2'). 89 | tr("-", "_"). 90 | downcase 91 | end 92 | 93 | # Converts a pathized or methodized string into a valid ruby 94 | # class or module name. This method is geared toward code 95 | # reflection. 96 | # 97 | # "camel_case".modulize #=> "CamelCase" 98 | # "camel/case".modulize #=> "Camel::Case" 99 | # "my_module__my_path".modulize #=> "MyModule::MyPath" 100 | # 101 | # See also #methodize, #pathize 102 | def modulize 103 | to_s. 104 | gsub(/__(.?)/){ "::#{$1.upcase}" }. 105 | gsub(/\/(.?)/){ "::#{$1.upcase}" }. 106 | gsub(/(?:_+)([a-z])/){ $1.upcase }. 107 | gsub(/(^|\s+)([a-z])/){ $1 + $2.upcase } 108 | end 109 | 110 | # Removes the module part from a modularized expression. 111 | # 112 | # "English::Style".demodulize #=> "Style" 113 | # "Style".demodulize #=> "Style" 114 | # 115 | #def demodulize 116 | # to_s.gsub(/^.*::/, '') 117 | #end 118 | 119 | # Include Replace mixin if base class/module supports #replace method. 120 | def self.included(base) 121 | if base.instance_methods.include?('replace') or 122 | base.instance_methods.include?(:replace) # Ruby 1.9 123 | base.module_eval{ include Replace } 124 | end 125 | end 126 | 127 | # In place versions of Stylize methods. 128 | module Replace 129 | def ordinalize! ; replace(ordinalize) ; end 130 | def pathize! ; replace(pathize) ; end 131 | def methodize! ; replace(methodize) ; end 132 | def modulize! ; replace(modulize) ; end 133 | def dasherize! ; replace(dasherize) ; end 134 | def underscore! ; replace(underscore) ; end 135 | end 136 | 137 | end 138 | 139 | end 140 | 141 | class String #:nodoc: 142 | include English::Stylize 143 | end 144 | 145 | -------------------------------------------------------------------------------- /work/deprecated/humanize.rb: -------------------------------------------------------------------------------- 1 | warn "English::Humanize is being deprecated. Use Facets instead." 2 | 3 | module English 4 | require 'english/inflect' 5 | require 'english/stylize' 6 | 7 | # = String Humanization 8 | # 9 | # == WARNING: This module is being deprecated. It's use is geared toward ORMs which can define their own if needed. 10 | # 11 | # Transform strings into human readable forms. Used for ORM. 12 | # 13 | module Humanize 14 | 15 | ######################################################### 16 | # ACTIVE SUPPORT # 17 | # # 18 | # The following were extracted from ActiveSupport's # 19 | # Inflector class. It seemed prudent to maintian this # 20 | # degree of compatbility, at least for the time being. # 21 | ######################################################### 22 | 23 | # By default, camelize converts strings to UpperCamelCase. If the 24 | # argument to camelize is set to ":lower" then camelize produces 25 | # lowerCamelCase. 26 | # 27 | # camelize will also convert '/' to '::' which is useful for 28 | # converting paths to namespaces 29 | # 30 | # "active_record".camelize #=> "ActiveRecord" 31 | # "active_record".camelize(true) #=> "activeRecord" 32 | # "active_record/errors".camelize #=> "ActiveRecord::Errors" 33 | # "active_record/errors".camelize(true) #=> "activeRecord::Errors" 34 | # 35 | def camelize(first_letter_in_uppercase = true) 36 | if first_letter_in_uppercase 37 | to_s.gsub(/\/(.?)/){ "::#{$1.upcase}" }.gsub(/(?:^|_)(.)/){ $1.upcase } 38 | else 39 | lowercase_and_underscored = to_s 40 | lowercase_and_underscored[0,1] + lowercase_and_underscored.camelize[1..-1] 41 | end 42 | end 43 | 44 | # Removes the module part from a modularized expression. 45 | # 46 | # "English::Style".demodulize #=> "Style" 47 | # "Style".demodulize #=> "Style" 48 | # 49 | # NOTE: This comes from ActiveSupport. The name of this 50 | # method blows. Think of a better one, please. 51 | def demodulize 52 | to_s.gsub(/^.*::/, '') 53 | end 54 | 55 | # Create a class name from a plural table name like Rails does 56 | # for table names to models. Note that this returns a string and 57 | # not a Class. (To convert to an actual class follow classify 58 | # with constantize.) 59 | # 60 | # "egg_and_hams".classify #=> "EggAndHam" 61 | # "posts".classify #=> "Post" 62 | # 63 | # Singular names are not handled correctly: 64 | # 65 | # "business".classify #=> "Busines" 66 | # 67 | def classify 68 | # strip out any leading schema name 69 | to_s.sub(/.*\./, '').singularize.camelize 70 | end 71 | 72 | # Capitalizes the first word and turns underscores into spaces and strips _id. 73 | # Like titleize, this is meant for creating pretty output. 74 | # 75 | # "employee_salary".humanize #=> "Employee salary" 76 | # "author_id".humanize #=> "Author" 77 | # 78 | def humanize 79 | to_s.gsub(/_id$/, "").gsub(/_/, " ").capitalize 80 | end 81 | 82 | # Create the name of a table like Rails does for models to table names. 83 | # This method uses the pluralize method on the last word in the string. 84 | # 85 | # "RawScaledScorer".tableize #=> "raw_scaled_scorers" 86 | # "egg_and_ham".tableize #=> "egg_and_hams" 87 | # "fancyCategory".tableize #=> "fancy_categories" 88 | # 89 | def tableize 90 | to_s.underscore.pluralize 91 | end 92 | 93 | # Capitalizes all the words and replaces some characters in the 94 | # string to create a nicer looking title. Titleize is meant for 95 | # creating pretty output. It is not used in the Rails internals. 96 | # 97 | # titleize is also aliased as as titlecase 98 | # 99 | # "man from the boondocks".titleize #=> "Man From The Boondocks" 100 | # "x-men: the last stand".titleize #=> "X Men: The Last Stand" 101 | # 102 | def titleize 103 | to_s.underscore.humanize.gsub(/\b('?[a-z])/){ $1.capitalize } 104 | end 105 | 106 | # Creates a foreign key name from a class name. 107 | # +separate_id_with_underscore+ sets whether the method 108 | # should put '_' between the name and 'id'. 109 | # 110 | # "Message".foreign_key #=> "message_id" 111 | # "Message".foreign_key(false) #=> "messageid" 112 | # "Admin::Post".foreign_key #=> "post_id" 113 | # 114 | def foreign_key(separate_id_with_underscore = true) 115 | to_s.demodulize.underscore + (separate_id_with_underscore ? "_id" : "id") 116 | end 117 | 118 | # Include Replace mixin if base class/module supports #replace method. 119 | def self.included(base) 120 | if base.instance_methods.include?('replace') or 121 | base.instance_methods.include?(:replace) # Ruby 1.9 122 | base.module_eval{ include Replace } 123 | end 124 | end 125 | 126 | module Replace 127 | def camelize! ; replace(camelize) ; end 128 | def demodulize! ; replace(demodulize) ; end 129 | def classify! ; replace(classify) ; end 130 | def humanize! ; replace(humanize) ; end 131 | def tableize! ; replace(tableize) ; end 132 | def titleize! ; replace(titleize) ; end 133 | def foreign_key! ; replace(foreign_key) ; end 134 | end 135 | 136 | end 137 | 138 | end 139 | 140 | class String #:nodoc: 141 | include English::Humanize 142 | end 143 | 144 | -------------------------------------------------------------------------------- /work/deprecated/words.rb: -------------------------------------------------------------------------------- 1 | module English 2 | #require 'facets/string/fold' 3 | module Words 4 | 5 | # Returns an array of characters. 6 | # 7 | # "abc 123".words #=> ["abc","123"] 8 | # 9 | def words 10 | split(/\s+/) 11 | end 12 | 13 | # Iterate through each word of a string. 14 | # 15 | # "a string".each_word { |word, range| ... } 16 | # 17 | def each_word(&yld) 18 | rest_of_string = self 19 | wordfind = /([-'\w]+)/ 20 | arity = yld.arity 21 | offset = 0 22 | while wmatch = wordfind.match(rest_of_string) 23 | word = wmatch[0] 24 | range = offset+wmatch.begin(0) ... offset+wmatch.end(0) 25 | rest_of_string = wmatch.post_match 26 | if arity == 1 27 | yld.call(word) 28 | else 29 | yld.call(word, range) 30 | end 31 | offset = self.length - rest_of_string.length 32 | end 33 | end 34 | 35 | # Filters out words from a string based on block test. 36 | # 37 | # "a string".word_filter { |word| word =~ /^a/ } #=> "string" 38 | # 39 | # CREDIT: George Moschovitis 40 | 41 | def word_filter( &blk ) 42 | s = self.dup 43 | s.word_filter!( &blk ) 44 | end 45 | 46 | # In place version of #word_filter. 47 | # 48 | # "a string".word_filter { |word| ... } 49 | # 50 | # CREDIT: George Moschovitis 51 | 52 | def word_filter! #:yield: 53 | rest_of_string = self 54 | wordfind = /(\w+)/ 55 | offset = 0 56 | while wmatch = wordfind.match(rest_of_string) 57 | word = wmatch[0] 58 | range = offset+wmatch.begin(0) ... offset+wmatch.end(0) 59 | rest_of_string = wmatch.post_match 60 | self[range] = yield( word ).to_s 61 | offset = self.length - rest_of_string.length 62 | end 63 | self 64 | end 65 | 66 | # TODO: This is alternateive from glue: worth providing? 67 | # 68 | # Enforces a maximum width of a string inside an 69 | # html container. If the string exceeds this maximum width 70 | # the string gets wraped. 71 | # 72 | # Not really useful, better use the CSS overflow: hidden 73 | # functionality. 74 | # 75 | # === Input: 76 | # the string to be wrapped 77 | # the enforced width 78 | # the separator used for wrapping 79 | # 80 | # === Output: 81 | # the wrapped string 82 | # 83 | # === Example: 84 | # text = "1111111111111111111111111111111111111111111" 85 | # text = wrap(text, 10, " ") 86 | # p text # => "1111111111 1111111111 1111111111" 87 | # 88 | # See the test cases to better understand the behaviour! 89 | 90 | # def wrap(width = 20, separator = " ") 91 | # re = /([^#{separator}]{1,#{width}})/ 92 | # scan(re).join(separator) 93 | # end 94 | 95 | # Word wrap a string not exceeding max width. 96 | # 97 | # puts "this is a test".word_wrap(4) 98 | # 99 | # _produces_ 100 | # 101 | # this 102 | # is a 103 | # test 104 | # 105 | # CREDIT: Gavin Kistner 106 | # CREDIT: Dayne Broderson 107 | 108 | def word_wrap( col_width=80 ) 109 | self.dup.word_wrap!( col_width ) 110 | end 111 | 112 | # As with #word_wrap, but modifies the string in place. 113 | # 114 | # CREDIT: Gavin Kistner 115 | # CREDIT: Dayne Broderson 116 | 117 | def word_wrap!( col_width=80 ) 118 | self.gsub!( /(\S{#{col_width}})(?=\S)/, '\1 ' ) 119 | self.gsub!( /(.{1,#{col_width}})(?:\s+|$)/, "\\1\n" ) 120 | self 121 | end 122 | 123 | # old def 124 | 125 | #def word_wrap(max=80) 126 | # c = dup 127 | # c.word_wrap!(max) 128 | # c 129 | #end 130 | 131 | #def word_wrap!(max=80) 132 | # raise ArgumentError, "Wrap margin too low: #{n}" if max <= 2 133 | # #gsub!( Regexp.new( "(.{1,#{max-1}}\\w)\\b\\s*" ), "\\1\n") 134 | # gsub!( /(.{1,#{max-1}}\S)([ ]|\n)/, "\\1\n") 135 | #end 136 | 137 | =begin 138 | # Returns a new string with all new lines removed from 139 | # adjacent lines of text. 140 | # 141 | # s = "This is\na test.\n\nIt clumps\nlines of text." 142 | # s.fold 143 | # 144 | # _produces_ 145 | # 146 | # "This is a test.\n\nIt clumps lines of text. " 147 | # 148 | # One arguable flaw with this, that might need a fix: 149 | # if the given string ends in a newline, it is replaced with 150 | # a single space. 151 | # 152 | # CREDIT: Trans 153 | 154 | def fold(ignore_indented=false) 155 | ns = '' 156 | i = 0 157 | br = self.scan(/(\n\s*\n|\Z)/m) do |m| 158 | b = $~.begin(1) 159 | e = $~.end(1) 160 | nl = $& 161 | tx = slice(i...b) 162 | if ignore_indented and slice(i...b) =~ /^[ ]+/ 163 | ns << tx 164 | else 165 | ns << tx.gsub(/[ ]*\n+/,' ') 166 | end 167 | ns << nl 168 | i = e 169 | end 170 | ns 171 | end 172 | 173 | # Returns short abstract of long strings; not exceeding +range+ 174 | # characters. If range is an integer then the minimum is 20% 175 | # of the maximum. The string is chopped at the nearest word 176 | # if possible, and appended by +ellipsis+, which defaults 177 | # to '...'. 178 | # 179 | # CREDIT: George Moschovitis 180 | # CREDIT: Trans 181 | # 182 | def brief(range=76, ellipsis="...") 183 | if Range===range 184 | min = range.first 185 | max = range.last 186 | else 187 | max = range 188 | min = max - (max/5).to_i 189 | range = min..max 190 | end 191 | 192 | if size > max 193 | cut_at = rindex(/\b/, max) || max 194 | cut_at = max if cut_at < min 195 | xstring = slice(0, cut_at) 196 | xstring.chomp(" ") + ellipsis 197 | else 198 | self 199 | end 200 | end 201 | =end 202 | 203 | end 204 | 205 | end 206 | 207 | class String #:nodoc: 208 | include English::Words 209 | end 210 | 211 | -------------------------------------------------------------------------------- /test/test_infinitive.rb: -------------------------------------------------------------------------------- 1 | # Unit test for English infinitive (stem) forms. 2 | # 3 | # Copyright (c) 2003 The FaerieMUD Consortium. 4 | 5 | require 'english/infinitive' 6 | 7 | class InfinitiveTest < Test::Unit::TestCase 8 | 9 | # Auto-generate tests for the dataset beneath the '__END__' 10 | begin 11 | inDataSection = false 12 | methodCounter = 5 13 | 14 | # Read the lines of this file below the __END__, splitting each 15 | # non-comment line into rule, original word, and expected infinitive 16 | # form. Then generate a test method for each one. 17 | lines = File::readlines( __FILE__ ).find_all do |line| 18 | case line 19 | when /^__END_DATA__$/ 20 | inDataSection = false 21 | when /^__END__$/ 22 | inDataSection = true 23 | false 24 | else 25 | inDataSection 26 | end 27 | end 28 | 29 | lines.each do |line| 30 | next if /^\s*#/ =~ line 31 | 32 | rule, oword, stemword = line.split( /\s+/ ) 33 | 34 | # Add a test method for the method interface with a name generated 35 | # from the origin word and the method counter. 36 | methodname = "test_%04d_method_infinitive%s" % [methodCounter, oword.capitalize.gsub(/\W+/, '')] 37 | 38 | define_method(methodname) do 39 | infs = oword.en.infinitives 40 | assert_instance_of(Array, infs) 41 | assert_block("Method iface: Stem for #{oword}: #{stemword} != #{infs.inspect}") do 42 | infs.any?{ |inf| stemword == inf } 43 | end 44 | irule = English::Infinitive.rule(oword) 45 | assert_equal(rule, irule.number, "Method iface: Infinitive rule for #{oword}") 46 | end 47 | 48 | methodCounter += 1 49 | 50 | # Add a test method for the functional interface with a name 51 | # generated from the origin word and the method counter. 52 | methodname = "test_%04d_function_infinitive%s" % [methodCounter, oword.capitalize.gsub(/\W+/, '')] 53 | 54 | define_method(methodname) do 55 | infs = English.infinitives(oword) 56 | assert_instance_of(Array, infs) 57 | assert_block("Method iface: Stem for #{oword}: #{stemword} != #{infs.inspect}") do 58 | infs.any?{ |inf| stemword == inf } 59 | end 60 | irule = English::Infinitive.rule(oword) 61 | assert_equal(rule, irule.number, "Function iface: Infinitive rule for #{oword}") 62 | end 63 | 64 | methodCounter += 1 65 | end 66 | end 67 | 68 | =begin 69 | # Overridden initializer: auto-generated test methods have an arity of 1 70 | # even though they don't require an argument (as of the current Ruby CVS), 71 | # and the default initializer throws an :invalid_test for methods with 72 | # arity != 0. 73 | def initialize( test_method_name ) 74 | if !respond_to?( test_method_name ) 75 | throw :invalid_test 76 | end 77 | @method_name = test_method_name 78 | @test_passed = true 79 | end 80 | =end 81 | 82 | ################################################################# 83 | ### T E S T S 84 | ################################################################# 85 | 86 | ### Test to be sure the infinitive module loaded. 87 | def test_000_module 88 | #printTestHeader "English: Infinitive method" 89 | assert_respond_to English, :infinitive 90 | end 91 | end 92 | 93 | 94 | # Dataset is copied from Lingua::EN::Infinitive by Ron Savage (with a few 95 | # bugfixes). 96 | __END__ 97 | 1 aches ache 98 | 1 arches arch 99 | 2 vases vase 100 | 2 basses bass 101 | 3 axes axe 102 | 3 fixes fix 103 | 4 hazes haze 104 | 4 buzzes buzz 105 | 6a caress caress 106 | 6b bans ban 107 | 7 Jones's Jones 108 | 8 creater creater 109 | 9 reacter reacter 110 | 10 copier copy 111 | 11 baker bake 112 | 11 smaller small 113 | 12a curried curry 114 | 12b bored bore 115 | 12b seated seat 116 | # Can't handle these 2 with the special code as for the following 5 because after 117 | # chopping the suffix, we are not left with a one-syllable word. Ie it's too hard. 118 | # Yes, that was 5 not 7. Look for the doubled-consonant in the middle of the word. 119 | # The special code is in Infinitive.pm @ line 1188. 120 | #12b bootstrapped bootstrap 121 | #12b bootstrapping bootstrap 122 | 12b tipped tip 123 | 12b kitted kit 124 | 12b capped cap 125 | 12b chopped chop 126 | 13a flies fly 127 | 13b palates palate 128 | 14a liveliest lively 129 | 14b wisest wise 130 | 14b strongest strong 131 | 15 living live 132 | 15 laughing laugh 133 | 15 swaying sway 134 | 15 catching catch 135 | 15 smiling smile 136 | 15 swimming swim 137 | 15 running run 138 | 15 floating float 139 | 15 keyboarding keyboard 140 | 15 wrestling wrestle 141 | 15 traveling travel 142 | 15 traipsing traipse 143 | 16 stylist style 144 | 16 dentist dent 145 | 17 cubism cube 146 | 17 socialism social 147 | 18 scarcity scarce 148 | 18 rapidity rapid 149 | 19 immunize immune 150 | 19 lionize lion 151 | 20c livable live 152 | 20c portable port 153 | 22 nobility noble 154 | 23 identifiable identify 155 | 24 psychologist psychology 156 | 25 photographic photography 157 | 26 stylistic stylist 158 | 27 martensitic martensite 159 | 27 politic polite 160 | 28 ladylike lady 161 | 29 biologic biology 162 | 30 battlement battle 163 | 31 supplemental supplement 164 | 32 thermometry thermometer 165 | 33 inadvertence inadvertent 166 | 34 potency potent 167 | 35 discipleship disciple 168 | 36 mystical mystic 169 | 37 regional region 170 | 37 national nation 171 | 38 horribly horrible 172 | 39 scantily scanty 173 | 40 partly part 174 | 41a dutiful duty 175 | 41b harmful harm 176 | 42a likelihood likely 177 | 42b neighborhood neighbor 178 | 42b neighbourhood neighbour 179 | 43a penniless penny 180 | 43b listless list 181 | 44a heartiness hearty 182 | 44b coolness cool 183 | 45 specification specify 184 | 46 rationalization rationalize 185 | 47 detection detect 186 | 48 exertion exert 187 | 49 creation create 188 | 50 creator create 189 | 51 detector detect 190 | 52 creative creation 191 | 52 decisive decision 192 | 53 Australian Australia 193 | 54 Jeffersonian Jefferson 194 | irregular rove reeve 195 | irregular dove dive 196 | irregular snuck sneak 197 | irregular wot wit 198 | -------------------------------------------------------------------------------- /lib/english/porter.rb: -------------------------------------------------------------------------------- 1 | require 'english/class' 2 | 3 | class English 4 | 5 | # An implementaion of the Porter Stemming algorithm by Martin Porter. 6 | # 7 | # This is the Porter Stemming algorithm, ported to Ruby from the 8 | # version coded up in Perl. It's easy to follow against the rules 9 | # in the original paper in: 10 | # 11 | # Porter, 1980, An algorithm for suffix stripping, Program, Vol. 14, 12 | # no. 3, pp 130-137, 13 | # 14 | # Taken from http://www.tartarus.org/~martin/PorterStemmer (Public Domain) 15 | # 16 | # This version based on Ray Pereda's stemmable.rb (c) 2003. 17 | # 18 | module PorterStemmer 19 | 20 | PORTER_STEMS = [] 21 | 22 | PORTER_STEMS[0] = { 23 | 'ational' => 'ate', 'tional' => 'tion', 'enci' => 'ence', 'anci' => 'ance', 24 | 'izer' => 'ize', 'bli' => 'ble', 25 | 'alli' => 'al', 'entli' => 'ent', 'eli' => 'e', 'ousli' => 'ous', 26 | 'ization' => 'ize', 'ation' => 'ate', 27 | 'ator' => 'ate', 'alism' => 'al', 'iveness' => 'ive', 'fulness' => 'ful', 28 | 'ousness' => 'ous', 'aliti' => 'al', 29 | 'iviti' => 'ive', 'biliti' => 'ble', 'logi' => 'log' 30 | } 31 | 32 | PORTER_STEMS[1] = { 33 | 'icate' => 'ic', 'ative' => '', 'alize' => 'al', 'iciti' => 'ic', 34 | 'ical' => 'ic', 'ful' => '', 'ness' => '' 35 | } 36 | 37 | PORTER_STEMS_RE = [] 38 | 39 | #PORTER_STEMS_RE[0] = Regexp.new('('+PORTER_STEMS[0].keys.join('|')+')', Regexp::EXTENDED) 40 | 41 | PORTER_STEMS_RE[0] = /( 42 | ational | 43 | tional | 44 | enci | 45 | anci | 46 | izer | 47 | bli | 48 | alli | 49 | entli | 50 | eli | 51 | ousli | 52 | ization | 53 | ation | 54 | ator | 55 | alism | 56 | iveness | 57 | fulness | 58 | ousness | 59 | aliti | 60 | iviti | 61 | biliti | 62 | logi)$/x 63 | 64 | #PORTER_STEMS_RE[1] = Regexp.new('('+PORTER_STEMS[1].keys.join('|')+')', Regexp::EXTENDED) 65 | 66 | PORTER_STEMS_RE[1] = /(icate|ative|alize|iciti|ical|ful|ness)$/ 67 | 68 | PORTER_STEMS_RE[2] = /( 69 | al | 70 | ance | 71 | ence | 72 | er | 73 | ic | 74 | able | 75 | ible | 76 | ant | 77 | ement | 78 | ment | 79 | ent | 80 | ou | 81 | ism | 82 | ate | 83 | iti | 84 | ous | 85 | ive | 86 | ize)$/x 87 | 88 | C = "[^aeiou]" # consonant 89 | V = "[aeiouy]" # vowel 90 | CC = "#{C}(?>[^aeiouy]*)" # consonant sequence 91 | VV = "#{V}(?>[aeiou]*)" # vowel sequence 92 | 93 | MGR0 = /^(#{CC})?#{VV}#{CC}/o # [cc]vvcc... is m>0 94 | MEQ1 = /^(#{CC})?#{VV}#{CC}(#{VV})?$/o # [cc]vvcc[vv] is m=1 95 | MGR1 = /^(#{CC})?#{VV}#{CC}#{VV}#{CC}/o # [cc]vvccvvcc... is m>1 96 | 97 | VOWEL_IN_STEM = /^(#{CC})?#{V}/o # vowel in stem 98 | 99 | # 100 | def self.stem(word) 101 | # make a copy of the given object and convert it to a string. 102 | word = word.dup.to_str 103 | 104 | return word if word.length < 3 105 | 106 | # now map initial y to Y so that the patterns never treat it as vowel 107 | word[0] = 'Y' if word[0] == ?y 108 | 109 | # Step 1a 110 | if word =~ /(ss|i)es$/ 111 | word = $` + $1 112 | elsif word =~ /([^s])s$/ 113 | word = $` + $1 114 | end 115 | 116 | # Step 1b 117 | if word =~ /eed$/ 118 | word.chop! if $` =~ MGR0 119 | elsif word =~ /(ed|ing)$/ 120 | stem = $` 121 | if stem =~ VOWEL_IN_STEM 122 | word = stem 123 | case word 124 | when /(at|bl|iz)$/ then word << "e" 125 | when /([^aeiouylsz])\1$/ then word.chop! 126 | when /^#{CC}#{V}[^aeiouwxy]$/o then word << "e" 127 | end 128 | end 129 | end 130 | 131 | if word =~ /y$/ 132 | stem = $` 133 | word = stem + "i" if stem =~ VOWEL_IN_STEM 134 | end 135 | 136 | # Step 2 137 | if word =~ PORTER_STEMS_RE[0] 138 | stem = $` 139 | suffix = $1 140 | # print "stem= " + stem + "\n" + "suffix=" + suffix + "\n" 141 | if stem =~ MGR0 142 | word = stem + PORTER_STEMS[0][suffix] 143 | end 144 | end 145 | 146 | # Step 3 147 | if word =~ PORTER_STEMS_RE[1] 148 | stem = $` 149 | suffix = $1 150 | if stem =~ MGR0 151 | word = stem + PORTER_STEMS[1][suffix] 152 | end 153 | end 154 | 155 | # Step 4 156 | if word =~ PORTER_STEMS_RE[2] 157 | stem = $` 158 | if stem =~ MGR1 159 | word = stem 160 | end 161 | elsif word =~ /(s|t)(ion)$/ 162 | stem = $` + $1 163 | if stem =~ MGR1 164 | word = stem 165 | end 166 | end 167 | 168 | # Step 5 169 | if word =~ /e$/ 170 | stem = $` 171 | if (stem =~ MGR1) || 172 | (stem =~ MEQ1 && stem !~ /^#{CC}#{V}[^aeiouwxy]$/o) 173 | word = stem 174 | end 175 | end 176 | 177 | if word =~ /ll$/ && word =~ MGR1 178 | word.chop! 179 | end 180 | 181 | # and turn initial Y back to y 182 | word[0] = 'y' if word[0] == ?Y 183 | 184 | word 185 | end 186 | 187 | end 188 | 189 | # Returns the word stem using the Porter Stemming algorithm by Martin Porter. 190 | def self.stem_porter(string) 191 | PorterStemmer.stem(string) 192 | end 193 | 194 | # Returns the word stem using the Porter Stemming algorithm by Martin Porter. 195 | def stem_porter 196 | self.class.stem_porter(@self) 197 | end 198 | 199 | end 200 | 201 | -------------------------------------------------------------------------------- /work/deprecated/stylize2.rb: -------------------------------------------------------------------------------- 1 | # 2 | # Examples 3 | # Stylist.snakecase("CamelCase") #=> "camel_case" 4 | 5 | module Stylist 6 | private *instance_methods.select{ |a| a !~ /^__|instace_|object_|send/ } 7 | 8 | extend self 9 | 10 | # Replaces underscores with dashes in the string. 11 | # 12 | # Example 13 | # "puni_puni" #=> "puni-puni" 14 | def dasherize(underscored_word) 15 | underscored_word.gsub(/_/, '-') 16 | end 17 | 18 | # By default, camelize converts strings to UpperCamelCase. If the argument to camelize 19 | # is set to ":lower" then camelize produces lowerCamelCase. 20 | # 21 | # camelize will also convert '/' to '::' which is useful for converting paths to namespaces 22 | # 23 | # Examples 24 | # "active_record".camelize #=> "ActiveRecord" 25 | # "active_record".camelize(:lower) #=> "activeRecord" 26 | # "active_record/errors".camelize #=> "ActiveRecord::Errors" 27 | # "active_record/errors".camelize(:lower) #=> "activeRecord::Errors" 28 | def camelize(lower_case_and_underscored_word, first_letter_in_uppercase = true) 29 | if first_letter_in_uppercase 30 | lower_case_and_underscored_word.to_s.gsub(/\/(.?)/) { "::#{$1.upcase}" }.gsub(/(?:^|_)(.)/) { $1.upcase } 31 | else 32 | lower_case_and_underscored_word.first + camelize(lower_case_and_underscored_word)[1..-1] 33 | end 34 | end 35 | 36 | # Capitalizes all the words and replaces some characters in the string to create 37 | # a nicer looking title. Titleize is meant for creating pretty output. It is not 38 | # used in the Rails internals. 39 | # 40 | # titleize is also aliased as as titlecase 41 | # 42 | # Examples 43 | # "man from the boondocks".titleize #=> "Man From The Boondocks" 44 | # "x-men: the last stand".titleize #=> "X Men: The Last Stand" 45 | def titleize(word) 46 | humanize(underscore(word)).gsub(/\b('?[a-z])/) { $1.capitalize } 47 | end 48 | 49 | # The reverse of +camelize+. Makes an underscored form from the expression in the string. 50 | # 51 | # Changes '::' to '/' to convert namespaces to paths. 52 | # 53 | # Examples 54 | # "ActiveRecord".underscore #=> "active_record" 55 | # "ActiveRecord::Errors".underscore #=> active_record/errors 56 | def snakecase(camel_cased_word) 57 | camel_cased_word.to_s.gsub(/::/, '/'). 58 | gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2'). 59 | gsub(/([a-z\d])([A-Z])/,'\1_\2'). 60 | tr("-", "_"). 61 | downcase 62 | end 63 | alias_method :underscore, :snakecase 64 | 65 | # Replaces underscores with dashes in the string. 66 | # 67 | # Example 68 | # "puni_puni" #=> "puni-puni" 69 | def dasherize(underscored_word) 70 | underscored_word.gsub(/_/, '-') 71 | end 72 | 73 | # Capitalizes the first word and turns underscores into spaces and strips _id. 74 | # Like titleize, this is meant for creating pretty output. 75 | # 76 | # Examples 77 | # "employee_salary" #=> "Employee salary" 78 | # "author_id" #=> "Author" 79 | def humanize(lower_case_and_underscored_word) 80 | lower_case_and_underscored_word.to_s.gsub(/_id$/, "").gsub(/_/, " ").capitalize 81 | end 82 | 83 | # Removes the module part from the expression in the string 84 | # 85 | # Examples 86 | # "ActiveRecord::CoreExtensions::String::Inflections".demodulize #=> "Inflections" 87 | # "Inflections".demodulize #=> "Inflections" 88 | def demodulize(class_name_in_module) 89 | class_name_in_module.to_s.gsub(/^.*::/, '') 90 | end 91 | 92 | # Create the name of a table like Rails does for models to table names. This method 93 | # uses the pluralize method on the last word in the string. 94 | # 95 | # Examples 96 | # "RawScaledScorer".tableize #=> "raw_scaled_scorers" 97 | # "egg_and_ham".tableize #=> "egg_and_hams" 98 | # "fancyCategory".tableize #=> "fancy_categories" 99 | def tableize(class_name) 100 | pluralize(underscore(class_name)) 101 | end 102 | 103 | # Create a class name from a plural table name like Rails does for table names to models. 104 | # Note that this returns a string and not a Class. (To convert to an actual class 105 | # follow classify with constantize.) 106 | # 107 | # Examples 108 | # "egg_and_hams".classify #=> "EggAndHam" 109 | # "posts".classify #=> "Post" 110 | # 111 | # Singular names are not handled correctly 112 | # "business".classify #=> "Busines" 113 | def classify(table_name) 114 | # strip out any leading schema name 115 | camelize(singularize(table_name.to_s.sub(/.*\./, ''))) 116 | end 117 | 118 | # Creates a foreign key name from a class name. 119 | # +separate_class_name_and_id_with_underscore+ sets whether 120 | # the method should put '_' between the name and 'id'. 121 | # 122 | # Examples 123 | # "Message".foreign_key #=> "message_id" 124 | # "Message".foreign_key(false) #=> "messageid" 125 | # "Admin::Post".foreign_key #=> "post_id" 126 | def foreign_key(class_name, separate_class_name_and_id_with_underscore = true) 127 | underscore(demodulize(class_name)) + (separate_class_name_and_id_with_underscore ? "_id" : "id") 128 | end 129 | 130 | # Converts a string into a unix path. 131 | # This method is geared toward code reflection. 132 | # 133 | # See : String#modulize, String#methodize 134 | # 135 | # "MyModule::MyClass".pathize #=> my_module/my_class 136 | # "my_module__my_class".pathize #=> my_module/my_class 137 | # 138 | # TODO: 139 | # * Make sure that all scenarios return a valid unix path 140 | # * Make sure it is revertible 141 | def pathize 142 | to_s.gsub(/([A-Z])/, '_\1').downcase.gsub(/^_/,'').gsub(/(::|__)_?/, '/') 143 | end 144 | 145 | # Converts a string into a valid ruby method name 146 | # This method is geared toward code reflection. 147 | # 148 | # "MyModule::MyClass".methodize #=> "my_module__my_class" 149 | # 150 | # See also String#modulize, String#pathize 151 | # 152 | # TODO: Make sure methodize is reversable (?) 153 | def methodize 154 | to_s.gsub(/([A-Z])/, '_\1').downcase.gsub(/^_/,'').gsub(/(::|\/)_?/, '__') 155 | end 156 | 157 | # Converts a string into a valid ruby class or module name 158 | # This method is geared toward code reflection. 159 | # 160 | # "my_module__my_path".modulize #=> "MyModule::MyPath" 161 | # 162 | # See also String#methodize, String#pathize 163 | # 164 | # 165 | # TODO: Make sure moduleize that all scenarios return a valid ruby class name 166 | def modulize 167 | to_s.gsub(/(__|\/)(.?)/){ "::" + $2.upcase }.gsub(/(^|_)(.)/){ $2.upcase } 168 | end 169 | 170 | end 171 | 172 | 173 | class Class 174 | 175 | # Translate a class name to a suitable method name. 176 | # 177 | # My::CoolClass.methodize => "my__cool_class" 178 | # 179 | def methodize 180 | name.gsub(/([A-Z]+)([A-Z])/,'\1_\2').gsub(/([a-z])([A-Z])/,'\1_\2').gsub('::','__').downcase 181 | end 182 | 183 | # Converts a class name to a unix path 184 | # 185 | # My::CoolClass.pathize #=> "/my/cool_class" 186 | # 187 | def pathize 188 | '/' + name.gsub(/([A-Z]+)([A-Z])/,'\1_\2').gsub(/([a-z])([A-Z])/,'\1_\2').gsub('::','/').downcase 189 | end 190 | 191 | end 192 | 193 | 194 | -------------------------------------------------------------------------------- /work/deprecated/case.rb: -------------------------------------------------------------------------------- 1 | warn "English::Case is being deprecated. Use Facets instead (except #namecase)." 2 | 3 | module English 4 | 5 | # = String Casing 6 | # 7 | # == WARNING: This is being deprecated! Use Facets instead. 8 | # 9 | # The Case mixin provides a means of case related alterations 10 | # to strings. 11 | # 12 | # This module is automatically mixed into the String class, but 13 | # the mixin is designed in such a way that it can be mixed into 14 | # any class that supports the #to_s method. 15 | # 16 | # Examples 17 | # 18 | # "SuperMan".snakecase #=> "super_man" 19 | # 20 | module Case 21 | 22 | # Standard downcase style. 23 | def downcase 24 | to_s.downcase 25 | end 26 | 27 | # Same as downcase style. 28 | def lowercase 29 | to_s.downcase 30 | end 31 | 32 | # Standard upcase style. 33 | def upcase 34 | to_s.upcase 35 | end 36 | 37 | # Same as upcase style. 38 | def uppercase 39 | to_s.upcase 40 | end 41 | 42 | # Standard capitialize style. 43 | # 44 | # NOTE: I hate this definition and think it 45 | # should be as capitalcase, but Matz 46 | # doesn't agree. 47 | def capitalize 48 | to_s.capitalize 49 | end 50 | 51 | # Upcase first letter. 52 | def capitalcase 53 | str = to_s 54 | str[0,1].upcase + str[1..-1] 55 | end 56 | 57 | # Downcase first letter. 58 | def uncapitalize 59 | str = to_s 60 | str[0,1].downcase + str[1..-1] 61 | end 62 | alias_method :uncapitalcase, :uncapitalize 63 | 64 | # Convert a phrase into a title. 65 | # 66 | # "this is a string".titlecase 67 | # => "This Is A String" 68 | # 69 | def titlecase 70 | to_s.gsub(/\b\w/){$&.upcase} 71 | end 72 | 73 | # The reverse of +camelize+. Converts a CamelCase word into an 74 | # underscored form. 75 | # 76 | # This also changes '::' to '/', usefule for converting namespaces 77 | # to pathnames. 78 | # 79 | # Examples 80 | # "ActiveRecord".underscore #=> "active_record" 81 | # "ActiveRecord::Errors".underscore #=> active_record/errors 82 | # 83 | def snakecase 84 | to_s. 85 | gsub(/::/, '/'). 86 | gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2'). 87 | gsub(/([a-z\d])([A-Z])/,'\1_\2'). 88 | tr("-", "_"). 89 | downcase 90 | end 91 | 92 | # By default, camelize converts strings to UpperCamelCase. 93 | # 94 | # camelize will also convert '/' to '::' which is useful for 95 | # converting paths to namespaces 96 | # 97 | # "active_record".camelcase #=> "ActiveRecord" 98 | # "active_record/errors".camelcase #=> "ActiveRecord::Errors" 99 | # 100 | def camelcase 101 | to_s.gsub(/\/(.?)/){ "::#{$1.upcase}" }.gsub(/(?:^|_)(.)/){ $1.upcase } 102 | end 103 | 104 | # Convert a snakecase phrase into a camelcase phrase, making 105 | # the first letter uppercase. 106 | #def upper_camelcase 107 | # to_s.gsub(/\/(.?)/){ "::#{$1.upcase}" }.gsub(/(?:^|_)(.)/){ $1.upcase } 108 | #end 109 | 110 | # Convert a snakecase phrase into a camelcase phrase, but making 111 | # the first letter lowercase. 112 | # 113 | # "active_record".camelcase #=> "activeRecord" 114 | # "active_record/errors".camelcase #=> "activeRecord::Errors" 115 | # 116 | def subcamelcase 117 | upper_camelcase.uncapitalize 118 | end 119 | 120 | # Returns a new +String+ with the contents properly namecased. 121 | #-- 122 | # Perl Version Copyright (c) Mark Summerfield 1998-2002 123 | # 124 | # 125 | # Ruby Version: 126 | # Copyright (c) Aaron Patterson 2006 127 | #++ 128 | def namecase 129 | localstring = downcase 130 | localstring.gsub!(/\b\w/) { |first| first.upcase } 131 | localstring.gsub!(/\'\w\b/) { |c| c.downcase } # Lowercase 's 132 | 133 | # Fixes for "Mac". 134 | if localstring =~ /\bMac[A-Za-z]{2,}[^aciozj]\b/ or localstring =~ /\bMc/ 135 | localstring.gsub!(/\b(Ma?c)([A-Za-z]+)/) { |match| $1 + $2.capitalize } 136 | localstring.gsub!(/\bMacEvicius/, 'Macevicius') 137 | localstring.gsub!(/\bMacHado/, 'Machado') 138 | localstring.gsub!(/\bMacHar/, 'Machar') 139 | localstring.gsub!(/\bMacHin/, 'Machin') 140 | localstring.gsub!(/\bMacHlin/, 'Machlin') 141 | localstring.gsub!(/\bMacIas/, 'Macias') 142 | localstring.gsub!(/\bMacIulis/, 'Maciulis') 143 | localstring.gsub!(/\bMacKie/, 'Mackie') 144 | localstring.gsub!(/\bMacKle/, 'Mackle') 145 | localstring.gsub!(/\bMacKlin/, 'Macklin') 146 | localstring.gsub!(/\bMacQuarie/, 'Macquarie') 147 | end 148 | localstring.gsub!('Macmurdo','MacMurdo') 149 | 150 | # Fixes for "son (daughter) of" etc. 151 | localstring.gsub!(/\bAl(?=\s+\w)/, 'al') # al Arabic or forename Al. 152 | localstring.gsub!(/\bAp\b/, 'ap') # ap Welsh. 153 | localstring.gsub!(/\bBen(?=\s+\w)/,'ben') # ben Hebrew or forename Ben. 154 | localstring.gsub!(/\bDell([ae])\b/,'dell\1') # della and delle Italian. 155 | localstring.gsub!(/\bD([aeiu])\b/,'d\1') # da, de, di Italian; du French. 156 | localstring.gsub!(/\bDe([lr])\b/,'de\1') # del Italian; der Dutch/Flemish. 157 | localstring.gsub!(/\bEl\b/,'el') # el Greek or El Spanish. 158 | localstring.gsub!(/\bLa\b/,'la') # la French or La Spanish. 159 | localstring.gsub!(/\bL([eo])\b/,'l\1') # lo Italian; le French. 160 | localstring.gsub!(/\bVan(?=\s+\w)/,'van') # van German or forename Van. 161 | localstring.gsub!(/\bVon\b/,'von') # von Dutch/Flemish 162 | 163 | # Fix roman numeral names 164 | localstring.gsub!( 165 | / \b ( (?: [Xx]{1,3} | [Xx][Ll] | [Ll][Xx]{0,3} )? 166 | (?: [Ii]{1,3} | [Ii][VvXx] | [Vv][Ii]{0,3} )? ) \b /x 167 | ) { |match| match.upcase } 168 | 169 | localstring 170 | end 171 | 172 | # TODO: Replace this will dynamic generate of inplace methods. 173 | # But only when the base defines #replace (?) Need to 174 | # think about this some more. 175 | module Replace 176 | def downcase! ; replace(downcase) ; end 177 | def lowercase! ; replace(lowercase) ; end 178 | def upcase! ; replace(upcase) ; end 179 | def uppercase! ; replace(uppercase) ; end 180 | def capitalize! ; replace(capitalize) ; end 181 | def capitalcase! ; replace(capitalcase) ; end 182 | def uncapitalcase! ; replace(uncapitalcase) ; end 183 | def titlecase! ; replace(titlecase) ; end 184 | def snakecase! ; replace(snakecase) ; end 185 | def camelcase! ; replace(camelcase) ; end 186 | def subcamelcase! ; replace(subcamelcase) ; end 187 | def namecase! ; replace(namecase) ; end 188 | end 189 | 190 | # Include Replace mixin if base class/module supports #replace method. 191 | def self.included(base) 192 | if base.instance_methods.include?('replace') or 193 | base.instance_methods.include?(:replace) # Ruby 1.9 194 | base.module_eval{ include Replace } 195 | end 196 | end 197 | 198 | end 199 | 200 | end 201 | 202 | class String #:nodoc: 203 | include English::Case 204 | end 205 | 206 | -------------------------------------------------------------------------------- /work/reference/grammer.bak/gramex01.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | English Grammar 8 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 |
21 | 22 | 23 | 24 | 25 |
26 |
Home | 27 | Table of Contents | Index 28 |
29 |
CHAPTER 1
30 |

31 | 32 |
33 | 34 |
EXERCISES for Chapter 1

35 | 36 | 37 | 1. Change the following pairs of words into sentences, using the 38 | correct forms of the Simple Present of the verb to be. For example:
39 |       I, cautious
40 |       I am cautious.
41 |
42 |       they, friendly
43 |       They are friendly.
44 |
45 | 1. you, careful
46 | 2. it, warm
47 | 3. he, here
48 | 4. we, bold
49 | 5. they, careless
50 | 6. she, clever
51 | 7. we, ready
52 | 8. you, reckless
53 | 9. I, shy
54 | 10. they, polite
55 | Answers 56 | 57 |
58 |
59 | 2. Change the affirmative statements resulting from Exercise 1 into 60 | questions. For example:
61 |       I am cautious.
62 |       Am I cautious?
63 |
64 |       They are friendly.
65 |       Are they friendly?
66 | Answers 67 | 68 |
69 |
70 | 3. Change the affirmative statements resulting from Exercise 1 into 71 | negative statements. For example:
72 |       I am cautious.
73 |       I am not cautious.
74 |
75 |       They are friendly.
76 |       They are not friendly.
77 | Answers 78 | 79 |
80 |
81 | 4. Change the affirmative statements resulting from Exercise 1 into 82 | negative questions. Except where the subject of the verb is I, write both the form without contractions and the form with contractions. For example:
83 |       I am cautious.
84 |       Am I not cautious?
85 |
86 |       They are friendly.
87 |       Are they not friendly?
88 |       Aren't they friendly?
89 | Answers 90 | 91 |
92 |
93 | 5. Add negative tag questions to the ends of the affirmative statements resulting from Exercise 1. Except where the subject of the verb is I, use contractions for the tag questions. For example:
94 |       I am cautious.
95 |       I am cautious, am I not?
96 |
97 |       They are friendly.
98 |       They are friendly, aren't they?
99 | Answers 100 | 101 |
102 |
103 | 6. Using the Simple Present of the verb to be, and making sure that the word order is correct, form the following groups of words into grammatically correct statements or questions. If the symbol ? is present, form the words into a question. If the word not is present, form the words into a negative statement or negative question. Do not use contractions in this exercise. For example:
104 |       it, brown
105 |       It is brown.
106 |
107 |       you, ?, excited
108 |       Are you excited?
109 |
110 |       I, satisfied, not
111 |       I am not satisfied.
112 |
113 |       not, ?, they, ready
114 |       Are they not ready?
115 |
116 | 1. you, ?, hungry
117 | 2. we, ?, not, correct
118 | 3. he, ?, happy
119 | 4. not, ?, it, cold
120 | 5. she, here
121 | 6. I, early, ?
122 | 7. they, wrong, not
123 | 8. you, ?, comfortable
124 | 9. they, ?, not, strong
125 | 10. not, ?, I, fortunate
126 | 11. it, slippery, ?
127 | 12. not, you, late
128 | 13. it, not, ?, important
129 | 14. we, famous
130 | 15. they, present, ?
131 | Answers
132 |
  133 |
134 | 135 |
136 | 137 |
ANSWERS TO THE EXERCISES for Chapter 1

138 | 139 | Answers to Exercise 1:
140 | 1. You are careful. 2. It is warm. 3. He is here. 4. We are 141 | bold. 5. They are careless. 6. She is clever. 7. We are ready. 142 | 8. You are reckless. 9. I am shy. 10. They are polite.
143 |
144 | 145 | Answers to Exercise 2:
146 | 1. Are you careful? 2. Is it warm? 3. Is he here? 4. Are we 147 | bold? 5. Are they careless? 6. Is she clever? 7. Are we ready? 148 | 8. Are you reckless? 9. Am I shy? 10. Are they polite?
149 |
150 | 151 | Answers to Exercise 3:
152 | 1. You are not careful. 2. It is not warm. 3. He is not here. 4. We are not bold. 5. They are not careless. 6. She is not clever. 7. We are not ready. 8. You are not reckless. 9. I am not shy. 10. They are not polite.
153 |
154 | 155 | Answers to Exercise 4:
156 | 1. Are you not careful? Aren't you careful? 2. Is it not warm? Isn't it warm? 3. Is he not here? Isn't he here? 4. Are we not bold? Aren't we bold? 5. Are they not careless? Aren't they careless? 157 | 6. Is she not clever? Isn't she clever? 7. Are we not ready? Aren't 158 | we ready? 8. Are you not reckless? Aren't you reckless? 9. Am I not 159 | shy? 10. Are they not polite? Aren't they polite?
160 |
161 | 162 | Answers to Exercise 5:
163 | 1. You are careful, aren't you? 2. It is warm, isn't it? 164 | 3. He is here, isn't he? 4. We are bold, aren't we? 5. They are 165 | careless, aren't they? 6. She is clever, isn't she? 7. We are ready, 166 | aren't we? 8. You are reckless, aren't you? 9. I am shy, am I not? 167 | 10. They are polite, aren't they?
168 |
169 | 170 | Answers to Exercise 6:
171 | 1. Are you hungry? 2. Are we not correct? 3. Is he happy? 172 | 4. Is it not cold? 5. She is here. 6. Am I early? 7. They are not 173 | wrong. 8. Are you comfortable? 9. Are they not strong? 10. Am I not 174 | fortunate? ii. Is it slippery? 12. You are not late. 13. Is it not 175 | important? 14. We are famous. 15. Are they present?
176 |
177 | 178 | 179 |
180 |
Home | 181 | Table of Contents | Index 182 |
183 |
Next Page
184 |

185 | 186 | 187 |

188 | 189 | 190 | 191 | 192 | -------------------------------------------------------------------------------- /site/grammar/gramex01.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | English Grammar 8 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 33 | 34 |
35 | 36 | 37 | 38 | 39 |

45 | 46 |
47 | 48 |
EXERCISES for Chapter 1

49 | 50 | 51 | 1. Change the following pairs of words into sentences, using the 52 | correct forms of the Simple Present of the verb to be. For example:
53 |       I, cautious
54 |       I am cautious.
55 |
56 |       they, friendly
57 |       They are friendly.
58 |
59 | 1. you, careful
60 | 2. it, warm
61 | 3. he, here
62 | 4. we, bold
63 | 5. they, careless
64 | 6. she, clever
65 | 7. we, ready
66 | 8. you, reckless
67 | 9. I, shy
68 | 10. they, polite
69 | Answers 70 | 71 |
72 |
73 | 2. Change the affirmative statements resulting from Exercise 1 into 74 | questions. For example:
75 |       I am cautious.
76 |       Am I cautious?
77 |
78 |       They are friendly.
79 |       Are they friendly?
80 | Answers 81 | 82 |
83 |
84 | 3. Change the affirmative statements resulting from Exercise 1 into 85 | negative statements. For example:
86 |       I am cautious.
87 |       I am not cautious.
88 |
89 |       They are friendly.
90 |       They are not friendly.
91 | Answers 92 | 93 |
94 |
95 | 4. Change the affirmative statements resulting from Exercise 1 into 96 | negative questions. Except where the subject of the verb is I, write both the form without contractions and the form with contractions. For example:
97 |       I am cautious.
98 |       Am I not cautious?
99 |
100 |       They are friendly.
101 |       Are they not friendly?
102 |       Aren't they friendly?
103 | Answers 104 | 105 |
106 |
107 | 5. Add negative tag questions to the ends of the affirmative statements resulting from Exercise 1. Except where the subject of the verb is I, use contractions for the tag questions. For example:
108 |       I am cautious.
109 |       I am cautious, am I not?
110 |
111 |       They are friendly.
112 |       They are friendly, aren't they?
113 | Answers 114 | 115 |
116 |
117 | 6. Using the Simple Present of the verb to be, and making sure that the word order is correct, form the following groups of words into grammatically correct statements or questions. If the symbol ? is present, form the words into a question. If the word not is present, form the words into a negative statement or negative question. Do not use contractions in this exercise. For example:
118 |       it, brown
119 |       It is brown.
120 |
121 |       you, ?, excited
122 |       Are you excited?
123 |
124 |       I, satisfied, not
125 |       I am not satisfied.
126 |
127 |       not, ?, they, ready
128 |       Are they not ready?
129 |
130 | 1. you, ?, hungry
131 | 2. we, ?, not, correct
132 | 3. he, ?, happy
133 | 4. not, ?, it, cold
134 | 5. she, here
135 | 6. I, early, ?
136 | 7. they, wrong, not
137 | 8. you, ?, comfortable
138 | 9. they, ?, not, strong
139 | 10. not, ?, I, fortunate
140 | 11. it, slippery, ?
141 | 12. not, you, late
142 | 13. it, not, ?, important
143 | 14. we, famous
144 | 15. they, present, ?
145 | Answers
146 |
  147 |
148 | 149 |
150 | 151 |
ANSWERS TO THE EXERCISES for Chapter 1

152 | 153 | Answers to Exercise 1:
154 | 1. You are careful. 2. It is warm. 3. He is here. 4. We are 155 | bold. 5. They are careless. 6. She is clever. 7. We are ready. 156 | 8. You are reckless. 9. I am shy. 10. They are polite.
157 |
158 | 159 | Answers to Exercise 2:
160 | 1. Are you careful? 2. Is it warm? 3. Is he here? 4. Are we 161 | bold? 5. Are they careless? 6. Is she clever? 7. Are we ready? 162 | 8. Are you reckless? 9. Am I shy? 10. Are they polite?
163 |
164 | 165 | Answers to Exercise 3:
166 | 1. You are not careful. 2. It is not warm. 3. He is not here. 4. We are not bold. 5. They are not careless. 6. She is not clever. 7. We are not ready. 8. You are not reckless. 9. I am not shy. 10. They are not polite.
167 |
168 | 169 | Answers to Exercise 4:
170 | 1. Are you not careful? Aren't you careful? 2. Is it not warm? Isn't it warm? 3. Is he not here? Isn't he here? 4. Are we not bold? Aren't we bold? 5. Are they not careless? Aren't they careless? 171 | 6. Is she not clever? Isn't she clever? 7. Are we not ready? Aren't 172 | we ready? 8. Are you not reckless? Aren't you reckless? 9. Am I not 173 | shy? 10. Are they not polite? Aren't they polite?
174 |
175 | 176 | Answers to Exercise 5:
177 | 1. You are careful, aren't you? 2. It is warm, isn't it? 178 | 3. He is here, isn't he? 4. We are bold, aren't we? 5. They are 179 | careless, aren't they? 6. She is clever, isn't she? 7. We are ready, 180 | aren't we? 8. You are reckless, aren't you? 9. I am shy, am I not? 181 | 10. They are polite, aren't they?
182 |
183 | 184 | Answers to Exercise 6:
185 | 1. Are you hungry? 2. Are we not correct? 3. Is he happy? 186 | 4. Is it not cold? 5. She is here. 6. Am I early? 7. They are not 187 | wrong. 8. Are you comfortable? 9. Are they not strong? 10. Am I not 188 | fortunate? ii. Is it slippery? 12. You are not late. 13. Is it not 189 | important? 14. We are famous. 15. Are they present?
190 |
191 | 192 | 193 |

199 | 200 | 201 |

202 | 203 | 204 | 205 | 206 | -------------------------------------------------------------------------------- /work/reference/grammer.bak/gramex14.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | English Grammar 8 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 |
21 | 22 | 23 | 24 | 25 |
26 |
Home | 27 | Table of Contents | Index 28 |
29 |
CHAPTER 14
30 |

31 | 32 |
33 | 34 |
EXERCISES for Chapter 14

35 | 36 | 37 | 1. Rewrite each of the following sentences, changing the subject of the verb to the singular, inserting a or an before the subject, as appropriate, and changing the verb to agree with the subject. For example:
38 |       Violins are difficult to play.
39 |       A violin is difficult to play.
40 |
41 |       Unions have been formed.
42 |       A union has been formed.
43 |
44 |       Answers are always provided.
45 |       An answer is always provided.
46 |
47 |       Heirs have many friends.
48 |       An heir has many friends.
49 |
50 | 1. Avocados are expensive.
51 | 2. Windows are an important feature of an artist's studio.
52 | 3. Umbrellas should not be used during a thunderstorm.
53 | 4. Horses can be useful in the mountains.
54 | 5. Cashews are a type of nut.
55 | 6. Onions can be used for flavoring soup.
56 | 7. Trucks have many uses.
57 | 8. Hours passed.
58 | 9. Sentences should have proper punctuation.
59 | 10. Escalators are very convenient.
60 | 11. Uniforms must be worn.
61 | 12. Boxes were found on the floor.
62 | 13. Marshes lie beyond the city boundary.
63 | 14. Ideas can be valuable.
64 | 15. Eggs are a good source of protein.
65 | Answers 66 | 67 |
68 |
69 | 2. Fill in each blank with either the indefinite article (a or an) or the definite article (the). Use a or an with nouns referring to people or things which have not been mentioned previously, and use the with nouns referring to people or things which have been mentioned 70 | previously.
71 |
72 | I had never visited Seretnay Park before. Last week I went to ____ park and chose ____ tour to take. There were twenty tourists and one guide. ____ guide asked what we wanted to see. I said I had never seen ____ eagle, and I would like to see one. ____ child on ____ tour said he would like to see ____ beaver, since he had heard there were many in ____ park. ____ guide said he would do his best. First he led us along ____ road, and then we turned off onto ____ path. To our right was ____ marshy pond.
73 |
74 | Suddenly ____ child who had spoken before shouted, "Look! I see ____ beaver!" Of course ____ beaver was startled. It slapped its tail and disappeared into pond.
75 |
76 | Our guide pointed to ____ pile of sticks and said, "That's where ____ 77 | beaver lives. That's his house." I had my camera with me, and took ____ photograph of ____ house.
78 |
79 | As we were standing there, ____ guide was looking across ____ pond 80 | through ____ small telescope. After a minute, he tapped my shoulder and handed me ____ telescope. He pointed to ____ tall tree and said, "Do you see that white speck? That's ____ bald eagle."
81 |
82 | I had difficulty focusing ____ telescope, but finally I saw ____ eagle. As I watched, ____ eagle spread its wings and soared over the water.
83 |
84 | It was ____ wonderful experience for me to see some of the wild 85 | creatures that live in ____ park.
86 | Answers 87 | 88 |
89 |
90 | 3. Fill in each blank with a, an or the. Be prepared to justify your choice. For example:
91 |       ___ moon is full tonight.
92 |       The moon is full tonight.
93 |
94 |       He is ___ singer.
95 |       He is a singer.
96 |
97 |       Please sit in ___ center of the boat.
98 |       Please sit in the center of the boat.
99 |
100 |       The room costs twenty dollars ___ day.
101 |       The room costs twenty dollars a day.
102 |
103 |       ___ wheel is considered one of mankind's most important inventions.
104 |       The wheel is considered one of mankind's most important inventions.
105 |
106 | 1. His aunt is ____ teacher.
107 | 2. ____ architect is trained in design, drafting, and economics.
108 | 3. ____ ostrich is the world's largest bird.
109 | 4. Buses pass this point two or three times ____ hour.
110 | 5. Plants gain energy from the light of ____ sun.
111 | 6. I woke up in ____ middle of the night.
112 | 7. She is ____ doctor.
113 | 8. ____ seal is an excellent swimmer.
114 | 9. Our eyes usually blink several times ____ minute.
115 | 10. At ____ equator, sunrise occurs at the same time each day.
116 | 11. He is ____ author.
117 | 12. They wanted to hear ____ end of the story.
118 | 13. Such a severe storm occurs only once ____ decade.
119 | 14. Mount Everest is tallest mountain in ____ world.
120 | 15. There is an index at ____ back of the book.
121 | Answers 122 |
123 | 124 |  
125 |
126 | 127 |
ANSWERS TO THE EXERCISES for Chapter 14

128 | 129 | Answers to Exercise 1:
130 | 1. An avocado is 2. A window is 3. An umbrella should not be used 131 | 4. A horse can be 5. A cashew is 6. An onion can be used 7. A truck has 8. An hour passed 9. A sentence should have 10. An escalator is 132 | 11. A uniform must be worn 12. A box was found 13. A marsh lies 133 | 14. An idea can be 15. An egg is
134 |
135 | 136 | Answers to Exercise 2:
137 | the park, a tour. The guide. an eagle. A child, the tour, a beaver, 138 | the park. The guide. a road, a path, a marshy pond. 139 | the child, a beaver. the beaver. the pond. 140 | a pile, the beaver. a photograph, the house. 141 | the guide, the pond, a small telescope. the telescope. a tall tree. 142 | a bald eagle. 143 | the telescope, the eagle. the eagle. 144 | a wonderful experience, the park.
145 |
146 | 147 | Answers to Exercise 3:
148 | 1. a [profession] 2. An [general statement] 3. The [considered 149 | as a class] 4. an [per] 5. the [obvious what is meant] 6. the [unique] 150 | 7. a [profession] 8. A [general statement] 9. a [per] 10. the [unique] 151 | 11. an [profession] 12. the [unique] 13. a [per] 14. the [unique], 152 | the [obvious what is meant] 15. the [unique]
153 |
154 | 155 | 156 |
157 |
Home | 158 | Table of Contents | Index 159 |
160 |
Next Page
161 |

162 | 163 | 164 |

165 | 166 | 167 | 168 | 169 | -------------------------------------------------------------------------------- /site/grammar/gramex14.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | English Grammar 8 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 33 | 34 |
35 | 36 | 37 | 38 | 39 |

45 | 46 |
47 | 48 |
EXERCISES for Chapter 14

49 | 50 | 51 | 1. Rewrite each of the following sentences, changing the subject of the verb to the singular, inserting a or an before the subject, as appropriate, and changing the verb to agree with the subject. For example:
52 |       Violins are difficult to play.
53 |       A violin is difficult to play.
54 |
55 |       Unions have been formed.
56 |       A union has been formed.
57 |
58 |       Answers are always provided.
59 |       An answer is always provided.
60 |
61 |       Heirs have many friends.
62 |       An heir has many friends.
63 |
64 | 1. Avocados are expensive.
65 | 2. Windows are an important feature of an artist's studio.
66 | 3. Umbrellas should not be used during a thunderstorm.
67 | 4. Horses can be useful in the mountains.
68 | 5. Cashews are a type of nut.
69 | 6. Onions can be used for flavoring soup.
70 | 7. Trucks have many uses.
71 | 8. Hours passed.
72 | 9. Sentences should have proper punctuation.
73 | 10. Escalators are very convenient.
74 | 11. Uniforms must be worn.
75 | 12. Boxes were found on the floor.
76 | 13. Marshes lie beyond the city boundary.
77 | 14. Ideas can be valuable.
78 | 15. Eggs are a good source of protein.
79 | Answers 80 | 81 |
82 |
83 | 2. Fill in each blank with either the indefinite article (a or an) or the definite article (the). Use a or an with nouns referring to people or things which have not been mentioned previously, and use the with nouns referring to people or things which have been mentioned 84 | previously.
85 |
86 | I had never visited Seretnay Park before. Last week I went to ____ park and chose ____ tour to take. There were twenty tourists and one guide. ____ guide asked what we wanted to see. I said I had never seen ____ eagle, and I would like to see one. ____ child on ____ tour said he would like to see ____ beaver, since he had heard there were many in ____ park. ____ guide said he would do his best. First he led us along ____ road, and then we turned off onto ____ path. To our right was ____ marshy pond.
87 |
88 | Suddenly ____ child who had spoken before shouted, "Look! I see ____ beaver!" Of course ____ beaver was startled. It slapped its tail and disappeared into pond.
89 |
90 | Our guide pointed to ____ pile of sticks and said, "That's where ____ 91 | beaver lives. That's his house." I had my camera with me, and took ____ photograph of ____ house.
92 |
93 | As we were standing there, ____ guide was looking across ____ pond 94 | through ____ small telescope. After a minute, he tapped my shoulder and handed me ____ telescope. He pointed to ____ tall tree and said, "Do you see that white speck? That's ____ bald eagle."
95 |
96 | I had difficulty focusing ____ telescope, but finally I saw ____ eagle. As I watched, ____ eagle spread its wings and soared over the water.
97 |
98 | It was ____ wonderful experience for me to see some of the wild 99 | creatures that live in ____ park.
100 | Answers 101 | 102 |
103 |
104 | 3. Fill in each blank with a, an or the. Be prepared to justify your choice. For example:
105 |       ___ moon is full tonight.
106 |       The moon is full tonight.
107 |
108 |       He is ___ singer.
109 |       He is a singer.
110 |
111 |       Please sit in ___ center of the boat.
112 |       Please sit in the center of the boat.
113 |
114 |       The room costs twenty dollars ___ day.
115 |       The room costs twenty dollars a day.
116 |
117 |       ___ wheel is considered one of mankind's most important inventions.
118 |       The wheel is considered one of mankind's most important inventions.
119 |
120 | 1. His aunt is ____ teacher.
121 | 2. ____ architect is trained in design, drafting, and economics.
122 | 3. ____ ostrich is the world's largest bird.
123 | 4. Buses pass this point two or three times ____ hour.
124 | 5. Plants gain energy from the light of ____ sun.
125 | 6. I woke up in ____ middle of the night.
126 | 7. She is ____ doctor.
127 | 8. ____ seal is an excellent swimmer.
128 | 9. Our eyes usually blink several times ____ minute.
129 | 10. At ____ equator, sunrise occurs at the same time each day.
130 | 11. He is ____ author.
131 | 12. They wanted to hear ____ end of the story.
132 | 13. Such a severe storm occurs only once ____ decade.
133 | 14. Mount Everest is tallest mountain in ____ world.
134 | 15. There is an index at ____ back of the book.
135 | Answers 136 |
137 | 138 |  
139 |
140 | 141 |
ANSWERS TO THE EXERCISES for Chapter 14

142 | 143 | Answers to Exercise 1:
144 | 1. An avocado is 2. A window is 3. An umbrella should not be used 145 | 4. A horse can be 5. A cashew is 6. An onion can be used 7. A truck has 8. An hour passed 9. A sentence should have 10. An escalator is 146 | 11. A uniform must be worn 12. A box was found 13. A marsh lies 147 | 14. An idea can be 15. An egg is
148 |
149 | 150 | Answers to Exercise 2:
151 | the park, a tour. The guide. an eagle. A child, the tour, a beaver, 152 | the park. The guide. a road, a path, a marshy pond. 153 | the child, a beaver. the beaver. the pond. 154 | a pile, the beaver. a photograph, the house. 155 | the guide, the pond, a small telescope. the telescope. a tall tree. 156 | a bald eagle. 157 | the telescope, the eagle. the eagle. 158 | a wonderful experience, the park.
159 |
160 | 161 | Answers to Exercise 3:
162 | 1. a [profession] 2. An [general statement] 3. The [considered 163 | as a class] 4. an [per] 5. the [obvious what is meant] 6. the [unique] 164 | 7. a [profession] 8. A [general statement] 9. a [per] 10. the [unique] 165 | 11. an [profession] 12. the [unique] 13. a [per] 14. the [unique], 166 | the [obvious what is meant] 15. the [unique]
167 |
168 | 169 | 170 |

176 | 177 | 178 |

179 | 180 | 181 | 182 | 183 | -------------------------------------------------------------------------------- /lib/english/inflect.rb: -------------------------------------------------------------------------------- 1 | require 'english/class' 2 | 3 | class English 4 | 5 | # = Noun Number Inflections 6 | # 7 | # This module provides english singular <-> plural noun inflections. 8 | module Inflect 9 | 10 | @singular_of = {} 11 | @plural_of = {} 12 | 13 | @singular_rules = [] 14 | @plural_rules = [] 15 | 16 | # This class provides the DSL for creating inflections, you can add additional rules. 17 | # Examples: 18 | # 19 | # word "ox", "oxen" 20 | # word "octopus", "octopi" 21 | # word "man", "men" 22 | # 23 | # rule "lf", "lves" 24 | # 25 | # word "equipment" 26 | # 27 | # Rules are evaluated by size, so rules you add to override specific cases should be longer than the rule 28 | # it overrides. For instance, if you want "pta" to pluralize to "ptas", even though a general purpose rule 29 | # for "ta" => "tum" already exists, simply add a new rule for "pta" => "ptas", and it will automatically win 30 | # since it is longer than the old rule. 31 | # 32 | # Also, single-word exceptions win over general words ("ox" pluralizes to "oxen", because it's a single word 33 | # exception, even though "fox" pluralizes to "foxes") 34 | class << self 35 | # Define a general two-way exception. 36 | # 37 | # This also defines a general rule, so foo_child will correctly become 38 | # foo_children. 39 | # 40 | # Whole words also work if they are capitalized (Goose => Geese). 41 | def word(singular, plural=nil) 42 | plural = singular unless plural 43 | singular_word(singular, plural) 44 | plural_word(singular, plural) 45 | rule(singular, plural) 46 | end 47 | 48 | # Define a singularization exception. 49 | def singular_word(singular, plural) 50 | @singular_of[plural] = singular 51 | @singular_of[plural.capitalize] = singular.capitalize 52 | end 53 | 54 | # Define a pluralization exception. 55 | def plural_word(singular, plural) 56 | @plural_of[singular] = plural 57 | @plural_of[singular.capitalize] = plural.capitalize 58 | end 59 | 60 | # Define a general rule. 61 | def rule(singular, plural) 62 | singular_rule(singular, plural) 63 | plural_rule(singular, plural) 64 | end 65 | 66 | # Define a singularization rule. 67 | def singular_rule(singular, plural) 68 | @singular_rules << [singular, plural] 69 | end 70 | 71 | # Define a plurualization rule. 72 | def plural_rule(singular, plural) 73 | @plural_rules << [singular, plural] 74 | end 75 | 76 | # Read prepared singularization rules. 77 | def singularization_rules 78 | if defined?(@singularization_regex) && @singularization_regex 79 | return [@singularization_regex, @singularization_hash] 80 | end 81 | # No sorting needed: Regexen match on longest string 82 | @singularization_regex = Regexp.new("(" + @singular_rules.map {|s,p| p}.join("|") + ")$", "i") 83 | @singularization_hash = Hash[*@singular_rules.flatten].invert 84 | [@singularization_regex, @singularization_hash] 85 | end 86 | 87 | # Read prepared singularization rules. 88 | #def singularization_rules 89 | # return @singularization_rules if @singularization_rules 90 | # sorted = @singular_rules.sort_by{ |s, p| "#{p}".size }.reverse 91 | # @singularization_rules = sorted.collect do |s, p| 92 | # [ /#{p}$/, "#{s}" ] 93 | # end 94 | #end 95 | 96 | # Read prepared pluralization rules. 97 | def pluralization_rules 98 | if defined?(@pluralization_regex) && @pluralization_regex 99 | return [@pluralization_regex, @pluralization_hash] 100 | end 101 | @pluralization_regex = Regexp.new("(" + @plural_rules.map {|s,p| s}.join("|") + ")$", "i") 102 | @pluralization_hash = Hash[*@plural_rules.flatten] 103 | [@pluralization_regex, @pluralization_hash] 104 | end 105 | 106 | # Read prepared pluralization rules. 107 | #def pluralization_rules 108 | # return @pluralization_rules if @pluralization_rules 109 | # sorted = @plural_rules.sort_by{ |s, p| "#{s}".size }.reverse 110 | # @pluralization_rules = sorted.collect do |s, p| 111 | # [ /#{s}$/, "#{p}" ] 112 | # end 113 | #end 114 | 115 | # 116 | def singular_of ; @singular_of ; end 117 | 118 | # 119 | def plural_of ; @plural_of ; end 120 | 121 | # Convert an English word from plurel to singular. 122 | # 123 | # "boys".singular #=> boy 124 | # "tomatoes".singular #=> tomato 125 | # 126 | def singular(word) 127 | return "" if word == "" 128 | if result = singular_of[word] 129 | return result.dup 130 | end 131 | result = word.dup 132 | 133 | regex, hash = singularization_rules 134 | result.sub!(regex) {|m| hash[m]} 135 | singular_of[word] = result 136 | return result 137 | #singularization_rules.each do |(match, replacement)| 138 | # break if result.gsub!(match, replacement) 139 | #end 140 | #return result 141 | end 142 | 143 | # Alias for #singular (a Railism). 144 | # 145 | alias_method(:singularize, :singular) 146 | 147 | # Convert an English word from singular to plurel. 148 | # 149 | # "boy".plural #=> boys 150 | # "tomato".plural #=> tomatoes 151 | # 152 | def plural(word) 153 | return "" if word == "" 154 | if result = plural_of[word] 155 | return result.dup 156 | end 157 | #return self.dup if /s$/ =~ self # ??? 158 | result = word.dup 159 | 160 | regex, hash = pluralization_rules 161 | result.sub!(regex) {|m| hash[m]} 162 | plural_of[word] = result 163 | return result 164 | #pluralization_rules.each do |(match, replacement)| 165 | # break if result.gsub!(match, replacement) 166 | #end 167 | #return result 168 | end 169 | 170 | # Alias for #plural (a Railism). 171 | alias_method(:pluralize, :plural) 172 | 173 | # Clear all rules. 174 | def clear(type = :all) 175 | if type == :singular || type == :all 176 | @singular_of = {} 177 | @singular_rules = [] 178 | @singularization_rules, @singularization_regex = nil, nil 179 | end 180 | if type == :plural || type == :all 181 | @singular_of = {} 182 | @singular_rules = [] 183 | @singularization_rules, @singularization_regex = nil, nil 184 | end 185 | end 186 | end 187 | 188 | # One argument means singular and plural are the same. 189 | 190 | word 'equipment' 191 | word 'information' 192 | word 'money' 193 | word 'species' 194 | word 'series' 195 | word 'fish' 196 | word 'sheep' 197 | word 'moose' 198 | word 'hovercraft' 199 | word 'news' 200 | word 'rice' 201 | word 'plurals' 202 | 203 | # Two arguments defines a singular and plural exception. 204 | 205 | word 'Swiss' , 'Swiss' 206 | word 'alias' , 'aliases' 207 | word 'analysis' , 'analyses' 208 | #word 'axis' , 'axes' 209 | word 'basis' , 'bases' 210 | word 'buffalo' , 'buffaloes' 211 | word 'child' , 'children' 212 | #word 'cow' , 'kine' 213 | word 'crisis' , 'crises' 214 | word 'criterion' , 'criteria' 215 | word 'datum' , 'data' 216 | word 'goose' , 'geese' 217 | word 'hive' , 'hives' 218 | word 'index' , 'indices' 219 | word 'life' , 'lives' 220 | word 'louse' , 'lice' 221 | word 'man' , 'men' 222 | word 'matrix' , 'matrices' 223 | word 'medium' , 'media' 224 | word 'mouse' , 'mice' 225 | word 'movie' , 'movies' 226 | word 'octopus' , 'octopi' 227 | word 'ox' , 'oxen' 228 | word 'person' , 'people' 229 | word 'potato' , 'potatoes' 230 | word 'quiz' , 'quizzes' 231 | word 'shoe' , 'shoes' 232 | word 'status' , 'statuses' 233 | word 'testis' , 'testes' 234 | word 'thesis' , 'theses' 235 | word 'thief' , 'thieves' 236 | word 'tomato' , 'tomatoes' 237 | word 'torpedo' , 'torpedoes' 238 | word 'vertex' , 'vertices' 239 | word 'virus' , 'viri' 240 | word 'wife' , 'wives' 241 | 242 | # One-way singularization exception (convert plural to singular). 243 | 244 | singular_word 'cactus', 'cacti' 245 | 246 | # One-way pluralizaton exception (convert singular to plural). 247 | 248 | plural_word 'axis', 'axes' 249 | 250 | # General rules. 251 | 252 | rule 'rf' , 'rves' 253 | rule 'ero' , 'eroes' 254 | rule 'ch' , 'ches' 255 | rule 'sh' , 'shes' 256 | rule 'ss' , 'sses' 257 | #rule 'ess' , 'esses' 258 | rule 'ta' , 'tum' 259 | rule 'ia' , 'ium' 260 | rule 'ra' , 'rum' 261 | rule 'ay' , 'ays' 262 | rule 'ey' , 'eys' 263 | rule 'oy' , 'oys' 264 | rule 'uy' , 'uys' 265 | rule 'y' , 'ies' 266 | rule 'x' , 'xes' 267 | rule 'lf' , 'lves' 268 | rule 'ffe' , 'ffes' 269 | rule 'af' , 'aves' 270 | rule 'us' , 'uses' 271 | rule 'ouse' , 'ouses' 272 | rule 'osis' , 'oses' 273 | rule 'ox' , 'oxes' 274 | rule '' , 's' 275 | 276 | # One-way singular rules. 277 | 278 | singular_rule 'of' , 'ofs' # proof 279 | singular_rule 'o' , 'oes' # hero, heroes 280 | #singular_rule 'f' , 'ves' 281 | 282 | # One-way plural rules. 283 | 284 | plural_rule 's' , 'ses' 285 | plural_rule 'ive' , 'ives' # don't want to snag wife 286 | plural_rule 'fe' , 'ves' # don't want to snag perspectives 287 | end 288 | 289 | # 290 | def self.singular(string) 291 | English::Inflect.singular(string) 292 | end 293 | 294 | # 295 | def self.plural(string) 296 | English::Inflect.plural(string) 297 | end 298 | 299 | # Convert an English word from plurel to singular. 300 | # 301 | # "boys".singular #=> boy 302 | # "tomatoes".singular #=> tomato 303 | # 304 | def singular 305 | self.class.singular(@self) 306 | end 307 | 308 | # Alias for #singular. 309 | alias_method(:singularize, :singular) 310 | 311 | # Convert an English word from plurel to singular. 312 | # 313 | # "boys".singular #=> boy 314 | # "tomatoes".singular #=> tomato 315 | # 316 | def plural 317 | self.class.plural(@self) 318 | end 319 | 320 | # Alias for #plural. 321 | alias_method(:pluralize, :plural) 322 | 323 | end 324 | 325 | -------------------------------------------------------------------------------- /work/reference/grammer.bak/gramex16.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | English Grammar 8 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 |
21 | 22 | 23 | 24 | 25 |
26 |
Home | 27 | Table of Contents | Index 28 |
29 |
CHAPTER 16
30 |

31 | 32 |
33 | 34 |
EXERCISES for Chapter 16

35 | 36 | 37 | 1. For the following sentences, fill in the blanks with a or an or leave the blanks empty, as appropriate. Fill in the blanks with a or an before countable nouns, and leave them empty before uncountable nouns. For example:
38 |       __ bird is singing outside the window.
39 |       A bird is singing outside the window.
40 |
41 |       ___ copper is used in making electrical wiring.
42 |       Copper is used in making electrical wiring.
43 |
44 | 1. ___ air is made up of elements such as ___ oxygen and ___ nitrogen.
45 | 2. ___ book is lying on the floor.
46 | 3. ___ Russian is a difficult language.
47 | 4. ___ onion is ___ vegetable.
48 | 5. ___ butter and ___ cream are made from ___ milk.
49 | 6. ___ letter has been delivered to the wrong house.
50 | 7. ___ child is playing on the sidewalk.
51 | 8. ___ asbestos is a fireproof material.
52 | 9. ___ tree is growing outside the house.
53 | 10. ___ curiosity is considered a sign of ___ intelligence.
54 | 11. They want to buy ___ camera.
55 | 12. ___ egg was added to the soup.
56 | 13. ___ rain is expected this evening.
57 | 14. The farmers wished for ___ peace and ___ prosperity.
58 | 15. ___ bicycle is parked in front of the store.
59 | Answers 60 | 61 |
62 |
63 | 2. Paying attention to whether the nouns in the following paragraphs 64 | are countable or uncountable, and to whether or not the nouns refer to things which have been mentioned before, fill in the blanks with a or the, or leave the blanks empty, as appropriate.
65 |
66 | Phil Jones was ____ prospector, who was looking for ____ gold. He had 67 | to travel a long way, crossing ___ mountains and ____ streams to reach his destination.
68 |
69 | Previously, he had been ____ miner and had mined ___ copper and ___ coal. But ____ copper had given out, and mining ____ coal was dangerous work. When he had heard about ___ gold in ____ mountains, Phil had left his job and traveled west. He knew he would need ___ courage and ___ determination to reach his goal.
70 |
71 | One evening he camped beside ___ stream. When he tested ____ stream, 72 | he found there was a small amount of glittering gold dust in it. As 73 | usual, Phil made ___ fire to prepare his evening meal. He took ____ 74 | ___ flour and ___ salt from his knapsack, and got ___ water from ____ 75 | stream. Then he mixed ___ salt with ___ flour, and gradually added 76 | ___ water, to make ___ pancakes over ___ fire.
77 |
78 | As ___ fire died away, Phil looked up and down ___ stream. Expecting 79 | to see only ___ darkness, to his surprise, he saw ____ lights from many small fires. He knew they must be ____ fires of other prospectors. "I've reached end of my journey", he thought. Now he was in the goldfields, and with ___ luck, he would find ___ gold he had come to seek.
80 | Answers 81 | 82 |
83 |
84 | 3. For each of the following sentences, change the word one to two, put the subject of the verb into the plural, and make sure that the verb agrees with its subject. For example:
85 |       One bar of soap will be provided.
86 |       Two bars of soap will be provided.
87 |
88 |       One bag of flour is on the counter.
89 |       Two bags of flour are on the counter.
90 |
91 | 1. One piece of luggage is allowed per passenger.
92 | 2. One bottle of water is enough.
93 | 3. One jar of honey is larger than the others.
94 | 4. One piece of furniture will be delivered.
95 | 5. One grain of rice has fallen onto the table.
96 | 6. One bucket of sand was needed to build the sand castle.
97 | 7. One cup of sugar should be mixed with the flour.
98 | 8. One game of chess will be played at four o'clock.
99 | Answers 100 | 101 |
102 |
103 | 4. Fill in each blank with a or an if the noun following the blank is used as a countable noun, or leave the blank empty if the noun following the blank is used as an uncountable noun. For example:
104 |       The bowl is made of ___ glass.
105 |       The bowl is made of glass.
106 |
107 |       Would you like __ glass of water?
108 |       Would you like a glass of water?
109 |
110 | 1. The sun gives off ___ heat and ___ light.
111 | 2. There is ___ light suspended from the ceiling.
112 | 3. She will buy ___ paper to find out what movies are being shown.
113 | 4. ___ paper can be made from ___ wood or ___ cloth.
114 | 5. She has a keen sense of ___ honor.
115 | 6. It is ___ honor to be invited to speak.
116 | 7. There is ___ bed near the window.
117 | 8. He has gone to ____ bed early because he is tired.
118 | 9. ___ iron used in making ___ steel.
119 | 10. If I had ___ iron, I would press my new suit.
120 | 11. They always eat ___ lunch at twelve o'clock.
121 | 12. We will pack you ____ lunch to take with you.
122 | Answers 123 | 124 |
125 |
126 | 5. Paying attention to which verbs can be followed by an infinitive and which can be followed by a gerund, for each sentence, fill in the blank with the infinitive or gerund of the verb shown in brackets. For example:
127 |       Please stop _____ that! (to do)
128 |       Please stop doing that!
129 |
130 |       He has decided _______ a holiday. (to take)
131 |       He has decided to take a holiday.
132 |
133 | 1. Has he finished __________ the report? (to read)
134 | 2. We plan __________ the concert. (to attend)
135 | 3. They will discuss __________ a club. (to organize)
136 | 4. She offered _________ the letter. (to write)
137 | 5. They asked __________ us. (to accompany)
138 | 6. You should practise __________ the speech. (to give)
139 | 7. I would suggest __________ the work by next week. (to finish)
140 | 8. He has not dared __________ you. (to contradict)
141 | 9. They delayed _________ us. (to call)
142 | 10. She deserves ___________. (to succeed)
143 | 11. We forgot _________ the letter. (to mail)
144 | 12. He enjoys __________. (to ski)
145 | 13. They would not risk _________ the bus. (to miss)
146 | 14. Do you want __________ the book? (to borrow)
147 | 15. I don't mind _________. (to wait)
148 | 16. Her daughter is learning __________ a bicycle. (to ride)
149 | 17. It has stopped __________. (to snow)
150 | 18. He is preparing __________ a business. (to open)
151 | 19. They hesitated __________ the invitation. (to accept)
152 | 20. I miss __________ from them. (to hear)
153 | Answers 154 |
155 | 156 |  
157 |
158 | 159 |
ANSWERS TO THE EXERCISES for Chapter 16

160 | 161 | Answers to Exercise 1:
162 | 1. __ Air, __ oxygen, __ nitrogen 2. A book 3. __ Russian 163 | 4. An onion, a vegetable 5. __ Butter, __ cream, __ milk 6. A letter 164 | 7. A child 8. __ Asbestos 9. A tree 10. __ Curiosity, __ intelligence 165 | 11. a camera 12. An egg 13. __ Rain 14. __ peace, __ prosperity 15. A bicycle
166 |
167 | 168 | Answers to Exercise 2:
169 | a prospector, __ gold. __ mountains, __ streams. 170 | a miner, __ copper, __ coal. the copper, the coal. the gold, 171 | the mountains, __ courage, __ determination. 172 | a stream. the stream. a fire. __ flour, __ salt, __ water, the stream. the salt, the flour the water, __ pancakes, the fire. 173 | the fire, the stream. __ darkness, __ lights. 174 | the fires. the end. __ luck, the gold.
175 |
176 | 177 | Answers to Exercise 3:
178 | 1. Two pieces of luggage are allowed 2. Two bottles of water are 179 | 3. Two jars of honey are 4. Two pieces of furniture will be delivered. 180 | 5. Two grains of rice have fallen 6. Two buckets of wand were needed 181 | 7. Two cups of sugar should be mixed 9. Two games of chess will be played
182 |
183 | 184 | Answers to Exercise 4:
185 | 1. __ heat, __ light 2. a light 3. a paper 4. __ Paper, __ wood, __ cloth 5. __ honor 6. an honor 7. a bed 8. __ bed 9. __ Iron, __ steel 10. an iron 11. __ lunch 12. a lunch
186 |
187 | 188 | Answers to Exercise 5:
189 | 1. reading 2. to attend 3. organizing 4. to write 5. to accompany 190 | 6. giving 7. finishing 8. to contradict 9. calling 10. to succeed 191 | 11. to mall 12. skiing 13. missing 14. to borrow 15. waiting 192 | 16. to ride 17. snowing 18. to open 19. to accept 20. hearing
193 |
194 | 195 | 196 |
197 |
Home | 198 | Table of Contents | Index 199 |
200 |
Next Page
201 |

202 | 203 | 204 |

205 | 206 | 207 | 208 | 209 | -------------------------------------------------------------------------------- /site/grammar/gramex16.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | English Grammar 8 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 33 | 34 |
35 | 36 | 37 | 38 | 39 |

45 | 46 |
47 | 48 |
EXERCISES for Chapter 16

49 | 50 | 51 | 1. For the following sentences, fill in the blanks with a or an or leave the blanks empty, as appropriate. Fill in the blanks with a or an before countable nouns, and leave them empty before uncountable nouns. For example:
52 |       __ bird is singing outside the window.
53 |       A bird is singing outside the window.
54 |
55 |       ___ copper is used in making electrical wiring.
56 |       Copper is used in making electrical wiring.
57 |
58 | 1. ___ air is made up of elements such as ___ oxygen and ___ nitrogen.
59 | 2. ___ book is lying on the floor.
60 | 3. ___ Russian is a difficult language.
61 | 4. ___ onion is ___ vegetable.
62 | 5. ___ butter and ___ cream are made from ___ milk.
63 | 6. ___ letter has been delivered to the wrong house.
64 | 7. ___ child is playing on the sidewalk.
65 | 8. ___ asbestos is a fireproof material.
66 | 9. ___ tree is growing outside the house.
67 | 10. ___ curiosity is considered a sign of ___ intelligence.
68 | 11. They want to buy ___ camera.
69 | 12. ___ egg was added to the soup.
70 | 13. ___ rain is expected this evening.
71 | 14. The farmers wished for ___ peace and ___ prosperity.
72 | 15. ___ bicycle is parked in front of the store.
73 | Answers 74 | 75 |
76 |
77 | 2. Paying attention to whether the nouns in the following paragraphs 78 | are countable or uncountable, and to whether or not the nouns refer to things which have been mentioned before, fill in the blanks with a or the, or leave the blanks empty, as appropriate.
79 |
80 | Phil Jones was ____ prospector, who was looking for ____ gold. He had 81 | to travel a long way, crossing ___ mountains and ____ streams to reach his destination.
82 |
83 | Previously, he had been ____ miner and had mined ___ copper and ___ coal. But ____ copper had given out, and mining ____ coal was dangerous work. When he had heard about ___ gold in ____ mountains, Phil had left his job and traveled west. He knew he would need ___ courage and ___ determination to reach his goal.
84 |
85 | One evening he camped beside ___ stream. When he tested ____ stream, 86 | he found there was a small amount of glittering gold dust in it. As 87 | usual, Phil made ___ fire to prepare his evening meal. He took ____ 88 | ___ flour and ___ salt from his knapsack, and got ___ water from ____ 89 | stream. Then he mixed ___ salt with ___ flour, and gradually added 90 | ___ water, to make ___ pancakes over ___ fire.
91 |
92 | As ___ fire died away, Phil looked up and down ___ stream. Expecting 93 | to see only ___ darkness, to his surprise, he saw ____ lights from many small fires. He knew they must be ____ fires of other prospectors. "I've reached end of my journey", he thought. Now he was in the goldfields, and with ___ luck, he would find ___ gold he had come to seek.
94 | Answers 95 | 96 |
97 |
98 | 3. For each of the following sentences, change the word one to two, put the subject of the verb into the plural, and make sure that the verb agrees with its subject. For example:
99 |       One bar of soap will be provided.
100 |       Two bars of soap will be provided.
101 |
102 |       One bag of flour is on the counter.
103 |       Two bags of flour are on the counter.
104 |
105 | 1. One piece of luggage is allowed per passenger.
106 | 2. One bottle of water is enough.
107 | 3. One jar of honey is larger than the others.
108 | 4. One piece of furniture will be delivered.
109 | 5. One grain of rice has fallen onto the table.
110 | 6. One bucket of sand was needed to build the sand castle.
111 | 7. One cup of sugar should be mixed with the flour.
112 | 8. One game of chess will be played at four o'clock.
113 | Answers 114 | 115 |
116 |
117 | 4. Fill in each blank with a or an if the noun following the blank is used as a countable noun, or leave the blank empty if the noun following the blank is used as an uncountable noun. For example:
118 |       The bowl is made of ___ glass.
119 |       The bowl is made of glass.
120 |
121 |       Would you like __ glass of water?
122 |       Would you like a glass of water?
123 |
124 | 1. The sun gives off ___ heat and ___ light.
125 | 2. There is ___ light suspended from the ceiling.
126 | 3. She will buy ___ paper to find out what movies are being shown.
127 | 4. ___ paper can be made from ___ wood or ___ cloth.
128 | 5. She has a keen sense of ___ honor.
129 | 6. It is ___ honor to be invited to speak.
130 | 7. There is ___ bed near the window.
131 | 8. He has gone to ____ bed early because he is tired.
132 | 9. ___ iron used in making ___ steel.
133 | 10. If I had ___ iron, I would press my new suit.
134 | 11. They always eat ___ lunch at twelve o'clock.
135 | 12. We will pack you ____ lunch to take with you.
136 | Answers 137 | 138 |
139 |
140 | 5. Paying attention to which verbs can be followed by an infinitive and which can be followed by a gerund, for each sentence, fill in the blank with the infinitive or gerund of the verb shown in brackets. For example:
141 |       Please stop _____ that! (to do)
142 |       Please stop doing that!
143 |
144 |       He has decided _______ a holiday. (to take)
145 |       He has decided to take a holiday.
146 |
147 | 1. Has he finished __________ the report? (to read)
148 | 2. We plan __________ the concert. (to attend)
149 | 3. They will discuss __________ a club. (to organize)
150 | 4. She offered _________ the letter. (to write)
151 | 5. They asked __________ us. (to accompany)
152 | 6. You should practise __________ the speech. (to give)
153 | 7. I would suggest __________ the work by next week. (to finish)
154 | 8. He has not dared __________ you. (to contradict)
155 | 9. They delayed _________ us. (to call)
156 | 10. She deserves ___________. (to succeed)
157 | 11. We forgot _________ the letter. (to mail)
158 | 12. He enjoys __________. (to ski)
159 | 13. They would not risk _________ the bus. (to miss)
160 | 14. Do you want __________ the book? (to borrow)
161 | 15. I don't mind _________. (to wait)
162 | 16. Her daughter is learning __________ a bicycle. (to ride)
163 | 17. It has stopped __________. (to snow)
164 | 18. He is preparing __________ a business. (to open)
165 | 19. They hesitated __________ the invitation. (to accept)
166 | 20. I miss __________ from them. (to hear)
167 | Answers 168 |
169 | 170 |  
171 |
172 | 173 |
ANSWERS TO THE EXERCISES for Chapter 16

174 | 175 | Answers to Exercise 1:
176 | 1. __ Air, __ oxygen, __ nitrogen 2. A book 3. __ Russian 177 | 4. An onion, a vegetable 5. __ Butter, __ cream, __ milk 6. A letter 178 | 7. A child 8. __ Asbestos 9. A tree 10. __ Curiosity, __ intelligence 179 | 11. a camera 12. An egg 13. __ Rain 14. __ peace, __ prosperity 15. A bicycle
180 |
181 | 182 | Answers to Exercise 2:
183 | a prospector, __ gold. __ mountains, __ streams. 184 | a miner, __ copper, __ coal. the copper, the coal. the gold, 185 | the mountains, __ courage, __ determination. 186 | a stream. the stream. a fire. __ flour, __ salt, __ water, the stream. the salt, the flour the water, __ pancakes, the fire. 187 | the fire, the stream. __ darkness, __ lights. 188 | the fires. the end. __ luck, the gold.
189 |
190 | 191 | Answers to Exercise 3:
192 | 1. Two pieces of luggage are allowed 2. Two bottles of water are 193 | 3. Two jars of honey are 4. Two pieces of furniture will be delivered. 194 | 5. Two grains of rice have fallen 6. Two buckets of wand were needed 195 | 7. Two cups of sugar should be mixed 9. Two games of chess will be played
196 |
197 | 198 | Answers to Exercise 4:
199 | 1. __ heat, __ light 2. a light 3. a paper 4. __ Paper, __ wood, __ cloth 5. __ honor 6. an honor 7. a bed 8. __ bed 9. __ Iron, __ steel 10. an iron 11. __ lunch 12. a lunch
200 |
201 | 202 | Answers to Exercise 5:
203 | 1. reading 2. to attend 3. organizing 4. to write 5. to accompany 204 | 6. giving 7. finishing 8. to contradict 9. calling 10. to succeed 205 | 11. to mall 12. skiing 13. missing 14. to borrow 15. waiting 206 | 16. to ride 17. snowing 18. to open 19. to accept 20. hearing
207 |
208 | 209 | 210 |

216 | 217 | 218 |

219 | 220 | 221 | 222 | 223 | -------------------------------------------------------------------------------- /work/deprecated/style.rb: -------------------------------------------------------------------------------- 1 | warn "use English instead" 2 | 3 | require 'facets/instantize' 4 | 5 | class String 6 | 7 | # Style a string. This method routes to the Style module. 8 | # 9 | # === Examples 10 | # 11 | # "super_man".style:camelcase #=> "SuperMan" 12 | # "SuperMan".style:underscore #=> "super_man" 13 | # 14 | def style(*formats) 15 | formats.inject(self) do |string, format| 16 | Style.__send__(format, string) 17 | end 18 | end 19 | 20 | # Stlyist module provides an extensible means of applying 21 | # common alteration patterns to strings. This library is likely to evolve 22 | # a great deal. For now it borrows most of it's styles from Rails Inflector 23 | # library. 24 | # 25 | # This module is used by the string/style extension. 26 | # 27 | # Examples 28 | # String::Style.snakecase("SuperMan") #=> "super_man" 29 | # String::Style.dasherize("super_man") #=> "super-man" 30 | # 31 | # TODO: With #pathize, is downcasing really needed? After all paths can have capitalize letters ;p 32 | # TODO: With #methodize, is downcasing any but the first letter really needed? Desipite Matz prefernce methods can have capitalized letters. 33 | 34 | module Style 35 | 36 | include Instantize 37 | 38 | private(*instance_methods.select{ |a| a !~ /^__|instance_|object_|send/ }) 39 | 40 | # Standard downcase style. 41 | # 42 | def self.downcase(string) 43 | string.downcase 44 | end 45 | 46 | # Same as downcase style. 47 | # 48 | def self.lowercase(string) 49 | string.downcase 50 | end 51 | 52 | # Standard upcase style. 53 | # 54 | def self.upcase(string) 55 | string.upcase 56 | end 57 | 58 | # Same as upcase style. 59 | # 60 | def self.uppercase(string) 61 | string.upcase 62 | end 63 | 64 | # Standard capitalize style. 65 | 66 | def self.capitalize(string) 67 | string.capitalize 68 | end 69 | 70 | # Titlecase 71 | # 72 | # "this is a string".style(:titlecase) 73 | # => "This Is A String" 74 | # 75 | def self.titlecase(phrase) 76 | phrase.gsub(/\b\w/){$&.upcase} 77 | end 78 | 79 | # The reverse of +camelize+. Makes an underscored form from the expression in the string. 80 | # 81 | # Changes '::' to '/' to convert namespaces to paths. 82 | # 83 | # Examples 84 | # "ActiveRecord".underscore #=> "active_record" 85 | # "ActiveRecord::Errors".underscore #=> active_record/errors 86 | 87 | def self.snakecase(camel_cased_word) 88 | camel_cased_word.to_s.gsub(/::/, '/'). 89 | gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2'). 90 | gsub(/([a-z\d])([A-Z])/,'\1_\2'). 91 | tr("-", "_"). 92 | downcase 93 | end 94 | 95 | # Converts a string into a unix path. 96 | # This method is geared toward code reflection. 97 | # 98 | # See : String#modulize, String#methodize 99 | # 100 | # Style.pathize("MyModule::MyClass") #=> my_module/my_class 101 | # Style.pathize("my_module__my_class") #=> my_module/my_class 102 | # 103 | # TODO: 104 | # * Make sure that all scenarios return a valid unix path 105 | # * Make sure it is revertible 106 | # 107 | # See also #modulize, #methodize 108 | 109 | def self.pathize(module_name) 110 | module_name.to_s. 111 | gsub(/__/, '/'). 112 | gsub(/::/, '/'). 113 | gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2'). 114 | gsub(/([a-z\d])([A-Z])/,'\1_\2'). 115 | tr("-", "_"). 116 | downcase 117 | end 118 | 119 | # Converts a module name into a valid method name 120 | # This method is geared toward code reflection. 121 | # 122 | # Examples 123 | # Style.methodize("SuperMan") #=> "super_man" 124 | # Style.methodize("SuperMan::Errors") #=> "super_man__errors 125 | # Style.methodize("MyModule::MyClass") #=> "my_module__my_class" 126 | #classes/ActiveSupport/CoreExtensions/String/Inflections.html 127 | # See also #modulize, #pathize 128 | 129 | def self.methodize(module_name) 130 | module_name.to_s. 131 | gsub(/\//, '__'). 132 | gsub(/::/, '__'). 133 | gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2'). 134 | gsub(/([a-z\d])([A-Z])/,'\1_\2'). 135 | tr("-", "_"). 136 | downcase 137 | end 138 | 139 | # Converts a string into a valid ruby class or module name 140 | # This method is geared toward code reflection. 141 | # 142 | # Examples 143 | # Style.modulize("camel_case") #=> "CamelCase" 144 | # Style.modulize("camel/case") #=> "Camel::Case" 145 | # Style.modulize("my_module__my_path") #=> "MyModule::MyPath" 146 | # 147 | # See also #methodize, #pathize 148 | 149 | def self.modulize(pathized_or_methodized_string) 150 | pathized_or_methodized_string. 151 | gsub(/__(.?)/){ "::#{$1.upcase}" }. 152 | gsub(/\/(.?)/){ "::#{$1.upcase}" }. 153 | gsub(/(?:_+)([a-z])/){ $1.upcase }. 154 | gsub(/(^|\s+)([a-z])/){ $1 + $2.upcase } 155 | end 156 | 157 | def self.lowercamel(snakecase_word) 158 | snakecase_word.first + camelize(lower_case_and_underscored_word)[1..-1] 159 | end 160 | 161 | def self.uppercamel(snakecase_word) 162 | snakecase_word.to_s.gsub(/\/(.?)/) { "::#{$1.upcase}" }.gsub(/(?:^|_)(.)/) { $1.upcase } 163 | end 164 | 165 | ################## 166 | # ACTIVE SUPPORT # 167 | ####################################################################### 168 | # These were extracted directly from ActiveSupport's Inflector class. # 169 | # It seemed prudent to maintian this desgree of compatbility. # 170 | ####################################################################### 171 | 172 | # By default, camelize converts strings to UpperCamelCase. If the argument to camelize 173 | # is set to ":lower" then camelize produces lowerCamelCase. 174 | # 175 | # camelize will also convert '/' to '::' which is useful for converting paths to namespaces 176 | # 177 | # Examples 178 | # Style.camelize("active_record") #=> "ActiveRecord" 179 | # Style.caemlize("active_record", true) #=> "activeRecord" 180 | # Style.camelize("active_record/errors") #=> "ActiveRecord::Errors" 181 | # Style.camelize("active_record/errors",true) #=> "activeRecord::Errors" 182 | # 183 | def self.camelize(snakecase_word, first_letter_in_uppercase = true) 184 | if first_letter_in_uppercase 185 | snakecase_word.to_s.gsub(/\/(.?)/) { "::#{$1.upcase}" }.gsub(/(?:^|_)(.)/) { $1.upcase } 186 | else 187 | snakecase_word.first + camelize(lower_case_and_underscored_word)[1..-1] 188 | end 189 | end 190 | 191 | #def camelize(first_letter_in_uppercase = true) 192 | # Style.camelize(self, first_letter_in_uppercase) 193 | #end 194 | 195 | # Capitalizes all the words and replaces some characters in the string to create 196 | # a nicer looking title. Titleize is meant for creating pretty output. It is not 197 | # used in the Rails internals. 198 | # 199 | # titleize is also aliased as as titlecase 200 | # 201 | # Examples 202 | # "man from the boondocks".titleize #=> "Man From The Boondocks" 203 | # "x-men: the last stand".titleize #=> "X Men: The Last Stand" 204 | 205 | def self.titleize(word) 206 | humanize(underscore(word)).gsub(/\b('?[a-z])/) { $1.capitalize } 207 | end 208 | 209 | # The reverse of +camelize+. Makes an underscored, lowercase form from the expression in the string. 210 | # 211 | # Changes '::' to '/' to convert namespaces to paths. 212 | # 213 | # Examples 214 | # "ActiveRecord".underscore #=> "active_record" 215 | # "ActiveRecord::Errors".underscore #=> active_record/errors 216 | def self.underscore(camel_cased_word) 217 | camel_cased_word.to_s.gsub(/::/, '/'). 218 | gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2'). 219 | gsub(/([a-z\d])([A-Z])/,'\1_\2'). 220 | tr("-", "_"). 221 | downcase 222 | end 223 | 224 | # Replaces underscores with dashes in the string. 225 | # 226 | # Example 227 | # dasherize("puni_puni") #=> "puni-puni" 228 | def self.dasherize(underscored_word) 229 | underscored_word.gsub(/_/, '-') 230 | end 231 | 232 | # Capitalizes the first word and turns underscores into spaces and strips _id. 233 | # Like titleize, this is meant for creating pretty output. 234 | # 235 | # Examples 236 | # "employee_salary" #=> "Employee salary" 237 | # "author_id" #=> "Author" 238 | def self.humanize(lower_case_and_underscored_word) 239 | lower_case_and_underscored_word.to_s.gsub(/_id$/, "").gsub(/_/, " ").capitalize 240 | end 241 | 242 | # Removes the module part from the expression in the string 243 | # 244 | # Examples 245 | # "ActiveRecord::CoreExtensions::String::Inflections".demodulize #=> "Inflections" 246 | # "Inflections".demodulize #=> "Inflections" 247 | def self.demodulize(class_name_in_module) 248 | class_name_in_module.to_s.gsub(/^.*::/, '') 249 | end 250 | 251 | # Create the name of a table like Rails does for models to table names. This method 252 | # uses the pluralize method on the last word in the string. 253 | # 254 | # Examples 255 | # "RawScaledScorer".tableize #=> "raw_scaled_scorers" 256 | # "egg_and_ham".tableize #=> "egg_and_hams" 257 | # "fancyCategory".tableize #=> "fancy_categories" 258 | def self.tableize(class_name) 259 | pluralize(underscore(class_name)) 260 | end 261 | 262 | # Create a class name from a plural table name like Rails does for table names to models. 263 | # Note that this returns a string and not a Class. (To convert to an actual class 264 | # follow classify with constantize.) 265 | # 266 | # Examples 267 | # "egg_and_hams".classify #=> "EggAndHam" 268 | # "posts".classify #=> "Post" 269 | # 270 | # Singular names are not handled correctly 271 | # "business".classify #=> "Busines" 272 | def self.classify(table_name) 273 | # strip out any leading schema name 274 | camelize(singularize(table_name.to_s.sub(/.*\./, ''))) 275 | end 276 | 277 | # Creates a foreign key name from a class name. 278 | # +separate_class_name_and_id_with_underscore+ sets whether 279 | # the method should put '_' between the name and 'id'. 280 | # 281 | # Examples 282 | # "Message".foreign_key #=> "message_id" 283 | # "Message".foreign_key(false) #=> "messageid" 284 | # "Admin::Post".foreign_key #=> "post_id" 285 | def self.foreign_key(class_name, separate_class_name_and_id_with_underscore = true) 286 | underscore(demodulize(class_name)) + (separate_class_name_and_id_with_underscore ? "_id" : "id") 287 | end 288 | 289 | # Ordinalize turns a number into an ordinal string used to denote the 290 | # position in an ordered sequence such as 1st, 2nd, 3rd, 4th. 291 | # 292 | # Examples 293 | # ordinalize('1') # => "1st" 294 | # ordinalize('2') # => "2nd" 295 | # ordinalize('1002') # => "1002nd" 296 | # ordinalize('1003') # => "1003rd" 297 | def self.ordinalize(number_string) 298 | if number_string =~ /\d{1,2}$/ 299 | number = $1.to_i 300 | if (11..13).include?(number.to_i % 100) 301 | r = "#{number}th" 302 | else 303 | r = case number.to_i % 10 304 | when 1; "#{number}st" 305 | when 2; "#{number}nd" 306 | when 3; "#{number}rd" 307 | else "#{number}th" 308 | end 309 | end 310 | number_string.sub(/\d{1,2}$/, r) 311 | else 312 | number_string 313 | end 314 | end 315 | 316 | end 317 | 318 | end 319 | 320 | -------------------------------------------------------------------------------- /site/grammar/gramirr.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | English Grammar 8 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 |
21 | 22 | 23 |

27 | 28 |
29 | 30 |
COMMON ENGLISH IRREGULAR VERBS

31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | 134 | 135 | 136 | 137 | 138 | 139 | 140 | 141 | 142 | 143 | 144 | 145 | 146 | 147 | 148 | 149 | 150 | 151 | 152 | 153 | 154 | 155 | 156 | 157 | 158 | 159 | 160 | 161 | 162 | 163 | 164 | 165 | 166 | 167 | 168 | 169 | 170 | 171 | 172 | 173 | 174 |
Bare InfinitiveSimple PastPast Participle
 be was/were been
 bear bore born
 beat beat beaten
 become became become
 begin began begun
 bend bent bent
 bind bound bound
 bite bit bitten
 bleed bled bled
 blow blew blown
 break broke broken
 breed bred bred
 bring brought brought
 build built built
 burst burst burst
 buy bought bought
 cast cast cast
 catch caught caught
 choose chose chosen
 cling clung clung
 come came come
 cost cost cost
 creep crept crept
 cut cut cut
 deal dealt dealt
 dig dug dug
 do did done
 draw drew drawn
 drink drank drunk
 drive drove driven
 eat ate eaten
 fall fell fallen
 feed fed fed
 feel felt felt
 fight fought fought
 find found found
 flee fled fled
 fling flung flung
 fly flew flown
 forbid forbade forbidden
 forecast forecast forecast
 forget forgot forgotten
 forgive forgave forgiven
 forsake forsook forsaken
 freeze froze frozen
 get got got
 give gave given
 go went gone
 grind ground ground
 grow grew grown
 hang hung hung
 have had had
 hear heard heard
 hide hid hidden
 hit hit hit
 hold held held
 hurt hurt hurt
 keep kept kept
 kneel knelt knelt
 know knew known
 lay laid laid
 lead led led
 leave left left
 lend lent lent
 let let let
 lie lay lain
 lose lost lost
 make made made
 mean meant meant
 meet met met
 mistake mistook mistaken
 partake partook partaken
 pay paid paid
 put put put
 read read read
 rid rid rid
 ride rode ridden
 ring rang rung
 rise rose risen
 run ran run
 say said said
 see saw seen
 seek sought sought
 sell sold sold
 send sent sent
 set set set
 shake shook shaken
 shed shed shed
 shine shone shone
 shoe shod shod
 shoot shot shot
 show showed shown
 shrink shrank or shrunk shrunk
 shut shut shut
 sing sang sung
 sink sank sunk
 sit sat sat
 sleep slept slept
 slide slid slid
 sling slung slung
 slink slunk slunk
 slit slit slit
 speak spoke spoken
 speed sped sped
 spend spent spent
 spin span or spun spun
 spit spit or spat spat
 split split split
 spread spread spread
 spring sprang sprung
 stand stood stood
 steal stole stolen
 stick stuck stuck
 sting stung stung
 stink stank stunk
 stride strode strode
 strike struck struck
 string strung strung
 strive strove striven
 swear swore sworn
 sweep swept swept
 swim swam swum
 take took taken
 teach taught taught
 tear tore torn
 tell told told
 think thought thought
 thrive throve thriven
 throw threw thrown
 thrust thrust thrust
 tread trod trodden
 understand understood understood
 wake woke woken
 wear wore worn
 weave wove woven
 weep wept wept
 win won won
 wind wound wound
 wring wrung wrung
 write wrote written

175 | 176 | 177 |

183 | 184 | 185 |

186 | 187 | 188 | 189 | 190 | --------------------------------------------------------------------------------