linguistics 1.0.9 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data.tar.gz.sig +0 -0
- data/.gemtest +0 -0
- data/ChangeLog +849 -342
- data/History.rdoc +11 -0
- data/LICENSE +9 -9
- data/Manifest.txt +44 -0
- data/README.rdoc +226 -0
- data/Rakefile +32 -349
- data/examples/endocs.rb +272 -0
- data/examples/generalize_sentence.rb +2 -1
- data/examples/klingon.rb +22 -0
- data/lib/linguistics.rb +130 -292
- data/lib/linguistics/en.rb +337 -1628
- data/lib/linguistics/en/articles.rb +138 -0
- data/lib/linguistics/en/conjugation.rb +2245 -0
- data/lib/linguistics/en/conjunctions.rb +202 -0
- data/lib/linguistics/en/{infinitive.rb → infinitives.rb} +41 -55
- data/lib/linguistics/en/linkparser.rb +41 -49
- data/lib/linguistics/en/numbers.rb +483 -0
- data/lib/linguistics/en/participles.rb +33 -0
- data/lib/linguistics/en/pluralization.rb +810 -0
- data/lib/linguistics/en/stemmer.rb +75 -0
- data/lib/linguistics/en/titlecase.rb +121 -0
- data/lib/linguistics/en/wordnet.rb +63 -97
- data/lib/linguistics/inflector.rb +89 -0
- data/lib/linguistics/iso639.rb +534 -448
- data/lib/linguistics/languagebehavior.rb +36 -0
- data/lib/linguistics/monkeypatches.rb +42 -0
- data/spec/lib/constants.rb +15 -0
- data/spec/lib/helpers.rb +38 -0
- data/spec/linguistics/en/articles_spec.rb +797 -0
- data/spec/linguistics/en/conjugation_spec.rb +2083 -0
- data/spec/linguistics/en/conjunctions_spec.rb +154 -0
- data/spec/linguistics/en/infinitives_spec.rb +518 -0
- data/spec/linguistics/en/linkparser_spec.rb +66 -0
- data/spec/linguistics/en/numbers_spec.rb +1295 -0
- data/spec/linguistics/en/participles_spec.rb +55 -0
- data/spec/linguistics/en/pluralization_spec.rb +4636 -0
- data/spec/linguistics/en/stemmer_spec.rb +72 -0
- data/spec/linguistics/en/titlecase_spec.rb +841 -0
- data/spec/linguistics/en/wordnet_spec.rb +85 -0
- data/spec/linguistics/en_spec.rb +45 -167
- data/spec/linguistics/inflector_spec.rb +40 -0
- data/spec/linguistics/iso639_spec.rb +49 -53
- data/spec/linguistics/monkeypatches_spec.rb +40 -0
- data/spec/linguistics_spec.rb +46 -76
- metadata +241 -113
- metadata.gz.sig +0 -0
- data/README +0 -166
- data/README.english +0 -245
- data/rake/191_compat.rb +0 -26
- data/rake/dependencies.rb +0 -76
- data/rake/documentation.rb +0 -123
- data/rake/helpers.rb +0 -502
- data/rake/hg.rb +0 -318
- data/rake/manual.rb +0 -787
- data/rake/packaging.rb +0 -129
- data/rake/publishing.rb +0 -341
- data/rake/style.rb +0 -62
- data/rake/svn.rb +0 -668
- data/rake/testing.rb +0 -152
- data/rake/verifytask.rb +0 -64
- data/tests/en/infinitive.tests.rb +0 -207
- data/tests/en/inflect.tests.rb +0 -1389
- data/tests/en/lafcadio.tests.rb +0 -77
- data/tests/en/linkparser.tests.rb +0 -42
- data/tests/en/lprintf.tests.rb +0 -77
- data/tests/en/titlecase.tests.rb +0 -73
- data/tests/en/wordnet.tests.rb +0 -95
data/History.rdoc
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
== v2.0.0 [2012-10-10] Michael Granger <ged@FaerieMUD.org>
|
2
|
+
|
3
|
+
Rewritten to be more modular, easier to extend and maintain, and to work under
|
4
|
+
1.9.
|
5
|
+
|
6
|
+
|
7
|
+
=== v1.0.9 [2011-09-01] Michael Granger <ged@FaerieMUD.org>
|
8
|
+
|
9
|
+
- Bugfix for Linguistics::EN.ordinate.
|
10
|
+
|
11
|
+
|
data/LICENSE
CHANGED
@@ -1,19 +1,19 @@
|
|
1
|
-
Copyright (c) 2003-
|
1
|
+
Copyright (c) 2003-20011, Michael Granger
|
2
2
|
All rights reserved.
|
3
3
|
|
4
4
|
Redistribution and use in source and binary forms, with or without
|
5
5
|
modification, are permitted provided that the following conditions are met:
|
6
6
|
|
7
|
-
|
8
|
-
|
7
|
+
* Redistributions of source code must retain the above copyright notice,
|
8
|
+
this list of conditions and the following disclaimer.
|
9
9
|
|
10
|
-
|
11
|
-
|
12
|
-
|
10
|
+
* Redistributions in binary form must reproduce the above copyright notice,
|
11
|
+
this list of conditions and the following disclaimer in the documentation
|
12
|
+
and/or other materials provided with the distribution.
|
13
13
|
|
14
|
-
|
15
|
-
|
16
|
-
|
14
|
+
* Neither the name of the author/s, nor the names of the project's
|
15
|
+
contributors may be used to endorse or promote products derived from this
|
16
|
+
software without specific prior written permission.
|
17
17
|
|
18
18
|
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
19
19
|
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
data/Manifest.txt
ADDED
@@ -0,0 +1,44 @@
|
|
1
|
+
ChangeLog
|
2
|
+
History.rdoc
|
3
|
+
LICENSE
|
4
|
+
Manifest.txt
|
5
|
+
README.rdoc
|
6
|
+
Rakefile
|
7
|
+
examples/endocs.rb
|
8
|
+
examples/generalize_sentence.rb
|
9
|
+
examples/klingon.rb
|
10
|
+
lib/linguistics.rb
|
11
|
+
lib/linguistics/en.rb
|
12
|
+
lib/linguistics/en/articles.rb
|
13
|
+
lib/linguistics/en/conjugation.rb
|
14
|
+
lib/linguistics/en/conjunctions.rb
|
15
|
+
lib/linguistics/en/infinitives.rb
|
16
|
+
lib/linguistics/en/linkparser.rb
|
17
|
+
lib/linguistics/en/numbers.rb
|
18
|
+
lib/linguistics/en/participles.rb
|
19
|
+
lib/linguistics/en/pluralization.rb
|
20
|
+
lib/linguistics/en/stemmer.rb
|
21
|
+
lib/linguistics/en/titlecase.rb
|
22
|
+
lib/linguistics/en/wordnet.rb
|
23
|
+
lib/linguistics/inflector.rb
|
24
|
+
lib/linguistics/iso639.rb
|
25
|
+
lib/linguistics/languagebehavior.rb
|
26
|
+
lib/linguistics/monkeypatches.rb
|
27
|
+
spec/lib/constants.rb
|
28
|
+
spec/lib/helpers.rb
|
29
|
+
spec/linguistics/en/articles_spec.rb
|
30
|
+
spec/linguistics/en/conjugation_spec.rb
|
31
|
+
spec/linguistics/en/conjunctions_spec.rb
|
32
|
+
spec/linguistics/en/infinitives_spec.rb
|
33
|
+
spec/linguistics/en/linkparser_spec.rb
|
34
|
+
spec/linguistics/en/numbers_spec.rb
|
35
|
+
spec/linguistics/en/participles_spec.rb
|
36
|
+
spec/linguistics/en/pluralization_spec.rb
|
37
|
+
spec/linguistics/en/stemmer_spec.rb
|
38
|
+
spec/linguistics/en/titlecase_spec.rb
|
39
|
+
spec/linguistics/en/wordnet_spec.rb
|
40
|
+
spec/linguistics/en_spec.rb
|
41
|
+
spec/linguistics/inflector_spec.rb
|
42
|
+
spec/linguistics/iso639_spec.rb
|
43
|
+
spec/linguistics/monkeypatches_spec.rb
|
44
|
+
spec/linguistics_spec.rb
|
data/README.rdoc
ADDED
@@ -0,0 +1,226 @@
|
|
1
|
+
= Linguistics
|
2
|
+
|
3
|
+
docs :: http://deveiate.org/code/linguistics
|
4
|
+
project :: https://bitbucket.org/ged/linguistics
|
5
|
+
github :: https://github.com/ged/linguistics
|
6
|
+
|
7
|
+
|
8
|
+
== Description
|
9
|
+
|
10
|
+
Linguistics is a framework for building linguistic utilities for Ruby
|
11
|
+
objects in any language. It includes a generic language-independant
|
12
|
+
front end, a module for mapping language codes into language names, and
|
13
|
+
a module which contains various English-language utilities.
|
14
|
+
|
15
|
+
Here are a few whimsical examples:
|
16
|
+
|
17
|
+
Linguistics.use( :en )
|
18
|
+
#
|
19
|
+
|
20
|
+
puts "Head of State".en.quantify( 11 )'
|
21
|
+
|
22
|
+
|
23
|
+
== Usage
|
24
|
+
|
25
|
+
The Linguistics module comes with a language-independant mechanism for
|
26
|
+
extending core Ruby classes with linguistic methods.
|
27
|
+
|
28
|
+
It consists of three parts: a core linguistics module which contains the
|
29
|
+
class-extension framework for languages, a generic inflector class that
|
30
|
+
serves as an extension point for linguistic methods on Ruby objects, and
|
31
|
+
one or more language-specific modules which contain the actual
|
32
|
+
linguistic functions.
|
33
|
+
|
34
|
+
The module works by adding a single instance method for each language
|
35
|
+
named after the language's two-letter code (or three-letter code, if no
|
36
|
+
two-letter code is defined by ISO639) to various Ruby classes. This
|
37
|
+
allows many language-specific methods to be added to objects without
|
38
|
+
cluttering up the interface or risking collision between them, albeit at
|
39
|
+
the cost of three or four more characters per method invocation. For
|
40
|
+
example:
|
41
|
+
|
42
|
+
Linguistics.use( :en )
|
43
|
+
"goose".en.plural
|
44
|
+
# => "geese"
|
45
|
+
|
46
|
+
If you prefer monkeypatching (around 70) linguistics methods directly onto core
|
47
|
+
classes, you can do that by adding a 'monkeypatch' option to ::use:
|
48
|
+
|
49
|
+
Linguistics.use( :en, monkeypatch: true )
|
50
|
+
"goose".plural
|
51
|
+
# => "geese"
|
52
|
+
|
53
|
+
=== Controlling Which Classes Get Extended
|
54
|
+
|
55
|
+
If you should wish to extend classes other than the ones in
|
56
|
+
<tt>Linguistics::DEFAULT_EXT_CLASSES</tt>, you have a few options.
|
57
|
+
|
58
|
+
You can modify the DEFAULT_EXT_CLASSES array directly (before you call
|
59
|
+
::use, of course):
|
60
|
+
|
61
|
+
Linguistics::DEFAULT_EXT_CLASSES << MyClass
|
62
|
+
|
63
|
+
You can also pass an Array of classes to .use:
|
64
|
+
|
65
|
+
Linguistics.use( :en, classes: [MyClass] )
|
66
|
+
|
67
|
+
Or you can add language methods to classes via mixin:
|
68
|
+
|
69
|
+
class MyClass
|
70
|
+
include Linguistics::EN
|
71
|
+
end
|
72
|
+
|
73
|
+
All Linguistics methods use Ruby's casting mechanism, so at a minimum,
|
74
|
+
your classes should provide an implementation of #to_s that returns
|
75
|
+
words or phrases.
|
76
|
+
|
77
|
+
|
78
|
+
|
79
|
+
|
80
|
+
=== Adding Language Modules
|
81
|
+
|
82
|
+
To add a new language to the framework, define a module that will act as
|
83
|
+
the top-level namespace for all your linguistic functions, and then
|
84
|
+
register it as being available, like so:
|
85
|
+
|
86
|
+
module Linguistics::TLH
|
87
|
+
|
88
|
+
# Add Klingon to the list of default languages
|
89
|
+
Linguistics.register_language( :tlh, self )
|
90
|
+
|
91
|
+
end
|
92
|
+
|
93
|
+
The first argument is either the two- or three-letter [ISO 639.2]
|
94
|
+
(http://www.loc.gov/standards/iso639-2/php/code_list.php) language code
|
95
|
+
for the language you're registering.
|
96
|
+
|
97
|
+
The second is the container module itself.
|
98
|
+
|
99
|
+
After you register your language, each class that Linguistics is told to
|
100
|
+
extend will have a method for your language code/s:
|
101
|
+
|
102
|
+
irb> Linguistics.use( :tlh, :classes => Object )
|
103
|
+
# => [Object]
|
104
|
+
irb> Object.new.tlh
|
105
|
+
# => #<(Klingon; tlhIngan-Hol-language inflector) for <Object:0x402d9674> >
|
106
|
+
|
107
|
+
If you use RSpec 2, you can test out any API requirements of the module
|
108
|
+
by requiring 'linguistics/languagebehavior' and adding a shared
|
109
|
+
behavior to your spec:
|
110
|
+
|
111
|
+
require 'rspec'
|
112
|
+
require 'linguistics/languagebehavior'
|
113
|
+
|
114
|
+
describe Linguistics::TLH do
|
115
|
+
|
116
|
+
it_should_behave_like "a Linguistics language module"
|
117
|
+
|
118
|
+
# ... any other specs for your module
|
119
|
+
|
120
|
+
end
|
121
|
+
|
122
|
+
If you wish to use the logging subsystem set up by Linguistics, you can
|
123
|
+
do so one of two ways: by logging to the logger directly:
|
124
|
+
|
125
|
+
Linguistics.log.debug "Registering Klingon language extension"
|
126
|
+
|
127
|
+
or by mixing the `Linguistics::Loggable' module into your class/module,
|
128
|
+
which will give you a 'log' method that prepends the object class on
|
129
|
+
each log message so it's easy to filter out the ones you want:
|
130
|
+
|
131
|
+
require 'linguistics/mixins'
|
132
|
+
class Linguistics::TLH::Generator
|
133
|
+
include Linguistics::Loggable
|
134
|
+
|
135
|
+
def generate_it
|
136
|
+
self.log.debug "starting generation..."
|
137
|
+
end
|
138
|
+
end
|
139
|
+
|
140
|
+
|
141
|
+
|
142
|
+
== English Language Module
|
143
|
+
|
144
|
+
Linguistics comes with an English-language module; see the API
|
145
|
+
documentation for Linguistics::EN for more information about it.
|
146
|
+
|
147
|
+
|
148
|
+
== Authors
|
149
|
+
|
150
|
+
* Michael Granger <ged@FaerieMUD.org>
|
151
|
+
* Martin Chase <stillflame@FaerieMUD.org>
|
152
|
+
|
153
|
+
|
154
|
+
== Contributors
|
155
|
+
|
156
|
+
* Robert Berry (bdigital on github) - English conjugation ported from
|
157
|
+
MorphAdorner
|
158
|
+
|
159
|
+
|
160
|
+
== Requirements
|
161
|
+
|
162
|
+
* Ruby >= 1.9.3
|
163
|
+
|
164
|
+
It may work under earlier versions, but I'll only be testing it on 1.9.3
|
165
|
+
or later.
|
166
|
+
|
167
|
+
|
168
|
+
== Optional
|
169
|
+
|
170
|
+
The English-language module for Linguistics has support for a few other
|
171
|
+
optional natural-language libraries:
|
172
|
+
|
173
|
+
linkparser[http://deveiate.org/projects/Ruby-LinkParser] ::
|
174
|
+
Ruby high-level interface to the CMU Link Grammar library
|
175
|
+
|
176
|
+
wordnet[http://deveiate.org/projects/Ruby-WordNet] ::
|
177
|
+
Adds integration for the Ruby binding for the WordNet®
|
178
|
+
lexical refrence system.
|
179
|
+
|
180
|
+
|
181
|
+
== Contributing
|
182
|
+
|
183
|
+
You can check out the current development source with Mercurial via its
|
184
|
+
{project page}[http://deveiate.org/projects/Linguistics]. Or if you prefer
|
185
|
+
Git, via {its Github mirror}[https://github.com/ged/linguistics].
|
186
|
+
|
187
|
+
After checking out the source, run:
|
188
|
+
|
189
|
+
$ rake newb
|
190
|
+
|
191
|
+
This task will install any missing dependencies, run the tests/specs, and
|
192
|
+
generate the API documentation.
|
193
|
+
|
194
|
+
|
195
|
+
== License
|
196
|
+
|
197
|
+
Copyright (c) 2003-2012, Michael Granger
|
198
|
+
All rights reserved.
|
199
|
+
|
200
|
+
Redistribution and use in source and binary forms, with or without
|
201
|
+
modification, are permitted provided that the following conditions are met:
|
202
|
+
|
203
|
+
* Redistributions of source code must retain the above copyright notice,
|
204
|
+
this list of conditions and the following disclaimer.
|
205
|
+
|
206
|
+
* Redistributions in binary form must reproduce the above copyright notice,
|
207
|
+
this list of conditions and the following disclaimer in the documentation
|
208
|
+
and/or other materials provided with the distribution.
|
209
|
+
|
210
|
+
* Neither the name of the author/s, nor the names of the project's
|
211
|
+
contributors may be used to endorse or promote products derived from this
|
212
|
+
software without specific prior written permission.
|
213
|
+
|
214
|
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
215
|
+
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
216
|
+
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
217
|
+
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
|
218
|
+
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
219
|
+
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
220
|
+
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
221
|
+
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
222
|
+
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
223
|
+
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
224
|
+
|
225
|
+
|
226
|
+
|
data/Rakefile
CHANGED
@@ -1,363 +1,46 @@
|
|
1
|
-
|
2
|
-
#
|
3
|
-
# Linguistics rakefile
|
4
|
-
#
|
5
|
-
# Based on various other Rakefiles, especially one by Ben Bleything
|
6
|
-
#
|
7
|
-
# Copyright (c) 2007-2011 The FaerieMUD Consortium
|
8
|
-
#
|
9
|
-
# Authors:
|
10
|
-
# * Michael Granger <ged@FaerieMUD.org>
|
11
|
-
#
|
1
|
+
#!/usr/bin/env rake
|
12
2
|
|
13
|
-
|
14
|
-
require 'rbconfig'
|
15
|
-
require 'pathname'
|
16
|
-
basedir = Pathname.new( __FILE__ ).dirname
|
3
|
+
require 'hoe'
|
17
4
|
|
18
|
-
|
19
|
-
|
5
|
+
Hoe.plugin :mercurial
|
6
|
+
Hoe.plugin :signing
|
20
7
|
|
21
|
-
|
22
|
-
$LOAD_PATH.unshift( libdir.to_s ) unless $LOAD_PATH.include?( libdir.to_s )
|
23
|
-
$LOAD_PATH.unshift( extdir.to_s ) unless $LOAD_PATH.include?( extdir.to_s )
|
24
|
-
}
|
8
|
+
Hoe.plugins.delete :rubyforge
|
25
9
|
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
def readline( text )
|
32
|
-
$stderr.print( text.chomp )
|
33
|
-
return $stdin.gets
|
34
|
-
end
|
35
|
-
end
|
36
|
-
|
37
|
-
begin
|
38
|
-
require 'rubygems'
|
39
|
-
rescue LoadError
|
40
|
-
module Gem
|
41
|
-
class Specification; end
|
42
|
-
end
|
43
|
-
end
|
44
|
-
|
45
|
-
require 'pathname'
|
46
|
-
require 'rbconfig'
|
47
|
-
require 'rake'
|
48
|
-
require 'rake/testtask'
|
49
|
-
require 'rake/packagetask'
|
50
|
-
require 'rake/clean'
|
51
|
-
# require 'rake/191_compat.rb'
|
52
|
-
|
53
|
-
$dryrun = false
|
10
|
+
hoespec = Hoe.spec 'linguistics' do
|
11
|
+
self.name = 'linguistics'
|
12
|
+
self.readme_file = 'README.rdoc'
|
13
|
+
self.history_file = 'History.rdoc'
|
14
|
+
self.extra_rdoc_files = FileList[ '*.rdoc' ]
|
54
15
|
|
55
|
-
|
56
|
-
BASEDIR = Pathname.new( __FILE__ ).dirname.relative_path_from( Pathname.getwd )
|
57
|
-
BINDIR = BASEDIR + 'bin'
|
58
|
-
LIBDIR = BASEDIR + 'lib'
|
59
|
-
EXTDIR = BASEDIR + 'ext'
|
60
|
-
DOCSDIR = BASEDIR + 'docs'
|
61
|
-
PKGDIR = BASEDIR + 'pkg'
|
62
|
-
DATADIR = BASEDIR + 'data'
|
16
|
+
self.developer 'Michael Granger', 'ged@FaerieMUD.org'
|
63
17
|
|
64
|
-
|
18
|
+
self.dependency 'hoe-deveiate', '~> 0.1', :development
|
19
|
+
self.dependency 'linkparser', '~> 1.1', :development
|
20
|
+
self.dependency 'wordnet', '~> 0.99', :development
|
21
|
+
self.dependency 'ruby-stemmer', '~> 0.9', :development
|
65
22
|
|
66
|
-
|
67
|
-
|
68
|
-
|
23
|
+
self.spec_extras[:licenses] = ["BSD"]
|
24
|
+
self.spec_extras[:rdoc_options] = ['-f', 'fivefish', '-t', 'Ruby Linguistics Toolkit']
|
25
|
+
self.spec_extras[:post_install_message] = [
|
26
|
+
"This library also presents tie-ins for the 'linkparser' and",
|
27
|
+
"'wordnet' libraries, which you can enable by installing the",
|
28
|
+
"gems of the same name."
|
29
|
+
].join( "\n" )
|
69
30
|
|
70
|
-
|
71
|
-
|
72
|
-
|
31
|
+
self.require_ruby_version( '>=1.9.3' )
|
32
|
+
self.hg_sign_tags = true if self.respond_to?( :hg_sign_tags= )
|
33
|
+
self.check_history_on_release = true if self.respond_to?( :check_history_on_release= )
|
73
34
|
|
74
|
-
|
75
|
-
if VERSION_FILE.exist? && buildrev = ENV['CC_BUILD_LABEL']
|
76
|
-
PKG_VERSION = VERSION_FILE.read[ /VERSION\s*=\s*['"](\d+\.\d+\.\d+)['"]/, 1 ] + '.' + buildrev
|
77
|
-
elsif VERSION_FILE.exist?
|
78
|
-
PKG_VERSION = VERSION_FILE.read[ /VERSION\s*=\s*['"](\d+\.\d+\.\d+)['"]/, 1 ]
|
35
|
+
self.rdoc_locations << "deveiate:/usr/local/www/public/code/#{remote_rdoc_dir}"
|
79
36
|
end
|
80
37
|
|
81
|
-
|
82
|
-
|
83
|
-
PKG_FILE_NAME = "#{PKG_NAME.downcase}-#{PKG_VERSION}"
|
84
|
-
GEM_FILE_NAME = "#{PKG_FILE_NAME}.gem"
|
85
|
-
|
86
|
-
# Universal VCS constants
|
87
|
-
DEFAULT_EDITOR = 'vi'
|
88
|
-
COMMIT_MSG_FILE = 'commit-msg.txt'
|
89
|
-
FILE_INDENT = " " * 12
|
90
|
-
LOG_INDENT = " " * 3
|
91
|
-
|
92
|
-
EXTCONF = EXTDIR + 'extconf.rb'
|
93
|
-
|
94
|
-
ARTIFACTS_DIR = Pathname.new( CC_BUILD_ARTIFACTS )
|
95
|
-
|
96
|
-
TEXT_FILES = Rake::FileList.new( %w[Rakefile ChangeLog README* LICENSE] )
|
97
|
-
BIN_FILES = Rake::FileList.new( "#{BINDIR}/*" )
|
98
|
-
LIB_FILES = Rake::FileList.new( "#{LIBDIR}/**/*.rb" )
|
99
|
-
EXT_FILES = Rake::FileList.new( "#{EXTDIR}/**/*.{c,h,rb}" )
|
100
|
-
DATA_FILES = Rake::FileList.new( "#{DATADIR}/**/*" )
|
101
|
-
|
102
|
-
SPECDIR = BASEDIR + 'spec'
|
103
|
-
SPECLIBDIR = SPECDIR + 'lib'
|
104
|
-
SPEC_FILES = Rake::FileList.new( "#{SPECDIR}/**/*_spec.rb", "#{SPECLIBDIR}/**/*.rb" )
|
105
|
-
|
106
|
-
TESTDIR = BASEDIR + 'tests'
|
107
|
-
TEST_FILES = Rake::FileList.new( "#{TESTDIR}/**/*.tests.rb" )
|
108
|
-
|
109
|
-
RAKE_TASKDIR = BASEDIR + 'rake'
|
110
|
-
RAKE_TASKLIBS = Rake::FileList.new( "#{RAKE_TASKDIR}/*.rb" )
|
111
|
-
PKG_TASKLIBS = Rake::FileList.new( "#{RAKE_TASKDIR}/{191_compat,helpers,packaging,rdoc,testing}.rb" )
|
112
|
-
PKG_TASKLIBS.include( "#{RAKE_TASKDIR}/manual.rb" ) if MANUALDIR.exist?
|
113
|
-
|
114
|
-
RAKE_TASKLIBS_URL = 'http://repo.deveiate.org/rake-tasklibs'
|
115
|
-
|
116
|
-
LOCAL_RAKEFILE = BASEDIR + 'Rakefile.local'
|
117
|
-
|
118
|
-
EXTRA_PKGFILES = Rake::FileList.new
|
119
|
-
EXTRA_PKGFILES.include( "#{BASEDIR}/examples/*.rb" )
|
120
|
-
EXTRA_PKGFILES.include( "#{BASEDIR}/README.english" )
|
121
|
-
|
122
|
-
RELEASE_FILES = TEXT_FILES +
|
123
|
-
SPEC_FILES +
|
124
|
-
TEST_FILES +
|
125
|
-
BIN_FILES +
|
126
|
-
LIB_FILES +
|
127
|
-
EXT_FILES +
|
128
|
-
DATA_FILES +
|
129
|
-
RAKE_TASKLIBS +
|
130
|
-
EXTRA_PKGFILES
|
38
|
+
ENV['VERSION'] ||= hoespec.spec.version.to_s
|
131
39
|
|
40
|
+
task 'hg:precheckin' => [ :check_history, :check_manifest, :spec ]
|
132
41
|
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
]
|
138
|
-
|
139
|
-
COVERAGE_MINIMUM = ENV['COVERAGE_MINIMUM'] ? Float( ENV['COVERAGE_MINIMUM'] ) : 85.0
|
140
|
-
RCOV_EXCLUDES = 'spec,tests,/Library/Ruby,/var/lib,/usr/local/lib'
|
141
|
-
RCOV_OPTS = [
|
142
|
-
'--exclude', RCOV_EXCLUDES,
|
143
|
-
'--xrefs',
|
144
|
-
'--save',
|
145
|
-
'--callsites',
|
146
|
-
#'--aggregate', 'coverage.data' # <- doesn't work as of 0.8.1.2.0
|
147
|
-
]
|
148
|
-
|
149
|
-
|
150
|
-
### Load some task libraries that need to be loaded early
|
151
|
-
if !RAKE_TASKDIR.exist?
|
152
|
-
$stderr.puts "It seems you don't have the build task directory. Shall I fetch it "
|
153
|
-
ans = readline( "for you? [y]" )
|
154
|
-
ans = 'y' if !ans.nil? && ans.empty?
|
155
|
-
|
156
|
-
if ans =~ /^y/i
|
157
|
-
$stderr.puts "Okay, fetching #{RAKE_TASKLIBS_URL} into #{RAKE_TASKDIR}..."
|
158
|
-
system 'hg', 'clone', RAKE_TASKLIBS_URL, "./#{RAKE_TASKDIR}"
|
159
|
-
if ! $?.success?
|
160
|
-
fail "Damn. That didn't work. Giving up; maybe try manually fetching?"
|
161
|
-
end
|
162
|
-
else
|
163
|
-
$stderr.puts "Then I'm afraid I can't continue. Best of luck."
|
164
|
-
fail "Rake tasklibs not present."
|
165
|
-
end
|
166
|
-
|
167
|
-
RAKE_TASKLIBS.include( "#{RAKE_TASKDIR}/*.rb" )
|
168
|
-
end
|
169
|
-
|
170
|
-
require RAKE_TASKDIR + 'helpers.rb'
|
171
|
-
include RakefileHelpers
|
172
|
-
|
173
|
-
# Set the build ID if the mercurial executable is available
|
174
|
-
if hg = which( 'hg' )
|
175
|
-
id = `#{hg} id -n`.chomp
|
176
|
-
PKG_BUILD = (id.chomp[ /^[[:xdigit:]]+/ ] || '1')
|
177
|
-
else
|
178
|
-
PKG_BUILD = '0'
|
42
|
+
desc "Build a coverage report"
|
43
|
+
task :coverage do
|
44
|
+
ENV["COVERAGE"] = 'yes'
|
45
|
+
Rake::Task[:spec].invoke
|
179
46
|
end
|
180
|
-
SNAPSHOT_PKG_NAME = "#{PKG_FILE_NAME}.#{PKG_BUILD}"
|
181
|
-
SNAPSHOT_GEM_NAME = "#{SNAPSHOT_PKG_NAME}.gem"
|
182
|
-
|
183
|
-
# Documentation constants
|
184
|
-
API_DOCSDIR = DOCSDIR + 'api'
|
185
|
-
README_FILE = TEXT_FILES.find {|path| path =~ /^README/ } || 'README'
|
186
|
-
RDOC_OPTIONS = [
|
187
|
-
'--tab-width=4',
|
188
|
-
'--show-hash',
|
189
|
-
'--include', BASEDIR.to_s,
|
190
|
-
"--main=#{README_FILE}",
|
191
|
-
"--title=#{PKG_NAME}",
|
192
|
-
]
|
193
|
-
YARD_OPTIONS = [
|
194
|
-
'--use-cache',
|
195
|
-
'--protected',
|
196
|
-
'-r', README_FILE,
|
197
|
-
'--exclude', 'extconf\\.rb',
|
198
|
-
'--files', 'ChangeLog,LICENSE',
|
199
|
-
'--output-dir', API_DOCSDIR.to_s,
|
200
|
-
'--title', "#{PKG_NAME} #{PKG_VERSION}",
|
201
|
-
]
|
202
|
-
|
203
|
-
# Release constants
|
204
|
-
SMTP_HOST = "mail.faeriemud.org"
|
205
|
-
SMTP_PORT = 465 # SMTP + SSL
|
206
|
-
|
207
|
-
# Project constants
|
208
|
-
PROJECT_HOST = 'deveiate'
|
209
|
-
PROJECT_PUBDIR = '/usr/local/www/public/code'
|
210
|
-
PROJECT_DOCDIR = "#{PROJECT_PUBDIR}/#{PKG_NAME}"
|
211
|
-
PROJECT_SCPPUBURL = "#{PROJECT_HOST}:#{PROJECT_PUBDIR}"
|
212
|
-
PROJECT_SCPDOCURL = "#{PROJECT_HOST}:#{PROJECT_DOCDIR}"
|
213
|
-
|
214
|
-
GEM_PUBHOST = 'rubygems.org'
|
215
|
-
|
216
|
-
# Gem dependencies: gemname => version
|
217
|
-
DEPENDENCIES = {
|
218
|
-
}
|
219
|
-
|
220
|
-
# Developer Gem dependencies: gemname => version
|
221
|
-
DEVELOPMENT_DEPENDENCIES = {
|
222
|
-
'rake' => '~> 0.8.7',
|
223
|
-
'rcodetools' => '~> 0.7.0.0',
|
224
|
-
'rcov' => '~> 0.8.1.2.0',
|
225
|
-
'RedCloth' => '~> 4.2.3',
|
226
|
-
'rspec' => '~> 1.2.6',
|
227
|
-
'ruby-termios' => '~> 0.9.6',
|
228
|
-
'text-format' => '~> 1.0.0',
|
229
|
-
'tmail' => '~> 1.2.3.1',
|
230
|
-
'wordnet' => '>=0.0.5',
|
231
|
-
'linkparser' => '>=1.0.3',
|
232
|
-
}
|
233
|
-
|
234
|
-
# Non-gem requirements: packagename => version
|
235
|
-
REQUIREMENTS = {
|
236
|
-
}
|
237
|
-
|
238
|
-
# RubyGem specification
|
239
|
-
GEMSPEC = Gem::Specification.new do |gem|
|
240
|
-
gem.name = PKG_NAME.downcase
|
241
|
-
gem.version = PKG_VERSION
|
242
|
-
|
243
|
-
gem.summary = PKG_SUMMARY
|
244
|
-
gem.description = [
|
245
|
-
"in any language. It includes a generic language-independant front end, a",
|
246
|
-
"module for mapping language codes into language names, and a module which",
|
247
|
-
"contains various English-language utilities.",
|
248
|
-
].join( "\n" )
|
249
|
-
|
250
|
-
gem.authors = ["Michael Granger"]
|
251
|
-
gem.email = ["ged@FaerieMUD.org"]
|
252
|
-
gem.homepage = 'http://deveiate.org/projects/Linguistics/'
|
253
|
-
gem.licenses = ["BSD"]
|
254
|
-
|
255
|
-
gem.has_rdoc = true
|
256
|
-
gem.rdoc_options = RDOC_OPTIONS
|
257
|
-
gem.extra_rdoc_files = TEXT_FILES - [ 'Rakefile' ]
|
258
|
-
|
259
|
-
gem.bindir = BINDIR.relative_path_from(BASEDIR).to_s
|
260
|
-
gem.executables = BIN_FILES.select {|pn| File.executable?(pn) }.
|
261
|
-
collect {|pn| File.basename(pn) }
|
262
|
-
gem.require_paths << EXTDIR.relative_path_from( BASEDIR ).to_s if EXTDIR.exist?
|
263
|
-
|
264
|
-
if EXTCONF.exist?
|
265
|
-
gem.extensions << EXTCONF.relative_path_from( BASEDIR ).to_s
|
266
|
-
end
|
267
|
-
|
268
|
-
gem.files = RELEASE_FILES
|
269
|
-
gem.test_files = SPEC_FILES
|
270
|
-
|
271
|
-
# signing key and certificate chain
|
272
|
-
gem.signing_key = '/Volumes/Keys/ged-private_gem_key.pem'
|
273
|
-
gem.cert_chain = [File.expand_path('~/.gem/ged-public_gem_cert.pem')]
|
274
|
-
|
275
|
-
|
276
|
-
gem.required_ruby_version = '>= 1.8.7'
|
277
|
-
|
278
|
-
DEPENDENCIES.each do |name, version|
|
279
|
-
version = '>= 0' if version.length.zero?
|
280
|
-
gem.add_runtime_dependency( name, version )
|
281
|
-
end
|
282
|
-
|
283
|
-
REQUIREMENTS.each do |name, version|
|
284
|
-
gem.requirements << [ name, version ].compact.join(' ')
|
285
|
-
end
|
286
|
-
end
|
287
|
-
|
288
|
-
$trace = Rake.application.options.trace ? true : false
|
289
|
-
$dryrun = Rake.application.options.dryrun ? true : false
|
290
|
-
$include_dev_dependencies = false
|
291
|
-
|
292
|
-
# Load any remaining task libraries
|
293
|
-
RAKE_TASKLIBS.each do |tasklib|
|
294
|
-
next if tasklib.to_s =~ %r{/helpers\.rb$}
|
295
|
-
begin
|
296
|
-
trace " loading tasklib %s" % [ tasklib ]
|
297
|
-
import tasklib
|
298
|
-
rescue ScriptError => err
|
299
|
-
fail "Task library '%s' failed to load: %s: %s" %
|
300
|
-
[ tasklib, err.class.name, err.message ]
|
301
|
-
trace "Backtrace: \n " + err.backtrace.join( "\n " )
|
302
|
-
rescue => err
|
303
|
-
log "Task library '%s' failed to load: %s: %s. Some tasks may not be available." %
|
304
|
-
[ tasklib, err.class.name, err.message ]
|
305
|
-
trace "Backtrace: \n " + err.backtrace.join( "\n " )
|
306
|
-
end
|
307
|
-
end
|
308
|
-
|
309
|
-
# Load any project-specific rules defined in 'Rakefile.local' if it exists
|
310
|
-
import LOCAL_RAKEFILE if LOCAL_RAKEFILE.exist?
|
311
|
-
|
312
|
-
|
313
|
-
#####################################################################
|
314
|
-
### T A S K S
|
315
|
-
#####################################################################
|
316
|
-
|
317
|
-
### Default task
|
318
|
-
task :default => [:clean, :local, :spec, :apidocs, :package]
|
319
|
-
|
320
|
-
### Task the local Rakefile can append to -- no-op by default
|
321
|
-
task :local
|
322
|
-
|
323
|
-
### Task: clean
|
324
|
-
CLEAN.include 'coverage', '**/*.orig', '**/*.rej'
|
325
|
-
CLOBBER.include 'artifacts', 'coverage.info', 'ChangeLog', PKGDIR
|
326
|
-
|
327
|
-
### Task: changelog
|
328
|
-
file 'ChangeLog' do |task|
|
329
|
-
log "Updating #{task.name}"
|
330
|
-
|
331
|
-
changelog = make_changelog()
|
332
|
-
File.open( task.name, 'w' ) do |fh|
|
333
|
-
fh.print( changelog )
|
334
|
-
end
|
335
|
-
end
|
336
|
-
|
337
|
-
|
338
|
-
### Task: cruise (Cruisecontrol task)
|
339
|
-
desc "Cruisecontrol build"
|
340
|
-
task :cruise => [:clean, 'spec:quiet', :package] do |task|
|
341
|
-
raise "Artifacts dir not set." if ARTIFACTS_DIR.to_s.empty?
|
342
|
-
artifact_dir = ARTIFACTS_DIR.cleanpath + (CC_BUILD_LABEL || Time.now.strftime('%Y%m%d-%T'))
|
343
|
-
artifact_dir.mkpath
|
344
|
-
|
345
|
-
coverage = BASEDIR + 'coverage'
|
346
|
-
if coverage.exist? && coverage.directory?
|
347
|
-
$stderr.puts "Copying coverage stats..."
|
348
|
-
FileUtils.cp_r( 'coverage', artifact_dir )
|
349
|
-
end
|
350
|
-
|
351
|
-
$stderr.puts "Copying packages..."
|
352
|
-
FileUtils.cp_r( FileList['pkg/*'].to_a, artifact_dir )
|
353
|
-
end
|
354
|
-
|
355
|
-
|
356
|
-
desc "Update the build system to the latest version"
|
357
|
-
task :update_build do
|
358
|
-
log "Updating the build system"
|
359
|
-
run 'hg', '-R', RAKE_TASKDIR, 'pull', '-u'
|
360
|
-
log "Updating the Rakefile"
|
361
|
-
sh 'rake', '-f', RAKE_TASKDIR + 'Metarakefile'
|
362
|
-
end
|
363
|
-
|