Skip to content
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

Fixes #243

Merged
merged 2 commits into from
Apr 8, 2024
Merged

Fixes #243

Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 0 additions & 68 deletions api/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import requests
import sys
import urllib
import json
from urllib.parse import urljoin


Expand Down Expand Up @@ -437,73 +436,6 @@ def check_metadata_terms_with_values(metadata, terms):
return df_access


def is_unique_id(item_id):
"""Returns True if the given identifier is unique. Otherwise, False.

Parameters
----------
item_id : str
Digital Object identifier, which can be a generic one (DOI, PID ...), or an internal (e.g. an
identifier from the repo)
Returns
-------
boolean
True if the item id is a persistent identifier. False if not
"""
is_unique = False
if idutils.is_doi(item_id):
is_unique = True
if idutils.is_handle(item_id):
is_unique = True
if is_uuid(item_id):
is_unique = True

return is_unique


def check_metadata_terms_with_values(metadata, terms):
"""Checks if provided terms are found in the metadata.

Parameters
----------
metadata: pd.DataFrame with metadata from repository
terms: pd.DataFrame with terms to search in the metadata

Returns
-------
DataFrame with the matching elements found in the metadata.
"""
term_dfs = []
for index, row in terms.iterrows():
_element = row["element"]
_qualifier = row["qualifier"]
# Select matching metadata row
_df = metadata.loc[
(metadata["element"] == _element)
& (metadata["qualifier"].apply(lambda x: x in [None, _qualifier]))
& (metadata["text_value"] != "")
]
if _df.empty:
logging.warning(
"Element (and qualifier) not found in metadata: %s (qualifier: %s)"
% (_element, _qualifier)
)
else:
term_dfs.append(_df)
logging.debug(
"Found matching <%s> element in metadata: %s"
% (_element, _df.to_json())
)
df_access = pd.DataFrame()
if term_dfs:
df_access = pd.concat(term_dfs)
logging.debug(
"DataFrame produced with matching metadata elements: \n%s" % df_access
)

return df_access


def oai_check_record_url(oai_base, metadata_prefix, pid):
endpoint_root = urllib.parse.urlparse(oai_base).netloc
try:
Expand Down
Loading