コード例 #1
0
def clean_doi(input_doi):
    input_doi = remove_nonprinting_characters(input_doi)
    try:
        input_doi = input_doi.lower()
        if input_doi.startswith("http"):
            match = re.match("^https*://(dx\.)*doi.org/(10\..+)", input_doi)
            doi = match.group(2)
        elif "doi.org" in input_doi:
            match = re.match("^(dx\.)*doi.org/(10\..+)", input_doi)
            doi = match.group(2)
        elif input_doi.startswith("doi:"):
            match = re.match("^doi:(10\..+)", input_doi)
            doi = match.group(1)
        elif input_doi.startswith("10."):
            doi = input_doi
        elif "10." in input_doi:
            match = re.match(".*(10\.\d+.+)", input_doi, re.DOTALL)
            doi = match.group(1)
        else:
            doi = None
            try:
                logger.debug(
                    u"MALFORMED DOI {input_doi}".format(input_doi=input_doi))
            except:
                logger.debug(u"MALFORMED DOI, can't print doi")

    except AttributeError:
        doi = None

    return doi
コード例 #2
0
def clean_doi(input_doi):
    input_doi = remove_nonprinting_characters(input_doi)
    try:
        input_doi = input_doi.lower()
        if input_doi.startswith("http"):
            match = re.match("^https*://(dx\.)*doi.org/(10\..+)", input_doi)
            doi = match.group(2)
        elif "doi.org" in input_doi:
            match = re.match("^(dx\.)*doi.org/(10\..+)", input_doi)
            doi = match.group(2)
        elif input_doi.startswith("doi:"):
            match = re.match("^doi:(10\..+)", input_doi)
            doi = match.group(1)
        elif input_doi.startswith("10."):
            doi = input_doi
        elif "10." in input_doi:
            match = re.match(".*(10\.\d+.+)", input_doi, re.DOTALL)
            doi = match.group(1)
        else:
            doi = None
            try:
                logger.debug(u"MALFORMED DOI {input_doi}".format(
                    input_doi=input_doi))
            except:
                logger.debug(u"MALFORMED DOI, can't print doi")


    except AttributeError:
        doi = None

    return doi
コード例 #3
0
def clean_id(nid):
    try:
        nid = nid.strip(' "')
        nid = unicode_helpers.remove_nonprinting_characters(nid)
    except (TypeError, AttributeError):
        #isn't a string.  That's ok, might be biblio
        pass
    return(nid)
コード例 #4
0
ファイル: item.py プロジェクト: imclab/total-impact-core
def clean_id(nid):
    try:
        nid = nid.strip(' "')
        nid = unicode_helpers.remove_nonprinting_characters(nid)
    except (TypeError, AttributeError):
        #isn't a string.  That's ok, might be biblio
        pass
    return(nid)
コード例 #5
0
ファイル: crossref.py プロジェクト: imclab/total-impact-core
def clean_doi(input_doi):
    doi = None
    input_doi = remove_nonprinting_characters(input_doi)
    if input_doi.startswith("http"):
        match = re.match("^https*://(dx\.)*doi.org/(10\..+)", input_doi)
        doi = match.group(2)
    elif input_doi.startswith("doi:"):
        match = re.match("^doi:(10\..+)", input_doi)
        doi = match.group(1)
    elif input_doi.startswith("10."):
        doi = input_doi
    return doi
コード例 #6
0
ファイル: crossref.py プロジェクト: dbeucke/total-impact-core
def clean_doi(input_doi):
    doi = None
    input_doi = remove_nonprinting_characters(input_doi)
    if input_doi.startswith("http"):
        match = re.match("^https*://(dx\.)*doi.org/(10\..+)", input_doi)
        doi = match.group(2)
    elif input_doi.startswith("doi:"):
        match = re.match("^doi:(10\..+)", input_doi)
        doi = match.group(1)
    elif input_doi.startswith("10."):
        doi = input_doi
    return doi
コード例 #7
0
def get_aliases_from_product_id_strings(product_id_strings):
    aliases = []
    for nid in product_id_strings:
        nid = remove_nonprinting_characters(nid)
        nid = nid.strip()  # also remove spaces
        if is_doi(nid):
            aliases += providers.crossref.Crossref().member_items(nid)
        elif is_pmid(nid):
            aliases += providers.pubmed.Pubmed().member_items(nid)
        elif is_arxiv(nid):
            aliases += providers.arxiv.Arxiv().member_items(nid)
        elif is_url(nid):
            aliases += providers.webpage.Webpage().member_items(nid)
    return aliases
コード例 #8
0
def get_aliases_from_product_id_strings(product_id_strings):
    aliases = []
    for nid in product_id_strings:
        nid = remove_nonprinting_characters(nid)
        nid = nid.strip()  # also remove spaces
        if is_doi(nid):
            aliases += providers.crossref.Crossref().member_items(nid)
        elif is_pmid(nid):
            aliases += providers.pubmed.Pubmed().member_items(nid)
        elif is_arxiv(nid):
            aliases += providers.arxiv.Arxiv().member_items(nid)
        elif is_url(nid):
            aliases += providers.webpage.Webpage().member_items(nid)
    return aliases
コード例 #9
0
def normalize_alias(alias):
    (ns, nid) = alias
    if ns == "biblio":
        return (ns, nid)

    nid = remove_nonprinting_characters(nid)
    nid = nid.strip()  # also remove spaces
    if is_doi(nid):
        nid = providers.crossref.clean_doi(nid)
    elif is_pmid(nid):
        nid = providers.pubmed.clean_pmid(nid)
    elif is_arxiv(nid):
        nid = providers.arxiv.clean_arxiv_id(nid)
    elif is_url(nid):
        nid = providers.webpage.clean_url(nid)

    return (ns, nid)
コード例 #10
0
def normalize_alias(alias):
    (ns, nid) = alias
    if ns == "biblio":
        return (ns, nid)

    nid = remove_nonprinting_characters(nid)
    nid = nid.strip()  # also remove spaces
    if is_doi(nid):
        nid = providers.crossref.clean_doi(nid)
    elif is_pmid(nid):
        nid = providers.pubmed.clean_pmid(nid)
    elif is_arxiv(nid):
        nid = providers.arxiv.clean_arxiv_id(nid)
    elif is_url(nid):
        nid = providers.webpage.clean_url(nid)

    return (ns, nid)
コード例 #11
0
def provider_memberitems_get(provider_name, query):
    """
    Gets aliases associated with a query from a given provider.
    """
    query = unicode_helpers.remove_nonprinting_characters(query)
    provider = ProviderFactory.get_provider(provider_name)

    try:
        items_dict = provider.member_items(query)

    except ProviderItemNotFoundError:
        abort_custom(404, "item not found")

    except (ProviderTimeout, ProviderServerError):
        abort_custom(503, "crossref lookup error, might be transient")

    except ProviderError:
        abort(500, "internal error from provider")

    resp = make_response(
        json.dumps({"memberitems": items_dict}, sort_keys=True, indent=4), 200)
    return resp
コード例 #12
0
ファイル: views.py プロジェクト: dbeucke/total-impact-core
def provider_memberitems_get(provider_name, query):
    """
    Gets aliases associated with a query from a given provider.
    """
    query = unicode_helpers.remove_nonprinting_characters(query)
    provider = ProviderFactory.get_provider(provider_name)

    try:
        items_dict = provider.member_items(query)

    except ProviderItemNotFoundError:
        abort_custom(404, "item not found")

    except (ProviderTimeout, ProviderServerError):
        abort_custom(503, "crossref lookup error, might be transient")

    except ProviderError:
        abort(500, "internal error from provider")

    resp = make_response(
        json.dumps({"memberitems": items_dict}, sort_keys=True, indent=4),
        200
    )
    return resp
コード例 #13
0
 def test_remove_nonprinting_characters_unicode_input(self):
     unicode_input = u'0000-0001-8907-4150\u200e'  # a nonprinting character at the end
     response = unicode_helpers.remove_nonprinting_characters(unicode_input)
     expected = u"0000-0001-8907-4150"
     assert_equals(response, expected)
コード例 #14
0
 def test_remove_nonprinting_characters(self):
     unicode_input = u"hi"
     response = unicode_helpers.remove_nonprinting_characters(unicode_input)
     expected = u"hi"
     assert_equals(response, expected)
コード例 #15
0
def clean_pmid(pmid):
    pmid = remove_nonprinting_characters(pmid)
    pmid = pmid.lower().replace("pmid:", "")
    return pmid
コード例 #16
0
def clean_url(input_url):
    url = remove_nonprinting_characters(input_url)
    return url
コード例 #17
0
ファイル: webpage.py プロジェクト: dbeucke/total-impact-core
def clean_url(input_url):
    url = unicode_helpers.remove_nonprinting_characters(input_url)
    return url
コード例 #18
0
 def test_remove_nonprinting_characters_unicode_input(self):
     unicode_input = u'0000-0001-8907-4150\u200e'  # a nonprinting character at the end
     response = unicode_helpers.remove_nonprinting_characters(unicode_input)
     expected = u"0000-0001-8907-4150"
     assert_equals(response, expected)
コード例 #19
0
ファイル: webpage.py プロジェクト: imclab/total-impact-core
def clean_url(input_url):
    url = unicode_helpers.remove_nonprinting_characters(input_url)
    return url
コード例 #20
0
def clean_arxiv_id(arxiv_id):
    arxiv_id = remove_nonprinting_characters(arxiv_id)
    arxiv_id = arxiv_id.lower().replace("arxiv:",
                                        "").replace("http://arxiv.org/abs/",
                                                    "")
    return arxiv_id
コード例 #21
0
def clean_arxiv_id(arxiv_id):
    arxiv_id = remove_nonprinting_characters(arxiv_id)    
    arxiv_id = arxiv_id.lower().replace("arxiv:", "").replace("http://arxiv.org/abs/", "")
    return arxiv_id
コード例 #22
0
 def test_remove_nonprinting_characters(self):
     unicode_input = u"hi"
     response = unicode_helpers.remove_nonprinting_characters(unicode_input)
     expected = u"hi"
     assert_equals(response, expected)
コード例 #23
0
def clean_url(input_url):
    url = remove_nonprinting_characters(input_url)
    return url