Skip to content

Commit

Permalink
Extract similar.
Browse files Browse the repository at this point in the history
  • Loading branch information
floere committed Jun 30, 2015
1 parent f159cc7 commit b183151
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 3 deletions.
5 changes: 3 additions & 2 deletions server/lib/picky/bundle.rb
Original file line number Diff line number Diff line change
Expand Up @@ -131,10 +131,11 @@ def delete
#
# Note: Also checks for itself.
#
def similar text
code = similarity_strategy.encode text
def similar str_or_sym
code = similarity_strategy.encode str_or_sym
return [] unless code
@similarity[code] || []

# similar_codes = @similarity[code]
# if similar_codes.blank?
# [] # Return a simple array.
Expand Down
7 changes: 7 additions & 0 deletions server/lib/picky/category_indexed.rb
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,13 @@ def ids token
end
end

# Gets the similars for this token's text.
#
def similar token
bundle = bundle_for token
bundle.similar str_or_sym(token.text)
end

def str_or_sym text
if @symbol_keys
text.to_sym
Expand Down
2 changes: 1 addition & 1 deletion server/lib/picky/query/token.rb
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ def combination_for category
# Returns all similar tokens for the token.
#
def similar_tokens_for category
similars = category.bundle_for(self).similar @text
similars = category.similar self
similars.map do |similar|
# The array describes all possible categories. There is only one here.
#
Expand Down

0 comments on commit b183151

Please sign in to comment.