forked from rism-digital/muscat
-
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 branch 'develop-787' into develop
* develop-787: New scripts Add experimental source to person "extended" relation Remove unused variable Rename function to be consistent Cleanup and document Functional implementation omn 787 Add experimental migration to add 'id' to sources_to_sources so that activerecord can have a primary key Fix non foreign_link links (i.e. 773) so they are not hardcoded and come from configuration Initial 787 implementation, remove uniused code and variables Initial test with has_many Rename "informazioni di possesso" to "esemplari" for comformity to other languages. Update changelog Hide tag 787 # Conflicts: # app/models/source.rb
- Loading branch information
Showing
19 changed files
with
350 additions
and
112 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
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,5 @@ | ||
class SourcePersonRelation < ApplicationRecord | ||
self.table_name = "sources_to_people" | ||
belongs_to :source | ||
belongs_to :person | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
class SourceRelation < ApplicationRecord | ||
self.table_name = "sources_to_sources" | ||
belongs_to :source_a, class_name: "Source" | ||
belongs_to :source_b, class_name: "Source" | ||
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
6 changes: 6 additions & 0 deletions
6
db/migrate/20210317115753_add_relator_code_to_sources_to_sources.rb
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,6 @@ | ||
class AddRelatorCodeToSourcesToSources < ActiveRecord::Migration[5.2] | ||
def change | ||
add_column :sources_to_sources, :marc_tag, :string | ||
add_column :sources_to_sources, :relator_code, :string | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
class AddIdToSourcesToSources < ActiveRecord::Migration[5.2] | ||
def self.up | ||
execute("ALTER TABLE `sources_to_sources` ADD `id` INT") | ||
execute("ALTER TABLE `sources_to_sources` MODIFY COLUMN `id` INT NOT NULL UNIQUE AUTO_INCREMENT FIRST;") | ||
execute("ALTER TABLE `sources_to_sources` ADD PRIMARY KEY (`id`)"); | ||
execute("ALTER TABLE `sources_to_sources` ADD UNIQUE INDEX `unique_records` (`marc_tag`, `relator_code`, `source_a_id`, `source_b_id`);") | ||
execute("UPDATE sources_to_sources SET marc_tag = 775;") | ||
end | ||
|
||
def self.down | ||
execute("ALTER TABLE `sources_to_sources` DROP INDEX `unique_records`;") | ||
execute("ALTER TABLE `sources_to_sources` DROP PRIMARY KEY;") | ||
execute("ALTER TABLE `sources_to_sources` DROP `id`;") | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
class ExtendSourcesToPeople < ActiveRecord::Migration[5.2] | ||
def change | ||
add_column :sources_to_people, :marc_tag, :string | ||
add_column :sources_to_people, :relator_code, :string | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
class AddIdToSourcesToPeople < ActiveRecord::Migration[5.2] | ||
def self.up | ||
execute("ALTER TABLE `sources_to_people` ADD `id` INT") | ||
execute("ALTER TABLE `sources_to_people` MODIFY COLUMN `id` INT NOT NULL UNIQUE AUTO_INCREMENT FIRST;") | ||
execute("ALTER TABLE `sources_to_people` ADD PRIMARY KEY (`id`)"); | ||
execute("ALTER TABLE `sources_to_people` ADD UNIQUE INDEX `unique_records` (`marc_tag`, `relator_code`, `source_id`, `person_id`);") | ||
end | ||
|
||
def self.down | ||
execute("ALTER TABLE `sources_to_people` DROP INDEX `unique_records`;") | ||
execute("ALTER TABLE `sources_to_people` DROP PRIMARY KEY;") | ||
execute("ALTER TABLE `sources_to_people` DROP `id`;") | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
tag_count = {} | ||
pb = ProgressBar.new(Source.count) | ||
|
||
Source.find_in_batches do |batch| | ||
|
||
batch.each do |src| | ||
s = Source.find(src.id) | ||
pb.increment! | ||
|
||
s.marc.load_source false | ||
marc = s.marc | ||
|
||
marc.all_tags.each do |tag| | ||
|
||
if !tag_count.include?(tag.tag) | ||
tag_count[tag.tag] = {} | ||
tag_count[tag.tag][:count] = 0 | ||
tag_count[tag.tag][:subtags] = {} | ||
end | ||
|
||
tag_count[tag.tag][:count] += 1 | ||
|
||
tag.children.each do |subtag| | ||
if !tag_count[tag.tag][:subtags].include?(subtag.tag) | ||
tag_count[tag.tag][:subtags][subtag.tag] = {} | ||
tag_count[tag.tag][:subtags][subtag.tag][:count] = 0 | ||
tag_count[tag.tag][:subtags][subtag.tag][:first] = src.id | ||
end | ||
tag_count[tag.tag][:subtags][subtag.tag][:count] += 1 | ||
end | ||
end | ||
end | ||
end | ||
|
||
puts tag_count.to_yaml |
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,43 @@ | ||
def tag2str | ||
end | ||
|
||
headers = %w( | ||
001 | ||
005 | ||
240a | ||
245a | ||
260a | ||
260b | ||
260c | ||
510a | ||
510c | ||
650a | ||
852a | ||
588a | ||
) | ||
|
||
CSV.open("referred_sources.csv", "w") do |csv| | ||
csv << headers | ||
|
||
Source.joins(:referring_sources).distinct.each do |s| | ||
line = [] | ||
|
||
line << s.id.to_s | ||
line << s.marc.first_occurance("005").content rescue line << "" | ||
|
||
line << s.marc.all_values_for_tags_with_subtag("240","a").join("; ") | ||
line << s.marc.all_values_for_tags_with_subtag("245","a").join("; ") | ||
line << s.marc.all_values_for_tags_with_subtag("260","a").join("; ") | ||
line << s.marc.all_values_for_tags_with_subtag("260","b").join("; ") | ||
line << s.marc.all_values_for_tags_with_subtag("260","c").join("; ") | ||
line << s.marc.all_values_for_tags_with_subtag("510","a").join("; ") | ||
line << s.marc.all_values_for_tags_with_subtag("510","c").join("; ") | ||
line << s.marc.all_values_for_tags_with_subtag("650","a").join("; ") | ||
line << s.marc.all_values_for_tags_with_subtag("852","a").join("; ") | ||
line << s.marc.all_values_for_tags_with_subtag("588","a").join("; ") | ||
|
||
#ap line | ||
csv << line | ||
|
||
end | ||
end |
Oops, something went wrong.