linguistics 1.0.8

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,77 @@
1
+ #!/usr/bin/ruby -w
2
+ #
3
+ # Unit test for additions donated by Francis Hwang, author of Lafcadio
4
+ # $Id$
5
+ #
6
+ # Converted from ts_english.rb.
7
+ #
8
+
9
+ unless defined? Linguistics::TestCase
10
+ testsdir = File::dirname( File::dirname(File::expand_path( __FILE__ )) )
11
+ $LOAD_PATH.unshift testsdir unless $LOAD_PATH.include?( testsdir )
12
+
13
+ require 'lingtestcase'
14
+ end
15
+
16
+ ### This test case tests ...
17
+ class LafcadioAdditionsTestCase < Linguistics::TestCase
18
+
19
+ Linguistics::use( :en )
20
+ include Linguistics::EN
21
+
22
+ CamelCaseStrings = [
23
+ ["productCategory", "product category"],
24
+ ["ProductCategory", "product category"],
25
+ ["catalogOrder", "catalog order"],
26
+ ["product", "product"],
27
+ ["theNameOfAMethod", "the name of a method"],
28
+ ]
29
+
30
+ ProperNouns = {
31
+ "albania" => "Albania",
32
+ "bosnia and herzegovina" => "Bosnia and Herzegovina",
33
+ "faroe islands" => "Faroe Islands",
34
+ "macedonia, the former yugoslav republic of" =>
35
+ "Macedonia, the Former Yugoslav Republic of",
36
+ "virgin islands, u.s." => "Virgin Islands, U.S.",
37
+ }
38
+
39
+
40
+
41
+ #################################################################
42
+ ### T E S T S
43
+ #################################################################
44
+
45
+ def test_camel_case_to_english_should_transform_to_english
46
+ printTestHeader "Lafcadio Additions: CamelCase to English"
47
+ res = nil
48
+
49
+ CamelCaseStrings.each do |src, dst|
50
+ assert_nothing_raised { res = src.en.camel_case_to_english }
51
+ assert_equal dst, res
52
+ end
53
+ end
54
+
55
+ ### This already worked before the additions, but might as well test 'em
56
+ ### some more.
57
+ def test_plural
58
+ assert_equal "product categories", "product category".en.plural
59
+ assert_equal "products", "product".en.plural
60
+ assert_equal 'addresses', 'address'.en.plural
61
+ assert_equal 'taxes', 'tax'.en.plural
62
+ end
63
+
64
+
65
+ ### String#proper_noun
66
+ def test_proper_noun_should_return_caseified_string
67
+ printTestHeader "Lafcadio Additions: Proper Nouns"
68
+
69
+ ProperNouns.each do |key,expected|
70
+ input = key.dup # Get around hash keys being frozen
71
+ debug_msg "Trying %p, expect: %p" % [input, expected]
72
+ assert_equal expected, input.en.proper_noun
73
+ end
74
+ end
75
+
76
+ end
77
+
@@ -0,0 +1,42 @@
1
+ #!/usr/bin/ruby -w
2
+ #
3
+ # Unit test for English link grammar
4
+ # $Id$
5
+ #
6
+ # Copyright (c) 2003-2005 The FaerieMUD Consortium.
7
+ #
8
+
9
+ unless defined? Linguistics::TestCase
10
+ testsdir = File::dirname( File::dirname(File::expand_path( __FILE__ )) )
11
+ $LOAD_PATH.unshift testsdir unless $LOAD_PATH.include?( testsdir )
12
+
13
+ require 'lingtestcase'
14
+ end
15
+
16
+ ### This test case tests the English language link grammar extension of
17
+ ### Linguistics::EN.
18
+ class LinkParserTestCase < Linguistics::TestCase
19
+
20
+ Linguistics::use(:en)
21
+ include Linguistics::EN
22
+
23
+ ### Overridden to skip tests if WordNet isn't installed.
24
+ def run( result )
25
+ return super if Linguistics::EN::has_link_parser?
26
+ yield( STARTED, name )
27
+ result.add_run
28
+ yield( FINISHED, name )
29
+ end
30
+
31
+
32
+ def test_sentence_should_return_a_parsed_linkparser_sentence
33
+ rval = nil
34
+
35
+ assert_nothing_raised do
36
+ rval = "He is a dog.".en.sentence
37
+ end
38
+
39
+ assert_instance_of LinkParser::Sentence, rval
40
+ end
41
+
42
+ end
@@ -0,0 +1,77 @@
1
+ #!/usr/bin/ruby -w
2
+ #
3
+ # Unit test for Linguistics::EN#lprintf
4
+ # $Id$
5
+ #
6
+ # Copyright (c) 2006 The FaerieMUD Consortium.
7
+ #
8
+
9
+ unless defined?( Linguistics::TestCase )
10
+ require 'pathname'
11
+ basedir = Pathname.new( __FILE__ ).dirname.parent.parent.expand_path
12
+
13
+ libdir = basedir + "lib"
14
+ testsdir = basedir + "tests"
15
+ $LOAD_PATH.unshift( libdir ) unless $LOAD_PATH.include?( libdir )
16
+ $LOAD_PATH.unshift( testsdir ) unless $LOAD_PATH.include?( testsdir )
17
+
18
+ require 'lingtestcase'
19
+ end
20
+
21
+ require 'linguistics/en'
22
+
23
+ ### This test case tests the lprintf method of the Linguistics English module
24
+ class Linguistics::LPrintfTestCase < Linguistics::TestCase
25
+
26
+ Items = %w{ruby moose mouse nexus}
27
+
28
+ def initialize( *args )
29
+ Linguistics::use( :en )
30
+ super
31
+ end
32
+
33
+ def test_lprintf_with_conjunct_tag_should_conjunctionize_the_corresponding_argument
34
+ rval = nil
35
+
36
+ assert_nothing_raised do
37
+ rval = "I have %CONJUNCT in my pocket".en.lprintf( Items )
38
+ end
39
+
40
+ assert_equal "I have a ruby, a moose, a mouse, and a nexus in my pocket",
41
+ rval
42
+ end
43
+
44
+
45
+ def test_lprintf_with_plural_tag_should_pluralize_the_corresponding_argument
46
+ rval = nil
47
+
48
+ assert_nothing_raised do
49
+ rval = "What's with all the %PL?".en.lprintf( "llama" )
50
+ end
51
+
52
+ assert_equal "What's with all the llamas?", rval
53
+ end
54
+
55
+
56
+ def test_lprintf_with_indef_article_tag_should_use_an_for_umbrella
57
+ rval = nil
58
+
59
+ assert_nothing_raised do
60
+ rval = "You pick up %A.".en.lprintf( "umbrella" )
61
+ end
62
+
63
+ assert_equal "You pick up an umbrella.", rval
64
+ end
65
+
66
+
67
+ def test_lprintf_with_indef_article_tag_should_use_a_for_flagon_of_mead
68
+ rval = nil
69
+
70
+ assert_nothing_raised do
71
+ rval = "You pick up %A.".en.lprintf( "flagon of mead" )
72
+ end
73
+
74
+ assert_equal "You pick up a flagon of mead.", rval
75
+ end
76
+
77
+ end
@@ -0,0 +1,73 @@
1
+ #!/usr/bin/ruby -w
2
+ #
3
+ # Unit test for English language module's title case method
4
+ # $Id$
5
+ #
6
+ # Copyright (c) 2005 The FaerieMUD Consortium.
7
+ #
8
+
9
+ unless defined? Linguistics::TestCase
10
+ testsdir = File::dirname( File::dirname(File::expand_path( __FILE__ )) )
11
+ $LOAD_PATH.unshift testsdir unless $LOAD_PATH.include?( testsdir )
12
+
13
+ require 'lingtestcase'
14
+ end
15
+
16
+ ### This test case tests the #titlecase method of the english-language extension
17
+ ### for the Linguistics library.
18
+ class TitleCaseTestCase < Linguistics::TestCase
19
+
20
+ Linguistics::use( :en )
21
+
22
+ Titles = File::open(__FILE__).read.split("__END__").last.split("\n")
23
+
24
+ def test_nothing
25
+ debug_msg "Not tested, as the functionality it tests hasn't been released yet."
26
+ end
27
+
28
+ def dont_test_titles
29
+ printTestHeader "TitleCase: Titles"
30
+ rval = nil
31
+
32
+ debug_msg "Titles = %p" % [Titles]
33
+
34
+ Titles.each do |title|
35
+ next if !/\w/.match( title )
36
+
37
+ assert_nothing_raised do
38
+ rval = title.downcase.en.titlecase
39
+ end
40
+
41
+ assert_instance_of String, rval
42
+ assert_equal title, rval
43
+ end
44
+ end
45
+
46
+ end
47
+
48
+
49
+ __END__
50
+ A Certain Kind of Longing
51
+ A Connecticut Yankee in King Arthur's Court
52
+ A Portrait of the Artist as a Young Man
53
+ Alice in Wonderland
54
+ Catcher in the Rye
55
+ Crime and Punishment
56
+ Death of a Salesman
57
+ Dr. Jekyll and Mr. Hyde
58
+ Gone With the Wind
59
+ Gone but Not Forgotten
60
+ Gulliver's Travels
61
+ Last of the Mohicans
62
+ Lord of the Flies
63
+ Love in the Time of Cholera
64
+ Maggie, A Girl of the Streets
65
+ Notes from the Underground
66
+ Of Mice and Men
67
+ Pride and Prejudice
68
+ The Adventures of Don Quixote
69
+ The Good Earth
70
+ The Heart of Darkness
71
+ The Lord of the Rings
72
+ The Old Man and the Sea
73
+ Mrs. Frisby and the Rats of N.I.M.H.
@@ -0,0 +1,95 @@
1
+ #!/usr/bin/ruby -w
2
+ #
3
+ # Unit test for Linguistics::EN WordNet functions
4
+ # $Id$
5
+ #
6
+ # Copyright (c) 2003 The FaerieMUD Consortium.
7
+ #
8
+
9
+ unless defined? Linguistics::TestCase
10
+ testsdir = File::dirname( File::dirname(File::expand_path( __FILE__ )) )
11
+ $LOAD_PATH.unshift testsdir unless $LOAD_PATH.include?( testsdir )
12
+
13
+ require 'lingtestcase'
14
+ end
15
+
16
+
17
+ ### This test case tests ...
18
+ class EnglishWordnetTestCase < Linguistics::TestCase
19
+
20
+ Linguistics::use( :en, :installProxy => true )
21
+
22
+ TestObjects = [ "auto", 5, [%w{ash bin}] ]
23
+
24
+ ### Overridden to skip tests if WordNet isn't installed.
25
+ def run( result )
26
+ return super if Linguistics::EN::has_wordnet?
27
+ yield( STARTED, name )
28
+ result.add_run
29
+ yield( FINISHED, name )
30
+ end
31
+
32
+
33
+ #################################################################
34
+ ### T E S T S
35
+ #################################################################
36
+
37
+ ### Test the wn_lexicon method of the EN module
38
+ def test_00_Lexicon
39
+ printTestHeader "English: WordNet: Lexicon"
40
+
41
+ assert_respond_to Linguistics::EN, :wn_lexicon
42
+ assert_nothing_raised {
43
+ lex = Linguistics::EN::wn_lexicon
44
+ assert_instance_of WordNet::Lexicon, lex
45
+ }
46
+ end
47
+
48
+ ### Test synset method
49
+ def test_05_Synset
50
+ printTestHeader "English: WordNet: Synsets"
51
+ rval = nil
52
+
53
+ TestObjects.each do |obj|
54
+ assert_respond_to obj, :en
55
+ assert_respond_to obj.en, :synset
56
+
57
+ assert_nothing_raised { rval = obj.en.synset }
58
+ assert_instance_of WordNet::Synset, rval,
59
+ ".en.synset for %p" % obj
60
+ end
61
+ end
62
+
63
+ ### Test proxy method
64
+ def test_06_ProxyMethod
65
+ printTestHeader "English: WordNet: Proxy method"
66
+ rval = nil
67
+
68
+ TestObjects.each do |obj|
69
+ assert_nothing_raised { rval = obj.synset }
70
+ assert_instance_of WordNet::Synset, rval,
71
+ ".synset for %p" % obj
72
+ end
73
+
74
+ self.class.addSetupBlock {
75
+ @obj = TestObjects[0]
76
+ }
77
+ self.class.addTeardownBlock {
78
+ @obj = nil
79
+ }
80
+ end
81
+
82
+ ### Test #coordinates
83
+ def test_10_Coordinates
84
+ printTestHeader "English: WordNet: Coordinate terms"
85
+ rval = nil
86
+
87
+ assert_nothing_raised {
88
+ rval = @obj.coordinates
89
+ }
90
+ assert_instance_of Array, rval
91
+ assert_instance_of WordNet::Synset, rval.first
92
+ end
93
+
94
+ end
95
+
metadata ADDED
@@ -0,0 +1,107 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: linguistics
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.8
5
+ platform: ruby
6
+ authors:
7
+ - Michael Granger
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-11-17 00:00:00 -08:00
13
+ default_executable:
14
+ dependencies: []
15
+
16
+ description: |-
17
+ in any language. It includes a generic language-independant front end, a
18
+ module for mapping language codes into language names, and a module which
19
+ contains various English-language utilities.
20
+ email:
21
+ - ged@FaerieMUD.org
22
+ executables: []
23
+
24
+ extensions: []
25
+
26
+ extra_rdoc_files:
27
+ - ChangeLog
28
+ - README
29
+ - LICENSE
30
+ files:
31
+ - Rakefile
32
+ - ChangeLog
33
+ - README
34
+ - LICENSE
35
+ - spec/linguistics/en_spec.rb
36
+ - spec/linguistics/iso639_spec.rb
37
+ - spec/linguistics_spec.rb
38
+ - tests/en/infinitive.tests.rb
39
+ - tests/en/inflect.tests.rb
40
+ - tests/en/lafcadio.tests.rb
41
+ - tests/en/linkparser.tests.rb
42
+ - tests/en/lprintf.tests.rb
43
+ - tests/en/titlecase.tests.rb
44
+ - tests/en/wordnet.tests.rb
45
+ - lib/linguistics/en/infinitive.rb
46
+ - lib/linguistics/en/linkparser.rb
47
+ - lib/linguistics/en/wordnet.rb
48
+ - lib/linguistics/en.rb
49
+ - lib/linguistics/iso639.rb
50
+ - lib/linguistics.rb
51
+ - rake/191_compat.rb
52
+ - rake/dependencies.rb
53
+ - rake/helpers.rb
54
+ - rake/hg.rb
55
+ - rake/manual.rb
56
+ - rake/packaging.rb
57
+ - rake/publishing.rb
58
+ - rake/rdoc.rb
59
+ - rake/style.rb
60
+ - rake/svn.rb
61
+ - rake/testing.rb
62
+ - rake/verifytask.rb
63
+ - rake/win32.rb
64
+ - ./examples/generalize_sentence.rb
65
+ - ./README.english
66
+ has_rdoc: true
67
+ homepage: http://deveiate.org/projects/Linguistics/
68
+ licenses: []
69
+
70
+ post_install_message:
71
+ rdoc_options:
72
+ - -w
73
+ - "4"
74
+ - -HN
75
+ - -i
76
+ - .
77
+ - -m
78
+ - README
79
+ - -t
80
+ - linguistics
81
+ - -W
82
+ - http://deveiate.org/projects/Linguistics/browser/
83
+ require_paths:
84
+ - lib
85
+ required_ruby_version: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: "0"
90
+ version:
91
+ required_rubygems_version: !ruby/object:Gem::Requirement
92
+ requirements:
93
+ - - ">="
94
+ - !ruby/object:Gem::Version
95
+ version: "0"
96
+ version:
97
+ requirements: []
98
+
99
+ rubyforge_project: deveiate
100
+ rubygems_version: 1.3.5
101
+ signing_key:
102
+ specification_version: 3
103
+ summary: a framework for building linguistic utilities for Ruby objects
104
+ test_files:
105
+ - spec/linguistics/en_spec.rb
106
+ - spec/linguistics/iso639_spec.rb
107
+ - spec/linguistics_spec.rb