-
Notifications
You must be signed in to change notification settings - Fork 123
feat(lsi): add hash-style API for adding items #101
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
ec21c8b
6bac00e
59e7396
d91567c
d5659c0
2b4a2c9
5a5362e
9a8f740
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||
|---|---|---|---|---|
|
|
@@ -115,19 +115,27 @@ require 'classifier' | |||
|
|
||||
| lsi = Classifier::LSI.new | ||||
|
|
||||
| # Add documents with categories | ||||
| lsi.add_item "Dogs are loyal pets that love to play fetch", :pets | ||||
| lsi.add_item "Cats are independent and love to nap", :pets | ||||
| lsi.add_item "Ruby is a dynamic programming language", :programming | ||||
| lsi.add_item "Python is great for data science", :programming | ||||
| # Add documents with hash-style syntax (category => item(s)) | ||||
| lsi.add("Pets" => "Dogs are loyal pets that love to play fetch") | ||||
| lsi.add("Pets" => "Cats are independent and love to nap") | ||||
| lsi.add("Programming" => "Ruby is a dynamic programming language") | ||||
|
|
||||
| # Add multiple items with the same category | ||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. style: comment restates what the code shows - passing an array is obvious
Suggested change
Context Used: Context from Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time! Prompt To Fix With AIThis is a comment left during a code review.
Path: README.md
Line: 123:123
Comment:
**style:** comment restates what the code shows - passing an array is obvious
```suggestion
```
**Context Used:** Context from `dashboard` - CLAUDE.md ([source](https://app.greptile.com/review/custom-context?memory=da491e84-75dc-41f4-bb96-ab9502d43917))
<sub>Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!</sub>
How can I resolve this? If you propose a fix, please make it concise. |
||||
| lsi.add("Programming" => ["Python is great for data science", "JavaScript runs in browsers"]) | ||||
|
|
||||
| # Batch operations with multiple categories | ||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. style: comment restates what the code shows - batch operations are self-evident from the hash syntax
Suggested change
Context Used: Context from Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time! Prompt To Fix With AIThis is a comment left during a code review.
Path: README.md
Line: 126:126
Comment:
**style:** comment restates what the code shows - batch operations are self-evident from the hash syntax
```suggestion
```
**Context Used:** Context from `dashboard` - CLAUDE.md ([source](https://app.greptile.com/review/custom-context?memory=da491e84-75dc-41f4-bb96-ab9502d43917))
<sub>Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!</sub>
How can I resolve this? If you propose a fix, please make it concise. |
||||
| lsi.add( | ||||
| "Pets" => ["Hamsters are small furry pets", "Birds can be great companions"], | ||||
| "Programming" => "Go is fast and concurrent" | ||||
| ) | ||||
|
|
||||
| # Classify new text | ||||
| lsi.classify "My puppy loves to run around" | ||||
| # => :pets | ||||
| # => "Pets" | ||||
|
|
||||
| # Get classification with confidence score | ||||
| lsi.classify_with_confidence "Learning to code in Ruby" | ||||
| # => [:programming, 0.89] | ||||
| # => ["Programming", 0.89] | ||||
| ``` | ||||
|
|
||||
| ### Search and Discovery | ||||
|
|
||||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -122,12 +122,39 @@ def singular_value_spectrum | |||||||||||||||||||||||||||||||||||||||
| end | ||||||||||||||||||||||||||||||||||||||||
| end | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| # Adds items to the index using hash-style syntax. | ||||||||||||||||||||||||||||||||||||||||
| # The hash keys are categories, and values are items (or arrays of items). | ||||||||||||||||||||||||||||||||||||||||
| # | ||||||||||||||||||||||||||||||||||||||||
| # For example: | ||||||||||||||||||||||||||||||||||||||||
| # lsi = Classifier::LSI.new | ||||||||||||||||||||||||||||||||||||||||
| # lsi.add("Dog" => "Dogs are loyal pets") | ||||||||||||||||||||||||||||||||||||||||
| # lsi.add("Cat" => "Cats are independent") | ||||||||||||||||||||||||||||||||||||||||
| # lsi.add(Bird: "Birds can fly") # Symbol keys work too | ||||||||||||||||||||||||||||||||||||||||
| # | ||||||||||||||||||||||||||||||||||||||||
| # Multiple items with the same category: | ||||||||||||||||||||||||||||||||||||||||
| # lsi.add("Dog" => ["Dogs are loyal", "Puppies are cute"]) | ||||||||||||||||||||||||||||||||||||||||
| # | ||||||||||||||||||||||||||||||||||||||||
| # Batch operations with multiple categories: | ||||||||||||||||||||||||||||||||||||||||
| # lsi.add( | ||||||||||||||||||||||||||||||||||||||||
| # "Dog" => ["Dogs are loyal", "Puppies are cute"], | ||||||||||||||||||||||||||||||||||||||||
| # "Cat" => ["Cats are independent", "Kittens are playful"] | ||||||||||||||||||||||||||||||||||||||||
| # ) | ||||||||||||||||||||||||||||||||||||||||
| # | ||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+125
to
+142
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. style: docstring repeats what method signature and usage already shows - all the examples can be understood from the method name and tests
Suggested change
Context Used: Context from Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time! Prompt To Fix With AIThis is a comment left during a code review.
Path: lib/classifier/lsi.rb
Line: 125:142
Comment:
**style:** docstring repeats what method signature and usage already shows - all the examples can be understood from the method name and tests
```suggestion
# @rbs (**untyped items) -> void
```
**Context Used:** Context from `dashboard` - CLAUDE.md ([source](https://app.greptile.com/review/custom-context?memory=da491e84-75dc-41f4-bb96-ab9502d43917))
<sub>Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!</sub>
How can I resolve this? If you propose a fix, please make it concise. |
||||||||||||||||||||||||||||||||||||||||
| # @rbs (**untyped items) -> void | ||||||||||||||||||||||||||||||||||||||||
| def add(**items) | ||||||||||||||||||||||||||||||||||||||||
| items.each do |category, value| | ||||||||||||||||||||||||||||||||||||||||
| Array(value).each { |doc| add_item(doc, category.to_s) } | ||||||||||||||||||||||||||||||||||||||||
| end | ||||||||||||||||||||||||||||||||||||||||
| end | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| # Adds an item to the index. item is assumed to be a string, but | ||||||||||||||||||||||||||||||||||||||||
| # any item may be indexed so long as it responds to #to_s or if | ||||||||||||||||||||||||||||||||||||||||
| # you provide an optional block explaining how the indexer can | ||||||||||||||||||||||||||||||||||||||||
| # fetch fresh string data. This optional block is passed the item, | ||||||||||||||||||||||||||||||||||||||||
| # so the item may only be a reference to a URL or file name. | ||||||||||||||||||||||||||||||||||||||||
| # | ||||||||||||||||||||||||||||||||||||||||
| # @deprecated Use {#add} instead for clearer hash-style syntax. | ||||||||||||||||||||||||||||||||||||||||
| # | ||||||||||||||||||||||||||||||||||||||||
| # For example: | ||||||||||||||||||||||||||||||||||||||||
| # lsi = Classifier::LSI.new | ||||||||||||||||||||||||||||||||||||||||
| # lsi.add_item "This is just plain text" | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
style: comment restates what the code already shows - the syntax
"category" => itemis self-documentingContext Used: Context from
dashboard- CLAUDE.md (source)Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!
Prompt To Fix With AI