-
Notifications
You must be signed in to change notification settings - Fork 8
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 #364 from datacite/refractor_multiple_dois_in_events
Refractor multiple dois in events
- Loading branch information
Showing
7 changed files
with
227 additions
and
151 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -54,3 +54,4 @@ doc/dependencies* | |
docker-compose.override.yml | ||
.ruby-version | ||
.vscode | ||
.solargraph |
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
Large diffs are not rendered by default.
Oops, something went wrong.
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,34 @@ | ||
# frozen_string_literal: true | ||
|
||
class EventsQuery | ||
|
||
include Facetable | ||
|
||
ACTIVE_RELATION_TYPES = [ | ||
"cites", | ||
"is-supplement-to", | ||
"references" | ||
] | ||
|
||
PASSIVE_RELATION_TYPES = [ | ||
"is-cited-by", | ||
"is-supplemented-by", | ||
"is-referenced-by" | ||
] | ||
|
||
def initialize() | ||
end | ||
|
||
def doi_citations(doi) | ||
pid = Event.new.normalize_doi(doi) | ||
query = "(subj_id:\"#{pid}\" AND (relation_type_id:#{PASSIVE_RELATION_TYPES.join(' OR relation_type_id:')})) OR (obj_id:\"#{pid}\" AND (relation_type_id:#{ACTIVE_RELATION_TYPES.join(' OR relation_type_id:')}))" | ||
results = Event.query(query, doi:doi, aggregations: "citation_count_aggregation", page: { size: 1, cursor: [] }).response.aggregations.citations.buckets | ||
results.any? ? results.first.total.value : 0 | ||
end | ||
|
||
def citations(doi) | ||
doi.downcase.split(",").map do |item| | ||
{ id: item, count: EventsQuery.new.doi_citations(item) } | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
# frozen_string_literal: true | ||
|
||
require "rails_helper" | ||
|
||
describe EventsQuery, elasticsearch: true do | ||
|
||
context "citation events" do | ||
let!(:event) { create(:event_for_datacite_related, subj_id:"http://doi.org/10.0260/co.2004960.v2", obj_id:"http://doi.org/10.0260/co.2004960.v1") } | ||
let!(:event_references) { create_list(:event_for_datacite_related, 3, obj_id:"10.5061/dryad.47sd5/2", relation_type_id: "references") } | ||
let!(:copies) { create(:event_for_datacite_related, subj_id:"http://doi.org/10.0260/co.2004960.v2", obj_id:"http://doi.org/10.0260/co.2004960.v1", relation_type_id: "cites") } | ||
|
||
before do | ||
Event.import | ||
sleep 1 | ||
end | ||
|
||
it "doi_citations" do | ||
expect(EventsQuery.new.doi_citations("10.0260/co.2004960.v1")).to eq(1) | ||
end | ||
|
||
it "doi_citations wiht 0 citations" do | ||
expect(EventsQuery.new.doi_citations("10.5061/dryad.dd47sd5/1")).to eq(0) | ||
end | ||
|
||
it "citations" do | ||
results = EventsQuery.new.citations("10.5061/dryad.47sd5/1,10.5061/dryad.47sd5/2,10.0260/co.2004960.v1") | ||
citations = results.select { |item| item[:id] == "10.5061/dryad.47sd5/2" }.first | ||
no_citations = results.select { |item| item[:id] == "10.5061/dryad.47sd5/1" }.first | ||
expect(citations[:count]).to eq(3) | ||
expect(no_citations[:count]).to eq(0) | ||
end | ||
end | ||
end |
Oops, something went wrong.