Skip to content

Commit 9ad363d

Browse files
authored
Merge pull request #49 from cardmagic/feature/rbs-types
Add RBS type signatures
2 parents 94c6b8a + c1cfb1c commit 9ad363d

9 files changed

Lines changed: 177 additions & 0 deletions

File tree

.github/workflows/ruby.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,3 +33,7 @@ jobs:
3333
bundler-cache: true # runs 'bundle install' and caches installed gems automatically
3434
- name: Run tests
3535
run: bundle exec rake test
36+
- name: Install RBS
37+
run: gem install rbs
38+
- name: Validate RBS types
39+
run: rbs -I sig validate

sig/classifier.rbs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
module Classifier
2+
end

sig/classifier/bayes.rbs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
module Classifier
2+
class Bayes
3+
@categories: Hash[Symbol, Hash[Symbol, Integer]]
4+
@total_words: Integer
5+
@category_counts: Hash[Symbol, Integer]
6+
@category_word_count: Hash[Symbol, Integer]
7+
8+
def initialize: (*_ToS categories) -> void
9+
10+
def train: (_ToS category, String text) -> void
11+
12+
def untrain: (_ToS category, String text) -> void
13+
14+
def classifications: (String text) -> Hash[String, Float]
15+
16+
def classify: (String text) -> String
17+
18+
def categories: () -> Array[String]
19+
20+
def add_category: (_ToS category) -> Hash[Symbol, Integer]
21+
22+
alias append_category add_category
23+
24+
def remove_category: (_ToS category) -> void
25+
end
26+
end
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
class Object
2+
def prepare_category_name: () -> Symbol
3+
end
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
class String
2+
CORPUS_SKIP_WORDS: Set[String]
3+
4+
def without_punctuation: () -> String
5+
6+
def word_hash: () -> Hash[Symbol, Integer]
7+
8+
def clean_word_hash: () -> Hash[Symbol, Integer]
9+
10+
def summary: (?Integer count, ?String separator) -> String
11+
12+
def paragraph_summary: (?Integer count, ?String separator) -> String
13+
14+
def split_sentences: () -> Array[String]
15+
16+
def split_paragraphs: () -> Array[String]
17+
18+
private
19+
20+
def word_hash_for_words: (Array[String] words) -> Hash[Symbol, Integer]
21+
22+
def word_hash_for_symbols: (Array[String] words) -> Hash[Symbol, Integer]
23+
24+
def perform_lsi: (Array[String] chunks, Integer count, String separator) -> String
25+
end
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
class Array[unchecked out Elem]
2+
def sum_with_identity: (?Float identity) ?{ (Elem) -> Numeric } -> Float
3+
end
4+
5+
module VectorExtensions
6+
def magnitude: () -> Float
7+
8+
def normalize: () -> Vector[Rational]
9+
end
10+
11+
class Vector[out Elem]
12+
include VectorExtensions
13+
end
14+
15+
class Matrix[out Elem]
16+
def self.diag: (Array[Numeric] diagonal_elements) -> Matrix[Numeric]
17+
18+
def trans: () -> Matrix[Elem]
19+
20+
def SV_decomp: (?Integer max_sweeps) -> [Matrix[Numeric], Matrix[Numeric], Array[Float]]
21+
22+
def []=: (Integer row_index, Integer col_index, Numeric value) -> Numeric
23+
end

sig/classifier/lsi.rbs

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
module Classifier
2+
class LSI
3+
@auto_rebuild: bool
4+
@word_list: WordList
5+
@items: Hash[untyped, ContentNode]
6+
@version: Integer
7+
@built_at_version: Integer
8+
9+
attr_reader word_list: WordList
10+
attr_accessor auto_rebuild: bool
11+
12+
def self.gsl_available: () -> bool
13+
def self.gsl_available=: (bool value) -> bool
14+
15+
def initialize: (?Hash[Symbol, untyped] options) -> void
16+
17+
def needs_rebuild?: () -> bool
18+
19+
def add_item: (untyped item, *untyped categories) ?{ (untyped) -> String } -> void
20+
21+
def <<: (untyped item) -> void
22+
23+
def categories_for: (untyped item) -> Array[untyped]
24+
25+
def remove_item: (untyped item) -> void
26+
27+
def items: () -> Array[untyped]
28+
29+
def build_index: (?Float cutoff) -> void
30+
31+
def highest_relative_content: (?Integer max_chunks) -> Array[untyped]
32+
33+
def proximity_array_for_content: (untyped doc) ?{ (untyped) -> String } -> Array[[untyped, Float]]
34+
35+
def proximity_norms_for_content: (untyped doc) ?{ (untyped) -> String } -> Array[[untyped, Float]]
36+
37+
def search: (String string, ?Integer max_nearest) -> Array[untyped]
38+
39+
def find_related: (untyped doc, ?Integer max_nearest) ?{ (untyped) -> String } -> Array[untyped]
40+
41+
def classify: (untyped doc, ?Float cutoff) ?{ (untyped) -> String } -> untyped
42+
43+
def vote: (untyped doc, ?Float cutoff) ?{ (untyped) -> String } -> Hash[untyped, Float]
44+
45+
def classify_with_confidence: (untyped doc, ?Float cutoff) ?{ (untyped) -> String } -> [untyped, Float?]
46+
47+
def highest_ranked_stems: (untyped doc, ?Integer count) -> Array[Symbol]
48+
49+
private
50+
51+
def build_reduced_matrix: (untyped matrix, ?Float cutoff) -> untyped
52+
53+
def node_for_content: (untyped item) ?{ (untyped) -> String } -> ContentNode
54+
55+
def make_word_list: () -> void
56+
end
57+
end
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
module Classifier
2+
class ContentNode
3+
@word_hash: Hash[Symbol, Integer]
4+
@categories: Array[untyped]
5+
6+
attr_accessor raw_vector: untyped
7+
attr_accessor raw_norm: untyped
8+
attr_accessor lsi_vector: untyped
9+
attr_accessor lsi_norm: untyped
10+
attr_accessor categories: Array[untyped]
11+
12+
attr_reader word_hash: Hash[Symbol, Integer]
13+
14+
def initialize: (Hash[Symbol, Integer] word_frequencies, *untyped categories) -> void
15+
16+
def search_vector: () -> untyped
17+
18+
def search_norm: () -> untyped
19+
20+
def raw_vector_with: (WordList word_list) -> untyped
21+
end
22+
end

sig/classifier/lsi/word_list.rbs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
module Classifier
2+
class WordList
3+
@location_table: Hash[Symbol, Integer]
4+
5+
def initialize: () -> void
6+
7+
def add_word: (Symbol word) -> Integer?
8+
9+
def []: (Symbol lookup) -> Integer?
10+
11+
def word_for_index: (Integer ind) -> Symbol?
12+
13+
def size: () -> Integer
14+
end
15+
end

0 commit comments

Comments
 (0)