Skip to content

Commit

Permalink
update schema to v0.14
Browse files Browse the repository at this point in the history
  • Loading branch information
mfenner committed May 16, 2024
1 parent 429c4df commit affc22c
Show file tree
Hide file tree
Showing 19 changed files with 645 additions and 94 deletions.
10 changes: 6 additions & 4 deletions commonmeta/crossref_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,8 @@ def insert_citation_list(metadata, xml):

citation_list = etree.SubElement(xml, "citation_list")
for ref in metadata.references:
if ref.get("id", None) is None:
continue
citation = etree.SubElement(
citation_list, "citation", {"key": ref.get("key", None)}
)
Expand All @@ -245,10 +247,10 @@ def insert_citation_list(metadata, xml):
etree.SubElement(citation, "cYear").text = ref.get("publicationYear")
if ref.get("title", None) is not None:
etree.SubElement(citation, "article_title").text = ref.get("title")
if ref.get("doi", None) is not None:
etree.SubElement(citation, "doi").text = doi_from_url(ref.get("doi"))
if ref.get("url", None) is not None:
etree.SubElement(citation, "unstructured_citation").text = ref.get("url")
if ref.get("id", None) is not None:
etree.SubElement(citation, "doi").text = doi_from_url(ref.get("id"))
if ref.get("unstructured", None) is not None:
etree.SubElement(citation, "unstructured_citation").text = ref.get("unstructured")
return xml


Expand Down
7 changes: 2 additions & 5 deletions commonmeta/readers/crossref_xml_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -392,15 +392,12 @@ def crossref_reference(reference: Optional[dict]) -> Optional[dict]:
doi = parse_attributes(reference.get("doi", None))
unstructured = reference.get("unstructured_citation", None)
if isinstance(unstructured, dict):
url = unstructured.get("u", None)
text = unstructured.get("font", None) or unstructured.get("#text", None)
else:
url = reference.get("url", None)
text = reference.get("unstructured_citation", None)
metadata = {
"key": reference.get("key", None),
"doi": normalize_doi(doi) if doi else None,
"url": normalize_url(url) if url else None,
"id": normalize_doi(doi) if doi else None,
"contributor": reference.get("author", None),
"title": reference.get("article_title", None),
"publisher": reference.get("publisher", None),
Expand All @@ -411,7 +408,7 @@ def crossref_reference(reference: Optional[dict]) -> Optional[dict]:
"lastPage": reference.get("last_page", None),
"containerTitle": reference.get("journal_title", None),
"edition": None,
"unstructured": sanitize(text) if text and doi is None else None,
"unstructured": sanitize(text) if text else None,
}
return compact(metadata)

Expand Down
2 changes: 1 addition & 1 deletion commonmeta/readers/csl_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ def read_csl(data: dict, **kwargs) -> Commonmeta:
descriptions = [
{
"description": sanitize(str(meta.get("abstract"))),
"descriptionType": "Abstract",
"type": "Abstract",
}
]
else:
Expand Down
2 changes: 1 addition & 1 deletion commonmeta/readers/datacite_xml_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ def format_subject(subject):
{
"subject": subject.get("#text", None),
"subjectScheme": subject.get("subjectScheme", None),
"lang": subject.get("xml:lang", None),
"language": subject.get("xml:lang", None),
}
)
return None
Expand Down
4 changes: 2 additions & 2 deletions commonmeta/readers/inveniordm_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,9 +127,9 @@ def map_reference(reference):
identifier = reference.get("relatedIdentifier", None)
identifier_type = reference.get("relatedIdentifierType", None)
if identifier and identifier_type == "DOI":
reference["doi"] = normalize_doi(identifier)
reference["id"] = normalize_doi(identifier)
elif identifier and identifier_type == "URL":
reference["url"] = normalize_url(identifier)
reference["id"] = normalize_url(identifier)
reference = py_.omit(
reference,
[
Expand Down
9 changes: 4 additions & 5 deletions commonmeta/readers/json_feed_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ def read_json_feed_item(data: Optional[dict], **kwargs) -> Commonmeta:
description = meta.get("summary", None)
if description is not None:
descriptions = [
{"description": sanitize(description), "descriptionType": "Abstract"}
{"description": sanitize(description), "type": "Abstract"}
]
else:
descriptions = None
Expand Down Expand Up @@ -165,13 +165,12 @@ def get_reference(reference: dict) -> Optional[dict]:
return None
try:
if reference.get("doi", None) and validate_doi(reference.get("doi")):
doi = normalize_doi(reference.get("doi"))
id_ = normalize_doi(reference.get("doi"))
return compact(
{
"doi": doi,
"id": id_,
"title": reference.get("title", None),
"publicationYear": reference.get("publicationYear", None),
"url": reference.get("url", None),
}
)

Expand All @@ -185,7 +184,7 @@ def get_reference(reference: dict) -> Optional[dict]:
if response.status_code in [404]:
return None
return {
"url": reference.get("url"),
"id": reference.get("url"),
}
except Exception as error:
print(error)
Expand Down
Loading

0 comments on commit affc22c

Please sign in to comment.