dogeify 1.0.0 → 1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +8 -8
- data/.travis.yml +9 -0
- data/README.md +12 -4
- data/lib/dogeify.rb +47 -8
- data/lib/dogeify/version.rb +1 -1
- data/spec/dogeify_spec.rb +42 -7
- data/tasks/rspec.rake +3 -0
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
ZGE1NDE5NzU4NGQxZjFlYjUyMGExNDRkOWFmNjIxN2YyMmNmYzcwNw==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
MzlkZjM2ODk1M2E5Yjg3OGU2YjU2NDNiZmJhNTQxMDMwZWFkMDFiYw==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
NDgwYTc3MDU4YjE4NDE3Nzg0MTA3OWMzNmZlYzYzNTI0NGEyYTBkMTdhNjIz
|
10
|
+
ZDdmMzFkMTY2ZWRiNjkyYjBkMTU0MGI5ZGFhM2NhMDE4ODkyMjE1NTJlZTRh
|
11
|
+
Y2Y0MDliNGRhOTY5NzMzNjJjZmM3MWRiNGQ1ZTNmYzU1MjgyMDE=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
N2FiNWVjZThhNDE0NzZiMTUzM2MwZjFlYmJlOTk1MDNjNzYzNWI3NTlmOGZl
|
14
|
+
ODMxZmRhM2NhMmFlZjg0MTZjY2YxNmFhYmI2NzdhMDA0ZDg4NjQ1N2RmZDJk
|
15
|
+
MTljZjhjYmFiZjY5MWNlMjJhNjA5MTQ3NjUzMDYzMzdlYzg3OTQ=
|
data/.travis.yml
ADDED
data/README.md
CHANGED
@@ -1,5 +1,8 @@
|
|
1
1
|
# Dogeify
|
2
2
|
|
3
|
+
[](http://travis-ci.org/mhuggins/dogeify)
|
4
|
+
[](https://codeclimate.com/github/mhuggins/dogeify)
|
5
|
+
|
3
6
|
Convert English to [Doge](http://en.wikipedia.org/wiki/Doge_(meme))!
|
4
7
|
|
5
8
|
Please note that this gem is using an extremely simple language natural
|
@@ -26,8 +29,8 @@ There are several ways of using Dogeify. The first way is to go through the
|
|
26
29
|
|
27
30
|
require 'dogeify'
|
28
31
|
|
29
|
-
|
30
|
-
|
32
|
+
dogeifier = Dogeify.new
|
33
|
+
dogeifier.process('My grandmom gave me a sweater for Christmas.')
|
31
34
|
# => "so grandmom. such sweater. very christmas. wow."
|
32
35
|
|
33
36
|
The second way is to modify the String or Array classes by including either
|
@@ -37,12 +40,17 @@ core extension.
|
|
37
40
|
require 'dogeify/core_ext/string' # extends only String
|
38
41
|
require 'dogeify/core_ext' # extends both Array/String
|
39
42
|
|
40
|
-
'My grandmom gave me a sweater for Christmas.'.
|
43
|
+
'My grandmom gave me a sweater for Christmas.'.dogeify
|
41
44
|
# => "so grandmom. such sweater. very christmas. wow."
|
42
45
|
|
43
|
-
['I like turtles.', 'It is during our darkest moments that we must focus to see the light.'].
|
46
|
+
['I like turtles.', 'It is during our darkest moments that we must focus to see the light.'].dogeify
|
44
47
|
# => ["so turtles. wow.", "so darkest. such moments. very light. wow."]
|
45
48
|
|
49
|
+
Lastly, the `Dogeify` class along with all core extensions can be loaded via
|
50
|
+
a single require.
|
51
|
+
|
52
|
+
require 'dogeify/all'
|
53
|
+
|
46
54
|
## Contributing
|
47
55
|
|
48
56
|
1. Fork it
|
data/lib/dogeify.rb
CHANGED
@@ -2,26 +2,65 @@ require 'dogeify/version'
|
|
2
2
|
require 'engtagger'
|
3
3
|
|
4
4
|
class Dogeify
|
5
|
-
ADJECTIVES = %w
|
5
|
+
ADJECTIVES = %w[so such very much many how].freeze
|
6
|
+
EMOTIONS = %w[wow amaze excite].freeze
|
6
7
|
|
7
8
|
def initialize
|
8
9
|
@tagger = EngTagger.new
|
9
10
|
end
|
10
11
|
|
11
12
|
def process(str)
|
12
|
-
|
13
|
-
|
13
|
+
# Parse sentences.
|
14
|
+
sentences = str.downcase.split(/[\.!?]+/).map(&:strip)
|
14
15
|
|
15
|
-
|
16
|
-
|
17
|
-
|
16
|
+
sentences = sentences.map do |sentence|
|
17
|
+
# Select just the nouns.
|
18
|
+
tagged_sentence = tagger.add_tags(sentence)
|
19
|
+
phrases = tagger.get_nouns(tagged_sentence).keys rescue []
|
20
|
+
|
21
|
+
# Prefix nouns with adjectives, and convert to sentences.
|
22
|
+
phrases.map! { |phrase| correct_spelling(phrase) }
|
23
|
+
phrases.map! { |phrase| "#{adjective} #{phrase}." }
|
24
|
+
|
25
|
+
# Append a word or phrase describing emotion.
|
26
|
+
phrases << "#{emotional_summary}."
|
27
|
+
|
28
|
+
phrases.join(' ')
|
29
|
+
end
|
30
|
+
|
31
|
+
sentences.join(' ')
|
18
32
|
end
|
19
33
|
|
20
34
|
private
|
21
35
|
|
22
36
|
attr_reader :tagger
|
23
37
|
|
24
|
-
def
|
25
|
-
|
38
|
+
def correct_spelling(word)
|
39
|
+
word.dup.tap do |word|
|
40
|
+
word.gsub!(/er$/, 'ar') # super => supar
|
41
|
+
word.gsub!(/ph/, 'f') # phone => fone
|
42
|
+
word.gsub!(/cious/, 'shus') # delicious => delishus, deliciousness => delishusness
|
43
|
+
word.gsub!(/([^s])tion(s$)?/, '\1shun\2') # emotion => emoshun, emotions => emoshuns, emotionless => emoshunless, question (unchanged)
|
44
|
+
word.gsub!(/stion$/, 'schun') # question => queschun, potion (unchanged)
|
45
|
+
word.gsub!(/dog([^e]|\b)/, 'doge\1') # dog => doge, dogs => doges, underdog => underdoge, doge (unchanged)
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
def adjective
|
50
|
+
ADJECTIVES[adjective_offset]
|
51
|
+
end
|
52
|
+
|
53
|
+
def adjective_offset
|
54
|
+
@adjective_offset ||= -1
|
55
|
+
@adjective_offset = (@adjective_offset + 1) % ADJECTIVES.size
|
56
|
+
end
|
57
|
+
|
58
|
+
def emotional_summary
|
59
|
+
EMOTIONS[emotional_summary_offset]
|
60
|
+
end
|
61
|
+
|
62
|
+
def emotional_summary_offset
|
63
|
+
@emotional_summary_offset ||= -1
|
64
|
+
@emotional_summary_offset = (@emotional_summary_offset + 1) % EMOTIONS.size
|
26
65
|
end
|
27
66
|
end
|
data/lib/dogeify/version.rb
CHANGED
data/spec/dogeify_spec.rb
CHANGED
@@ -1,10 +1,21 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe Dogeify do
|
4
|
-
subject {
|
4
|
+
subject { described_class.new }
|
5
5
|
|
6
6
|
describe '#process' do
|
7
|
-
let(:input)
|
7
|
+
let(:input) do
|
8
|
+
%q{Doge is a slang term for "dog" that is primarily associated with
|
9
|
+
pictures of Shiba Inus (nicknamed "Shibe") and internal monologue
|
10
|
+
captions on Tumblr. These photos may be photoshopped to change the
|
11
|
+
dog's face or captioned with interior monologues in Comic Sans font.
|
12
|
+
The use of the misspelled word "doge" to refer to a dog dates back
|
13
|
+
to June 24th, 2005, when it was mentioned in an episode of Homestar
|
14
|
+
Runner's puppet show. In the episode titled "Biz Cas Fri 1",
|
15
|
+
Homestar calls Strong Bad his "d-o-g-e" while trying to distract him
|
16
|
+
from his work.}
|
17
|
+
end
|
18
|
+
|
8
19
|
let(:output) { subject.process(input) }
|
9
20
|
|
10
21
|
it 'converts to lowercase' do
|
@@ -12,13 +23,37 @@ describe Dogeify do
|
|
12
23
|
end
|
13
24
|
|
14
25
|
it 'combines nouns with doge adjectives' do
|
15
|
-
|
16
|
-
|
17
|
-
|
26
|
+
expected = 'so doge. such slang. very term. much doge. many pictures. ' <<
|
27
|
+
'how shiba. so inus. such shibe. very monologue. much ' <<
|
28
|
+
'capshuns. many tumblr.'
|
29
|
+
expect(output).to start_with expected
|
30
|
+
end
|
31
|
+
|
32
|
+
it 'appends an emotional summary to the end of each sentence' do
|
33
|
+
expect(output).to match /(wow\.).*(amaze\.).*(excite\.).*(wow\.)/
|
18
34
|
end
|
19
35
|
|
20
|
-
|
21
|
-
|
36
|
+
describe 'when the input is an empty string' do
|
37
|
+
let(:input) { '' }
|
38
|
+
|
39
|
+
it 'does not raise an error' do
|
40
|
+
expect { output }.to_not raise_error
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
describe 'when the input contains misspellable words' do
|
45
|
+
let(:input) do
|
46
|
+
%q{Mister Phoebe is always so emotionless. Maybe he needs a dog to
|
47
|
+
cheer him up. It might be a question worth answering!}
|
48
|
+
end
|
49
|
+
|
50
|
+
it 'intentionally misspells words' do
|
51
|
+
expect(output).to include 'mistar'
|
52
|
+
expect(output).to include 'foebe'
|
53
|
+
expect(output).to include 'emoshunless'
|
54
|
+
expect(output).to include 'doge'
|
55
|
+
expect(output).to include 'queschun'
|
56
|
+
end
|
22
57
|
end
|
23
58
|
end
|
24
59
|
end
|
data/tasks/rspec.rake
ADDED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dogeify
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Matt Huggins
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-03-31 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: engtagger
|
@@ -76,6 +76,7 @@ extra_rdoc_files: []
|
|
76
76
|
files:
|
77
77
|
- .gitignore
|
78
78
|
- .rspec
|
79
|
+
- .travis.yml
|
79
80
|
- Gemfile
|
80
81
|
- LICENSE.txt
|
81
82
|
- README.md
|
@@ -93,6 +94,7 @@ files:
|
|
93
94
|
- spec/dogeify_spec.rb
|
94
95
|
- spec/spec_helper.rb
|
95
96
|
- tasks/debug.rake
|
97
|
+
- tasks/rspec.rake
|
96
98
|
homepage: ''
|
97
99
|
licenses:
|
98
100
|
- MIT
|