Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
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
1 change: 1 addition & 0 deletions services/authors-tools/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ FROM python:3.9-slim-bullseye AS dvcfiles
WORKDIR /dvc
RUN apt-get update && apt-get -y --no-install-recommends install git=1:2.30.2-1+deb11u5 && apt-get clean && rm -rf /var/lib/apt/lists/*
RUN pip install --no-cache-dir dvc[webdav]==3.42.0
RUN pip install "pathspec==0.10.3"
Comment thread
Luc-Ank marked this conversation as resolved.
Outdated
RUN --mount=type=secret,id=webdav_login \
--mount=type=secret,id=webdav_password \
--mount=type=secret,id=webdav_url \
Expand Down
35 changes: 27 additions & 8 deletions services/authors-tools/v1/orcid-disambiguation/disambiguate.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,13 @@
from requests.auth import HTTPBasicAuth
import os


def getPoints(liste):
return liste[2]

def getSecondaryPoints(liste):
return liste[3]


class disambiguate:
def __init__(self, infoDic, nameDepth = 20, worksDepth = 20):
Expand Down Expand Up @@ -166,9 +170,13 @@ def splitFirstName(self,name):
return choice

def checkEmail(self,email):
mails = []
for em in self.infoDic["email"]:
if em == email:
return True,em
for mail in email.split(","):
if em == mail:
mails.append(em)
if len(mails) > 0:
return True,em

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚨 issue: ‏Which em ?

You're outside of the loop!?
Shouldn't it be mails?

return False,0

def disambiguation(self):
Expand All @@ -183,7 +191,7 @@ def disambiguation(self):
if "email" in self.infoDic: #check email
end,em = self.checkEmail(personInfos["email"])
if end:
return [[orcid,["Email "+em],100]]
return [[orcid,["Email "+em],100]][0][0]

works = self.getWorksFromOrcid(orcid)
time.sleep(self.timeBetweenrequest)
Expand All @@ -194,7 +202,7 @@ def disambiguation(self):
for tit in [title.lower() for title in worksInfo["title"]]:
ratio = SequenceMatcher(None, title.lower(), tit).ratio() #check similarity between title
if ratio > 0.7:
return [[orcid,["title "+tit],100]]
return [[orcid,["title "+tit],100]][0][0]

if "coAuthors" in self.infoDic: #check coAuthors
authorsPutcode = []
Expand All @@ -206,7 +214,7 @@ def disambiguation(self):
choices = self.splitFirstName(author)
for choice in choices:
if choice in [auth.lower() for auth in authors]:
return [[orcid,["Co-authors "+choice],100]]
return [[orcid,["Co-authors "+choice],100]][0][0]

if "affiliations" in self.infoDic: #check affiliations
for affiliation in self.infoDic["affiliations"]:
Expand All @@ -226,14 +234,25 @@ def disambiguation(self):
points += 5
matchArg.append("Match LastName ")

personInfos["secondaryScore"] = len(worksInfo["title"])
personInfos["points"] = points
personInfos["matchArg"] = matchArg

#check first and last name
finalReturn = []
for personInfos in personsInfos:
if personInfos["points"] != 0:
finalReturn.append([personInfos["orcid"],personInfos["matchArg"],personInfos["points"]])

finalReturn.append([personInfos["orcid"],personInfos["matchArg"],
personInfos["points"], personInfos["secondaryScore"]])
#Better score first
finalReturn.sort(key=getPoints,reverse=True)
return finalReturn
#if multiples sort based on secondary score
if len(finalReturn) == 0:
return "None"
max_score = finalReturn[0][2]
finalReturn = [t for t in finalReturn if t[2] == max_score]
if len(finalReturn) == 1:
return finalReturn[0][0]
else:
finalReturn.sort(key=getSecondaryPoints, reverse=True)
return [t[0] for t in finalReturn]
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,7 @@ def main(nameDepth = 20, worksDepth = 20):
res = []
for info in data['value'].copy():
db = disambiguate(info,nameDepth=nameDepth, worksDepth=worksDepth )
result = db.disambiguation()
if len(result)>0:
res.append(result[0][0])
else:
res.append("None")
res.append(db.disambiguation())
data["value"] = res
sys.stdout.write(json.dumps(data))
sys.stdout.write('\n')
Expand Down
Loading