def test_match_ads_author05(self):
     matches = author_match.match_ads_author_fields([self.A1,self.C1,self.M1],[])
     self.assertEqual(matches, [(self.A1,None),(self.C1,None),(self.M1,None)])
     matches = author_match.match_ads_author_fields([self.A1,self.C1,self.M1],[], impl='np')
     self.assertEqual(matches, [(self.A1,None),(self.C1,None),(self.M1,None)])
     matches = author_match.match_ads_author_fields([],[self.A1,self.C1,self.M1])
     self.assertEqual(matches, [])
     matches = author_match.match_ads_author_fields([],[self.A1,self.C1,self.M1], impl='np')
     self.assertEqual(matches, [])
 def test_match_ads_author02(self):
     for f1,f2 in (([self.A2,self.C2,self.M2], [self.C1,self.M1,self.A1]), 
                   ([self.A2,self.C2,self.M2], [self.M1,self.A1,self.C1]),
                   ([self.A2,self.C2,self.M2], [self.A1,self.M1,self.C1]),
                   ([self.A2,self.C2,self.M2], [self.M1,self.C1,self.A1]),
                   ([self.A2,self.C2,self.M2], [self.C1,self.A1,self.M1])):
         matches = author_match.match_ads_author_fields(f1, f2)
         self.assertEqual(matches, [(self.A2,self.A1),(self.C2,self.C1),(self.M2,self.M1)])
         matches = author_match.match_ads_author_fields(f1, f2, impl='np')
         self.assertEqual(matches, [(self.A2,self.A1),(self.C2,self.C1),(self.M2,self.M1)])
 def test_match_ads_author06(self):
     # case where 1987Ap&SS.138...61H was incorrectly matched to 1986tnra.book.....D
     # (no match should be take place here)
     a1 = {"name": {"western": "Hadrava, P."}, "affiliations": ["Astronomical Institute of the Czechoslovak Academy of Sciences"]}
     a2 = {"name": {'western': 'de Waard, Gerrit Jan'}, "affiliations": []}
     matches = author_match.match_ads_author_fields([a1],[a2])
     self.assertEqual(matches,[(a1,None)])
     self.assertFalse(author_match.is_suitable_match(a1,a2))
 def test_match_ads_author04(self):
     # 1993AIAAJ..31..447M (crossref vs. sti)
     [c1,c2,c3,c4,c5] = [{'affiliations': [], 'name': {'western': 'Miles, Richard B.'}}, 
                         {'affiliations': [], 'name': {'western': 'Lempert, Walter R.'}}, 
                         {'affiliations': [], 'name': {'western': 'She, Zhen-Su'}}, 
                         {'affiliations': [], 'name': {'western': 'Zhang, Boying'}}, 
                         {'affiliations': [], 'name': {'western': 'Zhou, Deyu'}}]
     [s1,s2,s3,s4,s5] = [{'affiliations': ['Princeton Univ., NJ'], 'name': {'western': 'Miles, Richard B.'}}, 
                         {'affiliations': ['Princeton Univ., NJ'], 'name': {'western': 'Zhou, Deyu'}}, 
                         {'affiliations': ['Princeton Univ., NJ'], 'name': {'western': 'Zhang, Boying'}}, 
                         {'affiliations': ['Princeton Univ., NJ'], 'name': {'western': 'Lempert, Walter R.'}}, 
                         {'affiliations': ['Arizona Univ., Tucson, AZ'], 'name': {'western': 'She, Zhen-Su'}}]
     crossref = [c1,c2,c3,c4,c5]
     sti = [s1,s2,s3,s4,s5]
     res = [(c1,s1), (c2,s4), (c3,s5), (c4,s3), (c5,s2)]
     matches = author_match.match_ads_author_fields(crossref, sti)
     self.assertEqual(matches, res)
     matches = author_match.match_ads_author_fields(crossref, sti, impl='np')
     self.assertEqual(matches, res)
  def authorMerger(self,field='authors'):
    data = [ [i[field],i['tempdata']] for i in self.blocks if field in i]
    result = None
    while len(data) > 0:
      f1 = data.pop()
      f2 = result if result else data.pop()
      result = self._getBestOrigin(f1,f2,'authors')
      other = f2 if result == f1 else f1

      #Only do the matching if at least one of the the bestOrigin authors lacks an affiliation
      #AND the other author field has at least one
      if not all( [i['affiliations'] for i in result[0]] ) and\
            any( [i['affiliations'] for i in other[0]] ):
        best_matches = author_match.match_ads_author_fields(result[0],other[0])
        for match in best_matches:
          if not author_match.is_suitable_match(*match):
            continue
          if not match[0]['affiliations'] and match[1]['affiliations']:
            match[0]['affiliations'] = match[1]['affiliations']
        result = [[i[0] for i in best_matches],result[1]]
    return result[0]
 def test_match_ads_author03(self):
     matches = author_match.match_ads_author_fields([self.A1,self.C1],[self.M2,self.C2,self.A2])
     self.assertEqual(matches, [(self.A1,self.A2),(self.C1,self.C2)])
     matches = author_match.match_ads_author_fields([self.A1,self.C1],[self.M2,self.C2,self.A2], impl='np')
     self.assertEqual(matches, [(self.A1,self.A2),(self.C1,self.C2)])
     matches = author_match.match_ads_author_fields([self.M1,self.C1],[self.M2,self.C2,self.A2])
     self.assertEqual(matches, [(self.M1,self.M2),(self.C1,self.C2)])
     matches = author_match.match_ads_author_fields([self.M1,self.C1],[self.M2,self.C2,self.A2], impl='np')
     self.assertEqual(matches, [(self.M1,self.M2),(self.C1,self.C2)])
     matches = author_match.match_ads_author_fields([self.M1,self.A1],[self.M2,self.C2,self.A2])
     self.assertEqual(matches, [(self.M1,self.M2),(self.A1,self.A2)])
     matches = author_match.match_ads_author_fields([self.M1,self.A1],[self.M2,self.C2,self.A2], impl='np')
     self.assertEqual(matches, [(self.M1,self.M2),(self.A1,self.A2)])
     matches = author_match.match_ads_author_fields([self.A1],[self.M2,self.C2,self.A2])
     self.assertEqual(matches, [(self.A1,self.A2)])
     matches = author_match.match_ads_author_fields([self.A1],[self.M2,self.C2,self.A2], impl='np')
     self.assertEqual(matches, [(self.A1,self.A2)])
     matches = author_match.match_ads_author_fields([self.C1],[self.M2,self.C2,self.A2])
     self.assertEqual(matches, [(self.C1,self.C2)])
     matches = author_match.match_ads_author_fields([self.C1],[self.M2,self.C2,self.A2], impl='np')
     self.assertEqual(matches, [(self.C1,self.C2)])
     matches = author_match.match_ads_author_fields([self.M1],[self.M2,self.C2,self.A2])
     self.assertEqual(matches, [(self.M1,self.M2)])
     matches = author_match.match_ads_author_fields([self.M1],[self.M2,self.C2,self.A2], impl='np')
     self.assertEqual(matches, [(self.M1,self.M2)])
     matches = author_match.match_ads_author_fields([self.A1,self.C1,self.M1],[self.A2])
     self.assertEqual(matches, [(self.A1,self.A2),(self.C1,None),(self.M1,None)])
     matches = author_match.match_ads_author_fields([self.A1,self.C1,self.M1],[self.A2], impl='np')
     self.assertEqual(matches, [(self.A1,self.A2),(self.C1,None),(self.M1,None)])
     matches = author_match.match_ads_author_fields([self.A1,self.C1,self.M1],[self.C2])
     self.assertEqual(matches, [(self.A1,None),(self.C1,self.C2),(self.M1,None)])
     matches = author_match.match_ads_author_fields([self.A1,self.C1,self.M1],[self.C2], impl='np')
     self.assertEqual(matches, [(self.A1,None),(self.C1,self.C2),(self.M1,None)])
     matches = author_match.match_ads_author_fields([self.A1,self.C1,self.M1],[self.M2])
     self.assertEqual(matches, [(self.A1,None),(self.C1,None),(self.M1,self.M2)])
     matches = author_match.match_ads_author_fields([self.A1,self.C1,self.M1],[self.M2], impl='np')
     self.assertEqual(matches, [(self.A1,None),(self.C1,None),(self.M1,self.M2)])