-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #127 from MITLibraries/bulk-detections
Adds BulkChecker module for Detectors
- Loading branch information
Showing
9 changed files
with
107 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
# frozen_string_literal: true | ||
|
||
class Detector | ||
# BulkTermChecker is expected to be added to Detectors via `extend Detector::BulkTermChecker` to allow the | ||
# singleton class to access it | ||
# See also: `PatternChecker` for shared instance methods | ||
module BulkChecker | ||
# This method is intended to be used for inspecting detections during development. | ||
# Assumptions include | ||
# - the Class including this module implements a `detections` method (either via `attr_reader` or as a method) | ||
# that is only populated for Terms in which it has made a detection | ||
# - the initialize method accepts a `phrase` as a string | ||
# @param output [boolean] optional. Defaults to false as that is the more likely scenario useful in development as | ||
# the logger output is often what is desired. | ||
def check_all_matches(output: false) | ||
count = 0 | ||
matches = [] | ||
Term.find_each do |t| | ||
d = new(t.phrase) | ||
next if d.detections.blank? | ||
|
||
count += 1 | ||
|
||
matches.push [t.phrase, d.detections] | ||
end | ||
|
||
if Rails.env.development? | ||
Rails.logger.ap matches | ||
|
||
Rails.logger.ap "Total Terms: #{Term.count}" | ||
Rails.logger.ap "Total Matches: #{count}" | ||
end | ||
|
||
matches if output | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'test_helper' | ||
|
||
class Detector | ||
class CitationTest < ActiveSupport::TestCase | ||
test 'citation_bulk_checker' do | ||
bulk = Detector::Citation.check_all_matches(output: true) | ||
|
||
assert_equal(1, bulk.count) | ||
end | ||
|
||
test 'journal_bulk_checker' do | ||
skip 'Detector::Journal does not yet support bulk_checker' | ||
end | ||
|
||
test 'lcsh_bulk_checker' do | ||
bulk = Detector::Lcsh.check_all_matches(output: true) | ||
|
||
assert_equal(1, bulk.count) | ||
end | ||
|
||
test 'standard_identifier_bulk_checker' do | ||
bulk = Detector::StandardIdentifiers.check_all_matches(output: true) | ||
|
||
assert_equal(5, bulk.count) | ||
end | ||
|
||
test 'suggested_resources_bulk_checker' do | ||
skip 'Detector::SuggestedResources does not yet support bulk_checker' | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters