Skip to content

Commit

Permalink
Merge pull request #916 from datacite/doi-enrichment-part3
Browse files Browse the repository at this point in the history
Doi enrichment - Index DOIs with client/repository subject area classifications
  • Loading branch information
jrhoads authored Feb 15, 2023
2 parents 71965cb + 7b60d40 commit dd765cf
Show file tree
Hide file tree
Showing 38 changed files with 689 additions and 94 deletions.
2 changes: 1 addition & 1 deletion app/controllers/datacite_dois_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ def index
# sources = total.positive? ? facet_by_key(response.aggregations.sources.buckets) : nil
subjects = facet_by_key(response.aggregations.subjects.buckets)
fields_of_science = facet_by_fos(
response.aggregations.fields_of_science.subject.buckets,
response.aggregations.fields_of_science.buckets,
)
certificates = facet_by_key(response.aggregations.certificates.buckets)
licenses = facet_by_license(response.aggregations.licenses.buckets)
Expand Down
328 changes: 300 additions & 28 deletions app/graphql/schema.graphql

Large diffs are not rendered by default.

8 changes: 8 additions & 0 deletions app/graphql/types/audiovisual_connection_with_total_type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -75,4 +75,12 @@ def languages
[]
end
end

def fields_of_science
if object.aggregations.fields_of_science
facet_by_fos(object.aggregations.fields_of_science.buckets)
else
[]
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ def licenses

def fields_of_science
if object.aggregations.fields_of_science
facet_by_fos(object.aggregations.fields_of_science.subject.buckets)
facet_by_fos(object.aggregations.fields_of_science.buckets)
else
[]
end
Expand Down
2 changes: 1 addition & 1 deletion app/graphql/types/book_connection_with_total_type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ def licenses

def fields_of_science
if object.aggregations.fields_of_science
facet_by_fos(object.aggregations.fields_of_science.subject.buckets)
facet_by_fos(object.aggregations.fields_of_science.buckets)
else
[]
end
Expand Down
2 changes: 1 addition & 1 deletion app/graphql/types/collection_connection_with_total_type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ def licenses

def fields_of_science
if object.aggregations.fields_of_science
facet_by_fos(object.aggregations.fields_of_science.subject.buckets)
facet_by_fos(object.aggregations.fields_of_science.buckets)
else
[]
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ def licenses

def fields_of_science
if object.aggregations.fields_of_science
facet_by_fos(object.aggregations.fields_of_science.subject.buckets)
facet_by_fos(object.aggregations.fields_of_science.buckets)
else
[]
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ def licenses

def fields_of_science
if object.aggregations.fields_of_science
facet_by_fos(object.aggregations.fields_of_science.subject.buckets)
facet_by_fos(object.aggregations.fields_of_science.buckets)
else
[]
end
Expand Down
8 changes: 8 additions & 0 deletions app/graphql/types/data_paper_connection_with_total_type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,12 @@ def licenses
def languages
facet_by_language(object.aggregations.languages.buckets)
end

def fields_of_science
if object.aggregations.fields_of_science
facet_by_fos(object.aggregations.fields_of_science.buckets)
else
[]
end
end
end
2 changes: 1 addition & 1 deletion app/graphql/types/dataset_connection_with_total_type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ def licenses

def fields_of_science
if object.aggregations.fields_of_science
facet_by_fos(object.aggregations.fields_of_science.subject.buckets)
facet_by_fos(object.aggregations.fields_of_science.buckets)
else
[]
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ def licenses

def fields_of_science
if object.aggregations.fields_of_science
facet_by_fos(object.aggregations.fields_of_science.subject.buckets)
facet_by_fos(object.aggregations.fields_of_science.buckets)
else
[]
end
Expand Down
32 changes: 27 additions & 5 deletions app/graphql/types/doi_item.rb
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,15 @@ module DoiItem
field :fields_of_science,
[FieldOfScienceType],
null: true, description: "OECD Fields of Science of the resource"

field :fields_of_science_combined,
[FieldOfScienceType],
null: true, description: "OECD Fields of Science of the resource and containing repository"

field :fields_of_science_repository,
[FieldOfScienceType],
null: true, description: "OECD Fields of Science of the containing repository"

field :dates,
[DateType],
null: true, description: "Different dates relevant to the work"
Expand Down Expand Up @@ -382,6 +391,7 @@ module DoiItem
argument :has_views, Int, required: false
argument :has_downloads, Int, required: false
argument :field_of_science, String, required: false
argument :field_of_science_repository, String, required: false
argument :first, Int, required: false, default_value: 25
argument :after, String, required: false
end
Expand Down Expand Up @@ -418,15 +428,27 @@ def registration_agency
{ id: object.agency, name: REGISTRATION_AGENCIES[object.agency] }.compact
end

def fields_of_science
Array.wrap(object.subjects).select do |s|
s["subjectScheme"] == "Fields of Science and Technology (FOS)"
end.map do |s|
name = s["subject"].gsub("FOS: ", "")
def _fos_to_facet(fos_list)
Array.wrap(fos_list).map do |name|
{ "id" => name.parameterize(separator: "_"), "name" => name }
end.uniq
end

def fields_of_science_repository
if object.client.blank?
return []
end
_fos_to_facet(object.fields_of_science_repository)
end

def fields_of_science_combined
_fos_to_facet(object.fields_of_science_combined)
end

def fields_of_science
_fos_to_facet(object.fields_of_science)
end

def creators(**args)
Array.wrap(object.creators)[0...args[:first]].map do |c|
Hashie::Mash.new(
Expand Down
2 changes: 1 addition & 1 deletion app/graphql/types/event_connection_with_total_type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ def licenses

def fields_of_science
if object.aggregations.fields_of_science
facet_by_fos(object.aggregations.fields_of_science.subject.buckets)
facet_by_fos(object.aggregations.fields_of_science.buckets)
else
[]
end
Expand Down
8 changes: 8 additions & 0 deletions app/graphql/types/instrument_connection_with_total_type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -65,4 +65,12 @@ def languages
[]
end
end

def fields_of_science
if object.aggregations.fields_of_science
facet_by_fos(object.aggregations.fields_of_science.buckets)
else
[]
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -66,4 +66,12 @@ def languages
[]
end
end

def fields_of_science
if object.aggregations.fields_of_science
facet_by_fos(object.aggregations.fields_of_science.buckets)
else
[]
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -66,4 +66,12 @@ def languages
[]
end
end

def fields_of_science
if object.aggregations.fields_of_science
facet_by_fos(object.aggregations.fields_of_science.buckets)
else
[]
end
end
end
2 changes: 1 addition & 1 deletion app/graphql/types/model_connection_with_total_type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ def licenses

def fields_of_science
if object.aggregations.fields_of_science
facet_by_fos(object.aggregations.fields_of_science.subject.buckets)
facet_by_fos(object.aggregations.fields_of_science.buckets)
else
[]
end
Expand Down
2 changes: 1 addition & 1 deletion app/graphql/types/other_connection_with_total_type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ def licenses

def fields_of_science
if object.aggregations.fields_of_science
facet_by_fos(object.aggregations.fields_of_science.subject.buckets)
facet_by_fos(object.aggregations.fields_of_science.buckets)
else
[]
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ def licenses

def fields_of_science
if object.aggregations.fields_of_science
facet_by_fos(object.aggregations.fields_of_science.subject.buckets)
facet_by_fos(object.aggregations.fields_of_science.buckets)
else
[]
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ def licenses

def fields_of_science
if object.aggregations.fields_of_science
facet_by_fos(object.aggregations.fields_of_science.subject.buckets)
facet_by_fos(object.aggregations.fields_of_science.buckets)
else
[]
end
Expand Down
2 changes: 1 addition & 1 deletion app/graphql/types/preprint_connection_with_total_type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ def licenses

def fields_of_science
if object.aggregations.fields_of_science
facet_by_fos(object.aggregations.fields_of_science.subject.buckets)
facet_by_fos(object.aggregations.fields_of_science.buckets)
else
[]
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ def licenses

def fields_of_science
if object.aggregations.fields_of_science
facet_by_fos(object.aggregations.fields_of_science.subject.buckets)
facet_by_fos(object.aggregations.fields_of_science.buckets)
else
[]
end
Expand Down
43 changes: 41 additions & 2 deletions app/graphql/types/query_type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -271,13 +271,20 @@ def actor(id:)
argument :has_views, Int, required: false
argument :has_downloads, Int, required: false
argument :field_of_science, String, required: false
argument :field_of_science_repository, String, required: false
argument :field_of_science_combined, String, required: false
argument :facet_count, Int, required: false, default_value: 10
argument :first, Int, required: false, default_value: 25
argument :after, String, required: false
end

def works(**args)
ElasticsearchModelResponseConnection.new(response(args), context: context, first: args[:first], after: args[:after])
ElasticsearchModelResponseConnection.new(
response(args), {
context: context,
first: args[:first],
after: args[:after]
})
end

field :work, WorkType, null: false do
Expand Down Expand Up @@ -1253,7 +1260,39 @@ def usage_report(id:)
end

def response(**args)
Doi.gql_query(args[:query], ids: args[:ids], user_id: args[:user_id], client_id: args[:repository_id], provider_id: args[:member_id], resource_type_id: args[:resource_type_id], resource_type: args[:resource_type], published: args[:published], agency: args[:registration_agency], language: args[:language], license: args[:license], has_person: args[:has_person], has_funder: args[:has_funder], has_organization: args[:has_organization], has_affiliation: args[:has_affiliation], has_member: args[:has_member], has_citations: args[:has_citations], has_parts: args[:has_parts], has_versions: args[:has_versions], has_views: args[:has_views], has_downloads: args[:has_downloads], field_of_science: args[:field_of_science], facet_count: args[:facet_count], pid_entity: args[:pid_entity], state: "findable", page: { cursor: args[:after].present? ? Base64.urlsafe_decode64(args[:after]) : [], size: args[:first] })
Doi.gql_query(
args[:query],
ids: args[:ids],
user_id: args[:user_id],
client_id: args[:repository_id],
provider_id: args[:member_id],
resource_type_id: args[:resource_type_id],
resource_type: args[:resource_type],
published: args[:published],
agency: args[:registration_agency],
language: args[:language],
license: args[:license],
has_person: args[:has_person],
has_funder: args[:has_funder],
has_organization: args[:has_organization],
has_affiliation: args[:has_affiliation],
has_member: args[:has_member],
has_citations: args[:has_citations],
has_parts: args[:has_parts],
has_versions: args[:has_versions],
has_views: args[:has_views],
has_downloads: args[:has_downloads],
field_of_science: args[:field_of_science],
field_of_science_repository: args[:field_of_science_repository],
field_of_science_combined: args[:field_of_science_combined],
facet_count: args[:facet_count],
pid_entity: args[:pid_entity],
state: "findable",
page: {
cursor: args[:after].present? ? Base64.urlsafe_decode64(args[:after]) : [],
size: args[:first]
}
)
end

def set_doi(id)
Expand Down
2 changes: 1 addition & 1 deletion app/graphql/types/service_connection_with_total_type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ def licenses

def fields_of_science
if object.aggregations.fields_of_science
facet_by_fos(object.aggregations.fields_of_science.subject.buckets)
facet_by_fos(object.aggregations.fields_of_science.buckets)
else
[]
end
Expand Down
2 changes: 1 addition & 1 deletion app/graphql/types/software_connection_with_total_type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ def licenses

def fields_of_science
if object.aggregations.fields_of_science
facet_by_fos(object.aggregations.fields_of_science.subject.buckets)
facet_by_fos(object.aggregations.fields_of_science.buckets)
else
[]
end
Expand Down
2 changes: 1 addition & 1 deletion app/graphql/types/sound_connection_with_total_type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ def licenses

def fields_of_science
if object.aggregations.fields_of_science
facet_by_fos(object.aggregations.fields_of_science.subject.buckets)
facet_by_fos(object.aggregations.fields_of_science.buckets)
else
[]
end
Expand Down
20 changes: 19 additions & 1 deletion app/graphql/types/work_connection_with_total_type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ class WorkConnectionWithTotalType < BaseConnection
field :affiliations, [FacetType], null: true, cache: true
field :authors, [FacetType], null: true, cache: true
field :fields_of_science, [FacetType], null: true, cache: true
field :fields_of_science_combined, [FacetType], null: true, cache: true
field :fields_of_science_repository, [FacetType], null: true, cache: true
field :licenses, [FacetType], null: true, cache: true
field :languages, [FacetType], null: true, cache: true

Expand Down Expand Up @@ -100,7 +102,23 @@ def licenses

def fields_of_science
if object.aggregations.fields_of_science
facet_by_fos(object.aggregations.fields_of_science.subject.buckets)
facet_by_fos(object.aggregations.fields_of_science.buckets)
else
[]
end
end

def fields_of_science_combined
if object.aggregations.fields_of_science_combined
facet_by_fos(object.aggregations.fields_of_science_combined.buckets)
else
[]
end
end

def fields_of_science_repository
if object.aggregations.fields_of_science_repository
facet_by_fos(object.aggregations.fields_of_science_repository.buckets)
else
[]
end
Expand Down
2 changes: 1 addition & 1 deletion app/graphql/types/workflow_connection_with_total_type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ def licenses

def fields_of_science
if object.aggregations.fields_of_science
facet_by_fos(object.aggregations.fields_of_science.subject.buckets)
facet_by_fos(object.aggregations.fields_of_science.buckets)
else
[]
end
Expand Down
Loading

0 comments on commit dd765cf

Please sign in to comment.