Linguistics 1.0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/Artistic +127 -0
- data/ChangeLog +444 -0
- data/MANIFEST +19 -0
- data/README +178 -0
- data/README.english +245 -0
- data/TODO +17 -0
- data/experiments/randobjlist.rb +34 -0
- data/install.rb +154 -0
- data/lib/linguistics/en/infinitive.rb +1149 -0
- data/lib/linguistics/en/linkparser.rb +142 -0
- data/lib/linguistics/en/wordnet.rb +253 -0
- data/lib/linguistics/en.rb +1694 -0
- data/lib/linguistics/iso639.rb +456 -0
- data/lib/linguistics.rb +368 -0
- data/redist/crosscase.rb +298 -0
- data/test.rb +110 -0
- data/tests/en/conjunction.tests.rb +114 -0
- data/tests/en/inflect.tests.rb +1378 -0
- data/tests/lingtestcase.rb +239 -0
- data/tests/use.tests.rb +99 -0
- data/utils.rb +689 -0
- metadata +58 -0
data/test.rb
ADDED
@@ -0,0 +1,110 @@
|
|
1
|
+
#!/usr/bin/ruby
|
2
|
+
#
|
3
|
+
# Test suite for Linguistics classes
|
4
|
+
#
|
5
|
+
#
|
6
|
+
|
7
|
+
BEGIN {
|
8
|
+
$basedir = File::dirname( __FILE__ )
|
9
|
+
%w{lib tests redist}.each do |dir|
|
10
|
+
$LOAD_PATH.unshift File::join( $basedir, dir )
|
11
|
+
end
|
12
|
+
|
13
|
+
require "#$basedir/utils"
|
14
|
+
include UtilityFunctions
|
15
|
+
}
|
16
|
+
|
17
|
+
verboseOff {
|
18
|
+
require 'lingtestcase'
|
19
|
+
require 'find'
|
20
|
+
require 'test/unit'
|
21
|
+
require 'test/unit/testsuite'
|
22
|
+
require 'test/unit/ui/console/testrunner'
|
23
|
+
require 'optparse'
|
24
|
+
}
|
25
|
+
|
26
|
+
# Turn off output buffering
|
27
|
+
$stderr.sync = $stdout.sync = true
|
28
|
+
|
29
|
+
# Initialize variables
|
30
|
+
safelevel = 0
|
31
|
+
patterns = []
|
32
|
+
requires = []
|
33
|
+
|
34
|
+
# Parse command-line switches
|
35
|
+
ARGV.options {|oparser|
|
36
|
+
oparser.banner = "Usage: #$0 [options] [TARGETS]\n"
|
37
|
+
|
38
|
+
oparser.on( "--debug", "-d", TrueClass, "Turn debugging on" ) {
|
39
|
+
$DEBUG = true
|
40
|
+
debugMsg "Turned debugging on."
|
41
|
+
}
|
42
|
+
|
43
|
+
oparser.on( "--verbose", "-v", TrueClass, "Make progress verbose" ) {
|
44
|
+
$VERBOSE = true
|
45
|
+
debugMsg "Turned verbose on."
|
46
|
+
}
|
47
|
+
|
48
|
+
# Handle the 'help' option
|
49
|
+
oparser.on( "--help", "-h", "Display this text." ) {
|
50
|
+
$stderr.puts oparser
|
51
|
+
exit!(0)
|
52
|
+
}
|
53
|
+
|
54
|
+
oparser.parse!
|
55
|
+
}
|
56
|
+
|
57
|
+
# Parse test patterns
|
58
|
+
ARGV.each {|pat| patterns << Regexp::new( pat, Regexp::IGNORECASE )}
|
59
|
+
$stderr.puts "#{patterns.length} patterns given on the command line"
|
60
|
+
|
61
|
+
### Load all the tests from the tests dir
|
62
|
+
Find.find( File::join($basedir,"tests") ) {|file|
|
63
|
+
Find.prune if /\/\./ =~ file or /~$/ =~ file
|
64
|
+
Find.prune if /TEMPLATE/ =~ file
|
65
|
+
next if File.stat( file ).directory?
|
66
|
+
|
67
|
+
unless patterns.empty?
|
68
|
+
Find.prune unless patterns.find {|pat| pat =~ file}
|
69
|
+
end
|
70
|
+
|
71
|
+
debugMsg "Considering '%s': " % file
|
72
|
+
next unless file =~ /\.tests.rb$/
|
73
|
+
debugMsg "Requiring '%s'..." % file
|
74
|
+
require "#{file}"
|
75
|
+
requires << file
|
76
|
+
}
|
77
|
+
|
78
|
+
$stderr.puts "Required #{requires.length} files."
|
79
|
+
unless patterns.empty?
|
80
|
+
$stderr.puts "[" + requires.sort.join( ", " ) + "]"
|
81
|
+
end
|
82
|
+
|
83
|
+
# Build the test suite
|
84
|
+
class LinguisticsTests
|
85
|
+
class << self
|
86
|
+
def suite
|
87
|
+
suite = Test::Unit::TestSuite.new( "Linguistics" )
|
88
|
+
|
89
|
+
if suite.respond_to?( :add )
|
90
|
+
ObjectSpace.each_object( Class ) {|klass|
|
91
|
+
suite.add( klass.suite ) if klass < Linguistics::TestCase
|
92
|
+
}
|
93
|
+
else
|
94
|
+
ObjectSpace.each_object( Class ) {|klass|
|
95
|
+
suite << klass.suite if klass < Linguistics::TestCase
|
96
|
+
}
|
97
|
+
end
|
98
|
+
|
99
|
+
return suite
|
100
|
+
end
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
104
|
+
# Run tests
|
105
|
+
$SAFE = safelevel
|
106
|
+
Test::Unit::UI::Console::TestRunner.new( LinguisticsTests ).start
|
107
|
+
|
108
|
+
|
109
|
+
|
110
|
+
|
@@ -0,0 +1,114 @@
|
|
1
|
+
#!/usr/bin/ruby -w
|
2
|
+
#
|
3
|
+
# Unit test for English conjunctions
|
4
|
+
# $Id: conjunction.tests.rb,v 1.2 2003/09/11 05:03:12 deveiant Exp $
|
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 suite tests the stage1 (static) parser and the metagrammar it
|
18
|
+
### parses in which the actual parser-generator's behaviour is defined.
|
19
|
+
class EnglishConjunctionsTestCase < Linguistics::TestCase
|
20
|
+
|
21
|
+
Linguistics::use( :en )
|
22
|
+
include Linguistics::EN
|
23
|
+
|
24
|
+
Tests = {
|
25
|
+
# Test name => {
|
26
|
+
# target => {
|
27
|
+
# {<options>} => <expected output>
|
28
|
+
# },
|
29
|
+
:singleWord => {
|
30
|
+
['cat'] => {
|
31
|
+
{} => %{a cat}
|
32
|
+
},
|
33
|
+
},
|
34
|
+
|
35
|
+
:twoWord => {
|
36
|
+
%w{cat dog} => {
|
37
|
+
{} => 'a cat and a dog',
|
38
|
+
{:conjunctive => 'plus'} => 'a cat plus a dog',
|
39
|
+
{:conjunctive => ''} => 'a cat a dog',
|
40
|
+
},
|
41
|
+
%w{cat Cat} => {
|
42
|
+
{} => %{two cats},
|
43
|
+
{:combine => false} => 'a cat and a Cat',
|
44
|
+
{:casefold => false} => 'a cat and a Cat',
|
45
|
+
{:generalize => true} => 'several cats',
|
46
|
+
},
|
47
|
+
},
|
48
|
+
|
49
|
+
:manyWord => {
|
50
|
+
%w{cat dog fox dog chicken chicken Fox chicken goose Dog goose} => {
|
51
|
+
{} => 'three dogs, three chickens, two foxes, two geese, and a cat',
|
52
|
+
{:combine => false} =>
|
53
|
+
'a cat, a dog, a fox, a dog, a chicken, a chicken, a Fox, a '\
|
54
|
+
'chicken, a goose, a Dog, and a goose',
|
55
|
+
{:casefold => false} =>
|
56
|
+
'three chickens, two dogs, two geese, a cat, a fox, a Fox, '\
|
57
|
+
'and a Dog',
|
58
|
+
{:generalize => true} =>
|
59
|
+
'several dogs, several chickens, several foxes, several '\
|
60
|
+
'geese, and a cat',
|
61
|
+
}
|
62
|
+
},
|
63
|
+
}
|
64
|
+
|
65
|
+
# Auto-generate tests for the dataset
|
66
|
+
Tests.each_with_index {|test,i|
|
67
|
+
name = test[0]
|
68
|
+
methname = "test_%03d_%s" %
|
69
|
+
[ i + 50, name ]
|
70
|
+
define_method( methname ) {
|
71
|
+
printTestHeader "Conjunction: #{name}"
|
72
|
+
Tests[name].each {|target, tests|
|
73
|
+
rval = nil
|
74
|
+
tests.each {|opts, output|
|
75
|
+
op = "conjunction of %s with options=%s" %
|
76
|
+
[ target.inspect, opts.inspect ]
|
77
|
+
|
78
|
+
# Method interface
|
79
|
+
assert_nothing_raised( op ) {
|
80
|
+
rval = target.en.conjunction( opts )
|
81
|
+
}
|
82
|
+
assert_equal output, rval, op
|
83
|
+
|
84
|
+
# Function interface
|
85
|
+
assert_nothing_raised( op ) {
|
86
|
+
rval = conjunction( target, opts )
|
87
|
+
}
|
88
|
+
assert_equal output, rval, op
|
89
|
+
}
|
90
|
+
}
|
91
|
+
}
|
92
|
+
}
|
93
|
+
|
94
|
+
### Overridden initializer: auto-generated test methods have an arity of 1
|
95
|
+
### even though they don't require an argument (as of the current Ruby CVS),
|
96
|
+
### and the default initializer throws an :invalid_test for methods with
|
97
|
+
### arity != 0.
|
98
|
+
def initialize( test_method_name )
|
99
|
+
if !respond_to?( test_method_name )
|
100
|
+
throw :invalid_test
|
101
|
+
end
|
102
|
+
@method_name = test_method_name
|
103
|
+
@test_passed = true
|
104
|
+
end
|
105
|
+
|
106
|
+
|
107
|
+
#################################################################
|
108
|
+
### T E S T S
|
109
|
+
#################################################################
|
110
|
+
|
111
|
+
|
112
|
+
|
113
|
+
end
|
114
|
+
|