当前位置: 首页>>代码示例>>Python>>正文


Python Paper.get_by_doi方法代码示例

本文整理汇总了Python中papers.models.Paper.get_by_doi方法的典型用法代码示例。如果您正苦于以下问题:Python Paper.get_by_doi方法的具体用法?Python Paper.get_by_doi怎么用?Python Paper.get_by_doi使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在papers.models.Paper的用法示例。


在下文中一共展示了Paper.get_by_doi方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_unmerge_orcid_nones

# 需要导入模块: from papers.models import Paper [as 别名]
# 或者: from papers.models.Paper import get_by_doi [as 别名]
    def test_unmerge_orcid_nones(self):
        # First, fetch a few DOIs
        dois = [
            "10.1075/aicr.90.09ngo",
            "10.1075/aicr.90.04wad",
        ]
        for doi in dois:
            Paper.create_by_doi(doi)

        # Then, fetch an ORCID profile with a buggy version of the ORCID interface, which incorrectly merges papers together
        with patch.object(OrcidPaperSource, '_oai_id_for_doi') as mock_identifier:
            mock_identifier.return_value = "https://pub.orcid.org/v2.1/0000-0002-1909-134X/work/None"
            profile = OrcidProfileStub('0000-0002-1909-134X', instance='orcid.org')
            trung = Researcher.get_or_create_by_orcid('0000-0002-1909-134X', profile=profile)
            OrcidPaperSource().fetch_and_save(trung, profile=profile)

        # The two papers are incorrectly merged!
        papers = [Paper.get_by_doi(doi) for doi in dois]
        self.assertEqual(papers[0], papers[1])

        # We unmerge them
        unmerge_orcid_nones()

        # The two papers are now distinct
        papers = [Paper.get_by_doi(doi) for doi in dois]
        self.assertTrue(papers[0] != papers[1])
开发者ID:Phyks,项目名称:dissemin,代码行数:28,代码来源:test_maintenance.py

示例2: get_object

# 需要导入模块: from papers.models import Paper [as 别名]
# 或者: from papers.models.Paper import get_by_doi [as 别名]
    def get_object(self, queryset=None):
        if queryset is None:
            queryset = self.get_queryset()
        pk = self.kwargs.get('pk', None)
        doi = self.kwargs.get('doi', None)
        if doi:
            doi = unquote(doi)
            doi = to_doi(doi)

        paper = None
        try:
            if pk is not None:
                paper = queryset.get(pk=pk)
            elif doi is not None:
                paper = Paper.get_by_doi(doi)
            else:
                raise Http404(_("Paper view expects a DOI or a pk"))
        except ObjectDoesNotExist:
            pass

        if not paper:
            paper = Paper.create_by_doi(doi)
            if paper is None or paper.is_orphan():
                raise Http404(_("No %(verbose_name)s found matching the query") %
                              {'verbose_name': Paper._meta.verbose_name})

        if not paper.visible:
            raise Http404(_("This paper has been deleted."))

        return paper
开发者ID:Phyks,项目名称:dissemin,代码行数:32,代码来源:views.py

示例3: test_unmerge_paper

# 需要导入模块: from papers.models import Paper [as 别名]
# 或者: from papers.models.Paper import get_by_doi [as 别名]
 def test_unmerge_paper(self):
     # First we merge two unrelated papers
     p1 = Paper.create_by_doi("10.1016/j.bmc.2005.06.035")
     title1 = p1.title
     p2 = Paper.create_by_doi("10.1016/j.ijar.2017.06.011")
     title2 = p2.title
     p1.merge(p2)
     # Then we unmerge them
     unmerge_paper_by_dois(p1)
     # We have two new papers!
     p3 = Paper.get_by_doi("10.1016/j.bmc.2005.06.035")
     self.assertTrue(p3.id != p1.id)
     self.assertEqual(p3.title, title1)
     p4 = Paper.get_by_doi("10.1016/j.ijar.2017.06.011")
     self.assertTrue(p4.id != p1.id)
     self.assertTrue(p4.id != p3.id)
     self.assertEqual(p4.title, title2)
开发者ID:Phyks,项目名称:dissemin,代码行数:19,代码来源:test_maintenance.py

示例4: test_fetch_dois

# 需要导入模块: from papers.models import Paper [as 别名]
# 或者: from papers.models.Paper import get_by_doi [as 别名]
    def test_fetch_dois(self):
        profile = OrcidProfileStub('0000-0001-6723-6833', instance='orcid.org')
        pboesu = Researcher.get_or_create_by_orcid('0000-0001-6723-6833',
                    profile=profile)
        self.source.fetch_and_save(pboesu, profile=profile)

        doi = '10.3354/meps09890'
        p = Paper.get_by_doi(doi)
        dois_in_paper = [r.doi for r in p.oairecords]
        self.assertTrue(doi in dois_in_paper)
开发者ID:Phyks,项目名称:dissemin,代码行数:12,代码来源:test_orcid.py

示例5: test_ingest_dump

# 需要导入模块: from papers.models import Paper [as 别名]
# 或者: from papers.models.Paper import get_by_doi [as 别名]
    def test_ingest_dump(self):
        doi = '10.1080/21645515.2017.1330236'
        p = Paper.create_by_doi(doi)
        self.assertEqual(p.pdf_url, None)
        Paper.create_by_doi(doi)

        # then load an OAdoi dump
        oadoi = OadoiAPI()
        oadoi.load_dump(os.path.join(self.testdir, 'data/sample_unpaywall_snapshot.jsonl.gz'))

        # the paper is now OA, yay!
        p = Paper.get_by_doi(doi)
        self.assertEqual(p.pdf_url, 'http://europepmc.org/articles/pmc5718814?pdf=render')
开发者ID:Phyks,项目名称:dissemin,代码行数:15,代码来源:test_oadoi.py

示例6: redirect_by_doi

# 需要导入模块: from papers.models import Paper [as 别名]
# 或者: from papers.models.Paper import get_by_doi [as 别名]
def redirect_by_doi(request, doi):
    """
    This view is inherited from doai.io, migrated to this code base
    to preserve the existing behaviour. We could instead
    redirect to unpaywall, but that would not include ResearchGate urls.
    """
    doi = unquote(doi)
    doi = to_doi(doi)
    if not doi:
        raise Http404(_("Invalid DOI."))
    paper = Paper.get_by_doi(doi)
    if paper and paper.pdf_url:
        return HttpResponsePermanentRedirect(paper.pdf_url)
    return HttpResponsePermanentRedirect(doi_to_url(doi))
开发者ID:Phyks,项目名称:dissemin,代码行数:16,代码来源:views.py

示例7: api_paper_doi

# 需要导入模块: from papers.models import Paper [as 别名]
# 或者: from papers.models.Paper import get_by_doi [as 别名]
def api_paper_doi(request, doi):
    p = None
    try:
        p = Paper.get_by_doi(doi)
        if not p:
            p = Paper.create_by_doi(doi)
    except MetadataSourceException:
        pass
    if p is None:
        return JsonResponse({
            'error': 404,
            'message': 'The paper you requested could not be found.',
        }, status=404)

    return api_paper_common(request, p)
开发者ID:dissemin,项目名称:dissemin,代码行数:17,代码来源:api.py

示例8: api_paper_query

# 需要导入模块: from papers.models import Paper [as 别名]
# 或者: from papers.models.Paper import get_by_doi [as 别名]
def api_paper_query(request):
    try:
        fields = json.loads(request.body.decode('utf-8'))
    except (ValueError, UnicodeDecodeError):
        raise BadRequest('Invalid JSON payload')

    doi = fields.get('doi')
    if doi:
        p = None
        try:
            p = Paper.get_by_doi(doi)
            if not p:
                p = Paper.create_by_doi(doi)
        except MetadataSourceException:
            pass
        if p is None:
            raise BadRequest('Could not find a paper with this DOI')
        return {'status': 'ok', 'paper': p.json()}

    title = fields.get('title')
    if not isinstance(title,  str) or not title or len(title) > 512:
        raise BadRequest(
            'Invalid title, has to be a non-empty string shorter than 512 characters')

    date = fields.get('date')
    if not isinstance(date, str):
        raise BadRequest('A date is required')
    try:
        date = tolerant_datestamp_to_datetime(date)
    except ValueError as e:
        raise BadRequest(str(e))

    authors = fields.get('authors')
    if not isinstance(authors, list):
        raise BadRequest('A list of authors is expected')

    parsed_authors = []
    for a in authors:
        author = None
        if not isinstance(a, dict):
            raise BadRequest('Invalid author')

        if 'first' in a and 'last' in a:
            if not isinstance(a['first'], str) or not isinstance(a['last'], str) or not a['last']:
                raise BadRequest('Invalid (first,last) name provided')
            else:
                author = (a['first'], a['last'])
        elif 'plain' in a:
            if not isinstance(a['plain'], str) or not a['plain']:
                raise BadRequest('Invalid plain name provided')
            else:
                author = parse_comma_name(a['plain'])

        if author is None:
            raise BadRequest('Invalid author')

        parsed_authors.append(BareName.create(author[0], author[1]))

    if not authors:
        raise BadRequest('No authors provided')

    try:
        # Validate the metadata against our data model,
        # and compute the fingerprint to look up the paper in the DB.
        # This does NOT create a paper in the database - we do not want
        # to create papers for every search query we get!
        p = BarePaper.create(title, parsed_authors, date)
    except ValueError as e:
        raise BadRequest('Invalid paper: {}'.format(e))

    try:
        model_paper = Paper.objects.get(fingerprint=p.fingerprint)
        return {'status': 'ok', 'paper': model_paper.json()}
    except Paper.DoesNotExist:
        return {'status': 'not found'}, 404
开发者ID:dissemin,项目名称:dissemin,代码行数:77,代码来源:api.py

示例9: test_redirect_pdf

# 需要导入模块: from papers.models import Paper [as 别名]
# 或者: from papers.models.Paper import get_by_doi [as 别名]
 def test_redirect_pdf(self):
     p = Paper.get_by_doi('10.1145/2767109.2767116')
     p.pdf_url = 'http://my.fantastic.repository/'
     p.save()
     self.checkPermanentRedirect('paper-redirect-doi', kwargs={'doi':'10.1145/2767109.2767116'},
         url=p.pdf_url)
开发者ID:dissemin,项目名称:dissemin,代码行数:8,代码来源:test_pages.py

示例10: test_import_dump

# 需要导入模块: from papers.models import Paper [as 别名]
# 或者: from papers.models.Paper import get_by_doi [as 别名]
 def test_import_dump(self):
     self.api.ingest_dump(os.path.join(self.testdir, 'data/sample_crossref_dump.json.bz2'))
     p = Paper.get_by_doi('10.1016/j.jadohealth.2015.10.045')
     self.assertEqual("Sources, Type and Use of Social Support during Early Sexual Development of Black Gay and Bisexual Adolescent Males",
                      p.title)
开发者ID:Phyks,项目名称:dissemin,代码行数:7,代码来源:test_crossref.py

示例11: api_paper_query

# 需要导入模块: from papers.models import Paper [as 别名]
# 或者: from papers.models.Paper import get_by_doi [as 别名]
def api_paper_query(request):
    try:
        fields = json.loads(request.body.decode('utf-8'))
    except (ValueError, UnicodeDecodeError):
        raise BadRequest('Invalid JSON payload')

    doi = fields.get('doi')
    if doi:
        p = None
        try:
            p = Paper.get_by_doi(doi)
            if not p:
                p = Paper.create_by_doi(doi)
        except MetadataSourceException:
            pass
        if p is None:
            raise BadRequest('Could not find a paper with this DOI')
        return {'status': 'ok', 'paper': p.json()}

    title = fields.get('title')
    if not isinstance(title,  str) or not title or len(title) > 512:
        raise BadRequest(
            'Invalid title, has to be a non-empty string shorter than 512 characters')

    date = fields.get('date')
    if not isinstance(date, str):
        raise BadRequest('A date is required')
    try:
        date = tolerant_datestamp_to_datetime(date)
    except ValueError as e:
        raise BadRequest(str(e))

    authors = fields.get('authors')
    if not isinstance(authors, list):
        raise BadRequest('A list of authors is expected')

    parsed_authors = []
    for a in authors:
        author = None
        if not isinstance(a, dict):
            raise BadRequest('Invalid author')

        if 'first' in a and 'last' in a:
            if not isinstance(a['first'], str) or not isinstance(a['last'], str) or not a['last']:
                raise BadRequest('Invalid (first,last) name provided')
            else:
                author = (a['first'], a['last'])
        elif 'plain' in a:
            if not isinstance(a['plain'], str) or not a['plain']:
                raise BadRequest('Invalid plain name provided')
            else:
                author = parse_comma_name(a['plain'])

        if author is None:
            raise BadRequest('Invalid author')

        parsed_authors.append(BareName.create(author[0], author[1]))

    if not authors:
        raise BadRequest('No authors provided')

    try:
        p = BarePaper.create(title, parsed_authors, date)
    except ValueError:
        raise BadRequest('Invalid paper')

    return {'status': 'ok', 'paper': p.json()}
开发者ID:Phyks,项目名称:dissemin,代码行数:69,代码来源:api.py


注:本文中的papers.models.Paper.get_by_doi方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。