valkey-objects 0.3.0 → 0.3.3

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1c9ee2ffcc565ef127499ebbca13af2561bc8cf20b624d951b279f698ecd2363
4
- data.tar.gz: 5408e161d38630e5d60eed393a4f053b57bb2bd4d9868fcb45792fb0f33f1683
3
+ metadata.gz: b0169fefb3f14682d8d94681c51bd83280905df791df21831cb60040bd904c0c
4
+ data.tar.gz: 7db81c16c1e59c21f4f2d7907b345d894ce1be1f13cab653b00072be722bb725
5
5
  SHA512:
6
- metadata.gz: 503fa253eb7d383b88d8aa4a9efca028f1a181e9c6aa14925ea4eefc99938538073a964c164e70832962a6b136294258abc8482029c04c1b9d9b4650047191fb
7
- data.tar.gz: 7eebd37730a11425a5f1b3917492f9c5c437fc40c18f995a83c1d71555a47eee1bd00265a3e8bbeff51999e6b58883ef55e21297b02b32ee119702cc0c1453ef
6
+ metadata.gz: fc5442667bbb4b4481feababacbbf3567acf2c398003c9eedf6865bad701bddc9de352aad822e9c72cb9ddc3a6ba98843a17bfdb698cbd3232148bac3875e2d7
7
+ data.tar.gz: 0d40f4a1024c7aa4cd6e2be8c8043bd0791da88e8db09ee9124a643ce4076010f55bf623b8c21f0c92e557afdf1e34719cd85bec86285765832c4da7aa5e133d
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Valkey
4
4
  module Objects
5
- VERSION = "0.3.0"
5
+ VERSION = "0.3.3"
6
6
  end
7
7
  end
@@ -2,21 +2,25 @@
2
2
 
3
3
  require_relative "objects/version"
4
4
 
5
- #require 'connection_pool'
5
+ require 'connection_pool'
6
6
  require 'redis-client'
7
7
  require 'json'
8
8
  require 'amatch'
9
9
  require 'ap'
10
10
  require 'yaml'
11
+ require 'classifier-reborn'
12
+ require 'knn'
13
+ require 'sentimental'
11
14
 
12
15
  module VK
13
16
 
17
+
14
18
  @@XX = {}
15
19
 
16
20
  def self.included(x)
17
21
  x.extend VK
18
22
  end
19
-
23
+
20
24
  def self.extended(x)
21
25
  ##
22
26
  # Example:
@@ -179,11 +183,11 @@ module VK
179
183
  define_method(:vector) { |k, h={}| define_method(k.to_sym) { VECTOR.new(%[#{xx}:vector:#{k}:#{@id}], h); } };
180
184
 
181
185
  end
182
-
186
+
183
187
  def id
184
188
  @id
185
189
  end
186
-
190
+
187
191
  def self.at epoch
188
192
  Time.at epoch
189
193
  end
@@ -197,11 +201,73 @@ module VK
197
201
  end
198
202
 
199
203
  def self.redis
200
- #@redis ||= ConnectionPool::Wrapper.new do
204
+ @redis ||= ConnectionPool::Wrapper.new do
201
205
  RedisClient.config(host: "127.0.0.1", port: 6379, db: 0).new_client
202
- #end
206
+ end
203
207
  end
204
-
208
+
209
+ @@SENTIMENT_THRESHOLD = 0.9
210
+ ##
211
+ # Bayesean Classification
212
+ #
213
+ # Determine the A OR B of an example.
214
+ ##
215
+ # VK.classify("catagory A", "Catagory B").
216
+ def self.classify(a, b)
217
+ ClassifierReborn::Bayes.new(a, b)
218
+ end
219
+
220
+ def self.threshold n
221
+ @@SENTIMENT_THRESHOLD = n
222
+ end
223
+ ##
224
+ # Sentiment Analysis.
225
+ ##
226
+ # VK.feels("Some text")
227
+ def self.feels x
228
+ Sentimental.new(threshold: @@SENTIMENT_THRESHOLD).sentiment
229
+ end
230
+
231
+ @@CRi = Hash.new { |h,k| h[k] = CRi.new(k) }
232
+ class CRi
233
+ def initialize k
234
+ @id = k
235
+ @lsi = ClassifierReborn::LSI.new
236
+ end
237
+ def learn x, i
238
+ @lsi.add_item x.to_s, i.to_sym
239
+ end
240
+ def [] k
241
+ @lsi.classify k
242
+ end
243
+ def search x, *n
244
+ @lsi.search(x, n[0])
245
+ end
246
+ end
247
+ ##
248
+ # Vector Indexing
249
+ #
250
+ # Vector (of text) -> concept (index)
251
+ # - Find text concept based upon known examples.
252
+ # - Learn new examples of a concept.
253
+ # - Find examples from within clusters.
254
+ ##
255
+ # index[:vector]['Text to classify'] => :index
256
+ # index[:vector].learn("Text to classify", :index)
257
+ # index[:vector].search("Similar text.", 5) => ["Similar text?", "other similar text", ...]
258
+ def self.index
259
+ @@CRi
260
+ end
261
+ ##
262
+ # Vector Engine
263
+ #
264
+ # Return known string based upon nearest neighbor by vector of number.
265
+ ##
266
+ # vector([["return val", 0, 1, 2, ...], ...]).classify(["guess", 0, 1, 2, ...]) => "return val"
267
+ def self.vector vectors, size
268
+ Knn::Classifier.new(vectors, SquaredEuclideanCalculator)
269
+ end
270
+
205
271
  class O
206
272
  attr_reader :key
207
273
  def initialize k, h={}
@@ -547,6 +613,70 @@ module VK
547
613
  VK.redis.call("RPUSH", key, hx)
548
614
  end
549
615
  end
616
+
617
+ @@SENTIMENT_THRESHOLD = 0.9
618
+ @@RCB = ClassifierReborn::BayesRedisBackend.new {host: "127.0.0.1", port: 6379, db: 1}
619
+ ##
620
+ # Bayesean Classification
621
+ #
622
+ # Determine the A OR B of an example.
623
+ ##
624
+ # VK.classify("catagory A", "Catagory B").
625
+ def self.classify a, b
626
+ ClassifierReborn::Bayes.new a, b, @@RBC
627
+ end
628
+
629
+ def self.threshold= n
630
+ @@SENTIMENT_THRESHOLD = n
631
+ end
632
+ ##
633
+ # Sentiment Analysis.
634
+ ##
635
+ # VK.feels("Some text")
636
+ def self.feels x
637
+ Sentimental.new(threshold: @@SENTIMENT_THRESHOLD).sentiment
638
+ end
639
+
640
+ @@CRi = Hash.new { |h,k| h[k] = CRi.new(k) }
641
+ class CRi
642
+ def initialize k
643
+ @id = k
644
+ @lsi = ClassifierReborn::LSI.new
645
+ end
646
+ def learn x, i
647
+ @lsi.add_item x.to_s, i.to_sym
648
+ end
649
+ def [] k
650
+ @lsi.classify k
651
+ end
652
+ def search x, *n
653
+ @lsi.search(x, n[0])
654
+ end
655
+ end
656
+ ##
657
+ # Vector Indexing
658
+ #
659
+ # Vector (of text) -> concept (index)
660
+ # - Find text concept based upon known examples.
661
+ # - Learn new examples of a concept.
662
+ # - Find examples from within clusters.
663
+ ##
664
+ # index[:vector]['Text to classify'] => :index
665
+ # index[:vector].learn("Text to classify", :index)
666
+ # index[:vector].search("Similar text.", 5) => ["Similar text?", "other similar text", ...]
667
+ def self.index
668
+ @@CRi
669
+ end
670
+ ##
671
+ # Vector Engine
672
+ #
673
+ # Return known string based upon nearest neighbor by vector of number.
674
+ ##
675
+ # vector([["return val", 0, 1, 2, ...], ...]).classify(["guess", 0, 1, 2, ...]) => "return val"
676
+ def self.vector vectors, size
677
+ Knn::Classifier.new(vectors, distance_calculator = SquaredEuclideanCalculator)
678
+ end
679
+
550
680
 
551
681
  def self.flushdb!
552
682
  VK.redis.call("FLUSHDB")
@@ -31,12 +31,16 @@ Gem::Specification.new do |spec|
31
31
  spec.require_paths = ["lib"]
32
32
 
33
33
  # Uncomment to register a new dependency of your gem
34
-
34
+
35
+ spec.add_dependency "connection_pool"
35
36
  spec.add_dependency "redis-client"
36
37
  spec.add_dependency "json"
37
38
  spec.add_dependency "ruby-duration"
38
- spec.add_dependency "pry"
39
+ spec.add_dependency "classifier-reborn"
39
40
  spec.add_dependency "amatch"
41
+ spec.add_dependency "knn"
42
+
43
+ spec.add_dependency "pry"
40
44
  spec.add_dependency "awesome_print"
41
45
  # For more information and examples about making a new gem, check out our
42
46
  # guide at: https://bundler.io/guides/creating_gem.html
metadata CHANGED
@@ -1,14 +1,28 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: valkey-objects
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.3.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Erik Olson
8
8
  bindir: exe
9
9
  cert_chain: []
10
- date: 2025-02-15 00:00:00.000000000 Z
10
+ date: 2025-04-25 00:00:00.000000000 Z
11
11
  dependencies:
12
+ - !ruby/object:Gem::Dependency
13
+ name: connection_pool
14
+ requirement: !ruby/object:Gem::Requirement
15
+ requirements:
16
+ - - ">="
17
+ - !ruby/object:Gem::Version
18
+ version: '0'
19
+ type: :runtime
20
+ prerelease: false
21
+ version_requirements: !ruby/object:Gem::Requirement
22
+ requirements:
23
+ - - ">="
24
+ - !ruby/object:Gem::Version
25
+ version: '0'
12
26
  - !ruby/object:Gem::Dependency
13
27
  name: redis-client
14
28
  requirement: !ruby/object:Gem::Requirement
@@ -52,7 +66,7 @@ dependencies:
52
66
  - !ruby/object:Gem::Version
53
67
  version: '0'
54
68
  - !ruby/object:Gem::Dependency
55
- name: pry
69
+ name: classifier-reborn
56
70
  requirement: !ruby/object:Gem::Requirement
57
71
  requirements:
58
72
  - - ">="
@@ -79,6 +93,34 @@ dependencies:
79
93
  - - ">="
80
94
  - !ruby/object:Gem::Version
81
95
  version: '0'
96
+ - !ruby/object:Gem::Dependency
97
+ name: knn
98
+ requirement: !ruby/object:Gem::Requirement
99
+ requirements:
100
+ - - ">="
101
+ - !ruby/object:Gem::Version
102
+ version: '0'
103
+ type: :runtime
104
+ prerelease: false
105
+ version_requirements: !ruby/object:Gem::Requirement
106
+ requirements:
107
+ - - ">="
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
110
+ - !ruby/object:Gem::Dependency
111
+ name: pry
112
+ requirement: !ruby/object:Gem::Requirement
113
+ requirements:
114
+ - - ">="
115
+ - !ruby/object:Gem::Version
116
+ version: '0'
117
+ type: :runtime
118
+ prerelease: false
119
+ version_requirements: !ruby/object:Gem::Requirement
120
+ requirements:
121
+ - - ">="
122
+ - !ruby/object:Gem::Version
123
+ version: '0'
82
124
  - !ruby/object:Gem::Dependency
83
125
  name: awesome_print
84
126
  requirement: !ruby/object:Gem::Requirement