-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
OA: changed golden access calculations
- Loading branch information
Showing
7 changed files
with
21,162 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import xml.etree.ElementTree as ET | ||
from io import StringIO | ||
|
||
|
||
def parse_without_names_spaces(xml): | ||
if type(xml) == str: | ||
it = ET.iterparse(StringIO(xml)) | ||
else: | ||
it = ET.iterparse(StringIO(xml.getvalue().decode("utf-8"))) | ||
for _, el in it: | ||
el.tag = el.tag.rpartition("}")[-1] | ||
root = it.root | ||
return root | ||
|
||
|
||
def get_golden_access_records_ids(data): | ||
xml = parse_without_names_spaces(data) | ||
records = xml.findall(".record") | ||
golden_access = [] | ||
for record in records: | ||
datafields = record.find("datafield/[@tag='540']") | ||
record_type = datafields.find("subfield/[@code='3']") | ||
license = datafields.find("subfield/[@code='a']") | ||
if record_type is not None and license is not None: | ||
if ( | ||
"CC" in license.text | ||
and "BY" in license.text | ||
and record_type.text == "publication" | ||
): | ||
record_id = record.find("controlfield/[@tag='001']") | ||
if record_id is not None: | ||
doi = record_id.text | ||
golden_access.append(doi) | ||
return golden_access |
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 |
---|---|---|
|
@@ -2,3 +2,4 @@ pre-commit==3.6.2 | |
pytest==7.4.4 | ||
coverage==7.4.3 | ||
pytest-cov==4.1.0 | ||
pytest-datadir==1.5.0 |
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,19 @@ | ||
from open_access.parsers import get_golden_access_records_ids | ||
|
||
expected = [ | ||
"2891488", | ||
"2888511", | ||
"2884471", | ||
"2884470", | ||
"2883672", | ||
"2882429", | ||
"2882335", | ||
"2882324", | ||
"2882311", | ||
] | ||
|
||
|
||
def test_get_golden_access_records_dois(shared_datadir): | ||
with open(shared_datadir / "search.xml") as file: | ||
records_ids = get_golden_access_records_ids(file.read()) | ||
assert records_ids == expected |