예제 #1
0
    def process_payload(self, claim, **kwargs):
        """
        :param claim: contains the message inside the packet
            {'bibcode': '....',
            'orcidid': '.....',
            'name': 'author name',
            'facts': 'author name variants',
            }
        :return: no return
        """
        
        if not isinstance(claim, dict):
            raise ProcessingException('Received unknown payload {0}'.format(claim))
        
        if not claim.get('orcidid'):
            raise ProcessingException('Unusable payload, missing orcidid {0}'.format(claim))

        bibcode = claim['bibcode']
        rec = updater.retrieve_record(bibcode)
        
        
        cl = updater.update_record(rec, claim)
        if cl:
            updater.record_claims(bibcode, rec['claims'], rec['authors'])
            self.publish({'authors': rec.get('authors'), 'bibcode': rec['bibcode'], 'claims': rec.get('claims')})
        else:
            self.logger.warning('Claim refused for bibcode:{0} and orcidid:{1}'
                            .format(claim['bibcode'], claim['orcidid']))
예제 #2
0
    def test_exact_match(self):
        """
        Given an author with an exact name match, the Levenshtein matching function should not be called.

        :return: None
        """

        with patch.object(updater, 'find_orcid_position') as next_task:

            self.assertFalse(next_task.called)
            doc1 = {
                'bibcode':
                "2001RadR..155..543L",
                "authors": [
                    "Li, Zhongkui", "Xia, Liqun", "Lee, Leo M.",
                    "Khaletskiy, Alexander", "Wang, J.", "Wong, J. Y.",
                    "Li, Jian-Jian"
                ],
                'claims': {}
            }
            orcid_name = u'Wong, Jeffrey Yang'
            r = updater.update_record(
                doc1, {
                    'bibcode': '2001RadR..155..543L',
                    'orcidid': '0000-0003-2686-9241',
                    'account_id': '1',
                    'orcid_name': [orcid_name],
                    'author': [u'Wong, J Y'],
                    'author_norm': [u'Wong, J'],
                    'name': u'Wong, J Y',
                    'short_name': names.build_short_forms(orcid_name)
                }, 0.8)
            self.assertEqual(r, ('verified', 5))
            self.assertEqual(
                doc1['claims']['verified'],
                ['-', '-', '-', '-', '-', '0000-0003-2686-9241', '-'])
            # find_orcid_position should be bypassed by the exact string match
            self.assertFalse(next_task.called)
예제 #3
0
def task_match_claim(claim, **kwargs):
    """
    Takes the claim, matches it in the database (will create
    entry for the record, if not existing yet) and updates
    the metadata.

    :param claim: contains the message inside the packet
        {'bibcode': '....',
        'orcidid': '.....',
        'name': 'author name',
        'facts': 'author name variants',
        }
    :return: no return
    """

    if not isinstance(claim, dict):
        raise ProcessingException('Received unknown payload {0}'.format(claim))

    if not claim.get('orcidid'):
        raise ProcessingException(
            'Unusable payload, missing orcidid {0}'.format(claim))

    bibcode = claim['bibcode']
    if claim.get('status') != 'removed':
        identifiers = claim['identifiers']
        authors = claim['author_list']
    else:
        metadata = app.retrieve_metadata(bibcode)
        identifiers = metadata.get('identifier', [])
        authors = metadata.get('author', [])

    rec = app.retrieve_record(bibcode, authors)

    cl = updater.update_record(rec, claim,
                               app.conf.get('MIN_LEVENSHTEIN_RATIO', 0.9))
    if cl:
        unique_bibs = list(set([bibcode] + identifiers))
        app.record_claims(bibcode, rec['claims'], rec['authors'])
        msg = OrcidClaims(authors=rec.get('authors'),
                          bibcode=rec['bibcode'],
                          verified=rec.get('claims', {}).get('verified', []),
                          unverified=rec.get('claims',
                                             {}).get('unverified', []))
        r = app.client.post(app.conf.get('API_ORCID_UPDATE_BIB_STATUS') %
                            claim.get('orcidid'),
                            json={
                                'bibcodes': unique_bibs,
                                'status': 'verified'
                            },
                            headers={
                                'Authorization':
                                'Bearer {0}'.format(app.conf.get('API_TOKEN'))
                            })
        if r.status_code != 200:
            logger.warning(
                'IDs {ids} for {orcidid} not updated to: verified'.format(
                    ids=unique_bibs, orcidid=claim.get('orcidid')))
        elif len(r.json()) != 1:
            logger.warning(
                'Number of updated bibcodes ({0}) does not match input ({1}) for {2}'
                .format(r.text, unique_bibs, claim.get('orcidid')))
        task_output_results.delay(msg)
    else:
        logger.warning('Claim refused for bibcode:{0} and orcidid:{1}'.format(
            claim['bibcode'], claim['orcidid']))
예제 #4
0
    def test_update_record(self):
        """
        Update ADS document with the claim info

        :return: no return
        """
        
        doc = {
            'bibcode': '2015ApJ...799..123B', 
            'authors': [
              "Barrière, Nicolas M.",
              "Krivonos, Roman",
              "Tomsick, John A.",
              "Bachetti, Matteo",
              "Boggs, Steven E.",
              "Chakrabarty, Deepto",
              "Christensen, Finn E.",
              "Craig, William W.",
              "Hailey, Charles J.",
              "Harrison, Fiona A.",
              "Hong, Jaesub",
              "Mori, Kaya",
              "Stern, Daniel",
              "Zhang, William W."
            ],
            'claims': {}
        }
        r = updater.update_record(
          doc,
          {
           'bibcode': '2015ApJ...799..123B', 
           'orcidid': '0000-0003-2686-9241',
           'account_id': '1',
           'orcid_name': [u'Stern, Daniel'],
           'author': [u'Stern, D', u'Stern, D K', u'Stern, Daniel'],
           'author_norm': [u'Stern, D'],
           'name': u'Stern, D K' 
          }                          
        )
        self.assertEqual(r, ('verified', 12))
        self.assertEqual(doc['claims']['verified'], 
            ['-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '0000-0003-2686-9241', '-'])
        
        updater.update_record(
          doc,
          {
           'bibcode': '2015ApJ...799..123B', 
           'orcidid': '0000-0003-2686-9241',
           'account_id': '1',
           'orcid_name': [u'Stern, Daniel'],
           'author': [u'Stern, D', u'Stern, D K', u'Stern, Daniel'],
           'author_norm': [u'Stern, D'],
           'name': u'Stern, D K',
           'status': 'removed'
          }                          
        )
        self.assertEqual(doc['claims']['verified'], 
            ['-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-'])
        
        # the size differs
        doc['claims']['verified'] = ['-']
        r = updater.update_record(
          doc,
          {
           'bibcode': '2015ApJ...799..123B', 
           'orcidid': '0000-0003-2686-9241',
           'account_id': '1',
           'orcid_name': [u'Stern, Daniel'],
           'author': [u'Stern, D', u'Stern, D K', u'Stern, Daniel'],
           'author_norm': [u'Stern, D'],
           'name': u'Stern, D K' 
          }                          
        )
        self.assertEqual(r, ('verified', 12))
        self.assertEqual(doc['claims']['verified'], 
            ['-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '0000-0003-2686-9241', '-'])
        
        self.assertEqual(14, len(doc['claims']['verified']))
예제 #5
0
    def test_update_record(self):
        """
        Update ADS document with the claim info

        :return: no return
        """
        doc = {
            'bibcode':
            '2015ApJ...799..123B',
            'authors': [
                "Barrière, Nicolas M.", "Krivonos, Roman", "Tomsick, John A.",
                "Bachetti, Matteo", "Boggs, Steven E.", "Chakrabarty, Deepto",
                "Christensen, Finn E.", "Craig, William W.",
                "Hailey, Charles J.", "Harrison, Fiona A.", "Hong, Jaesub",
                "Mori, Kaya", "Stern, Daniel", "Yıldız, Umut"
            ],
            'claims': {}
        }
        r = updater.update_record(
            doc, {
                'bibcode': '2015ApJ...799..123B',
                'orcidid': '0000-0003-2686-9241',
                'account_id': '1',
                'orcid_name': [u'Stern, Daniel'],
                'author': [u'Stern, D', u'Stern, D K', u'Stern, Daniel'],
                'author_norm': [u'Stern, D'],
                'name': u'Stern, D K'
            }, 0.9)
        self.assertEqual(r, ('verified', 12))
        self.assertEqual(doc['claims']['verified'], [
            '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-',
            '0000-0003-2686-9241', '-'
        ])

        updater.update_record(
            doc, {
                'bibcode': '2015ApJ...799..123B',
                'orcidid': '0000-0003-2686-9241',
                'account_id': '1',
                'orcid_name': [u'Stern, Daniel'],
                'author': [u'Stern, D', u'Stern, D K', u'Stern, Daniel'],
                'author_norm': [u'Stern, D'],
                'name': u'Stern, D K',
                'status': 'removed'
            }, 0.9)
        self.assertEqual(doc['claims']['verified'], [
            '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-',
            '-'
        ])

        # the size differs
        doc['claims']['verified'] = ['-']
        r = updater.update_record(
            doc, {
                'bibcode': '2015ApJ...799..123B',
                'orcidid': '0000-0003-2686-9241',
                'account_id': '1',
                'orcid_name': [u'Stern, Daniel'],
                'author': [u'Stern, D', u'Stern, D K', u'Stern, Daniel'],
                'author_norm': [u'Stern, D'],
                'name': u'Stern, D K'
            }, 0.9)
        self.assertEqual(r, ('verified', 12))
        self.assertEqual(doc['claims']['verified'], [
            '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-',
            '0000-0003-2686-9241', '-'
        ])

        self.assertEqual(14, len(doc['claims']['verified']))

        # check transliterated name version
        r = updater.update_record(
            doc, {
                'bibcode': '2015ApJ...799..123B',
                'orcidid': '0000-0001-2345-6789',
                'account_id': '2',
                'orcid_name': [u'Yildiz, Umut'],
                'author': [u'Yildiz, U', u'Yildiz, Umut'],
                'author_norm': [u'Yildiz, U'],
                'name': u'Yildiz, Umut'
            }, 0.9)
        self.assertEqual(r, ('verified', 13))
        self.assertEqual(doc['claims']['verified'], [
            '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-',
            '0000-0003-2686-9241', '0000-0001-2345-6789'
        ])

        doc_lev = {
            'bibcode':
            '2015ApJ...799..123B',
            'authors': [
                "Barrière, Nicolas M.", "Krivonos, Roman", "Tomsick, John A.",
                "Bachetti, Matteo", "Boggs, Steven E.", "Chakrabarty, Deepto",
                "Christensen, Finn E.", "Craig, William W.",
                "Hailey, Charles J.", "Harrison, Fiona A.", "Hong, Jaesub",
                "Mori, Kaya", "Stern, Daniel", "Zhang, William W."
            ],
            'claims': {}
        }
        r_lev = updater.update_record(
            doc_lev, {
                'bibcode': '2015ApJ...799..123B',
                'orcidid': '0000-0001-2345-6789',
                'account_id': '1',
                'orcid_name': [u'Zhang, Will'],
                'author': [u'Zhang, Will'],
                'author_norm': [u'Zhang, Will'],
                'name': u'Zhang, Will'
            }, 0.75)
        self.assertEqual(r_lev, ('verified', 13))
        self.assertEqual(doc_lev['claims']['verified'], [
            '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-',
            '0000-0001-2345-6789'
        ])

        doc_blank = {
            'bibcode':
            '2018Test.........1A',
            'authors': [
                "Evans, D. F.", "Southworth, J.", "Smalley, B.",
                "Jorgensen, U. G.", "Dominik, M.", "Tronsgaard, R."
            ],
            'claims': {
                'verified': ['0000-0009-8765-4321', '-', '-', '-', '-', '-']
            }
        }
        r_blank = updater.update_record(
            doc_blank, {
                'bibcode': '2018Test.........1A',
                'orcidid': '0000-0009-8765-4321',
                'account_id': '2',
                'orcid_name': [u'Tronsgaard, Rene'],
                'author': [''],
                'name': ''
            }, 0.75)
        self.assertEqual(r_blank, ('verified', 5))
        self.assertEqual(doc_blank['claims']['verified'],
                         ['-', '-', '-', '-', '-', '0000-0009-8765-4321'])