Class: Relaton::Jis::HitCollection
- Inherits:
-
Core::HitCollection
- Object
- Core::HitCollection
- Relaton::Jis::HitCollection
- Defined in:
- lib/relaton/jis/hit_collection.rb
Constant Summary collapse
- GH_URL =
"https://raw.githubusercontent.com/relaton/relaton-data-jis/v2/"
Instance Method Summary collapse
-
#attach_relations(umbrella, skip_id) ⇒ Object
Attach every candidate except ‘skip_id` to `umbrella` as an `instanceOf` relation and return the umbrella.
- #create_relation(hit) ⇒ Object
-
#find ⇒ Relaton::Bib::ItemData, Array<Integer>
Find the best hit for the reference.
-
#find_all_parts ⇒ Object
The lowest-numbered part becomes the all-parts umbrella; every candidate sharing the series and number is attached as an ‘instanceOf` relation.
-
#find_all_years ⇒ Object
The main item is the latest edition of the requested type; every other candidate sharing the series and number (older editions, amendments, explanations) is attached as an ‘instanceOf` relation.
- #find_by_year(ref_year) ⇒ Object
-
#index ⇒ Object
Index of pubid identifiers (‘index-v2`), deserialized via `pubid_class`.
-
#initialize(pubid) ⇒ HitCollection
constructor
Initialize hit collection.
-
#pubid ⇒ Pubid::Jis::Identifier
Parsed reference.
Constructor Details
#initialize(pubid) ⇒ HitCollection
Initialize hit collection.
Searches the pubid-based ‘index-v2` for every entry sharing the reference’s series and number (a supplement is filed under its base number, so editions and amendments come back together). Narrowing to a specific type/year/part happens later in #find.
20 21 22 23 24 25 |
# File 'lib/relaton/jis/hit_collection.rb', line 20 def initialize(pubid) super(pubid, pubid.year&.to_s) @array = index.search(pubid) { |row| same_base? row[:id] } .map { |row| Hit.new row, self } .sort_by { |hit| hit.pubid.to_s } end |
Instance Method Details
#attach_relations(umbrella, skip_id) ⇒ Object
Attach every candidate except ‘skip_id` to `umbrella` as an `instanceOf` relation and return the umbrella.
81 82 83 84 85 86 87 88 |
# File 'lib/relaton/jis/hit_collection.rb', line 81 def attach_relations(umbrella, skip_id) @array.each do |hit| next if hit.pubid.to_s == skip_id umbrella.relation << create_relation(hit) end umbrella end |
#create_relation(hit) ⇒ Object
90 91 92 93 94 95 96 97 98 |
# File 'lib/relaton/jis/hit_collection.rb', line 90 def create_relation(hit) id = hit.pubid.to_s docid = Docidentifier.new content: id, type: "JIS", primary: true bibitem = ItemData.new( formattedref: Bib::Formattedref.new(content: id), docidentifier: [docid], ) Relation.new type: "instanceOf", bibitem: bibitem end |
#find ⇒ Relaton::Bib::ItemData, Array<Integer>
Find the best hit for the reference.
38 39 40 41 42 43 44 |
# File 'lib/relaton/jis/hit_collection.rb', line 38 def find if pubid.year find_by_year pubid.year else find_all_years end end |
#find_all_parts ⇒ Object
The lowest-numbered part becomes the all-parts umbrella; every candidate sharing the series and number is attached as an ‘instanceOf` relation.
72 73 74 75 76 77 |
# File 'lib/relaton/jis/hit_collection.rb', line 72 def find_all_parts parts = @array.select { |hit| hit.matches? all_parts: true } lowest = parts.min_by { |hit| hit.pubid.parts.first.to_i } item = lowest.item.to_all_parts attach_relations item, item.docidentifier.first.content end |
#find_all_years ⇒ Object
The main item is the latest edition of the requested type; every other candidate sharing the series and number (older editions, amendments, explanations) is attached as an ‘instanceOf` relation.
61 62 63 64 65 66 67 68 |
# File 'lib/relaton/jis/hit_collection.rb', line 61 def find_all_years editions = @array.select(&:matches?) return [] if editions.empty? item = editions.max_by { |hit| hit.pubid.year.to_i }.item attach_relations item.to_most_recent_reference, item.docidentifier.first.content end |
#find_by_year(ref_year) ⇒ Object
46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/relaton/jis/hit_collection.rb', line 46 def find_by_year(ref_year) missed_years = [] @array.each do |hit| next unless hit.matches? return hit.item if hit.pubid.year.to_s == ref_year.to_s missed_years << hit.pubid.year end missed_years end |
#index ⇒ Object
Index of pubid identifiers (‘index-v2`), deserialized via `pubid_class`.
101 102 103 104 105 106 107 108 |
# File 'lib/relaton/jis/hit_collection.rb', line 101 def index @index ||= Relaton::Index.find_or_create( :jis, url: "#{GH_URL}#{INDEXFILE_V2}.zip", file: "#{INDEXFILE_V2}.yaml", pubid_class: ::Pubid::Jis::Identifier, ) end |
#pubid ⇒ Pubid::Jis::Identifier
Returns parsed reference.
28 29 30 |
# File 'lib/relaton/jis/hit_collection.rb', line 28 def pubid ref end |