research_topicgen 0.1.5 → 0.1.6

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c5ef9c146178296caced8f9e09f4390e59cf3e0a
4
- data.tar.gz: bb8835e7aea709305471e93afab6b776bc4926d1
3
+ metadata.gz: 654292e2322811e50513736473f49eaf74006d21
4
+ data.tar.gz: 51f2a4ea238e8c94f71ebd8b9d0724bce7b8ff16
5
5
  SHA512:
6
- metadata.gz: 19a2e9bc86cdd870775ea797621e38c7c264c8f7d1a31b6bf958b13968ca80ff44d289d9ebb066c9eaa3666f06c9be865fc2f74848a10d91fadd1f305051b68e
7
- data.tar.gz: 66049c36d754e387706508331cc3cda173ed42598bfcb13c3abf16248fce53e80d62206d77a9b4c0a6b83777a1a53b9f488c16a52b4f3714dbac97cae0eed7c1
6
+ metadata.gz: 74c779957016325da464929f22b149fa3eb14fe87a4ae6e5ab03fedfa1bd1bbccdfc39aa4d7004373231dba8cf9a1e416e8f40a9991bb18dafd77e5c5cebc9a4
7
+ data.tar.gz: c2176872c561085c96fc37c6a9b165e47bcc4d356be4ebb78aaf02e4b9d34c62ec500603d31996690c99e32d0383c4da126236f7c9b506573246fda6b6b57a2d
File without changes
File without changes
File without changes
@@ -1,123 +1,149 @@
1
1
  require 'psych'
2
2
 
3
3
  module ResearchTopicGen
4
- VERSION = '0.1.3'.freeze
4
+ VERSION = '0.1.6'.freeze
5
+ BZS = %i[buzz1 buzz2 buzz3]
5
6
 
6
- def self.load_yml_data(topic)
7
- Psych.load_file(File.join(File.dirname(__FILE__), "data", "#{topic}.yml"))
8
- end
9
-
10
- def self.load_file(topic)
11
- case topic
12
- when 'cs'
13
- [load_yml_data('connectives'), load_yml_data('cs_data')]
14
- when 'system'
15
- [load_yml_data('connectives'), load_yml_data('system_data')]
16
- when 'crypto'
17
- load_yml_data('crypto_data')
7
+ # Crypto Research Topic Generator
8
+ def self.crypto
9
+ cf = self.load_yml_data( 'crypto' )
10
+ word1, word2, word3 = self.samples( BZS, cf )
11
+ until word1 != word2
12
+ word2 = cf[:buzz2].sample
18
13
  end
14
+ pre_connective = self.add_article(word1, caps=true)
15
+ "#{pre_connective} #{word1}, #{word2} #{word3}."
19
16
  end
20
-
17
+
21
18
  # CS Research Topic Generator
22
19
  def self.cs
23
20
  connectives_file, cs_file = self.load_file('cs')
24
- connectives = *connectives_file[:common_connectives], *connectives_file[:extra_connectives][1]
25
- connectives.flatten!
26
- sentence = [cs_file[:buzz1].sample,
27
- cs_file[:buzz2].sample,
28
- cs_file[:buzz3].sample,
29
- connectives.sample,
30
- cs_file[:buzz1].sample,
31
- cs_file[:buzz2].sample,
32
- cs_file[:buzz3].sample
33
- ]
34
- pre_connective = ResearchTopicGen.add_article(sentence[0], true)
35
- mid_connective = ResearchTopicGen.add_article(sentence[4], false)
36
- sentence.insert(0, pre_connective)
37
- sentence.insert(5, mid_connective)
38
- "#{sentence.join(' ')}."
21
+ com_connective = [
22
+ connectives_file[:common_connectives].sample,
23
+ connectives_file[:extra_connectives][1]
24
+ ].sample
25
+
26
+ pre_wrds = self.samples( %i[buzz1 buzz2 buzz3], cs_file )
27
+ pst_wrds = self.samples( %i[buzz1 buzz2 buzz3], cs_file )
28
+ pre_connective = self.add_article(pre_wrds.first, caps=true)
29
+ mid_connective = self.add_article(pst_wrds.first)
30
+
31
+ sentence = [
32
+ pre_connective,
33
+ *pre_wrds,
34
+ com_connective,
35
+ mid_connective,
36
+ *pst_wrds
37
+ ]
38
+ "#{sentence.join ' '}."
39
39
  end
40
40
 
41
41
  # System Research Topic Generatorg
42
42
  def self.system
43
- connectives_file, system_file = self.load_file('system')
44
- connectives = *connectives_file[:common_connectives], *connectives_file[:extra_connectives][0]
45
- connectives.flatten!
46
- word1, word2, word3, word4 = system_file[:buzz1].sample, system_file[:buzz2].sample, system_file[:buzz3].sample, system_file[:buzz2].sample
47
- name, ingword = system_file[:names].sample, system_file[:ings].sample
48
-
49
- word2, word3, word4 =
50
- case
51
- when word2 == word1
52
- self.random_word(system_file, 1, word1, word2)
53
- when word3 == word1 || word3 == word2
54
- self.random_word(system_file, 2, word1, word2, word3)
55
- when word4 == word2 || word4 == word3 || word4 == word1
56
- self.random_word(system_file, 3, word1, word2, word3, word4)
57
- else
58
- [word2, word3, word4]
59
- end
60
-
61
- # generic: [name]: [word1], [word2] [word3]
62
- pre_connective = self.add_article(word1, true)
63
- result1 = "#{name}: #{pre_connective} #{word1}, #{word2} #{word3}"
64
-
65
- # approach-based: [generic] - [a/an] [buzz2] approach
66
- mid_connective = self.add_article(word4, false)
67
- result2 = "#{name}:#{word1}, #{word2} #{word3}s-- #{mid_connective} #{word4} approach"
68
-
69
- # on...: on[foo]s
70
- result3 = "On #{word1}, #{word2} #{word3}s"
71
- word5, word6, word7 = system_file[:buzz1].sample, system_file[:buzz2].sample, system_file[:buzz3].sample
72
- mid_connective = self.add_article(word5, false)
73
- word6 = self.random_word(system_file, 4, word1, word2, word3, word5, word6) if word5 == word6 || word5 == word3 || word5 == word2 || word5 == word1
74
- word7 = self.random_word(system_file, 5, word1, word2, word3, word5, word6, word7) if word7 == word5 || word7 == word6 || word7 == word3 || word7 == word2 || word7 == word1
75
- result4 = "#{result1} #{mid_connective} #{word5} #{word6} #{word7}s"
76
- result5 = "#{ingword} #{word1}, #{word2} #{word3}s"
77
- results = [result1, result2, result3, result4, result5]
78
- "#{results.sample}."
79
- end
80
-
81
- # Crypto Research Topic Generator
82
- def self.crypto
83
- crypto_file = self.load_file('crypto')
84
- word1, word2, word3 = crypto_file[:buzz1].sample, crypto_file[:buzz2].sample, crypto_file[:buzz3].sample
85
- word2 = word2.match(word1) ? ResearchTopicGen.random_word(crypto_file, 1, word1, word2) : word2 #If word1 and word2 are same, replace word2 with a different word.
86
- pre_connective = ResearchTopicGen.add_article(word1, true)
87
- sentence = "#{pre_connective} #{word1}, #{word2} #{word3}."
43
+ mtds = [:generic, :approach_based, :onfoo, :looong, :ings]
44
+ gen = SystemTopicGenerator.new
45
+ gen.send( mtds.sample )
88
46
  end
89
47
 
90
48
  # Generate Random Topic
91
49
  def self.random
92
- result = [ResearchTopicGen.cs, ResearchTopicGen.system, ResearchTopicGen.crypto].sample
50
+ topic = %w[ cs system crypto ].sample
51
+ self.send( topic )
93
52
  end
94
53
 
95
- # Logic here needs a change.
96
- def self.random_word(file, checks, *col)
97
- if checks == 2
98
- col[2] = file[:buzz3].sample until col[0] != col[2] || col[1] != col[2]
99
- col[1..checks]
100
- elsif checks == 3
101
- col[3] = file[:buzz2].sample until col[3] != col[1] || col[3] != col[2] || col[3] != col[0]
102
- col[1..checks]
103
- elsif checks == 4
104
- col[4] = file[:buzz2].sample until col[3] != col[4] || col[3] != col[2] || col[3] != col[1] || col[3] != col[0]
105
- elsif checks == 5
106
- col[5] = file[:buzz3].sample until col[5] != col[3] || col[5] != col[4] || col[5] != col[2] || col[5] != col[1]
107
- else
108
- col[1] = file[:buzz2].sample until col[0] != col[1]
109
- col[1]
54
+ # System Research Topic Generatorg
55
+ class SystemTopicGenerator
56
+ def initialize
57
+ @connectives_file, @system_file = ResearchTopicGen.load_file('system')
58
+ @added = {}
59
+ @words = []
60
+ end
61
+
62
+ # generic: [name]: [word1], [word2] [word3]
63
+ def generic
64
+ w1_3 = format_words( 0, caps = true )
65
+ "#{gen_word( :names )}: #{w1_3}"
66
+ end
67
+
68
+ # approach-based: [generic] - [a/an] [buzz2] approach
69
+ def approach_based
70
+ buzz2 = gen_word :buzz2
71
+ article = ResearchTopicGen.add_article( buzz2 )
72
+ "#{generic} - #{article} #{buzz2} approach"
73
+ end
74
+
75
+ # on...: on[foo]s
76
+ def onfoo
77
+ foo = format_words( 0, article=false )
78
+ "on #{foo}s"
79
+ end
80
+
81
+ # [generic] [a/an] [buzz1], [buzz2] [buzz3]s
82
+ def looong
83
+ rest = format_words( 4 )
84
+ "#{generic} #{rest}s"
85
+ end
86
+
87
+ # [ing] [buzz1] [buzz2] [buzz3]s
88
+ def ings
89
+ ing = gen_word( :ings )
90
+ rest = format_words(0, article=false)
91
+ "#{ing} #{rest}s"
92
+ end
93
+
94
+ private
95
+
96
+ def format_words( offset, caps = false, article = true )
97
+ gen_words # (re-)generate a fresh set of words
98
+ ws = @words[offset, 3]
99
+ bz1 = ws.first
100
+ bz2_3 = ws[1, 2].join( ' ' )
101
+ article = article ? ResearchTopicGen.add_article( bz1, caps ) : ''
102
+ "#{article} #{bz1}, #{bz2_3}"
103
+ end
104
+
105
+ def gen_word( bz )
106
+ loop do
107
+ word = @system_file[bz].sample
108
+ unless @added[word]
109
+ @added[word] = true
110
+ return word
111
+ end
112
+ end
113
+ end
114
+
115
+ def gen_words
116
+ # flush stored results
117
+ @added = {}
118
+ @words = []
119
+ BZS.cycle(2).map do |bz|
120
+ @words.push gen_word( bz )
121
+ end
122
+ @words.insert(3, gen_word(:buzz2))
110
123
  end
111
124
  end
112
125
 
113
- # return the correct article
114
- def self.add_article(word, caps)
115
- if word.match(/^[aeiou]/i)
116
- article = "an"
126
+
127
+ def self.add_article(word, caps=false)
128
+ if word.downcase.start_with?('a', 'e', 'i', 'o', 'u')
129
+ article = "an"
117
130
  else
118
- article = 'a'
119
- end
120
- caps ? article.capitalize : article
131
+ article = 'a'
121
132
  end
122
- end
133
+ caps ? article.capitalize : article
134
+ end
135
+
136
+ def self.samples( keys , table )
137
+ keys.map { |key| table[key].sample }
138
+ end
123
139
 
140
+ def self.load_yml_data(topic)
141
+ data = File.join( File.dirname(__FILE__), "data", "#{topic}.yml" )
142
+ Psych.load_file( data )
143
+ end
144
+
145
+ def self.load_file(topic)
146
+ conf = load_yml_data('connectives')
147
+ [ conf, load_yml_data(topic) ]
148
+ end
149
+ end
metadata CHANGED
@@ -1,17 +1,17 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: research_topicgen
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.5
4
+ version: 0.1.6
5
5
  platform: ruby
6
6
  authors:
7
- - slackr
7
+ - rmNULL
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-01-22 00:00:00.000000000 Z
11
+ date: 2017-08-01 00:00:00.000000000 Z
12
12
  dependencies: []
13
- description: A simple gem to generate worthy Research Topics.
14
- email: slackErEhth77@openmailbox.org
13
+ description: A simple gem to generate worthy research Topics.
14
+ email: none
15
15
  executables:
16
16
  - research_topicgen
17
17
  extensions: []
@@ -19,9 +19,9 @@ extra_rdoc_files: []
19
19
  files:
20
20
  - bin/research_topicgen
21
21
  - lib/data/connectives.yml
22
- - lib/data/crypto_data.yml
23
- - lib/data/cs_data.yml
24
- - lib/data/system_data.yml
22
+ - lib/data/crypto.yml
23
+ - lib/data/cs.yml
24
+ - lib/data/system.yml
25
25
  - lib/research_topicgen.rb
26
26
  homepage: https://github.com/and-the-rest/research_topicgen
27
27
  licenses:
@@ -43,7 +43,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
43
43
  version: '0'
44
44
  requirements: []
45
45
  rubyforge_project:
46
- rubygems_version: 2.5.1
46
+ rubygems_version: 2.6.11
47
47
  signing_key:
48
48
  specification_version: 4
49
49
  summary: research_topicgen - A Research Topic Generator