Skip to content

Commit

Permalink
api citation-count - handle mem address
Browse files Browse the repository at this point in the history
  • Loading branch information
ivanhb committed Sep 5, 2024
1 parent 21c208f commit 7008935
Showing 1 changed file with 18 additions and 11 deletions.
29 changes: 18 additions & 11 deletions indexapi_v2.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,9 +181,9 @@ def count_unique_brs(res, *args):
l_brs.append(row[idx_omid_br_uri][1])
l_brs = ["<"+_c+">" for _c in l_brs]
l_brs_anyids = __get_ids_from_meta(l_brs)

unique_brs_anyid = []
for s in l_brs_anyids:
for _l in l_brs_anyids:
s = set(_l)
# check the unique br anyids
_c_intersection = 0
for __unique in unique_brs_anyid:
Expand Down Expand Up @@ -395,8 +395,12 @@ def ___contains_days(date):

return result

def __get_ids_from_meta(values, final_res = dict()):
MAX_VALUES = 3000
def __get_ids_from_meta(values, finalres = None):

if finalres == None:
finalres = []

MAX_VALUES = 2000

values_part = values[:MAX_VALUES]
values_rest = values[MAX_VALUES:]
Expand All @@ -415,28 +419,31 @@ def __get_ids_from_meta(values, final_res = dict()):
headers={"Accept": "application/sparql-results+json", "Content-Type": "application/sparql-query"}
data = {"query": sparql_query}

res = defaultdict(set)
res = dict()

try:
response = post(sparql_endpoint, headers=headers, data=sparql_query)
if response.status_code == 200:
r = loads(response.text)
results = r["results"]["bindings"]

if len(results) > 0:
for elem in results:
omid_br = elem["br_omid"]["value"]
anyid_pref = elem["scheme"]["value"].split("datacite/")[1]
anyid_val = elem["identifier_val"]["value"]
res[omid_br].add(anyid_pref+":"+anyid_val)

if omid_br not in res:
res[omid_br] = []
res[omid_br].append(anyid_pref+":"+anyid_val)
except:
pass

for k in res:
final_res[k] = res[k]
finalres += [res[k] for k in res]
res = None
if len(values_rest) > 0:
return __get_ids_from_meta(values_rest, final_res)
return __get_ids_from_meta(values_rest, finalres)
else:
return final_res.values()
return finalres


def __br_meta_metadata(values):
Expand Down

0 comments on commit 7008935

Please sign in to comment.