Skip to content

Commit

Permalink
citations info opr index v1
Browse files Browse the repository at this point in the history
  • Loading branch information
ivanhb committed Sep 11, 2023
1 parent b31f2b7 commit 2a1d852
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 3 deletions.
2 changes: 1 addition & 1 deletion index_v1.hf
Original file line number Diff line number Diff line change
Expand Up @@ -529,7 +529,7 @@ SELECT ?val (count(?oci) as ?citation_count) (GROUP_CONCAT(?citing; separator=";
#type operation
#doi str(10\..+)
#preprocess lower(doi) --> doi2omid(doi)
#postprocess metadata(cited)
#postprocess citations_info(citing,cited)
#method get
#description This operation retrieves the citation data for all the references appearing in the reference lists of other citing works to the bibliographic entity identified by the input DOI, that constitute the incoming citations of that identified bibliographic entity.

Expand Down
56 changes: 54 additions & 2 deletions indexapi_v1.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,36 @@ def metadata(res, *args):

return res, True

# args must contain the [[citing]] and [[cited]]
def citations_info(res, *args):
header = res[0]
fields = {"citing":header.index(args[0]), "cited": header.index(args[1])}
index_meta = {}

additional_fields = ["creation", "timespan", "journal_sc","author_sc"]
header.extend(additional_fields)

for row in res[1:]:
entities_data = {"citing":[],"cited":[]}
for f in fields:

f_col = field_idx[fields[f]]
# org value: <https://w3id.org/oc/meta/br/06NNNNNN>
entity = row[f_col][1].split("oc/meta/")[1][:-1]

if not entity in index_meta:
r = __ocmeta_parser(entity,"omid")
if r is None or all([i in ("", None) for i in r]):
r = ["" for i in r]
index_meta[entity] = r

entities_data[f] = r

# process and elaborate additional fields
row.extend([entities_data["citing"]["year"],"","",""])

return res, True


def __get_issn(body):
cur_id = ""
Expand Down Expand Up @@ -245,7 +275,9 @@ def __ocmeta_parser(doi,pre="doi"):
source_title = source_title_string

year = ""
pub_date = ""
if "pub_date" in body:
pub_date = __normalise(body["pub_date"])
if len(body["pub_date"]) >= 4:
year = __normalise(body["pub_date"][:4])

Expand All @@ -265,10 +297,30 @@ def __ocmeta_parser(doi,pre="doi"):
if "page" in body:
page = __normalise(body["page"])

return ["; ".join(authors), year, title, source_title, volume, issue, page, source_id]
return {
"author": "; ".join(authors),
"year": year,
"pub_date": pub_date,
"title": title,
"source_title": source_title,
"source_id": source_id,
"volume": volume,
"issue": issue,
"page": pages
}

except Exception as e:
return ["", "", "", "", "", "", "", ""]
return {
"author": "",
"year": "",
"pub_date": "",
"title": "",
"source_title": "",
"source_id": "",
"volume": "",
"issue": "",
"page": ""
}

def __crossref_parser(doi):
api = "https://api.crossref.org/works/%s"
Expand Down

0 comments on commit 2a1d852

Please sign in to comment.