# SciPDF Parser
A Python parser for scientific PDF based on [GROBID](https://github.com/kermitt2/grobid).
## Installation
Use `pip` to install from this Github repository
```bash
pip install git+https://github.com/titipata/scipdf_parser
```
**Note**
* We also need an `en_core_web_sm` model for spacy, where you can run `python -m spacy download en_core_web_sm` to download it
* You can change GROBID version in `serve_grobid.sh` to test the parser on a new GROBID version
## Usage
Run the GROBID using the given bash script before parsing PDF
```bash
bash serve_grobid.sh
```
This script will download GROBID and run the service at default port 8070 (see more [here](https://grobid.readthedocs.io/en/latest/Grobid-service/)).
To parse a PDF provided in `example_data` folder or direct URL, use the following function:
```python
import scipdf
article_dict = scipdf.parse_pdf_to_dict('example_data/futoma2017improved.pdf') # return dictionary
# option to parse directly from URL to PDF, if as_list is set to True, output 'text' of parsed section will be in a list of paragraphs instead
article_dict = scipdf.parse_pdf_to_dict('https://www.biorxiv.org/content/biorxiv/early/2018/11/20/463760.full.pdf', as_list=False)
# output example
>> {
'title': 'Proceedings of Machine Learning for Healthcare',
'abstract': '...',
'sections': [
{'heading': '...', 'text': '...'},
{'heading': '...', 'text': '...'},
...
],
'references': [
{'title': '...', 'year': '...', 'journal': '...', 'author': '...'},
...
],
'figures': [
{'figure_label': '...', 'figure_type': '...', 'figure_id': '...', 'figure_caption': '...', 'figure_data': '...'},
...
],
'doi': '...'
}
xml = scipdf.parse_pdf('example_data/futoma2017improved.pdf', soup=True) # option to parse full XML from GROBID
```
To parse figures from PDF using [pdffigures2](https://github.com/allenai/pdffigures2), you can run
```python
scipdf.parse_figures('example_data', output_folder='figures') # folder should contain only PDF files
```
You can see example output figures in `figures` folder.
Raw data
{
"_id": null,
"home_page": "https://github.com/titipata/scipdf_parser",
"name": "scipdf-parser",
"maintainer": "",
"docs_url": null,
"requires_python": "",
"maintainer_email": "",
"keywords": "PDF parser,GROBID,Python PDF parser",
"author": "Titipat Achakulvisut",
"author_email": "my.titipat@gmail.com",
"download_url": "https://files.pythonhosted.org/packages/74/1f/7f7371f54696b30f2e436934cafd8bb3b294ef874558894207dc022c57ed/scipdf_parser-0.52.tar.gz",
"platform": null,
"description": "# SciPDF Parser\n\nA Python parser for scientific PDF based on [GROBID](https://github.com/kermitt2/grobid).\n\n## Installation\n\nUse `pip` to install from this Github repository\n\n```bash\npip install git+https://github.com/titipata/scipdf_parser\n```\n\n**Note**\n* We also need an `en_core_web_sm` model for spacy, where you can run `python -m spacy download en_core_web_sm` to download it\n* You can change GROBID version in `serve_grobid.sh` to test the parser on a new GROBID version\n\n## Usage\n\nRun the GROBID using the given bash script before parsing PDF\n\n```bash\nbash serve_grobid.sh\n```\n\nThis script will download GROBID and run the service at default port 8070 (see more [here](https://grobid.readthedocs.io/en/latest/Grobid-service/)).\nTo parse a PDF provided in `example_data` folder or direct URL, use the following function:\n\n```python\nimport scipdf\narticle_dict = scipdf.parse_pdf_to_dict('example_data/futoma2017improved.pdf') # return dictionary\n \n# option to parse directly from URL to PDF, if as_list is set to True, output 'text' of parsed section will be in a list of paragraphs instead\narticle_dict = scipdf.parse_pdf_to_dict('https://www.biorxiv.org/content/biorxiv/early/2018/11/20/463760.full.pdf', as_list=False)\n\n# output example\n>> {\n 'title': 'Proceedings of Machine Learning for Healthcare',\n 'abstract': '...',\n 'sections': [\n {'heading': '...', 'text': '...'},\n {'heading': '...', 'text': '...'},\n ...\n ],\n 'references': [\n {'title': '...', 'year': '...', 'journal': '...', 'author': '...'},\n ...\n ],\n 'figures': [\n {'figure_label': '...', 'figure_type': '...', 'figure_id': '...', 'figure_caption': '...', 'figure_data': '...'},\n ...\n ],\n 'doi': '...'\n}\n\nxml = scipdf.parse_pdf('example_data/futoma2017improved.pdf', soup=True) # option to parse full XML from GROBID\n```\n\nTo parse figures from PDF using [pdffigures2](https://github.com/allenai/pdffigures2), you can run\n\n```python\nscipdf.parse_figures('example_data', output_folder='figures') # folder should contain only PDF files\n```\n\nYou can see example output figures in `figures` folder.\n",
"bugtrack_url": null,
"license": "(c) MIT License 2019 Titipat Achakulvisut",
"summary": "Python parser for scientific PDF based on GROBID.",
"version": "0.52",
"project_urls": {
"Homepage": "https://github.com/titipata/scipdf_parser"
},
"split_keywords": [
"pdf parser",
"grobid",
"python pdf parser"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "d29c755427ef9f58815d19cf060e9f0d85a4851267dbdf39189097bf8b47892c",
"md5": "35ad7ab74db7918071bb4d675d3331e6",
"sha256": "63a7fa588ac039bd913fb0ea175f533535ad70f89b602ba726caac64e81c423a"
},
"downloads": -1,
"filename": "scipdf_parser-0.52-py3-none-any.whl",
"has_sig": false,
"md5_digest": "35ad7ab74db7918071bb4d675d3331e6",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": null,
"size": 10698,
"upload_time": "2023-11-12T16:46:29",
"upload_time_iso_8601": "2023-11-12T16:46:29.975702Z",
"url": "https://files.pythonhosted.org/packages/d2/9c/755427ef9f58815d19cf060e9f0d85a4851267dbdf39189097bf8b47892c/scipdf_parser-0.52-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "741f7f7371f54696b30f2e436934cafd8bb3b294ef874558894207dc022c57ed",
"md5": "6f631e9c4b81fe4bf371a9b9152486b6",
"sha256": "750df1af1adf9393d0844fa1292a2689e0e2c05e14285389212b16181d406716"
},
"downloads": -1,
"filename": "scipdf_parser-0.52.tar.gz",
"has_sig": false,
"md5_digest": "6f631e9c4b81fe4bf371a9b9152486b6",
"packagetype": "sdist",
"python_version": "source",
"requires_python": null,
"size": 10436,
"upload_time": "2023-11-12T16:46:32",
"upload_time_iso_8601": "2023-11-12T16:46:32.015919Z",
"url": "https://files.pythonhosted.org/packages/74/1f/7f7371f54696b30f2e436934cafd8bb3b294ef874558894207dc022c57ed/scipdf_parser-0.52.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2023-11-12 16:46:32",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "titipata",
"github_project": "scipdf_parser",
"travis_ci": false,
"coveralls": false,
"github_actions": false,
"requirements": [],
"lcname": "scipdf-parser"
}