classifier 2.6.0 → 2.7.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.
data/CLAUDE.md DELETED
@@ -1,77 +0,0 @@
1
- # CLAUDE.md
2
-
3
- This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
4
-
5
- ## Project Overview
6
-
7
- Ruby gem providing text classification via two algorithms:
8
- - **Bayes** (`Classifier::Bayes`) - Naive Bayesian classification
9
- - **LSI** (`Classifier::LSI`) - Latent Semantic Indexing for semantic classification, clustering, and search
10
-
11
- ## Common Commands
12
-
13
- ```bash
14
- # Compile native C extension
15
- bundle exec rake compile
16
-
17
- # Run all tests (compiles first)
18
- bundle exec rake test
19
-
20
- # Run a single test file
21
- ruby -Ilib test/bayes/bayesian_test.rb
22
- ruby -Ilib test/lsi/lsi_test.rb
23
-
24
- # Run tests with pure Ruby (no native extension)
25
- NATIVE_VECTOR=true bundle exec rake test
26
-
27
- # Run benchmarks
28
- bundle exec rake benchmark
29
- bundle exec rake benchmark:compare
30
-
31
- # Interactive console
32
- bundle exec rake console
33
-
34
- # Generate documentation
35
- bundle exec rake doc
36
- ```
37
-
38
- ## Architecture
39
-
40
- ### Core Components
41
-
42
- **Bayesian Classifier** (`lib/classifier/bayes.rb`)
43
- - Train with `train(category, text)` or dynamic methods like `train_spam(text)`
44
- - Classify with `classify(text)` returning the best category
45
- - Uses log probabilities for numerical stability
46
-
47
- **LSI Classifier** (`lib/classifier/lsi.rb`)
48
- - Uses Singular Value Decomposition (SVD) for semantic analysis
49
- - Native C extension for 5-50x faster matrix operations; falls back to pure Ruby
50
- - Key operations: `add_item`, `classify`, `find_related`, `search`
51
- - `auto_rebuild` option controls automatic index rebuilding after changes
52
-
53
- **String Extensions** (`lib/classifier/extensions/word_hash.rb`)
54
- - `word_hash` / `clean_word_hash` - tokenize text to stemmed word frequencies
55
- - `CORPUS_SKIP_WORDS` - stopwords filtered during tokenization
56
- - Uses `fast-stemmer` gem for Porter stemming
57
-
58
- **Vector Extensions** (`lib/classifier/extensions/vector.rb`)
59
- - Pure Ruby SVD implementation (`Matrix#SV_decomp`) - used as fallback
60
- - Vector normalization and magnitude calculations
61
-
62
- ### Native C Extension (`ext/classifier/`)
63
-
64
- LSI uses a native C extension for fast linear algebra operations:
65
- - `Classifier::Linalg::Vector` - Vector operations (alloc, normalize, dot product)
66
- - `Classifier::Linalg::Matrix` - Matrix operations (alloc, transpose, multiply)
67
- - Jacobi SVD implementation for singular value decomposition
68
-
69
- Check current backend: `Classifier::LSI.backend` returns `:native` or `:ruby`
70
- Force pure Ruby: `NATIVE_VECTOR=true bundle exec rake test`
71
-
72
- ### Content Nodes (`lib/classifier/lsi/content_node.rb`)
73
-
74
- Internal data structure storing:
75
- - `word_hash` - term frequencies
76
- - `raw_vector` / `raw_norm` - initial vector representation
77
- - `lsi_vector` / `lsi_norm` - reduced dimensionality representation after SVD