Skip to content
Snippets Groups Projects
Commit 16e22d91 authored by Elias Chetouane's avatar Elias Chetouane
Browse files

Ajout d'un historique de toutes les relations des jeux de données (hasversion...)

parent e8b7601a
No related branches found
No related tags found
1 merge request!3Prise en compte des relations des jeux de données, versions, jeux identiques...
...@@ -66,6 +66,7 @@ if temp_rows : ...@@ -66,6 +66,7 @@ if temp_rows :
df_fresh.loc[df_fresh.index[i], "doi"] = result[0] df_fresh.loc[df_fresh.index[i], "doi"] = result[0]
df_fresh.loc[df_fresh.index[i], "relation_nbInstances"] = result[1] df_fresh.loc[df_fresh.index[i], "relation_nbInstances"] = result[1]
df_fresh.loc[df_fresh.index[i], "relation_nbCitation"] = result[2] df_fresh.loc[df_fresh.index[i], "relation_nbCitation"] = result[2]
df_fresh.loc[df_fresh.index[i], "relations_all"] = str(result[3])
else: else:
to_del.append(i) to_del.append(i)
......
import requests, json import requests, json
def get_origin_version(doi, count=0, cited=0): def get_origin_version(doi, count=0, cited=0, history=[]):
cited = 0 cited = 0
req = requests.get( f"https://api.datacite.org/dois/{doi}" ) req = requests.get( f"https://api.datacite.org/dois/{doi}" )
res = req.json() res = req.json()
result = (doi, count, cited) result = (doi, count, cited, history)
try: try:
related = res["data"]["attributes"]["relatedIdentifiers"] related = res["data"]["attributes"]["relatedIdentifiers"]
except: except:
...@@ -13,17 +13,17 @@ def get_origin_version(doi, count=0, cited=0): ...@@ -13,17 +13,17 @@ def get_origin_version(doi, count=0, cited=0):
ignore = False ignore = False
duplicate = False duplicate = False
for i in related: for i in related:
if i["relationType"] == "IsVersionOf" and i.get("relatedIdentifierType") == "DOI": history.append([i.get("relationType"), i.get("relatedIdentifier")])
if i.get("relationType") == "IsVersionOf" and i.get("relatedIdentifierType") == "DOI":
ignore = True ignore = True
elem_to_save_i = i["relatedIdentifier"] elem_to_save_i = i.get("relatedIdentifier")
# supprimer le doi courant s'il apparait dans la liste if i.get("relationType") == "isCitedBy" and i.get("relatedIdentifierType") == "DOI": cited += 1
if i["relationType"] == "isCitedBy" and i.get("relatedIdentifierType") == "DOI": cited += 1 if i.get("relationType") == "IsIdenticalTo" and i.get("relatedIdentifierType") == "DOI":
if i["relationType"] == "IsIdenticalTo" and i.get("relatedIdentifierType") == "DOI":
duplicate = True duplicate = True
elem_to_save_d = i["relatedIdentifier"] elem_to_save_d = i.get("relatedIdentifier")
if duplicate and not(ignore): if duplicate and not(ignore):
result = (elem_to_save_d, count, cited) result = (elem_to_save_d, count, cited, history)
if ignore: result = get_origin_version(elem_to_save_i, count+1, cited) if ignore: result = get_origin_version(elem_to_save_i, count+1, cited, history)
return result return result
def get_md_from_datacite( doi ) : def get_md_from_datacite( doi ) :
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment