Skip to content

Commit

Permalink
Cv2 4582 no urls for similarity (#1885)
Browse files Browse the repository at this point in the history
* Add test (should fail)

* Now reject strings that are only URLs too

---------

Co-authored-by: computermacgyver <computermacgyver>
  • Loading branch information
computermacgyver authored May 9, 2024
1 parent 7299af1 commit 59ee448
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
3 changes: 2 additions & 1 deletion app/models/bot/alegre.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
require 'open-uri'
require 'uri'

class Bot::Alegre < BotUser
check_settings
Expand All @@ -20,7 +21,7 @@ class Error < ::StandardError

REPORT_TEXT_SIMILARITY_FIELDS = ['report_text_title', 'report_text_content', 'report_visual_card_title', 'report_visual_card_content']
ALL_TEXT_SIMILARITY_FIELDS = REPORT_TEXT_SIMILARITY_FIELDS + ['original_title', 'original_description', 'extracted_text', 'transcription', 'claim_description_content', 'fact_check_title', 'fact_check_summary']
BAD_TITLE_REGEX = /^[a-z\-]+-[0-9\-]+$/
BAD_TITLE_REGEX = /^[a-z\-]+-[0-9\-]+$|^#{URI.regexp}$/
::ProjectMedia.class_eval do
attr_accessor :alegre_similarity_thresholds, :alegre_matched_fields

Expand Down
10 changes: 10 additions & 0 deletions test/models/bot/alegre_4_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,16 @@ def teardown
Bot::Alegre.unstub.stubs(:request)
end

test "/text/similarity/ request should not be called for URL title" do
text = "http://meedan.com/@fun/thing?abc=def&hij=123"
pm1 = create_project_media team: @team, quote: text
Bot::Alegre.stubs(:request).raises("Request method called when it should not be")
assert_nothing_raised do
Bot::Alegre.send_to_text_similarity_index(pm1, create_field_instance, text, Bot::Alegre.item_doc_id(pm1, create_field_instance))
end
Bot::Alegre.unstub.stubs(:request)
end

test "/text/similarity/ request should not be called for blank title" do
text = ""
pm1 = create_project_media team: @team, quote: text
Expand Down

0 comments on commit 59ee448

Please sign in to comment.