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/README
ADDED
@@ -0,0 +1,178 @@
|
|
1
|
+
|
2
|
+
= Linguistics
|
3
|
+
|
4
|
+
== Authors
|
5
|
+
|
6
|
+
* Michael Granger <ged@FaerieMUD.org>
|
7
|
+
* Martin Chase <stillflame@FaerieMUD.org>
|
8
|
+
|
9
|
+
|
10
|
+
== Requirements
|
11
|
+
|
12
|
+
* Ruby >= 1.8.0
|
13
|
+
|
14
|
+
The following libraries are required, but are included in the redist/
|
15
|
+
directory. The installer script should install these for you if you don't
|
16
|
+
already have them.
|
17
|
+
|
18
|
+
* HashSlice - Adds slicing to the builtin Hash class
|
19
|
+
|
20
|
+
|
21
|
+
== Optional
|
22
|
+
|
23
|
+
* CrossCase - Provide auto-aliasing of camelCase to under_barred methods and
|
24
|
+
vice-versa. (Included in redist/)
|
25
|
+
|
26
|
+
* Ruby-WordNet (>= 0.02) - adds integration for the Ruby binding for the WordNet� lexical
|
27
|
+
reference system.
|
28
|
+
|
29
|
+
URL: http://www.deveiate.org/code/Ruby-WordNet.html
|
30
|
+
Download: http://www.deveiate.org/code/Ruby-WordNet-0.02.tar.gz
|
31
|
+
|
32
|
+
* LinkParser (>= 0.0.4) - adds integration for the Ruby Link Grammar Parser by
|
33
|
+
Martin Chase.
|
34
|
+
|
35
|
+
URL: http://dev.faeriemud.org/~stillflame/linkparse.html
|
36
|
+
Download: http://www.faeriemud.org/code/Ruby-LinkParser-0.0.4.tgz
|
37
|
+
|
38
|
+
|
39
|
+
== General Information
|
40
|
+
|
41
|
+
This module is a framework for building linguistic utilities for Ruby objects in
|
42
|
+
any language. It includes a generic language-independant front end, a module for
|
43
|
+
mapping language codes into language names, and a module which contains various
|
44
|
+
English-language utilities.
|
45
|
+
|
46
|
+
|
47
|
+
=== Method Interface
|
48
|
+
|
49
|
+
The Linguistics module comes with a language-independant mechanism for extending
|
50
|
+
core Ruby classes with linguistic methods.
|
51
|
+
|
52
|
+
It consists of three parts: a core linguistics module which contains the
|
53
|
+
class-extension framework for languages, a generic inflector class that serves
|
54
|
+
as a delegator for linguistic methods on Ruby objects, and one or more
|
55
|
+
language-specific modules which contain the actual linguistic functions.
|
56
|
+
|
57
|
+
The module works by adding a single instance method for each language named
|
58
|
+
after the language's two-letter code (or three-letter code, if no two-letter
|
59
|
+
code is defined by ISO639) to various Ruby classes. This allows many
|
60
|
+
language-specific methods to be added to objects without cluttering up the
|
61
|
+
interface or risking collision between them, albeit at the cost of three or four
|
62
|
+
more characters per method invocation.
|
63
|
+
|
64
|
+
If you don't like extending core Ruby classes, the language modules should also
|
65
|
+
allow you to use them as a function library as well.
|
66
|
+
|
67
|
+
For example, the English-language module contains a #plural function which can
|
68
|
+
be accessed via a method on a core class:
|
69
|
+
|
70
|
+
Linguistics::use( :en )
|
71
|
+
"goose".en.plural
|
72
|
+
# => "geese"
|
73
|
+
|
74
|
+
or via the Linguistics::EN::plural function directly:
|
75
|
+
|
76
|
+
include Linguistics::EN
|
77
|
+
plural( "goose" )
|
78
|
+
# => "geese"
|
79
|
+
|
80
|
+
The class-extension mechanism actually uses the functional interface behind the
|
81
|
+
scenes.
|
82
|
+
|
83
|
+
A new feature with the 0.02 release: You can now omit the language-code method
|
84
|
+
for unambiguous methods by calling Linguistics::use with the +:installProxy+
|
85
|
+
configuration key, with the language code of the language module whose methods
|
86
|
+
you wish to be available. For example, instead of having to call:
|
87
|
+
|
88
|
+
"goose".en.plural
|
89
|
+
|
90
|
+
from the example above, you can now do this:
|
91
|
+
|
92
|
+
Lingusitics::use( :en, :installProxy => :en )
|
93
|
+
"goose".plural
|
94
|
+
# => "geese"
|
95
|
+
|
96
|
+
More about how this works in the documentation for Linguistics::use.
|
97
|
+
|
98
|
+
|
99
|
+
==== Adding Language Modules
|
100
|
+
|
101
|
+
To add a new language to the framework, create a file named the same as the
|
102
|
+
ISO639 2- or 3-letter language code for the language you're adding. It must be
|
103
|
+
placed under lib/linguistics/ to be recognized by the linguistics module, but
|
104
|
+
you can also just require it yourself prior to calling Linguistics::use(). This
|
105
|
+
file should define a module under Linguistics that is an all-caps version of the
|
106
|
+
code used in the filename. Any methods you wish to be exposed to users should be
|
107
|
+
declared as module functions (ie., using Module#module_function).
|
108
|
+
|
109
|
+
You may also wish to add your module to the list of default languages by adding
|
110
|
+
the appropriate symbol to the Linguistics::DefaultLanguages array.
|
111
|
+
|
112
|
+
For example, to create a Portuguese-language module, create a file called
|
113
|
+
'lib/linguistics/pt.rb' which contains the following:
|
114
|
+
|
115
|
+
module Linguistics
|
116
|
+
module PT
|
117
|
+
Linguistics::DefaultLanguages << :pt
|
118
|
+
|
119
|
+
module_function
|
120
|
+
<language methods here>
|
121
|
+
end
|
122
|
+
end
|
123
|
+
|
124
|
+
See the English language module (lib/linguistics/en.rb) for an example.
|
125
|
+
|
126
|
+
|
127
|
+
=== English Language Module
|
128
|
+
|
129
|
+
See the README.english file for a synopsis.
|
130
|
+
|
131
|
+
The English-language module currently contains linguistic functions ported from
|
132
|
+
a few excellent Perl modules:
|
133
|
+
|
134
|
+
Lingua::EN::Inflect
|
135
|
+
Lingua::Conjunction
|
136
|
+
Lingua::EN::Infinitive
|
137
|
+
|
138
|
+
See the lib/linguistics/en.rb file for specific attributions.
|
139
|
+
|
140
|
+
New with version 0.02: integration with the Ruby WordNet� and LinkParser modules
|
141
|
+
(which must be installed separately).
|
142
|
+
|
143
|
+
|
144
|
+
== To Do
|
145
|
+
|
146
|
+
* I am planning on improving the results from the infinitive functions, which
|
147
|
+
currently return useful results only part of the time. Investigations into
|
148
|
+
additional stemming functions and some other strategies are ongoing.
|
149
|
+
|
150
|
+
* Martin Chase <stillflame at FaerieMUD dot org> is working on an integration
|
151
|
+
module for his excellent work on a Ruby interface to the CMU Link Grammar (an
|
152
|
+
english-sentence parser). This will make writing fairly accurate natural
|
153
|
+
language parsers in Ruby much easier.
|
154
|
+
|
155
|
+
* Suggestions (and patches) for any of these items or additional features are
|
156
|
+
welcomed.
|
157
|
+
|
158
|
+
|
159
|
+
|
160
|
+
== Legal
|
161
|
+
|
162
|
+
This module is Open Source Software which is Copyright (c) 2003 by The FaerieMUD
|
163
|
+
Consortium. All rights reserved.
|
164
|
+
|
165
|
+
You may use, modify, and/or redistribute this software under the terms of the
|
166
|
+
Perl Artistic License, a copy of which should have been included in this
|
167
|
+
distribution (See the file Artistic). If it was not, a copy of it may be
|
168
|
+
obtained from http://language.perl.com/misc/Artistic.html or
|
169
|
+
http://www.faeriemud.org/artistic.html).
|
170
|
+
|
171
|
+
THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES,
|
172
|
+
INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND
|
173
|
+
FITNESS FOR A PARTICULAR PURPOSE.
|
174
|
+
|
175
|
+
|
176
|
+
$Id: README,v 1.6 2003/10/09 13:21:48 deveiant Exp $
|
177
|
+
|
178
|
+
|
data/README.english
ADDED
@@ -0,0 +1,245 @@
|
|
1
|
+
|
2
|
+
= English Ruby Linguistics Module - Synopsis
|
3
|
+
|
4
|
+
This is an overview of the functionality currently in the English functions of
|
5
|
+
the Ruby Linguistics module as of version 0.02:
|
6
|
+
|
7
|
+
|
8
|
+
== Pluralization
|
9
|
+
|
10
|
+
require 'linguistics'
|
11
|
+
Linguistics::use( :en ) # extends Array, String, and Numeric
|
12
|
+
|
13
|
+
"box".en.plural
|
14
|
+
# => "boxes"
|
15
|
+
|
16
|
+
"mouse".en.plural
|
17
|
+
# => "mice"
|
18
|
+
|
19
|
+
"ruby".en.plural
|
20
|
+
# => "rubies"
|
21
|
+
|
22
|
+
|
23
|
+
== Indefinite Articles
|
24
|
+
|
25
|
+
"book".en.a
|
26
|
+
# => "a book"
|
27
|
+
|
28
|
+
"article".en.a
|
29
|
+
# => "an article"
|
30
|
+
|
31
|
+
|
32
|
+
== Present Participles
|
33
|
+
|
34
|
+
"runs".en.present_participle
|
35
|
+
# => "running"
|
36
|
+
|
37
|
+
"eats".en.present_participle
|
38
|
+
# => "eating"
|
39
|
+
|
40
|
+
"spies".en.present_participle
|
41
|
+
# => "spying"
|
42
|
+
|
43
|
+
|
44
|
+
== Ordinal Numbers
|
45
|
+
|
46
|
+
5.en.ordinal
|
47
|
+
# => "5th"
|
48
|
+
|
49
|
+
2004.en.ordinal
|
50
|
+
# => "2004th"
|
51
|
+
|
52
|
+
|
53
|
+
== Numbers to Words
|
54
|
+
|
55
|
+
5.en.numwords
|
56
|
+
# => "five"
|
57
|
+
|
58
|
+
2004.en.numwords
|
59
|
+
# => "two thousand and four"
|
60
|
+
|
61
|
+
2385762345876.en.numwords
|
62
|
+
# => "two trillion, three hundred and eighty-five billion,
|
63
|
+
seven hundred and sixty-two million, three hundred and
|
64
|
+
forty-five thousand, eight hundred and seventy-six"
|
65
|
+
|
66
|
+
|
67
|
+
== Quantification
|
68
|
+
|
69
|
+
"cow".en.quantify( 5 )
|
70
|
+
# => "several cows"
|
71
|
+
|
72
|
+
"cow".en.quantify( 1005 )
|
73
|
+
# => "thousands of cows"
|
74
|
+
|
75
|
+
"cow".en.quantify( 20_432_123_000_000 )
|
76
|
+
# => "tens of trillions of cows"
|
77
|
+
|
78
|
+
|
79
|
+
== Conjunctions
|
80
|
+
|
81
|
+
animals = %w{dog cow ox chicken goose goat cow dog rooster llama
|
82
|
+
pig goat dog cat cat dog cow goat goose goose ox alpaca}
|
83
|
+
puts "The farm has: " + animals.en.conjunction
|
84
|
+
|
85
|
+
# => The farm has: four dogs, three cows, three geese, three goats,
|
86
|
+
two oxen, two cats, a chicken, a rooster, a llama, a pig,
|
87
|
+
and an alpaca
|
88
|
+
|
89
|
+
Note that 'goose' and 'ox' are both correctly pluralized, and the correct
|
90
|
+
indefinite article 'an' has been used for 'alpaca'.
|
91
|
+
|
92
|
+
You can also use the generalization function of the #quantify method to give
|
93
|
+
general descriptions of object lists instead of literal counts:
|
94
|
+
|
95
|
+
allobjs = []
|
96
|
+
ObjectSpace::each_object {|obj| allobjs << obj.class.name}
|
97
|
+
|
98
|
+
puts "The current Ruby objectspace contains: " +
|
99
|
+
allobjs.en.conjunction( :generalize => true )
|
100
|
+
|
101
|
+
which will print something like:
|
102
|
+
|
103
|
+
The current Ruby objectspace contains: thousands of Strings,
|
104
|
+
thousands of Arrays, hundreds of Hashes, hundreds of
|
105
|
+
Classes, many Regexps, a number of Ranges, a number of
|
106
|
+
Modules, several Floats, several Procs, several MatchDatas,
|
107
|
+
several Objects, several IOS, several Files, a Binding, a
|
108
|
+
NoMemoryError, a SystemStackError, a fatal, a ThreadGroup,
|
109
|
+
and a Thread
|
110
|
+
|
111
|
+
|
112
|
+
== Infinitives
|
113
|
+
|
114
|
+
New in version 0.02:
|
115
|
+
|
116
|
+
"leaving".en.infinitive
|
117
|
+
# => "leave"
|
118
|
+
|
119
|
+
"left".en.infinitive
|
120
|
+
# => "leave"
|
121
|
+
|
122
|
+
"leaving".en.infinitive.suffix
|
123
|
+
# => "ing"
|
124
|
+
|
125
|
+
|
126
|
+
== WordNet� Integration
|
127
|
+
|
128
|
+
Also new in version 0.02, if you have the Ruby-WordNet module installed, you can
|
129
|
+
look up WordNet synsets using the Linguistics interface:
|
130
|
+
|
131
|
+
# Test to be sure the WordNet module loaded okay.
|
132
|
+
Linguistics::EN.has_wordnet?
|
133
|
+
# => true
|
134
|
+
|
135
|
+
# Fetch the default synset for the word "balance"
|
136
|
+
"balance".synset
|
137
|
+
# => #<WordNet::Synset:0x40376844 balance (noun): "a state of equilibrium"
|
138
|
+
(derivations: 3, antonyms: 1, hypernyms: 1, hyponyms: 3)>
|
139
|
+
|
140
|
+
# Fetch the synset for the first verb sense of "balance"
|
141
|
+
"balance".en.synset( :verb )
|
142
|
+
# => #<WordNet::Synset:0x4033f448 balance, equilibrate, equilibrize, equilibrise
|
143
|
+
(verb): "bring into balance or equilibrium; "She has to balance work and her
|
144
|
+
domestic duties"; "balance the two weights"" (derivations: 7, antonyms: 1,
|
145
|
+
verbGroups: 2, hypernyms: 1, hyponyms: 5)>
|
146
|
+
|
147
|
+
# Fetch the second noun sense
|
148
|
+
"balance".en.synset( 2, :noun )
|
149
|
+
# => #<WordNet::Synset:0x404ebb24 balance (noun): "a scale for weighing; depends
|
150
|
+
on pull of gravity" (hypernyms: 1, hyponyms: 5)>
|
151
|
+
|
152
|
+
# Fetch the second noun sense's hypernyms (more-general words, like a superclass)
|
153
|
+
"balance".en.synset( 2, :noun ).hypernyms
|
154
|
+
# => [#<WordNet::Synset:0x404e5620 scale, weighing machine (noun): "a measuring
|
155
|
+
instrument for weighing; shows amount of mass" (derivations: 2, hypernyms: 1,
|
156
|
+
hyponyms: 2)>]
|
157
|
+
|
158
|
+
# A simpler way of doing the same thing:
|
159
|
+
"balance".en.hypernyms( 2, :noun )
|
160
|
+
# => [#<WordNet::Synset:0x404e5620 scale, weighing machine (noun): "a measuring
|
161
|
+
instrument for weighing; shows amount of mass" (derivations: 2, hypernyms: 1,
|
162
|
+
hyponyms: 2)>]
|
163
|
+
|
164
|
+
# Fetch the first hypernym's hypernyms
|
165
|
+
"balance".en.synset( 2, :noun ).hypernyms.first.hypernyms
|
166
|
+
# => [#<WordNet::Synset:0x404c60b8 measuring instrument, measuring system,
|
167
|
+
measuring device (noun): "instrument that shows the extent or amount or quantity
|
168
|
+
or degree of something" (hypernyms: 1, hyponyms: 83)>]
|
169
|
+
|
170
|
+
# Find the synset to which both the second noun sense of "balance" and the
|
171
|
+
# default sense of "shovel" belong.
|
172
|
+
("balance".en.synset( 2, :noun ) | "shovel".en.synset)
|
173
|
+
# => #<WordNet::Synset:0x40473da4 instrumentality, instrumentation (noun): "an
|
174
|
+
artifact (or system of artifacts) that is instrumental in accomplishing some
|
175
|
+
end" (derivations: 1, hypernyms: 1, hyponyms: 13)>
|
176
|
+
|
177
|
+
# Fetch just the words for the other kinds of "instruments"
|
178
|
+
"instrument".en.hyponyms.collect {|synset| synset.words}.flatten
|
179
|
+
# => ["analyzer", "analyser", "cautery", "cauterant", "drafting instrument",
|
180
|
+
"extractor", "instrument of execution", "instrument of punishment", "measuring
|
181
|
+
instrument", "measuring system", "measuring device", "medical instrument",
|
182
|
+
"navigational instrument", "optical instrument", "plotter", "scientific
|
183
|
+
instrument", "sonograph", "surveying instrument", "surveyor's instrument",
|
184
|
+
"tracer", "weapon", "arm", "weapon system", "whip"]
|
185
|
+
|
186
|
+
There are many more WordNet methods supported � too many to list here. See the
|
187
|
+
documentation for the complete list.
|
188
|
+
|
189
|
+
|
190
|
+
== LinkParser Integration
|
191
|
+
|
192
|
+
Another new feature in version 0.02 is integration with the Ruby version of the
|
193
|
+
CMU Link Grammar Parser by Martin Chase. If you have the LinkParser module
|
194
|
+
installed, you can create linkages from English sentences that let you query for
|
195
|
+
parts of speech:
|
196
|
+
|
197
|
+
# Test to see whether or not the link parser is loaded.
|
198
|
+
Linguistics::EN.has_link_parser?
|
199
|
+
# => true
|
200
|
+
|
201
|
+
# Diagram the first linkage for a test sentence
|
202
|
+
puts "he is a big dog".sentence.linkages.first.to_s
|
203
|
+
+---O*---+
|
204
|
+
| +--Ds--+
|
205
|
+
+Ss+ | +-A-+
|
206
|
+
| | | | |
|
207
|
+
he is a big dog
|
208
|
+
|
209
|
+
# Find the verb in the sentence
|
210
|
+
"he is a big dog".en.sentence.verb.to_s
|
211
|
+
# => "is"
|
212
|
+
|
213
|
+
# Combined infinitive + LinkParser: Find the infinitive form of the verb of the
|
214
|
+
given sentence.
|
215
|
+
"he is a big dog".en.sentence.verb.infinitive
|
216
|
+
# => "be"
|
217
|
+
|
218
|
+
# Find the direct object of the sentence
|
219
|
+
"he is a big dog".en.sentence.object.to_s
|
220
|
+
# => "dog"
|
221
|
+
|
222
|
+
# Look at the raw LinkParser::Word for the direct object of the sentence.
|
223
|
+
"he is a big dog".en.sentence.object
|
224
|
+
# => #<LinkParser::Word:0x403da0a0 @definition=[[{@A-}, Ds-, {@M+}, J-], [{@A-},
|
225
|
+
Ds-, {@M+}, Os-], [{@A-}, Ds-, {@M+}, Ss+, {@CO-}, {C-}], [{@A-}, Ds-, {@M+},
|
226
|
+
Ss+, R-], [{@A-}, Ds-, {@M+}, SIs-], [{@A-}, Ds-, {R+}, {Bs+}, J-], [{@A-}, Ds-,
|
227
|
+
{R+}, {Bs+}, Os-], [{@A-}, Ds-, {R+}, {Bs+}, Ss+, {@CO-}, {C-}], [{@A-}, Ds-,
|
228
|
+
{R+}, {Bs+}, Ss+, R-], [{@A-}, Ds-, {R+}, {Bs+}, SIs-]], @right=[], @suffix="",
|
229
|
+
@left=[#<LinkParser::Connection:0x403da028 @rword=#<LinkParser::Word:0x403da0a0
|
230
|
+
...>, @lword=#<LinkParser::Word:0x403da0b4 @definition=[[Ss-, O+, {@MV+}], [Ss-,
|
231
|
+
B-, {@MV+}], [Ss-, P+], [Ss-, AF-], [RS-, Bs-, O+, {@MV+}], [RS-, Bs-, B-,
|
232
|
+
{@MV+}], [RS-, Bs-, P+], [RS-, Bs-, AF-], [{Q-}, SIs+, O+, {@MV+}], [{Q-}, SIs+,
|
233
|
+
B-, {@MV+}], [{Q-}, SIs+, P+], [{Q-}, SIs+, AF-]],
|
234
|
+
@right=[#<LinkParser::Connection:0x403da028 ...>], @suffix="", @left=[],
|
235
|
+
@name="is", @position=1>, @subName="*", @name="O", @length=3>], @name="dog",
|
236
|
+
@position=4>
|
237
|
+
|
238
|
+
# Combine WordNet + LinkParser to find the definition of the direct object of
|
239
|
+
# the sentence
|
240
|
+
"he is a big dog".en.sentence.object.gloss
|
241
|
+
# => "a member of the genus Canis (probably descended from the common wolf) that
|
242
|
+
has been domesticated by man since prehistoric times; occurs in many breeds;
|
243
|
+
\"the dog barked all night\""
|
244
|
+
|
245
|
+
|
data/TODO
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
|
2
|
+
= Linguistics Module To-Do List
|
3
|
+
|
4
|
+
* Add missing Lingua::EN::Inflect features:
|
5
|
+
* Number-insensitive Equality methods, e.g., +PL_eq()+, +PL_N_eq()+, etc.
|
6
|
+
* String iterpolation methods? This can already be done via things like +"The
|
7
|
+
#{'cat'.en.no(catCount)} in the hat."+, but it might be nice to have some
|
8
|
+
more convenient notation and an #interpolate method.
|
9
|
+
* User-defined inflections
|
10
|
+
|
11
|
+
* Ask the stemmable.rb authors if they'd let me put it into the en.rb module.
|
12
|
+
|
13
|
+
* Port more Perl modules:
|
14
|
+
* Lingua::Phonology?
|
15
|
+
* Others?
|
16
|
+
|
17
|
+
|
@@ -0,0 +1,34 @@
|
|
1
|
+
#!/usr/bin/ruby
|
2
|
+
|
3
|
+
BEGIN {
|
4
|
+
$LOAD_PATH.unshift File::dirname(File::dirname( __FILE__ )) + "/lib"
|
5
|
+
require 'linguistics'
|
6
|
+
}
|
7
|
+
|
8
|
+
Linguistics::use( :en )
|
9
|
+
|
10
|
+
# Just a fun little demo of the conjunction (junction, what's your) function.
|
11
|
+
|
12
|
+
MinObjects = 5
|
13
|
+
MaxObjects = 35
|
14
|
+
Objects = %w[
|
15
|
+
butcher baker candlestick-maker
|
16
|
+
mouse clock
|
17
|
+
cat fiddle cow moon dog sport dish spoon
|
18
|
+
tisket tasket
|
19
|
+
jack jill hill pail crown
|
20
|
+
]
|
21
|
+
|
22
|
+
def randobjlist
|
23
|
+
objs = []
|
24
|
+
0.upto( rand(MaxObjects - MinObjects) + MinObjects ) do
|
25
|
+
objs << Objects[ rand(Objects.nitems) - 1 ]
|
26
|
+
end
|
27
|
+
|
28
|
+
return objs
|
29
|
+
end
|
30
|
+
|
31
|
+
|
32
|
+
puts "Random object list:\n\t" +
|
33
|
+
randobjlist().en.conjunction
|
34
|
+
|
data/install.rb
ADDED
@@ -0,0 +1,154 @@
|
|
1
|
+
#!/usr/bin/ruby
|
2
|
+
#
|
3
|
+
# Linguistics Module Install Script
|
4
|
+
# $Id: install.rb,v 1.3 2003/10/09 13:23:09 deveiant Exp $
|
5
|
+
#
|
6
|
+
# Thanks to Masatoshi SEKI for ideas found in his install.rb.
|
7
|
+
#
|
8
|
+
# Copyright (c) 2001-2004 The FaerieMUD Consortium.
|
9
|
+
#
|
10
|
+
# This is free software. You may use, modify, and/or redistribute this
|
11
|
+
# software under the terms of the Perl Artistic License. (See
|
12
|
+
# http://language.perl.com/misc/Artistic.html)
|
13
|
+
#
|
14
|
+
|
15
|
+
require './utils.rb'
|
16
|
+
include UtilityFunctions
|
17
|
+
|
18
|
+
require 'rbconfig'
|
19
|
+
include Config
|
20
|
+
|
21
|
+
require 'find'
|
22
|
+
require 'ftools'
|
23
|
+
|
24
|
+
|
25
|
+
$version = %q$Revision: 1.3 $
|
26
|
+
$rcsId = %q$Id: install.rb,v 1.3 2003/10/09 13:23:09 deveiant Exp $
|
27
|
+
|
28
|
+
# Define required libraries
|
29
|
+
RequiredLibraries = [
|
30
|
+
# libraryname, nice name, RAA URL, Download URL
|
31
|
+
# [ 'hashslice', "Ruby-Hashslice",
|
32
|
+
# 'http://www.ruby-lang.org/en/raa-list.rhtml?name=Ruby-HashSlice',
|
33
|
+
# 'http://www.devEiate.org/code/Ruby-HashSlice-1.03.tar.gz' ],
|
34
|
+
]
|
35
|
+
|
36
|
+
class Installer
|
37
|
+
|
38
|
+
@@PrunePatterns = [
|
39
|
+
/CVS/,
|
40
|
+
/~$/,
|
41
|
+
%r:(^|/)\.:,
|
42
|
+
/\.tpl$/,
|
43
|
+
]
|
44
|
+
|
45
|
+
def initialize( testing=false )
|
46
|
+
@ftools = (testing) ? self : File
|
47
|
+
end
|
48
|
+
|
49
|
+
### Make the specified dirs (which can be a String or an Array of Strings)
|
50
|
+
### with the specified mode.
|
51
|
+
def makedirs( dirs, mode=0755, verbose=false )
|
52
|
+
dirs = [ dirs ] unless dirs.is_a? Array
|
53
|
+
|
54
|
+
oldumask = File::umask
|
55
|
+
File::umask( 0777 - mode )
|
56
|
+
|
57
|
+
for dir in dirs
|
58
|
+
if @ftools == File
|
59
|
+
File::mkpath( dir, $verbose )
|
60
|
+
else
|
61
|
+
$stderr.puts "Make path %s with mode %o" % [ dir, mode ]
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
File::umask( oldumask )
|
66
|
+
end
|
67
|
+
|
68
|
+
def install( srcfile, dstfile, mode=nil, verbose=false )
|
69
|
+
dstfile = File.catname(srcfile, dstfile)
|
70
|
+
unless FileTest.exist? dstfile and File.cmp srcfile, dstfile
|
71
|
+
$stderr.puts " install #{srcfile} -> #{dstfile}"
|
72
|
+
else
|
73
|
+
$stderr.puts " skipping #{dstfile}: unchanged"
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
public
|
78
|
+
|
79
|
+
def installFiles( src, dstDir, mode=0444, verbose=false )
|
80
|
+
directories = []
|
81
|
+
files = []
|
82
|
+
|
83
|
+
if File.directory?( src )
|
84
|
+
Find.find( src ) {|f|
|
85
|
+
Find.prune if @@PrunePatterns.find {|pat| f =~ pat}
|
86
|
+
next if f == src
|
87
|
+
|
88
|
+
if FileTest.directory?( f )
|
89
|
+
directories << f.gsub( /^#{src}#{File::Separator}/, '' )
|
90
|
+
next
|
91
|
+
|
92
|
+
elsif FileTest.file?( f )
|
93
|
+
files << f.gsub( /^#{src}#{File::Separator}/, '' )
|
94
|
+
|
95
|
+
else
|
96
|
+
Find.prune
|
97
|
+
end
|
98
|
+
}
|
99
|
+
else
|
100
|
+
files << File.basename( src )
|
101
|
+
src = File.dirname( src )
|
102
|
+
end
|
103
|
+
|
104
|
+
dirs = [ dstDir ]
|
105
|
+
dirs |= directories.collect {|d| File.join(dstDir,d)}
|
106
|
+
makedirs( dirs, 0755, verbose )
|
107
|
+
files.each {|f|
|
108
|
+
srcfile = File.join(src,f)
|
109
|
+
dstfile = File.dirname(File.join( dstDir,f ))
|
110
|
+
|
111
|
+
if verbose
|
112
|
+
if mode
|
113
|
+
$stderr.puts "Install #{srcfile} -> #{dstfile} (mode %o)" % mode
|
114
|
+
else
|
115
|
+
$stderr.puts "Install #{srcfile} -> #{dstfile}"
|
116
|
+
end
|
117
|
+
end
|
118
|
+
|
119
|
+
@ftools.install( srcfile, dstfile, mode, verbose )
|
120
|
+
}
|
121
|
+
end
|
122
|
+
|
123
|
+
end
|
124
|
+
|
125
|
+
if $0 == __FILE__
|
126
|
+
header "Linguistics Installer #$version"
|
127
|
+
|
128
|
+
for lib in RequiredLibraries
|
129
|
+
testForRequiredLibrary( *lib )
|
130
|
+
end
|
131
|
+
|
132
|
+
viewOnly = ARGV.include? '-n'
|
133
|
+
verbose = ARGV.include? '-v'
|
134
|
+
|
135
|
+
# "Compatibility" with Aoki-san's install.rb
|
136
|
+
if ARGV.include?( 'config' ) || ARGV.include?( 'setup' )
|
137
|
+
print "Ok."
|
138
|
+
exit
|
139
|
+
end
|
140
|
+
|
141
|
+
debugMsg "Sitelibdir = '#{CONFIG['sitelibdir']}'"
|
142
|
+
sitelibdir = CONFIG['sitelibdir']
|
143
|
+
debugMsg "Sitearchdir = '#{CONFIG['sitearchdir']}'"
|
144
|
+
sitearchdir = CONFIG['sitearchdir']
|
145
|
+
|
146
|
+
message "Installing\n"
|
147
|
+
i = Installer.new( viewOnly )
|
148
|
+
i.installFiles( "redist", sitelibdir, 0444, verbose )
|
149
|
+
i.installFiles( "lib", sitelibdir, 0444, verbose )
|
150
|
+
end
|
151
|
+
|
152
|
+
|
153
|
+
|
154
|
+
|