spicy-proton 2.0.2 → 2.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +23 -9
- data/lib/corpus.rb +40 -0
- data/lib/corpus/adverbs-fixed.bin +0 -0
- data/lib/corpus/adverbs.bin +0 -0
- data/lib/corpus/verbs-fixed.bin +0 -0
- data/lib/corpus/verbs.bin +0 -0
- data/lib/disk-corpus.rb +8 -18
- data/lib/memory-corpus.rb +34 -16
- data/lib/spicy-proton.rb +10 -43
- metadata +8 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 28481edad03c822b978caa8f1555f6a7ecb93083
|
4
|
+
data.tar.gz: 50ee9d4827eb08a40798078fb36940b7ba567995
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fdb6e19b9b443858792846853693f1d7ab3e3b2bd3a43e8d131e92857d640cceddd01121393e4cc00f1aef75e24b5f242a51938a33f4605261ca5270c466e447
|
7
|
+
data.tar.gz: 491b27d08194a110a0bd1840cc51533f3fabf3c0f0037ab5ba70d006d64ba7a019579319cd6c986940bc7f91003ce776afeb85ff5cdaeb7111bc72c51ad0e281
|
data/README.md
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
# Spicy::Proton
|
2
|
+
|
2
3
|
Generate a random English adjective-noun word pair. Works with Ruby 1.9.x and newer.
|
3
4
|
|
4
5
|
[![Gem Version](https://badge.fury.io/rb/spicy-proton.svg)](http://rubygems.org/gems/spicy-proton)
|
@@ -26,13 +27,18 @@ Spicy::Proton.adjective # => "extreme"
|
|
26
27
|
Spicy::Proton.noun # => "loan"
|
27
28
|
Spicy::Proton.pair # => "opportune-spacesuit"
|
28
29
|
Spicy::Proton.pair(':') # => "hip:squash"
|
30
|
+
Spicy::Proton.adverb # => "energetically"
|
31
|
+
Spicy::Proton.verb # => "refrained"
|
29
32
|
Spicy::Proton.format('%a/%a/%n') # => "dapper/festive/fedora"
|
33
|
+
Spicy::Proton.format('%b %v') # => "artfully stained"
|
30
34
|
|
31
35
|
# With length constraints.
|
32
36
|
Spicy::Proton.adjective(max: 5) # => "dank"
|
33
37
|
Spicy::Proton.noun(min: 10) # => "interpolation"
|
34
38
|
Spicy::Proton.adjective(length: 8) # => "medieval"
|
35
39
|
Spicy::Proton.noun(min: 5, max: 7) # => "dolphin"
|
40
|
+
Spicy::Proton.adverb(min: 0) # => "prophetically"
|
41
|
+
Spicy::Proton.verb(max: 100) # => "sparkles"
|
36
42
|
```
|
37
43
|
|
38
44
|
When generating multiple specimens, instance methods are faster. The instance keeps the word corpus in memory. The instance methods are the same as their class method counterparts.
|
@@ -40,23 +46,31 @@ When generating multiple specimens, instance methods are faster. The instance ke
|
|
40
46
|
```ruby
|
41
47
|
require 'spicy-proton'
|
42
48
|
|
43
|
-
|
49
|
+
gen = Spicy::Proton.new
|
44
50
|
1000.times do
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
51
|
+
gen.adjective
|
52
|
+
gen.noun(min: 7)
|
53
|
+
gen.pair
|
54
|
+
gen.pair('.')
|
55
|
+
gen.adverb(length: 6)
|
56
|
+
gen.verb(max: 5)
|
57
|
+
gen.format('The %a %n %b %v the %n.')
|
50
58
|
end
|
51
59
|
```
|
52
60
|
|
53
|
-
Instances
|
61
|
+
Instances also provide raw word lists in length order:
|
54
62
|
|
55
63
|
```ruby
|
56
|
-
|
57
|
-
|
64
|
+
gen.adjectives # => ["aft", "apt", "bad", "big", ...]
|
65
|
+
gen.nouns # => ["ad", "ax, "ox", "pi", ...]
|
66
|
+
gen.adverbs # => ["no", "aft", "ago", "all", ...]
|
67
|
+
gen.verbs # => ["am", "be", "do", "go", ...]
|
58
68
|
```
|
59
69
|
|
70
|
+
## Credits
|
71
|
+
|
72
|
+
Inspired by [btford/adj-noun](https://github.com/btford/adj-noun). Thanks to [NLTK](http://www.nltk.org/) for the word corpus.
|
73
|
+
|
60
74
|
## License
|
61
75
|
|
62
76
|
Copyright © 2017 Chris Schmich
|
data/lib/corpus.rb
ADDED
@@ -0,0 +1,40 @@
|
|
1
|
+
module Spicy
|
2
|
+
module Corpus
|
3
|
+
def adjective(*args)
|
4
|
+
generate(:adjectives, *args)
|
5
|
+
end
|
6
|
+
|
7
|
+
def noun(*args)
|
8
|
+
generate(:nouns, *args)
|
9
|
+
end
|
10
|
+
|
11
|
+
def verb(*args)
|
12
|
+
generate(:verbs, *args)
|
13
|
+
end
|
14
|
+
|
15
|
+
def adverb(*args)
|
16
|
+
generate(:adverbs, *args)
|
17
|
+
end
|
18
|
+
|
19
|
+
def pair(separator = '-')
|
20
|
+
"#{adjective}#{separator}#{noun}"
|
21
|
+
end
|
22
|
+
|
23
|
+
def format(format)
|
24
|
+
format.gsub(/%([anbv%])/) do
|
25
|
+
case $1
|
26
|
+
when 'a'
|
27
|
+
adjective
|
28
|
+
when 'n'
|
29
|
+
noun
|
30
|
+
when 'b'
|
31
|
+
adverb
|
32
|
+
when 'v'
|
33
|
+
verb
|
34
|
+
when '%'
|
35
|
+
'%'
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
data/lib/disk-corpus.rb
CHANGED
@@ -1,22 +1,20 @@
|
|
1
|
-
require 'yaml'
|
2
1
|
require 'seek'
|
3
2
|
require 'header'
|
3
|
+
require 'corpus'
|
4
4
|
|
5
5
|
module Spicy
|
6
6
|
end
|
7
7
|
|
8
8
|
module Spicy::Disk
|
9
9
|
module Files
|
10
|
+
@@files = {}
|
11
|
+
|
10
12
|
def self.dir
|
11
13
|
@@dir ||= File.join(File.dirname(__FILE__), 'corpus')
|
12
14
|
end
|
13
15
|
|
14
|
-
def self.
|
15
|
-
@@
|
16
|
-
end
|
17
|
-
|
18
|
-
def self.nouns
|
19
|
-
@@nouns ||= File.join(dir, 'nouns-fixed.bin')
|
16
|
+
def self.corpus(type)
|
17
|
+
@@files[type] ||= File.join(dir, "#{type}-fixed.bin")
|
20
18
|
end
|
21
19
|
end
|
22
20
|
|
@@ -25,11 +23,9 @@ module Spicy::Disk
|
|
25
23
|
|
26
24
|
def initialize(file_name)
|
27
25
|
@file = File.open(file_name, 'rb')
|
28
|
-
|
29
26
|
@cumulative = Spicy::Header.cumulative(@file)
|
30
27
|
@min = @cumulative.keys.min
|
31
28
|
@max = @cumulative.keys.max
|
32
|
-
|
33
29
|
@origin = @file.pos
|
34
30
|
end
|
35
31
|
|
@@ -46,6 +42,8 @@ module Spicy::Disk
|
|
46
42
|
end
|
47
43
|
|
48
44
|
class Corpus
|
45
|
+
include Spicy::Corpus
|
46
|
+
|
49
47
|
private_class_method :new
|
50
48
|
|
51
49
|
def self.use
|
@@ -65,19 +63,11 @@ module Spicy::Disk
|
|
65
63
|
@lists.values.each(&:close)
|
66
64
|
end
|
67
65
|
|
68
|
-
def adjective(*args)
|
69
|
-
generate(:adjectives, *args)
|
70
|
-
end
|
71
|
-
|
72
|
-
def noun(*args)
|
73
|
-
generate(:nouns, *args)
|
74
|
-
end
|
75
|
-
|
76
66
|
private
|
77
67
|
|
78
68
|
def generate(type, *args)
|
79
69
|
@lists[type] ||= begin
|
80
|
-
WordList.new(Files.
|
70
|
+
WordList.new(Files.corpus(type))
|
81
71
|
end
|
82
72
|
@lists[type].word(*args)
|
83
73
|
end
|
data/lib/memory-corpus.rb
CHANGED
@@ -1,22 +1,20 @@
|
|
1
|
-
require 'yaml'
|
2
1
|
require 'seek'
|
3
2
|
require 'header'
|
3
|
+
require 'corpus'
|
4
4
|
|
5
5
|
module Spicy
|
6
6
|
end
|
7
7
|
|
8
8
|
module Spicy::Memory
|
9
9
|
module Files
|
10
|
+
@@files = {}
|
11
|
+
|
10
12
|
def self.dir
|
11
13
|
@@dir ||= File.join(File.dirname(__FILE__), 'corpus')
|
12
14
|
end
|
13
15
|
|
14
|
-
def self.
|
15
|
-
@@
|
16
|
-
end
|
17
|
-
|
18
|
-
def self.nouns
|
19
|
-
@@nouns ||= File.join(dir, 'nouns.bin')
|
16
|
+
def self.corpus(type)
|
17
|
+
@@files[type] ||= File.join(dir, "#{type}.bin")
|
20
18
|
end
|
21
19
|
end
|
22
20
|
|
@@ -37,25 +35,45 @@ module Spicy::Memory
|
|
37
35
|
@words[index]
|
38
36
|
end
|
39
37
|
end
|
38
|
+
|
39
|
+
def words
|
40
|
+
@words
|
41
|
+
end
|
40
42
|
end
|
41
43
|
|
42
44
|
class Corpus
|
45
|
+
include Spicy::Corpus
|
46
|
+
|
43
47
|
def initialize
|
44
|
-
|
45
|
-
|
46
|
-
|
48
|
+
@lists = {}
|
49
|
+
end
|
50
|
+
|
51
|
+
def adjectives
|
52
|
+
list(:adjectives).words
|
53
|
+
end
|
54
|
+
|
55
|
+
def nouns
|
56
|
+
list(:nouns).words
|
47
57
|
end
|
48
58
|
|
49
|
-
def
|
50
|
-
|
59
|
+
def adverbs
|
60
|
+
list(:adverbs).words
|
51
61
|
end
|
52
62
|
|
53
|
-
def
|
54
|
-
|
63
|
+
def verbs
|
64
|
+
list(:verbs).words
|
55
65
|
end
|
56
66
|
|
57
|
-
|
58
|
-
|
67
|
+
private
|
68
|
+
|
69
|
+
def generate(type, *args)
|
70
|
+
list(type).word(*args)
|
71
|
+
end
|
72
|
+
|
73
|
+
def list(type)
|
74
|
+
@lists[type] ||= begin
|
75
|
+
WordList.new(Files.corpus(type))
|
76
|
+
end
|
59
77
|
end
|
60
78
|
end
|
61
79
|
end
|
data/lib/spicy-proton.rb
CHANGED
@@ -6,53 +6,20 @@ module Spicy
|
|
6
6
|
class Proton
|
7
7
|
extend Forwardable
|
8
8
|
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
end
|
17
|
-
end
|
18
|
-
|
19
|
-
def self.noun(*args)
|
20
|
-
Disk::Corpus.use do |c|
|
21
|
-
c.noun(*args)
|
22
|
-
end
|
23
|
-
end
|
24
|
-
|
25
|
-
def self.pair(separator = '-')
|
26
|
-
Disk::Corpus.use do |c|
|
27
|
-
"#{c.adjective}#{separator}#{c.noun}"
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
31
|
-
def self.format(format)
|
32
|
-
Disk::Corpus.use do |c|
|
33
|
-
self.format_with(c, format)
|
9
|
+
class << self
|
10
|
+
[:adjective, :noun, :adverb, :verb, :pair, :format].each do |method|
|
11
|
+
define_method(method) do |*args, &block|
|
12
|
+
Disk::Corpus.use do |c|
|
13
|
+
c.send(method, *args, &block)
|
14
|
+
end
|
15
|
+
end
|
34
16
|
end
|
35
17
|
end
|
36
18
|
|
37
|
-
def
|
38
|
-
|
19
|
+
def initialize
|
20
|
+
@corpus = Memory::Corpus.new
|
39
21
|
end
|
40
22
|
|
41
|
-
def_delegators :@corpus, :adjective, :noun, :
|
42
|
-
|
43
|
-
private
|
44
|
-
|
45
|
-
def self.format_with(source, format)
|
46
|
-
format.gsub(/%([an%])/) do
|
47
|
-
case $1
|
48
|
-
when 'a'
|
49
|
-
source.adjective
|
50
|
-
when 'n'
|
51
|
-
source.noun
|
52
|
-
when '%'
|
53
|
-
'%'
|
54
|
-
end
|
55
|
-
end
|
56
|
-
end
|
23
|
+
def_delegators :@corpus, :adjective, :noun, :adverb, :verb, :adjectives, :nouns, :adverbs, :verbs, :pair, :format
|
57
24
|
end
|
58
25
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: spicy-proton
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.0
|
4
|
+
version: 2.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Chris Schmich
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-02-
|
11
|
+
date: 2017-02-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bindata
|
@@ -46,10 +46,15 @@ extra_rdoc_files: []
|
|
46
46
|
files:
|
47
47
|
- LICENSE
|
48
48
|
- README.md
|
49
|
+
- lib/corpus.rb
|
49
50
|
- lib/corpus/adjectives-fixed.bin
|
50
51
|
- lib/corpus/adjectives.bin
|
52
|
+
- lib/corpus/adverbs-fixed.bin
|
53
|
+
- lib/corpus/adverbs.bin
|
51
54
|
- lib/corpus/nouns-fixed.bin
|
52
55
|
- lib/corpus/nouns.bin
|
56
|
+
- lib/corpus/verbs-fixed.bin
|
57
|
+
- lib/corpus/verbs.bin
|
53
58
|
- lib/disk-corpus.rb
|
54
59
|
- lib/header.rb
|
55
60
|
- lib/memory-corpus.rb
|
@@ -75,7 +80,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
75
80
|
version: '0'
|
76
81
|
requirements: []
|
77
82
|
rubyforge_project:
|
78
|
-
rubygems_version: 2.
|
83
|
+
rubygems_version: 2.6.8
|
79
84
|
signing_key:
|
80
85
|
specification_version: 4
|
81
86
|
summary: Generate a random English adjective-noun word pair.
|