def test_is_suitable_match(self):
     self.assertTrue(author_match.is_suitable_match(self.A1,self.A1))
     self.assertTrue(author_match.is_suitable_match(self.C1,self.C1))
     self.assertTrue(author_match.is_suitable_match(self.M1,self.M1))
     self.assertTrue(author_match.is_suitable_match(self.A1,self.A2))
     self.assertTrue(author_match.is_suitable_match(self.C1,self.C2))
     self.assertTrue(author_match.is_suitable_match(self.M1,self.M2))
     self.assertFalse(author_match.is_suitable_match(self.A1,self.C1))
     self.assertFalse(author_match.is_suitable_match(self.A1,self.M1))
     self.assertFalse(author_match.is_suitable_match(self.A1,self.C2))
     self.assertFalse(author_match.is_suitable_match(self.A1,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 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]