moo_ebooks 1.0.2 → 1.1.0

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
- SHA256:
3
- metadata.gz: 1e80f927457320bab78361c0b196276251fbb94c952f0c4a43f1efd9c4fd301c
4
- data.tar.gz: fa1a1a0a2b0e42b2eec417543116cb8c5a0ba3a5e7376e7c2375d9722695067b
2
+ SHA1:
3
+ metadata.gz: ca3871121fb9d2f07baf2afa539686b46a7f1d8c
4
+ data.tar.gz: 6b219bdc101f8620b8e5ff827165835ffc5065c2
5
5
  SHA512:
6
- metadata.gz: 9958e0e4943746da9fbc269c407718eeb0628422cf2e6489f545fa0c59c875fa3dcb6d6cb438b6fcedfed8d45d6dad4c0a0fd9871efaa0293f3f2f58ea096790
7
- data.tar.gz: 342594b950cc0d1615fd40aee9b09c5f67d73c55a1a3202fea4feae1f7ba9a057fad7871f9c1231f07a65281c546cee6eab94e7976b48c8e29325b6409086600
6
+ metadata.gz: 917a354b63c9549569e0bd7141261d22d2d39488c6b85d2f928c44da3b2f36b2039ce151995610f3657223c7e8adf3a8d4f6c574308c159f8f627cfe643175b5
7
+ data.tar.gz: ff0784492e5c5cbf3a905bf5ec946cdede1235cc061b04ca7cb8a089f3488e862e0177febd92f35a054bd27cdc723e971ffd975899d7d35692314c1a797242c8
data/README.md CHANGED
@@ -34,8 +34,14 @@ or simply run `gem install moo_ebooks`
34
34
 
35
35
  ## Example usage code
36
36
 
37
+ Say, for example, we have a json file full of statuses in 'statuses.json'. These statuses are arranged so that there is an array of strings with the key ':statuses'. The following code will read that file in, create a model based off of it and print out a randomly generated status based off of them.
38
+
37
39
  ``` ruby
38
- # No example ready yet.
40
+ require 'moo_ebooks'
41
+
42
+ Model = Ebooks::Model.from_json(File.read('statuses.json'))
43
+
44
+ Model.update
39
45
  ```
40
46
 
41
47
  ## Versioning
@@ -1,6 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'json'
4
+ require 'yaml'
4
5
  require 'set'
5
6
  require 'digest/md5'
6
7
 
@@ -41,6 +42,13 @@ module Ebooks
41
42
  @tikis = {}
42
43
  end
43
44
 
45
+ # Load a saved model
46
+ # @param data [String]
47
+ # @return [Ebooks::Model]
48
+ def self.from_yaml(data)
49
+ from_hash(YAML.load(data))
50
+ end
51
+
44
52
  # Load a saved model
45
53
  # @param data [Hash]
46
54
  # @return [Ebooks::Model]
@@ -60,6 +68,11 @@ module Ebooks
60
68
  from_hash(JSON.parse(data, symbolize_names: true))
61
69
  end
62
70
 
71
+ # Turn this model into its YAML representation.
72
+ def to_yaml
73
+ to_hash.to_yaml
74
+ end
75
+
63
76
  # Turn this model into its JSON representation.
64
77
  def to_json
65
78
  to_hash.to_json
@@ -218,8 +231,20 @@ module Ebooks
218
231
  end
219
232
 
220
233
  text = statuses.join("\n").encode('UTF-8', invalid: :replace)
221
- @sentences = mass_tikify(text)
222
- @keywords = NLP.keywords(text).top(200).map(&:to_s)
234
+
235
+ # adds the new sentence structures into the sentence array
236
+ # instead of overwriting it
237
+ mass_tikify(text).each do |sentence|
238
+ @sentences << sentence
239
+ end
240
+
241
+ # if we're gonna keep the keyword limit at 200 and we want to preserve
242
+ # our old keywords array then my solution is to union the new array
243
+ # with the old, randomize them and take the first 200
244
+ @keywords = @keywords.union(NLP
245
+ .keywords(text)
246
+ .top(200)
247
+ .map(&:to_s)).sample(200)
223
248
 
224
249
  nil
225
250
  end
@@ -232,7 +257,11 @@ module Ebooks
232
257
  end
233
258
 
234
259
  mention_text = mentions.join("\n").encode('UTF-8', invalid: :replace)
235
- @mentions = mass_tikify(mention_text)
260
+ # the same as above, we just add onto our array instead of
261
+ # overwriting it
262
+ mass_tikify(mention_text).each do |mention|
263
+ @mentions << mention
264
+ end
236
265
 
237
266
  nil
238
267
  end
@@ -2,8 +2,8 @@
2
2
 
3
3
  module Ebooks
4
4
  MAJOR = 1
5
- MINOR = 0
6
- PATH = 2
5
+ MINOR = 1
6
+ PATH = 0
7
7
 
8
8
  VERSION = "#{MAJOR}.#{MINOR}.#{PATH}"
9
9
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: moo_ebooks
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.2
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jaiden Mispy
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2018-09-17 00:00:00.000000000 Z
12
+ date: 2019-07-29 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec
@@ -148,7 +148,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
148
148
  version: '0'
149
149
  requirements: []
150
150
  rubyforge_project:
151
- rubygems_version: 2.7.7
151
+ rubygems_version: 2.5.2.1
152
152
  signing_key:
153
153
  specification_version: 4
154
154
  summary: A minimalistic ebook library