def convert_to_name_pair(dct): """ Converts a dictionary {'family':'Last','given':'First'} to ('First','Last') """ result = None if 'family' in dct and 'given' in dct: result = (dct['given'],dct['family']) elif 'family' in dct: # The 'Arvind' case result = ('',dct['family']) elif 'literal' in dct: result = parse_comma_name(dct['literal']) if result: result = (normalize_name_words(result[0]), normalize_name_words(result[1])) return result
def name(self): """ Returns a parsed version of the "credit name" in the ORCID profile. If there is no such name, returns the given and family names on the profile (they should exist) """ name_item = jpath('orcid-profile/orcid-bio/personal-details', self.json) name = jpath('credit-name/value', name_item) if name is not None: return parse_comma_name(name) return (normalize_name_words(jpath('given-names/value', name_item, '')), normalize_name_words(jpath('family-name/value', name_item, '')))
def name(self): """ Returns a parsed version of the "credit name" in the ORCID profile. If there is no such name, returns the given and family names on the profile (they should exist) """ name_item = jpath('person/name', self.json) name = jpath('credit-name/value', name_item) if name: return parse_comma_name(name) return (normalize_name_words(jpath('given-names/value', name_item, '')), normalize_name_words(jpath('family-name/value', name_item, '')))
def import_from_tsv(filename): f = open(filename, 'r', 'utf-8') for line in f: fields = line.strip().split('\t') print fields dept = fields[dept_f] (department, found) = Department.objects.get_or_create(name__iexact=dept, defaults={'name':dept.strip()}) email = fields[email_f] if email == '': email = None first = fields[first_name_f] last = normalize_name_words(fields[last_name_f]) homepage = fields[url_f] role = fields[role_f] if homepage == '': homepage = None try: researcher = Researcher.create_from_scratch(first, last, department, email, role, homepage) except ValueError: print "ValueError" continue group = fields[group_f] if group: g, created = ResearchGroup.objects.get_or_create(name=group) researcher.groups.add(g)
def other_names(self): """ Returns the list of other names listed on the ORCiD profile. This includes the (given,family) name if a credit name was defined. """ name_item = jpath('orcid-profile/orcid-bio/personal-details', self.json) names = [] credit_name = jpath('credit-name/value', name_item) if credit_name is not None: names.append((normalize_name_words(jpath('given-names/value', name_item)), normalize_name_words(jpath('family-name/value', name_item)))) other_names = jpath('other-names/other-name', name_item, default=[]) for name in other_names: val = name.get('value') if val is not None: names.append(parse_comma_name(val)) return names
def newUnaffiliatedResearcher(request): form = AddUnaffiliatedResearcherForm(request.POST) researcher = None if form.is_valid(): first = normalize_name_words(form.cleaned_data['first']) last = normalize_name_words(form.cleaned_data['last']) # Check that the researcher is not already known under a different name. if not form.cleaned_data.get('force'): name, created = Name.get_or_create(first, last) candidates = researcherCandidatesByName(name) if candidates: return {'disambiguation': candidates} researcher = Researcher.create_by_name(first, last) researcher.fetch_everything_if_outdated() return {'url': researcher.url} else: return form.errors, 403
def newUnaffiliatedResearcher(request): form = AddUnaffiliatedResearcherForm(request.POST) researcher = None if form.is_valid(): first = normalize_name_words(form.cleaned_data['first']) last = normalize_name_words(form.cleaned_data['last']) # Check that the researcher is not already known under a different name. if not form.cleaned_data.get('force'): name, created = Name.get_or_create(first, last) candidates = researcherCandidatesByName(name) if candidates: return {'disambiguation':candidates} researcher = Researcher.create_by_name(first, last) researcher.fetch_everything_if_outdated() return {'url':researcher.url} else: return form.errors, 403
def other_names(self): """ Returns the list of other names listed on the ORCiD profile. This includes the (given,family) name if a credit name was defined. """ person = jpath('person', self.json) names = [] credit_name = jpath('name/credit-name/value', person) if credit_name is not None: names.append((normalize_name_words( jpath('name/given-names/value', person, '')), normalize_name_words( jpath('name/family-name/value', person, '')))) other_names = jpath('other-names/other-name', person, default=[]) for name in other_names: val = name.get('content') if val is not None: names.append(parse_comma_name(val)) return names
def test_involutive(self): lst = [ 'Jean', 'Jean-Pierre', 'John Mark', 'JEAN-PIERRE', 'JOHN MARK', 'JOSÉ', 'JOSÉ-ALAIN', 'José', 'ÉMILIE', 'Émilie', 'John Mark', 'Jean - Pierre', 'J.P. Morgan', 'JP. Morgan', 'Jp. Morgan', ] for sample in lst: normalized = normalize_name_words(sample) self.assertEqual(normalized, normalize_name_words(normalized))
def other_names(self): """ Returns the list of other names listed on the ORCiD profile. This includes the (given,family) name if a credit name was defined. """ name_item = jpath('orcid-profile/orcid-bio/personal-details', self.json) names = [] credit_name = jpath('credit-name/value', name_item) if credit_name is not None: names.append( (normalize_name_words(jpath('given-names/value', name_item, '')), normalize_name_words(jpath('family-name/value', name_item, '')))) other_names = jpath('other-names/other-name', name_item, default=[]) for name in other_names: val = name.get('value') if val is not None: names.append(parse_comma_name(val)) return names
def test_simple(self): self.assertEqual(normalize_name_words('Jean'), 'Jean') self.assertEqual(normalize_name_words('Jean-Pierre'), 'Jean-Pierre') self.assertEqual(normalize_name_words('Jean-pierre'), 'Jean-Pierre') self.assertEqual(normalize_name_words('John Mark'), 'John Mark') self.assertEqual(normalize_name_words('JEAN-PIERRE'), 'Jean-Pierre') self.assertEqual(normalize_name_words('JOHN MARK'), 'John Mark')
def test_flattened(self): self.assertEqual(normalize_name_words('JP.'), 'J.-P.') self.assertEqual(normalize_name_words('Jp.'), 'J.-P.')
def test_comma(self): self.assertEqual(normalize_name_words('John, Mark'), 'John Mark') self.assertEqual(normalize_name_words('John,, Mark'), 'John Mark') self.assertEqual(normalize_name_words('John Mark,'), 'John Mark') self.assertEqual(normalize_name_words('John Mark,,'), 'John Mark') self.assertEqual(normalize_name_words('John, Mark,,'), 'John Mark')
def test_lower(self): self.assertEqual(normalize_name_words('catalin'), 'Catalin') self.assertEqual(normalize_name_words('Colin de Verdière'), 'Colin de Verdière')
def test_spacing(self): self.assertEqual(normalize_name_words('John Mark'), 'John Mark') self.assertEqual(normalize_name_words(' John Mark'), 'John Mark') self.assertEqual(normalize_name_words(' John Mark \n'), 'John Mark') self.assertEqual(normalize_name_words('Jean - Pierre'), 'Jean-Pierre') self.assertEqual(normalize_name_words('J.P.'), 'J. P.')
def test_unicode(self): self.assertEqual(normalize_name_words('JOSÉ'), 'José') self.assertEqual(normalize_name_words('JOSÉ-ALAIN'), 'José-Alain') self.assertEqual(normalize_name_words('José'), 'José') self.assertEqual(normalize_name_words('ÉMILIE'), 'Émilie') self.assertEqual(normalize_name_words('Émilie'), 'Émilie')
def test_lower(self): self.assertEqual(normalize_name_words('catalin'), 'Catalin') self.assertEqual(normalize_name_words( 'Colin de Verdière'), 'Colin de Verdière')