Skip to content

Commit fe24d99

Browse files
authored
feat: Add streaming training and incremental SVD support (#109)
* feat(knn): add train alias and standardize API for classifier consistency - Add `train` as alias for `add` method - Add dynamic `train_*` methods (train_spam, train_ham, etc.) - Standardize `classify` to return String instead of String|Symbol - Standardize `categories` to return Array[String] - Add tests for new API consistency features This enables writing classifier-agnostic code that works with Bayes, LogisticRegression, and kNN interchangeably. * refactor: remove redundant inline comments from incremental SVD Strip inline step comments that restate what the code does while keeping method-level RDoc descriptions and @RBS type annotations. Simplifies code without losing documentation value. * fix(types): resolve Steep type errors and improve RBS coverage Reduce Steep errors from 183 to 2 warnings by: - Adding Matrix/Vector methods to sig/vendor/matrix.rbs - Fixing train_batch signatures to allow nil optional params - Adding type assertions for type narrowing in streaming code - Using explicit type casts for storage.path access - Fixing Enumerable generic type for LineReader The remaining 2 warnings are Steep limitations with restarg (*). * test: add enforcement test for Streaming module inclusion Ensures all classifiers (Bayes, LSI, KNN, LogisticRegression, TFIDF) include the Streaming module and respond to required methods. This catches missing implementations when new classifiers are added. * refactor(test): auto-discover classifiers for Streaming enforcement Replace hardcoded CLASSIFIERS list with dynamic discovery using Classifier.constants. Classes with `classify` or `transform` methods are considered classifiers/vectorizers that must include Streaming. New classifiers are automatically tested when added to the module. * refactor(test): auto-discover classifiers for Storage API enforcement Apply same dynamic discovery pattern to StorageAPIConsistencyTest. New classifiers are automatically tested for storage API methods. * refactor: use early returns and remove redundant check Address PR review feedback: - Remove duplicate respond_to?(:size) check in LineReader - Convert nested if/elsif to early return in LSI#add_item - Use next to flatten synchronize block in perform_incremental_update * fix: resolve RBS syntax errors from multiline @RBS annotations - Collapse multiline @RBS annotations to single lines (rbs-inline requirement) - Add explicit @RBS! block for KNN alias declaration - Increase RuboCop line length limit to 140 for type annotations - Fix Style/IfUnlessModifier in tfidf.rb * refactor: simplify code per PR review feedback - Remove unnecessary defensive code in IncrementalSVD#project - Use early return in reproject_all_documents * fix(types): resolve RBS validation errors for Matrix/Vector/Enumerable - Make Matrix and Vector non-generic in sig/vendor/matrix.rbs - Add type parameter to Enumerable include in LineReader (#[String]) This fixes InvalidTypeApplicationError from rbs validate. * fix(types): resolve Steep type checking errors - Make train_batch params nilable (?(Type)? syntax) in all classifiers - Add _StreamingHost interface for Streaming module dependencies - Fix TFIDF stub methods with proper RBS and steep:ignore - Make Matrix/Vector non-generic in vendor RBS - Add Enumerable type param to LineReader
1 parent 0aa800c commit fe24d99

23 files changed

Lines changed: 3108 additions & 495 deletions

.rubocop.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@ plugins:
55
Layout/LeadingCommentSpace:
66
AllowRBSInlineAnnotation: true
77

8+
# @rbs type annotations can be long
9+
Layout/LineLength:
10+
Max: 140
11+
812
AllCops:
913
TargetRubyVersion: 3.1
1014
NewCops: enable

0 commit comments

Comments
 (0)