Solve ImportError in Python < 3.5 due to cyclic import

This commit is contained in:
Lucas Verney 2016-02-17 16:37:02 +01:00
parent a2ee654eac
commit 0e2066c180
8 changed files with 57 additions and 27 deletions

View File

@ -59,6 +59,9 @@ This list is especially useful for the `libbmc.papers.identifiers` module,
which is using it to loop through all the available identifier types, to fetch which is using it to loop through all the available identifier types, to fetch
for them in the paper and retrieve BibTeX from it. for them in the paper and retrieve BibTeX from it.
You can also write a specific citation extraction module for this repository
in `libbmc/citations/repositories/{REPOSITORY}.py`.
## License ## License

View File

@ -1,5 +1,5 @@
""" """
This files contains all the functions to extract DOIs of citations from .bbl This file contains all the functions to extract DOIs of citations from .bbl
files. files.
""" """
import os import os

View File

@ -1,5 +1,5 @@
""" """
This files contains all the functions to extract DOIs of citations from This file contains all the functions to extract DOIs of citations from
BibTeX files. BibTeX files.
""" """
import os import os

View File

@ -1,5 +1,5 @@
""" """
This files contains all the functions to extract DOIs of citations from This file contains all the functions to extract DOIs of citations from
PDF files. PDF files.
""" """
import os import os

View File

@ -1,5 +1,5 @@
""" """
This files contains all the functions to extract DOIs of citations from This file contains all the functions to extract DOIs of citations from
plaintext files. plaintext files.
""" """
import os import os

View File

@ -0,0 +1,50 @@
"""
This file contains all the functions to extract DOIs of citations from arXiv
papers.
"""
from libbmc.citations import bbl
from libbmc.repositories import arxiv
def get_plaintext_citations(arxiv_id):
"""
Get the citations of a given preprint, in plain text.
.. note::
Bulk download of sources from arXiv is not permitted by their API. \
You should have a look at http://arxiv.org/help/bulk_data_s3.
:param arxiv_id: The arXiv id (e.g. ``1401.2910`` or ``1401.2910v1``) in \
a canonical form.
:returns: A list of cleaned plaintext citations.
"""
plaintext_citations = []
# Get the list of bbl files for this preprint
bbl_files = arxiv.get_bbl(arxiv_id)
for bbl_file in bbl_files:
# Fetch the cited DOIs for each of the bbl files
plaintext_citations.extend(bbl.get_plaintext_citations(bbl_file))
return plaintext_citations
def get_cited_dois(arxiv_id):
"""
Get the DOIs of the papers cited in a .bbl file.
.. note::
Bulk download of sources from arXiv is not permitted by their API. \
You should have a look at http://arxiv.org/help/bulk_data_s3.
:param arxiv_id: The arXiv id (e.g. ``1401.2910`` or ``1401.2910v1``) in \
a canonical form.
:returns: A dict of cleaned plaintext citations and their associated DOI.
"""
dois = {}
# Get the list of bbl files for this preprint
bbl_files = arxiv.get_bbl(arxiv_id)
for bbl_file in bbl_files:
# Fetch the cited DOIs for each of the bbl files
dois.update(bbl.get_cited_dois(bbl_file))
return dois

View File

@ -18,7 +18,6 @@ from requests.exceptions import RequestException
from libbmc import __valid_identifiers__ from libbmc import __valid_identifiers__
from libbmc import tools from libbmc import tools
from libbmc.citations import bbl
# Append arXiv to the valid identifiers list # Append arXiv to the valid identifiers list
__valid_identifiers__ += ["repositories.arxiv"] __valid_identifiers__ += ["repositories.arxiv"]
@ -475,25 +474,3 @@ def get_bbl(arxiv_id):
bbl_files = [tar_file.extractfile(member).read().decode(tarfile.ENCODING) bbl_files = [tar_file.extractfile(member).read().decode(tarfile.ENCODING)
for member in bbl_files] for member in bbl_files]
return bbl_files return bbl_files
def get_citations(arxiv_id):
"""
Get the DOIs cited by a given preprint.
.. note::
Bulk download of sources from arXiv is not permitted by their API. \
You should have a look at http://arxiv.org/help/bulk_data_s3.
:param arxiv_id: The arXiv id (e.g. ``1401.2910`` or ``1401.2910v1``) in \
a canonical form.
:returns: A dict of cleaned plaintext citations and their associated DOI.
"""
dois = {}
# Get the list of bbl files for this preprint
bbl_files = get_bbl(arxiv_id)
for bbl_file in bbl_files:
# Fetch the cited DOIs for each of the bbl files
dois.update(bbl.get_cited_dois(bbl_file))
return dois