-
Notifications
You must be signed in to change notification settings - Fork 56
Extend publication type list #2408
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 9 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
998bef9
use publication_types.yml to populate publication types
whomingbird 2d4d86e
Check consistency between DB and YAML
whomingbird 32480b5
Update publication types to align with the DataCite Metadata Schema.
whomingbird b067202
Add Project Deliverable publication type and update naming for readab…
whomingbird a373a28
Synchronize publication types with YAML definitions, migrate legacy t…
whomingbird 0ee7837
add seed:005_publication_types to upgrade task
whomingbird b690cfb
Refactor publication code to adopt the new publication types.
whomingbird 27ce570
update and add new tests
whomingbird c41af8d
update publication type in api responses
whomingbird d539480
code update according to copilot review
whomingbird 38eb875
Merge branch 'seek-1.17' into extended-publication-type
whomingbird e363eda
update code according to the PR review.
whomingbird 109393a
remove unnecessary code
whomingbird File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or 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 | ||||
|---|---|---|---|---|---|---|
|
|
@@ -248,7 +248,7 @@ def extract_bibtex_metadata(bibtex_record) | |||||
| month = bibtex_record[:month].try(:to_s) | ||||||
| year = bibtex_record[:year].try(:to_s) | ||||||
| self.published_date = Date.new(bibtex_record.year.try(:to_i) || 1, bibtex_record.month_numeric || 1, bibtex_record[:day].try(:to_i) || 1) | ||||||
| self.published_date = nil if self.published_date.to_s == "0001-01-01" | ||||||
| self.published_date = nil if self.published_date.to_s == '0001-01-01' | ||||||
| self.doi = bibtex_record[:doi].try(:to_s) | ||||||
| self.pubmed_id = bibtex_record[:pubmed_id].try(:to_s) | ||||||
| self.booktitle = bibtex_record[:booktitle].try(:to_s) | ||||||
|
|
@@ -326,7 +326,7 @@ def generate_citation(bibtex_record) | |||||
| self.citation = '' | ||||||
| month = bibtex_record[:month].try(:to_s) | ||||||
| year = bibtex_record[:year].try(:to_s) | ||||||
| page_or_pages = (bibtex_record[:pages].try(:to_s).match?(/[^0-9]/) ? "pp." : "p." ) unless bibtex_record[:pages].nil? | ||||||
| page_or_pages = (bibtex_record[:pages].try(:to_s).match?(/[^0-9]/) ? 'pp.' : 'p.' ) unless bibtex_record[:pages].nil? | ||||||
| pages = bibtex_record[:pages].try(:to_s) | ||||||
| volume = bibtex_record[:volume].try(:to_s) | ||||||
| series = bibtex_record[:series].try(:to_s) | ||||||
|
|
@@ -344,25 +344,16 @@ def generate_citation(bibtex_record) | |||||
| url = parse_bibtex_url(bibtex_record).try(:to_s) | ||||||
| publication_type = PublicationType.find(self.publication_type_id) | ||||||
|
|
||||||
| if publication_type.is_journal? | ||||||
| case publication_type.key | ||||||
| when 'journalarticle' | ||||||
| self.citation += self.journal.nil? ? '':self.journal | ||||||
| self.citation += volume.blank? ? '': " #{volume}" | ||||||
| self.citation += number.nil? ? '' : "(#{number})" | ||||||
| self.citation += pages.blank? ? '' : (":#{pages}") | ||||||
| =begin | ||||||
| unless year.nil? | ||||||
| self.citation += year.nil? ? '' : (' '+year) | ||||||
| end | ||||||
| =end | ||||||
| elsif publication_type.is_booklet? | ||||||
| when 'booklet' | ||||||
| self.citation += howpublished.blank? ? '': "#{howpublished}" | ||||||
| self.citation += address.nil? ? '' : (", #{address}") | ||||||
| =begin | ||||||
| unless year.nil? | ||||||
| self.citation += year.nil? ? '' : (' '+year) | ||||||
| end | ||||||
| =end | ||||||
| elsif publication_type.is_inbook? | ||||||
| when 'bookchapter' | ||||||
| self.citation += self.booktitle.nil? ? '' : ("In #{self.booktitle}") | ||||||
| self.citation += volume.blank? ? '' : (", volume #{volume}") | ||||||
| self.citation += series.blank? ? '' : (" of #{series}") | ||||||
|
|
@@ -372,14 +363,7 @@ def generate_citation(bibtex_record) | |||||
| unless address.nil? || (self.booktitle.try(:include?, address)) | ||||||
| self.citation += address.nil? ? '' : (", #{address}") | ||||||
| end | ||||||
| =begin | ||||||
| unless self.booktitle.try(:include?, year) | ||||||
| unless year.nil? | ||||||
| self.citation += year.nil? ? '' : (' '+year) | ||||||
| end | ||||||
| end | ||||||
| =end | ||||||
| elsif publication_type.is_inproceedings? || publication_type.is_incollection? || publication_type.is_book? | ||||||
| when 'conferencepaper', 'collection', 'book' | ||||||
| # InProceedings / InCollection | ||||||
| self.citation += self.booktitle.nil? ? '' : ("In #{self.booktitle}") | ||||||
| self.citation += volume.blank? ? '' : (", vol. #{volume}") | ||||||
|
|
@@ -390,39 +374,25 @@ def generate_citation(bibtex_record) | |||||
| unless address.nil? || (self.booktitle.try(:include?, address)) | ||||||
| self.citation += address.nil? ? '' : (", #{address}") | ||||||
| end | ||||||
| =begin | ||||||
| unless self.booktitle.try(:include?, year) | ||||||
| unless year.nil? | ||||||
| self.citation += year.nil? ? '' : (', '+year) | ||||||
| end | ||||||
| end | ||||||
| =end | ||||||
| elsif publication_type.is_phd_thesis? || publication_type.is_masters_thesis? || publication_type.is_bachelor_thesis? | ||||||
| when 'bachelorsthesis', 'mastersthesis', 'phdthesis' | ||||||
| #PhD/Master Thesis | ||||||
whomingbird marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||||||
| self.citation += school.nil? ? '' : (" #{school}") | ||||||
| self.errors.add(:base,'A thesis need to have a school') if school.nil? | ||||||
| self.citation += year.nil? ? '' : (", #{year}") | ||||||
| self.citation += tutor.nil? ? '' : (", #{tutor}(Tutor)") | ||||||
| self.citation += tutorhits.nil? ? '' : (", #{tutorhits}(HITS Tutor)") | ||||||
| self.citation += url.nil? ? '' : (", #{url}") | ||||||
| elsif publication_type.is_proceedings? | ||||||
| when 'conferenceproceeding' | ||||||
| # Proceedings are conference proceedings, it has no authors but editors | ||||||
| # Book | ||||||
| self.journal = self.title | ||||||
| self.citation += volume.blank? ? '' : ("vol. #{volume}") | ||||||
| self.citation += series.blank? ? '' : (" of #{series}") | ||||||
| self.citation += self.publisher.blank? ? '' : (", #{self.publisher}") | ||||||
| =begin | ||||||
| unless month.nil? && year.nil? | ||||||
| self.citation += self.citation.blank? ? '' : ',' | ||||||
| self.citation += month.nil? ? '' : (' '+ month.capitalize) | ||||||
| self.citation += year.nil? ? '' : (' '+year) | ||||||
| end | ||||||
| =end | ||||||
| elsif publication_type.is_tech_report? | ||||||
| when 'report' | ||||||
| self.citation += institution.blank? ? ' ': institution | ||||||
| self.citation += type.blank? ? ' ' : (", #{type}") | ||||||
| elsif publication_type.is_unpublished? | ||||||
| when 'preprint' | ||||||
| self.citation += note.blank? ? ' ': note | ||||||
| end | ||||||
|
|
||||||
|
|
@@ -583,7 +553,7 @@ def pubmed_entry | |||||
| if pubmed_id | ||||||
| Rails.cache.fetch("bio-reference-#{pubmed_id}") do | ||||||
| entry = Bio::PubMed.efetch(pubmed_id).first | ||||||
| raise "PubMed entry was nil" if entry.nil? | ||||||
| raise 'PubMed entry was nil' if entry.nil? | ||||||
| entry | ||||||
| end | ||||||
| end | ||||||
|
|
@@ -620,23 +590,23 @@ def check_bibtex_file (bibtex_record) | |||||
|
|
||||||
|
|
||||||
| if self.title.blank? | ||||||
| errors.add(:base, "Please check your bibtex files, each publication should contain a title or a chapter name.") | ||||||
| errors.add(:base, 'Please check your bibtex files, each publication should contain a title or a chapter name.') | ||||||
| return false | ||||||
| end | ||||||
|
|
||||||
| if (%w[InCollection InProceedings].include? self.publication_type.title) && (bibtex_record[:booktitle].blank?) | ||||||
| if (['Collection','Conference Paper'].include? self.publication_type.title) && (bibtex_record[:booktitle].blank?) | ||||||
|
||||||
| if (['Collection','Conference Paper'].include? self.publication_type.title) && (bibtex_record[:booktitle].blank?) | |
| if (['Collection', 'Conference Paper'].include? self.publication_type.title) && (bibtex_record[:booktitle].blank?) |
whomingbird marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
whomingbird marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
whomingbird marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
whomingbird marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
whomingbird marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
whomingbird marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
This file contains hidden or 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 |
|---|---|---|
| @@ -1,143 +1,52 @@ | ||
| class PublicationType < ActiveRecord::Base | ||
|
|
||
| class PublicationType < ActiveRecord::Base | ||
| has_many :publications | ||
|
|
||
| #this returns an instance of PublicationType according to one of the publication types | ||
| #if there is not a match nil is returned | ||
|
|
||
| #http://bib-it.sourceforge.net/help/fieldsAndEntryTypes.php#Entries | ||
|
|
||
| def self.for_type type | ||
| keys = { "Journal"=>"article", | ||
| "Book"=>"book", | ||
| "Booklet"=>"booklet", | ||
| "InBook"=>"inbook", | ||
| "InCollection"=>"incollection", | ||
| "InProceedings"=>"inproceedings", | ||
| "Manual"=>"manual", | ||
| "Masters_Thesis"=>"masters_thesis", | ||
| "Misc"=>"misc", | ||
| "Phd_Thesis"=>"phd_thesis", | ||
| "Bachelor_Thesis"=>"bachelorsthesis", | ||
| "Proceedings"=>"proceedings", | ||
| "Tech_Report"=>"tech_report", | ||
| "Unpublished"=>"unpublished" } | ||
| return PublicationType.find_by(key: keys[type]) | ||
| end | ||
|
|
||
|
|
||
|
|
||
| # Map BibTeX keys → DataCite keys | ||
| BIBTEX_TO_DATACITE_KEY = { | ||
| 'article' => 'journalarticle', | ||
| 'book' => 'book', | ||
| 'booklet' => 'booklet', | ||
| 'inbook' => 'bookchapter', | ||
| 'incollection' => 'collection', | ||
| 'inproceedings' => 'conferencepaper', | ||
| 'proceedings' => 'conferenceproceeding', | ||
| 'manual' => 'text', | ||
| 'misc' => 'other', | ||
| 'unpublished' => 'preprint', | ||
| 'techreport' => 'report', | ||
| 'phdthesis' => 'phdthesis', | ||
| 'mastersthesis' => 'mastersthesis', | ||
| 'bachelorsthesis' => 'bachelorsthesis' | ||
whomingbird marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| }.freeze | ||
|
|
||
|
|
||
| # Load expected publication types from YAML | ||
| def self.type_registry | ||
| @type_registry ||= begin | ||
| path = Rails.root.join('config/default_data/publication_types.yml') | ||
whomingbird marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| YAML.load_file(path).values.index_by { |h| h['title'] } | ||
| end | ||
| end | ||
|
|
||
| def self.for_type(type) | ||
| yaml_entry = type_registry[type] | ||
| return nil unless yaml_entry | ||
| find_by(key: yaml_entry['key']) | ||
| end | ||
|
|
||
| # Extract publication type from BibTeX record | ||
| def self.get_publication_type_id(bibtex_record) | ||
| str_begin = "@" | ||
| str_end = "{" | ||
| publication_key = bibtex_record.try(:to_s)[/#{str_begin}(.*?)#{str_end}/m, 1] | ||
| unless PublicationType.find_by(key: publication_key).nil? | ||
| return PublicationType.find_by(key: publication_key).id | ||
| else | ||
| return PublicationType.find_by(key: "misc").id | ||
| end | ||
| end | ||
|
|
||
|
|
||
| def self.Journal | ||
| self.for_type('Journal') | ||
| end | ||
|
|
||
| def self.Book | ||
| self.for_type('Book') | ||
| end | ||
|
|
||
| def self.Booklet | ||
| self.for_type('Booklet') | ||
| end | ||
| def self.InBook | ||
| self.for_type('InBook') | ||
| end | ||
| def self.InCollection | ||
| self.for_type('InCollection') | ||
| end | ||
| def self.InProceedings | ||
| self.for_type('InProceedings') | ||
| end | ||
| def self.Manual | ||
| self.for_type('Manual') | ||
| end | ||
| def self.Masters_Thesis | ||
| self.for_type('Masters_Thesis') | ||
| end | ||
| def self.Misc | ||
| self.for_type('Misc') | ||
| end | ||
| def self.Bachelor_Thesis | ||
| self.for_type('Bachelor_Thesis') | ||
| end | ||
| def self.Phd_Thesis | ||
| self.for_type('Phd_Thesis') | ||
| end | ||
| def self.Proceedings | ||
| self.for_type('Proceedings') | ||
| end | ||
| def self.Tech_Report | ||
| self.for_type('Tech_Report') | ||
| end | ||
| def self.Unpublished | ||
| self.for_type('Unpublished') | ||
| end | ||
|
|
||
| def is_journal? | ||
| key == "article" | ||
| # Extract the BibTeX entry type, e.g. article, inbook, misc... | ||
| publication_key = bibtex_record.to_s[/@(.*?)\{/m, 1].to_s.downcase.strip | ||
| datacite_key = BIBTEX_TO_DATACITE_KEY[publication_key] || 'other' | ||
| pub_type = PublicationType.find_by(key: datacite_key) | ||
| pub_type.id | ||
whomingbird marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| end | ||
|
|
||
| def is_book? | ||
| key == 'book' | ||
| end | ||
|
|
||
| def is_booklet? | ||
| key == 'booklet' | ||
| end | ||
|
|
||
| def is_inbook? | ||
| key == 'inbook' | ||
| end | ||
|
|
||
| def is_incollection? | ||
| key == 'incollection' | ||
| end | ||
|
|
||
| def is_inproceedings? | ||
| key == 'inproceedings' | ||
| end | ||
|
|
||
| def is_manual? | ||
| key == 'manual' | ||
| end | ||
|
|
||
| def is_masters_thesis? | ||
| key == 'mastersthesis' | ||
| end | ||
|
|
||
| def is_misc? | ||
| key == 'misc' | ||
| end | ||
|
|
||
| def is_phd_thesis? | ||
| key == 'phdthesis' | ||
| end | ||
|
|
||
| def is_bachelor_thesis? | ||
| key == 'bachelorsthesis' | ||
| end | ||
|
|
||
| def is_proceedings? | ||
| key == 'proceedings' | ||
| end | ||
|
|
||
| def is_tech_report? | ||
| key == 'techreport' | ||
| end | ||
|
|
||
| def is_unpublished? | ||
| key == 'unpublished' | ||
| type_registry.each_key do |title| | ||
| define_singleton_method(title.gsub(/\s+/, '')) do | ||
| find_by(key: type_registry[title]['key']) | ||
| end | ||
whomingbird marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| end | ||
|
|
||
| end | ||
| end | ||
This file contains hidden or 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
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.